Search code examples
c++clinuxdhcpioctl

In general How to find out whether client has assigned static Ip or it is dhcp client


I have retrieved IP, subnet and broadcast using ioctl() system call. can anyone help me to find out whether client is static or dhcp?? I am asking about in general and using system call. it is all about client instead of interface.


Solution

  • The interface itself has nothing to do with dhcp. It can be configured to have a particular IP address, gateway, etc. but that's all. This configuration, however, can be done with a smart little program called dhcp client :) So what you need is to find out who (i mean, which program) has configured your interface.

    UPDATE:

    For example, under the majority of linux distributions you may do a

    ps aux | grep 'dhcpcd .* eth0'
    

    If it gives a result like

    /sbin/dhcpcd --netconfig -L -E -HHH -c /etc/sysconfig/network/scripts/dhcpcd-hook -t 0 -h somehostname eth0
    

    you can say that eth0 is configured with dhcp