Cat /proc/sys/net/ipv4/ip_local_port_range

Hello,

/proc/sys/net/ipv4/ip_local_port_range returns 32000 - 61000, 

i have a client TCP and a Server TCP. i have used bind() only on the server, the port of socket client is given by the OS that's it ?
it retrieves this port from this range (/proc/sys/net/ipv4/ip_local_port_range) ?

That's it ?

Thanks a lot.
Best Regards.

Yup, first and last local port number available, that's it.

Ok, but when i use:

 printf("%d", ClientAddr.sin_port);

it display a value (29000) not in this range 32000- 61000

Have you an explanation please ?

Thanks a lot.
Best Regards.

and when you

printf"%d", htons(ClientAddr.sin_port);

I have set this code:

printf"%d", htons(ClientAddr.sin_port);

in

the Server.c 

after the system call

Accept()

So it's htons or ntohs ?

Thanks a lot.

They're symmetric, so it doesn't matter. Whether you're converting to or from the network, the bytes get rearranged the exact same way.

Not all systems need to swap bytes at all; big-endian machines already keep their bytes in the proper order. On these machines, ntohs(), etc. do nothing at all.

1 Like