gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gpsd-dev] regression test puzling non-failure which should probably


From: Hal Murray
Subject: Re: [gpsd-dev] regression test puzling non-failure which should probably fail
Date: Fri, 30 Jan 2015 14:30:36 -0800

address@hidden said:
>> Isn't there a way of asking the system to pick an unused port
>> number and then getting it to tell you the one it assigned?

> If there is, I don't know of it. 

If you specify a port number of 0, it assigns one for you.

>From the man page for bind:
       EADDRINUSE
              (Internet domain sockets) The port number was specified as  zero
              in the socket address structure, but, upon attempting to bind to
              an ephemeral port, it was determined that all  port  numbers  in
              the  ephemeral port range are currently in use.  See the 
discus‐
              sion of /proc/sys/net/ipv4/ip_local_port_range ip(7).

>From the man page for ip:
       When listen(2) is called on an
       unbound socket, the socket is automatically bound to a random free port
       with the local address set to INADDR_ANY.

I think getsockname can be used to retrieve the local address.

-------

>From the NetBSD man page for getsockname:

     Common uses of this function are as follows:

     o   When bind(2) is called with a port number of 0 (indicating the kernel
         should pick an ephemeral port) getsockname() is used to retrieve the
         kernel-assigned port number.


-- 
These are my opinions.  I hate spam.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]