NayabSD
NayabSD

Reputation: 1120

How to extract client data from DHCP packet?

I need to develop router software that displays something like this (Note: This post is related to network-programming):

enter image description here

I captured DHCP packets through Wireshark and observed that it contains all the details I need to display. The data looks like this:

enter image description here

I checked the same with dhcpdump and tcpdump tools.

me@linux:$ sudo dhcpdump -i wlp6s0

Part of the output I am interested in is:

  TIME: 2016-06-23 12:20:50.976
    IP: 10.42.0.1 (b0:c0:90:69:72:57) > 10.42.0.99 (fc:64:ba:1b:40:e5)
    OP: 2 (BOOTPREPLY)
 HTYPE: 1 (Ethernet)
  HLEN: 6
  HOPS: 0
   XID: e277d896
  SECS: 0
 FLAGS: 0
CIADDR: 0.0.0.0
YIADDR: 10.42.0.99
SIADDR: 10.42.0.1
GIADDR: 0.0.0.0
CHADDR: fc:64:ba:1b:40:e5:00:00:00:00:00:00:00:00:00:00
 SNAME: .
 FNAME: .
OPTION:  53 (  1) DHCP message type         5 (DHCPACK)
OPTION:  54 (  4) Server identifier         10.42.0.1
OPTION:  51 (  4) IP address leasetime      3600 (60m)
OPTION:  58 (  4) T1                        1800 (30m)
OPTION:  59 (  4) T2                        3150 (52m30s)
OPTION:   1 (  4) Subnet mask               255.255.255.0
OPTION:  28 (  4) Broadcast address         10.42.0.255
OPTION:   6 (  4) DNS server                10.42.0.1
OPTION:   3 (  4) Routers                   10.42.0.1
---------------------------------------------------------------------------

But without using these tools (those tools can't be added on router board), how to extract client data like MAC address, IP address and other information from dhcp packet (or how those tools extracted the information) programmatically (if possible in C)?

Upvotes: 0

Views: 834

Answers (1)

Florin Petriuc
Florin Petriuc

Reputation: 1176

Assuming your DHCP server does not provide any means to get the information you need, you can use a socket of type:

socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))

With it you will be able to see all ETH packets and process them same as wireshark. You will need some knowledge of OSI layers (ETH2, IP, UDP and DHCP) in order to process the headers and content from the packets.

Upvotes: 0

Related Questions