![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| IP Networking Learn TCP/IP, Internet Protocol, Routing, Routers, Network protocols in this UNIX and Linux forum. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please help! accept function problems in Socket programming | natxie | High Level Programming | 1 | 02-07-2009 05:01 PM |
| number of lines returned from a grep command | cesarNZ | Shell Programming and Scripting | 4 | 10-09-2008 09:57 PM |
| Socket programming : Accept return 0. | abc.working | UNIX for Dummies Questions & Answers | 7 | 10-17-2007 04:03 AM |
| [Problem]Reuse port in BSD socket | Namely | High Level Programming | 1 | 11-28-2003 11:36 AM |
| socket on serial port | kintoo | High Level Programming | 2 | 07-31-2001 03:44 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Port number of socket returned by accept()
Hi,
I typed a few tcp/ip client/server examples from a book and it works - sort of - but I noticed something strange. When I run my server I set it to use port 3001 and the client uses the same port to connect to server. They succeed, but the server prints something that doesn't really make much sense: it prints that the client uses port 30152. Next time I run it is 30153 and next time is 30154 and so on. Here is the code of the server, accept() call and printf() call. Code:
struct sockaddr_in clntAddr, testAddr;
socklen_t clntAddrLen = sizeof (struct sockaddr_in);
int clntSock = accept (servSock, (struct sockaddr *)&clntAddr, &clntAddrLen);
if (clntSock < 0)
DieWithSystemMessage ("accept() failed");
char clntName[INET_ADDRSTRLEN]; // str to contain client address
if (inet_ntop(AF_INET, &clntAddr.sin_addr.s_addr, clntName, INET_ADDRSTRLEN))
printf ("Handling client %s/%hu\n", clntName, ntohs(clntAddr.sin_port));
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|