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