#include #include #include #include "dp_dhcpv6.h" #include "dp_helpers.h" void dp_dhcpv6_check(dp_conf *conf, unsigned char *pkt, int pktlen, int offset, unsigned char **remoteid, int *remoteidlen) { uint8_t msgtype = (uint8_t)pkt[offset]; if ( conf->debug ) printf("offset=%i\n",offset); switch(msgtype) { case 12: // RELAY-FORW case 13: // RELAY-REPL offset += 2 + 16 + 16; // msg-type, hop-count, link-addr, peer-addr if ( conf->debug ) printf("this is a relay msg\n"); break; default: // all other msgtypes offset += 4; // msg-type, transaction-id } if ( conf->debug ) printf("offset=%i\n",offset); while(offset+4<=pktlen) { uint16_t code = ntohs(*(uint16_t*)(pkt+offset)); uint16_t len = ntohs(*(uint16_t*)(pkt+offset+2)); if ( conf->debug ) printf("code %i len %i\n", code, len); offset+=4; if ( code == 9 ) { // relay message if ( conf->debug ) printf("option 9, relay msg\n"); offset+=4; continue; } if ( code == 1 ) { // Client identifier / DUID // make sure there's enough space if ( offset + len <= pktlen ) { *remoteid = pkt+offset; *remoteidlen = len; break; } } offset+=len; } }