Shared library providing C utilities to render networking management with minimal dependencies.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Aitor 53d8054c1a Fixed conflicting types for ‘interface_detect_beat_ethtool’. 20 hours ago
backend_src Fixed conflicting types for ‘interface_detect_beat_ethtool’. 20 hours ago
debian Initial release. 6 days ago
CMakeLists.txt Initial release. 6 days ago
README.md Fixed a typo in the README.md file 4 days ago

README.md

libnetaid

libnetaid is a shared C library based on the RTnetlink service routines of the linux kernel. It provides useful utilities focused to the development of both CLI and GUI user interfaces to render networking management with minimal dependencies and following the KISS principle, together with other tools like wpasupplicant, ifupdown and libiw.

Installation

Use the APT package manager to install libnetaid.

apt-get install libnetaid libnetaid-dev

After that, development headers will be located in:

/usr/include/i386-linux-gnu/simple-netaid    (for 32 bits) 
/usr/include/x86_64-linux-gnu/simple-netaid  (for 64 bits)

Usage

libnetaid uses sbuf structs to handle char arrays, whose life cycle is (have a look at the sbuf.c file):

struct sbuf s;
sbuf_init(&s);
sbuf_addch(&s, 'F');     /* adds a character */
sbuf_addstr(&s, "oo");   /* adds an array */
free(s.buf);

The following example consists of a very simple C program showing the names of the network interfaces:

/ * *
  *
  *  main.c
  *
  */

#include <simple-netaid/sbuf.h>
#include <simple-netaid/interfaces.h>

int main(int argc, char **argv)
{
	struct sbuf wired_device, wireless_device;
	sbuf_init(&wired_device);
	sbuf_init(&wireless_device);	
	get_interfaces(&wired_device, &wireless_device);	
	printf("Wired device: %s\n", wired_device.buf);
	printf("Wireless device: %s\n", wireless_device.buf);	
	free(wired_device.buf);
	free(wireless_device.buf);
	return 0;
}

You can build it as follows:

gcc main.c -o main -lnetaid `pkg-config --cflags --libs glib-2.0`

Output example:

Wired device: eth0
Wireless device: wlan0

Another example using netproc might be:

/ * *
  *
  *  main.c
  *
  */
 
#include <simple-netaid/sbuf.h>
#include <simple-netaid/netproc.h>

int main( int argc, char **argv)
{
	struct sbuf s;
	sbuf_init(&s);
	netproc(&s);
	printf("%s\n", s.buf);
	free(s.buf);
	return 0;
}

Output example:

Connected to wlan0
MAC Address=2C:D0:5A:E8:9E:9F
IP Address=192.168.0.12
BROADCAST=192.168.0.255
NETMASK=255.255.255.0
PROTOCOL=IEEE 802.11
ESSID=Euskaltel-58YA
QUALITY=94%

Functions

Here you are a list of other available functionalities:

// Brings up the interface (analogous to "ip link set <interface> up")
void interface_up (const char* interface); 
// Brings down the interface (analogous to "ip link set <interface> down")
void interface_down (const char* interface);
// Returns the current status of the interface ( 1 | 0 ) -> ( UP | DOWN )
int get_interface_status (const char* interface);
// Brings up the interface (analogous to "ifup <interface>")
void ifup (const char* interface);
// Brings down the interface (analogous to "ifdown <interface>")
void ifdown (const char* interface);
// Shows all the available active wifis (as root)
void print_active_wifis(const char* wireless_device);
// Wireless connection attempt via wpa_supplicant
void wireless_connection(const char *ifname, const char *essid, const char *password);
// Wired connection attempt
void wired_connection(const char* wired_device);
// Disconnects the network device
void disconnect(const char* device);
// Returns the name of the connected network device, null if we are disconnected.
char* iproute();
// Asigns a detailed information about the network connection to the buffer.
void netproc (struct sbuf* buffer);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License