-
Notifications
You must be signed in to change notification settings - Fork 683
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
Unable to use recvfrom() on TCP socket #1144
Comments
You're correct, and it's somewhat shocking that nobody has noticed that bug for more than four years. Maybe most people don't use |
recvfrom(2) only returns the sender's address for protocols that provide it. Usually, that means it returns the sender's address for datagram sockets but not for stream sockets. Fixes nix-rust#1144
recvfrom(2) only returns the sender's address for protocols that provide it. Usually, that means it returns the sender's address for datagram sockets but not for stream sockets. Fixes nix-rust#1144
Amazing, thank you ! |
Could you please check PR #1145 and tell me if that change works for you? |
Hi, It works like a charm with your fix 👍 Thanks, |
1145: Fix sys::socket::recvfrom for TCP sockets r=asomers a=asomers recvfrom(2) only returns the sender's address for protocols that provide it. Usually, that means it returns the sender's address for datagram sockets but not for stream sockets. Fixes #1144 Co-authored-by: Alan Somers <[email protected]>
Hello,
I try to use the
socket::recvfrom()
function on a TCP socket and I get an errorENOTCONN
.I agree I could use the
socket::recv()
function but the docs says using recvfrom is allowedhttps://linux.die.net/man/2/recvfrom
I believe the issue comes from the function
sockaddr_storage_to_addr()
:https://github.com/nix-rust/nix/blob/master/src/sys/socket/mod.rs#L1243
Here is an example of the problem. If you connect to this server with a tcp client (telnet for ex). You will get errors:
Read err ENOTCONN: Transport endpoint is not connected
On the other hand, with this C code, it works as expected
Thanks,
Thibaut
The text was updated successfully, but these errors were encountered: