azulay7
azulay7

Reputation: 305

discover if ip address is DHCP or static

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 :)

Upvotes: 3

Views: 1663

Answers (1)

unwind
unwind

Reputation: 399803

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.

Upvotes: 5

Related Questions