discover if ip address is DHCP or static

1.5k Views Asked by At

im trying to get in c programing (LINUX) what kind of ip I have DHCP or static. Does someone know how do that?? I extract my ip using struct ifaddrs; it will be nice to find out if that stucture can provide the information. thanks on advance :)

1

There are 1 best solutions below

1
On

That property is not something you can deduce statically from the IP address alone.

You can probably make a guess by determining if the IP address is in the "non-routable" series (10.x.y.z or 192.168.x.y), but the address could just as well have been manually assigned.

Figuring out if the system has a current lease from a DHCP server is (very) platform-dependent, and will require information that is not in the IP address itself.