c++ - Get IP address, gateway, Mask and broadcast information using DHCP -


i write program interface mac address, sends dhcp request , gets ip address, gateway, mask , broadcast address dhcp server.

i used this implementation of dhcp client, gives ip address , gateway addresses.

i read dhcp message format , didn't find mask or broadcast fileds. however, when using dhcpclient command line, can see using ifconfig interface has mask , broadcast addresses, below:

arm@arm-desktop:~/dhclient wlp2s0 arm@arm-desktop:~/ifconfig wlp2s0 wlp2s0 link encap:ethernet  hwaddr 54:da:d0:15:4b:04         inet addr:153.179.154.55  bcast:153.179.169.255  mask:255.255.240.0       inet6 addr: fe80::2037:c031:5db1:445c/64 scope:link       broadcast running multicast  mtu:1500  metric:1       rx packets:113 errors:0 dropped:0 overruns:0 frame:0       tx packets:56 errors:0 dropped:0 overruns:0 carrier:0       collisions:0 txqueuelen:1000        rx bytes:112130 (112.1 kb)  tx bytes:9520 (9.5 kb) 

could tell me how information acquired?

see this question, may want.

i take writing own dhcp client uses raw sockets or else put bytes directly on wire.

you can read more dhcp here or elsewhere if google. can see, subnet mask can acquired dhcp server, broadcast address. done through dhcp options when comunicating dhcp server.

you have put right bytes on wire in right order, , read bytes coming able information want.

using client linked, can expand code request , process more information dhcp server, broadcast address , subnet mask. see dhcp documentation how ask information in dhcp options field.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -