@@ -127,6 +127,10 @@ def send_dhcp_message(self, state, time_elapsed):
127
127
:param float time_elapsed: Number of seconds elapsed since renewal.
128
128
129
129
"""
130
+ # before making send packet, shoule init _BUFF. if not, DHCP sometimes fails, wrong padding, garbage bytes, ...
131
+ for i in range (len (_BUFF )):
132
+ _BUFF [i ] = 0
133
+
130
134
# OP
131
135
_BUFF [0 ] = DHCP_BOOT_REQUEST
132
136
# HTYPE
@@ -361,9 +365,9 @@ def request_dhcp_lease(
361
365
print ("* DHCP: Parsing OFFER" )
362
366
msg_type , xid = self .parse_dhcp_response (self ._response_timeout )
363
367
if msg_type == DHCP_OFFER :
364
- # use the _transaction_id the offer returned,
365
- # rather than the current one
366
- self ._transaction_id = self ._transaction_id .from_bytes (xid , "l" )
368
+ # # use the _transaction_id the offer returned,
369
+ # # rather than the current one
370
+ # self._transaction_id = self._transaction_id.from_bytes(xid, "l")
367
371
if self ._debug :
368
372
print ("* DHCP: Request" )
369
373
self .send_dhcp_message (
@@ -372,7 +376,7 @@ def request_dhcp_lease(
372
376
self ._dhcp_state = STATE_DHCP_REQUEST
373
377
else :
374
378
print ("* Received DHCP Message is not OFFER" )
375
- elif STATE_DHCP_REQUEST :
379
+ elif self . _dhcp_state == STATE_DHCP_REQUEST :
376
380
if self ._debug :
377
381
print ("* DHCP: Parsing ACK" )
378
382
msg_type , xid = self .parse_dhcp_response (self ._response_timeout )
0 commit comments