def RCVD_INFORM(self,pkt): print"now build the DHCP ACK" ackinstance = DHCP_ACK() ack = ackinstance.p ack[Ether].dst = pkt[Ether].src ack[BOOTP].xid = pkt[BOOTP].xid if pkt[BOOTP].flags == 1: ack[BOOTP].flags = 1 if self.offerip == '': ack[BOOTP].yiaddr = self.ippool[0] else: ack[BOOTP].yiaddr = self.offerip ack[BOOTP].chaddr = pkt[Ether].src ack[MSGTYPE].type = 5 ack[DHCP].options.pop(2) np = compute_pad(ack) #compute the number of pads if np == 1: pad = PAD() pad.code = 0 ack[DHCP].options.append(pad) else: raw = Raw() raw.load = '\x00'*np #p[DHCP].options.insert(4,raw) ack[DHCP].options.append(raw) print "now show the DHCP ACK" ack.show2() print"now send the DHCP ACK" sendp(ack)
def __init__(self): DHCP_OFFER.__init__(self) self.p[DHCP].options.remove(self.leasetime) self.p[DHCP].options.remove(self.submask) self.p[DHCP].options.remove(self.router) self.p[DHCP].options.remove(self.dns) try: self.p[DHCP].options.remove(self.pad) except: self.p[DHCP].options.remove(self.raw) self.np = compute_pad(self.p) #compute the number of pads if self.np == 1: pad = PAD() pad.code = 0 self.p[DHCP].options.append(pad) else: raw = Raw() raw.load = '\x00'*self.np self.p[DHCP].options.append(raw)