1 #include <headers.h>
2 #include <datatypes.h>
3 #include <display.h>
4 #include <options.h>
5 
6 int display_dhcp_packet( DHCPMESSAGE *dhcpm, DHCPOPTIONS *dhcpo )
7 {
8   char *mtype;
9   if( dhcpm == NULL )
10     return -1;
11 
12   fprintf( stdout, "op: %s\t|htype: %s\t|hlen: %u\t|hops: %u\n", (dhcpm->op == 1)?"BOOTREQUEST":"BOOTREPLY", (dhcpm->htype==1)?"Ethernet 10Mb":"unknown", dhcpm->hlen, dhcpm->hops);
13   fprintf( stdout, "xid: %u \n", dhcpm->xid );
14   fprintf( stdout, "secs: %u\t\t|flags: %u\n", dhcpm->secs, dhcpm->flags );
15   fprintf( stdout, "ciaddr: %u.%u.%u.%u \n", (dhcpm->ciaddr >> 24), ((dhcpm->ciaddr>>16)&0xFF), ((dhcpm->ciaddr>>8)&0xFF), ((dhcpm->ciaddr)&0xFF));
16   fprintf( stdout, "yiaddr: %u.%u.%u.%u \n", (dhcpm->yiaddr >> 24), ((dhcpm->yiaddr>>16)&0xFF), ((dhcpm->yiaddr>>8)&0xFF), ((dhcpm->yiaddr)&0xFF));
17   fprintf( stdout, "siaddr: %u.%u.%u.%u \n", (dhcpm->siaddr >> 24), ((dhcpm->siaddr>>16)&0xFF), ((dhcpm->siaddr>>8)&0xFF), ((dhcpm->siaddr)&0xFF));
18   fprintf( stdout, "giaddr: %u.%u.%u.%u \n", (dhcpm->giaddr >> 24), ((dhcpm->giaddr>>16)&0xFF), ((dhcpm->giaddr>>8)&0xFF), ((dhcpm->giaddr)&0xFF));
19   fprintf( stdout, "chaddr: %X::%X::%X::%X::%X::%X \n", dhcpm->chaddr[0], dhcpm->chaddr[1], dhcpm->chaddr[2], dhcpm->chaddr[3], dhcpm->chaddr[4], dhcpm->chaddr[5] );
20   fprintf( stdout, "sname: %s \n", dhcpm->sname );
21   fprintf( stdout, "file: %s \n", dhcpm->file );
22   /* options come here */
23   switch( dhcpo->type )
24     {
25     case DHCPDISCOVER:
26       mtype = (char *)malloc( strlen( "DHCPDISCOVER" ) +1);
27       strcpy( mtype, "DHCPDISCOVER" );
28       break;
29     case DHCPREQUEST:
30       mtype = (char *)malloc( strlen( "DHCPREQUEST" ) +1);
31       strcpy( mtype, "DHCPREQUEST" );
32       break;
33     case DHCPACK:
34       mtype = (char *)malloc( strlen( "DHCPACK" ) +1);
35       strcpy( mtype, "DHCPACK" );
36       break;
37     case DHCPNAK:
38       mtype = (char *)malloc( strlen( "DHCPNAK" ) +1);
39       strcpy( mtype, "DHCPNAK" );
40       break;
41     case DHCPRELEASE:
42       mtype = (char *)malloc( strlen( "DHCPRELEASE" ) +1);
43       strcpy( mtype, "DHCPRELEASE" );
44       break;
45     case DHCPDECLINE:
46       mtype = (char *)malloc( strlen( "DHCPDECLINE" ) +1);
47       strcpy( mtype, "DHCPDECLINE" );
48       break;
49     case DHCPOFFER:
50       mtype = (char *)malloc( strlen( "DHCPOFFER" ) +1);
51       strcpy( mtype, "DHCPOFFER" );
52       break;
53     default:
54       mtype = (char *)malloc( strlen("Unknown Type") +1);
55       strcpy( mtype, "Unknown Type" );
56       break;
57     }
58   fprintf( stdout, "Message Type: %s \n", mtype );
59   free( mtype );
60   return 0;
61 }
62 
63