int release_lease( DHCPLEASE *dhcpl, u32b xid, u8b chaddr[16] ) { int result = -1, i; DHCPLIST *temp; u8b nchaddr[16]; for( i = 0; i < 16; i++ ) nchaddr[i] = 0; if( !dhcpl ) return -1; for( temp = list; temp; temp=temp->next ) if( !maccmp( temp->chaddr, chaddr ) ) { /* We found the address */ result = 0; fprintf( stdout, "Deleting %X::%X::%X::%X::%X::%X \n", temp->chaddr[0], temp->chaddr[1], temp->chaddr[2], temp->chaddr[3], temp->chaddr[4], temp->chaddr[5] ); temp->available = FREE; temp->xid = 0; /* maccpy( temp->chaddr, nchaddr ); */ } else { /* No such address */ result = -1; } return result; }
int find_lease( DHCPLEASE *dhcpl, u32b xid, u8b chaddr[] ) { int result = -2; DHCPLIST *temp; if( !dhcpl ) return -1; for( temp = list; temp; temp=temp->next ) if( !maccmp( temp->chaddr, chaddr ) ) release_lease( dhcpl, xid, chaddr); for( temp = list; temp; temp=temp->next ) if( ( !maccmp( temp->chaddr, chaddr )) && ( temp->type == STATIC )) { dhcpl->ip = temp->data.ip; dhcpl->router = temp->data.router; dhcpl->mask = temp->data.mask; dhcpl->lease = temp->data.lease; dhcpl->siaddr = temp->data.siaddr; fprintf( stdout, "Assigning Static IP! \n"); temp->available = PROCESSING; temp->xid = xid; temp->ltime = MAX_PROCESS_TIME; maccpy( temp->chaddr, chaddr); result = 0; return result; } else if( ( temp->available & FREE ) && ( temp->type == DYNAMIC )) { dhcpl->ip = temp->data.ip; dhcpl->router = temp->data.router; dhcpl->mask = temp->data.mask; dhcpl->lease = temp->data.lease; dhcpl->siaddr = temp->data.siaddr; fprintf( stdout, "Assigning Dynamic IP! \n"); temp->available = PROCESSING; temp->xid = xid; temp->ltime = MAX_PROCESS_TIME; maccpy( temp->chaddr, chaddr); result = 0; return result; } return result; }
struct wframe * buffertowframe(char * buffer, int size) { //First remove radiotap. struct wframe *frame; frame = (struct wframe *) malloc(sizeof(struct wframe)); memset(frame, 0, sizeof(struct wframe)); int pos = 0; uint8_t radiotap_version = buffer[pos++]; uint8_t radiotap_pad = buffer[pos++]; uint16_t radiotap_length = buffer[pos]; if (radiotap_version != 0 || radiotap_pad != 0 || radiotap_length > 1000) { return NULL; } pos += radiotap_length - 4 + 2; //Decode packet type uint16_t fc = buffer[pos]; //frame control info pos += 2; if((fc & 0x04) != 0) frame->type += 0x2; if((fc & 0x08) != 0) frame->type += 0x1; if((fc & 0x10) != 0) frame->stype += 0x1; if((fc & 0x20) != 0) frame->stype += 0x2; if((fc & 0x40) != 0) frame->stype += 0x4; if((fc & 0x80) != 0) frame->stype += 0x8; if(frame->type != IEEE80211_FTYPE_MGMT) return NULL; if(frame->stype != IEEE80211_STYPE_PROBE_REQ && frame->stype != IEEE80211_STYPE_PROBE_RESP) return NULL; pos += 2; memcpy(&frame->addr1, buffer+pos, 6); pos += 6; memcpy(&frame->addr2, buffer+pos, 6); pos += 6; memcpy(&frame->addr3, buffer+pos, 6); pos += 6 + 2; if(maccmp(frame->addr1, stamac) || maccmp(frame->addr2, stamac) || maccmp(frame->addr3, stamac)) return frame; return NULL; }