Ticket #2060 (closed bug: invalid)

Opened 5 months ago

Last modified 5 months ago

this client test program fails to connect to the server test program

Reported by: kaoutsis Owned by: axeld
Priority: normal Milestone: R1
Component: - General Version: R1 development
Cc: Blocked By:
Platform: All Blocking:

Description

r24888 * on qemu, client: connect failed: Connection refused

Attachments

net_sockets.diff (7.3 kB) - added by kaoutsis 5 months ago.

Change History

  Changed 5 months ago by kaoutsis

on real hardware (r24888), connect() doesn't return

follow-up: ↓ 3   Changed 5 months ago by axeld

  • status changed from new to closed
  • resolution set to invalid

You're using something like this several times: struct sockaddr_in server_addr = {AF_INET, htons(serverPort)};

But this is wrong - the first member is sin_len, not sin_family. The code you probably copied that from is broken :-) BTW there is already a similar test app, called tcp_server.cpp, and tcp_client.cpp.

in reply to: ↑ 2   Changed 5 months ago by kaoutsis

Replying to axeld:

You're using something like this several times: struct sockaddr_in server_addr = {AF_INET, htons(serverPort)}; But this is wrong - the first member is sin_len, not sin_family. The code you probably copied that from is broken :-)

or historic? :-) http://www.fortunecity.com/skyscraper/arpanet/6/cc.htm i made the corrections, and now the program runs fine on haiku, thanks! But i still can't find why linux had no complains with the historic implementation. (Before the corrections, linux had no problem; even then the connection was fine)

BTW there is already a similar test app, called tcp_server.cpp, and tcp_client.cpp.

Yes. That was my first network program; i wanted to try something different :-)

Changed 5 months ago by kaoutsis

follow-up: ↓ 5   Changed 5 months ago by axeld

The problem with using the {...} initialization is that it makes assumptions on how the sockaddr structure (or sockaddr_in) looks like. The result is that it may or may not work on a platform - it's like Russian roulette. The actual members and the order of the sockaddr fields is unspecified.

in reply to: ↑ 4   Changed 5 months ago by kaoutsis

Replying to axeld:

The problem with using the {...} initialization is that it makes assumptions on how the sockaddr structure (or sockaddr_in) looks like. The result is that it may or may not work on a platform - it's like Russian roulette. The actual members and the order of the sockaddr fields is unspecified.

You are right. I'll keep that in mind, thanks.

Note: See TracTickets for help on using tickets.