how to check third parameter of socket(2)?

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

 



Hi,

to prepare a TCP socket, usually someone calls something like:

   int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

however, on older linux versions, for example 2.2.16, this
returns a socket on which bind(2) will fail with `address already
in use'. Here, the following works:

   int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);

from netinet/in.h:

   IPPROTO_IP = 0,      /* Dummy protocol for TCP.  */

however, we also have socket APIs that /require/ to use the first
form. So we have platforms that accept both (recent linux
versions), only the first form (3rd party socket APIs) and others
only the second form (older linux versions).

I have no idea how to handle this. Best would be to have some
#define set by some configure check, but there are problems:

  - it is not the socket calls that fails but a subsequent bind
  - the bind fails with exactly the same error that will happen
    when the test-port is really in use (e.g. by a running
    server)
  - and, last but not least, this requires to RUN the program,
    which cannot work for cross-compilation.

Is this topic known? I think it could be an almost-FAQ because of
`IPPROTO_IP == Dummy protocol for TCP' and that tutorials in the
internet tell to use IPPROTO_TCP instead, which seems to be more
correct.

Any proposals how to handle this issue?

oki,

Steffen


_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux