3

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

azulay7
  • 305
  • 3
  • 16
  • 2
    What platform, OS, etc ? – Paul R Feb 08 '11 at 15:29
  • What do you hope to do with the information? Bear in mind that there can be non-static IP addresses not assigned with DHCP (eg those assigned with RARP or BOOTP); and static addresses assigned through DHCP. – caf Feb 09 '11 at 04:16
  • I'm not familiar with RARP & BOOTP but I think it's not relevent. I need to extract the data that have been choosen from the setup menu in network configuration while there is only two choices there DHCP or STATIC for eth0. I need this information only for display.. I've build and lcd module to a device that display data like LAN ip address. – azulay7 Feb 09 '11 at 12:40
  • @azulay7: Then what you need is to read the configuration file that the network configuration utility produces. That will vary depending on the utility in use - different Linux distributions use different network configuration files. – caf Feb 10 '11 at 02:12
  • yes this is ehat I ment... I fount it under /etc/sysconfig/networking/devices/ifcfg-eth0 case closed! :) – azulay7 Feb 11 '11 at 20:22

1 Answers1

5

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • I didn't mean to deduce it from the ip. I want to discover it with another function if there is any.. – azulay7 Feb 08 '11 at 15:54