Skip to content

Commit c91daed

Browse files
author
Bongjun Hur
committed
before sending, _BUFF buf clear in DHCP
1 parent 6473abe commit c91daed

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def send_dhcp_message(self, state, time_elapsed):
127127
:param float time_elapsed: Number of seconds elapsed since renewal.
128128
129129
"""
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+
130134
# OP
131135
_BUFF[0] = DHCP_BOOT_REQUEST
132136
# HTYPE
@@ -361,9 +365,9 @@ def request_dhcp_lease(
361365
print("* DHCP: Parsing OFFER")
362366
msg_type, xid = self.parse_dhcp_response(self._response_timeout)
363367
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")
367371
if self._debug:
368372
print("* DHCP: Request")
369373
self.send_dhcp_message(
@@ -372,7 +376,7 @@ def request_dhcp_lease(
372376
self._dhcp_state = STATE_DHCP_REQUEST
373377
else:
374378
print("* Received DHCP Message is not OFFER")
375-
elif STATE_DHCP_REQUEST:
379+
elif self._dhcp_state == STATE_DHCP_REQUEST:
376380
if self._debug:
377381
print("* DHCP: Parsing ACK")
378382
msg_type, xid = self.parse_dhcp_response(self._response_timeout)

0 commit comments

Comments
 (0)