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

Bug Report: the port of socket is incorrect when I use socket.bind(...) #203

Open
L-Sun opened this issue Jun 12, 2021 · 1 comment
Open

Comments

@L-Sun
Copy link

L-Sun commented Jun 12, 2021

ipv4Sockaddr.sin_port = localEndPoint.to_ipv4().port();

is the correct code following?

    ipv4Sockaddr.sin_port = htons(localEndPoint.to_ipv4().port()); 
                            ^^^^^
@jdoubleu
Copy link

Had the exact same issue.

My current workaround is to manually create an endpoint with a fixed port:

#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif

// ...

auto endpoint = cppcoro::net::ipv4_endpoint::from_string("127.0.0.1:7001");
endpoint = cppcoro::net::ipv4_endpoint{endpoint.address(), htons(endpoint.port())};

The actual bound port is accessible from socket.local_endpoint() after the call to socket.bind(..).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants