How to change IP address in C ++?

I need to do a few network-related things in C ++ that I would normally do with ifconfigon Linux, but I would like to do this without parsing the output of a group of system calls. What C or C ++ libraries can I use to determine up or down the network adapter, read or change the adapter IP address and network mask, and change the default DNS gateway?

+3
source share
3 answers

Basically you need to make a bunch of ioctl calls using the socket descriptor (SIOCGIFADDR, SIOCADDRT). You can find examples of programs that use it in the Linux kernel source in the Documentation / networking section. Some other links that may be helpful:

EDIT: let me also add that if your goal is desktop Linux, then you can use the DBUS API to query network parameters using NetworkManager.

+4
source

NetworkManager API dbus / . (, , dbus/NetworkManager ...), , .

dbus ++ NetworkManager API (, , ).

0

All Articles