Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swap recvfrom_into() port byte-order #4465

Merged
merged 1 commit into from
Mar 23, 2021
Merged

swap recvfrom_into() port byte-order #4465

merged 1 commit into from
Mar 23, 2021

Conversation

anecdata
Copy link
Member

@anecdata anecdata commented Mar 23, 2021

Addresses UDP server issue #4445 by changing the recvfrom_into() port number into network byte-order, so that sendto() replies back to the correct port that a client initiated the transaction from.

Successful sequence:

CircuitPython socketpool UDP Server:

code.py output:
Connecting to Wifi
Self IP 192.168.6.198
Server ping 192.168.6.198 0.0 ms
Create UDP Server socket ('192.168.6.198', 5000)

CPython UDP Client:

Create UDP Client Socket
Sent 12 bytes

tcpdump:

20:15:52.771675 IP: (tos 0x0, ttl 64, id 63564, offset 0, flags [none], proto UDP (17), length 40, bad cksum 0 (->f541)!)
    192.168.5.32.61409 > 192.168.6.198.5000: UDP, length 12

CircuitPython socketpool UDP Server:

Received bytearray(b'Hello, world') 12 bytes from ('192.168.5.32', 61409)
Sent bytearray(b'Hello, world') 12 bytes to ('192.168.5.32', 61409)

tcpdump:

20:15:52.885491 IP: (tos 0x0, ttl 255, id 233, offset 0, flags [none], proto UDP (17), length 40)
    192.168.6.198.5000 > 192.168.5.32.61409: UDP, length 12

CPython UDP Client:

Received bytearray(b'Hello, world') 12 bytes from ('192.168.6.198', 5000)

@anecdata anecdata added the espressif applies to multiple Espressif chips label Mar 23, 2021
@anecdata anecdata requested a review from hierophect March 23, 2021 01:55
@anecdata
Copy link
Member Author

anecdata commented Mar 23, 2021

Regression tested with this repo's NTP example, and with all supported combinations of CPython, CircuitPython ESP32SPI, and CircuitPython native (esp32s2) TCP and UDP clients and servers.

Copy link
Collaborator

@hierophect hierophect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for fixing this!

@hierophect hierophect merged commit 278d53c into adafruit:main Mar 23, 2021
@anecdata anecdata deleted the udp_server branch March 23, 2021 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug espressif applies to multiple Espressif chips network
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants