I try to print client port in my server application which is in C.
But I get negative numbers of the Client port, what is strange behaviour:-/
Any one have an idea where could be a problem?
Part of my code which cause the problem:
struct sockaddr_in client_address;
int chosenPort = (int) ntohl(client_address.sin_port);
pritf("Client port is %d, chosenPort");
I get port like -2121400320.
Use
ntohs()instead –sin_portis a 16-bit value.