-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
[socket] Fix getpeername() returning local address instead of remote in LWIP raw TCP #12475
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
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#12475
components: [socket]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #12475 +/- ##
==========================================
- Coverage 72.60% 72.57% -0.03%
==========================================
Files 53 53
Lines 11192 11192
Branches 1517 1517
==========================================
- Hits 8126 8123 -3
- Misses 2674 2676 +2
- Partials 392 393 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a copy-paste bug in the LWIP raw TCP socket implementation where getpeername() was incorrectly returning the local address instead of the remote peer's address. The sockaddr overload was mistakenly using pcb_->local_ip and pcb_->local_port instead of pcb_->remote_ip and pcb_->remote_port, making it behave identically to getsockname(). This violated standard socket API semantics and was inconsistent with the string overload of getpeername() which was already correct.
Key Changes
- Fixed
getpeername(struct sockaddr *name, socklen_t *addrlen)to usepcb_->remote_ipandpcb_->remote_portinstead ofpcb_->local_ipandpcb_->local_port
|
Thanks |
…in LWIP raw TCP (#12475)
What does this implement/fix?
Fix
getpeername()in LWIP raw TCP socket implementation to return the remote peer's address instead of the local address.The sockaddr overload of
getpeername()was incorrectly usingpcb_->local_ipandpcb_->local_portinstead ofpcb_->remote_ipandpcb_->remote_port. This made it return the same result asgetsockname(), which is incorrect:getsockname()should return the local address (our side)getpeername()should return the remote address (peer's side)This was a copy-paste bug - the string overloads were already correct:
But the sockaddr overloads were identical:
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:# No configuration changes - this is an internal socket API fixChecklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: