AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
Expand all | Collapse all

AIX 7: bind() system call fails with error "Address already in use" if same port number is used for ipv4 socket (AF_INET) and ipv6 socket (AF_INET6)

  • 1.  AIX 7: bind() system call fails with error "Address already in use" if same port number is used for ipv4 socket (AF_INET) and ipv6 socket (AF_INET6)

    Posted Sun December 07, 2014 04:46 AM

    Originally posted by: TejinderSingh


     
    Hi Team,
    On AIX platform, I am facing different behavior of bind() system call thAn other unix-platforms (Linux and Solaris).
    My server application creates two sockets one for ipv4 address (AF_INET) and another for ipv6 addresses (AF_INET6). The PORT number here used is same in both the sockets. The first bind is successfull whether ipv4 or ipv6, but second bind fails with error "Address already in use".
    OS - AIX 7.1
    Code snippets:
    ---------------------
    struct addrinfo      srvr_hints, *SrvAddr6 = NULL, *Addr_Info = NULL;
    struct sockaddr_in    SrvAddr4;
    inf fd4, fd6, sts1, sts2;
       
    srvr_hints.ai_flags    = AI_PASSIVE;
    srvr_hints.ai_family   = AF_INET6;
    srvr_hints.ai_socktype = SOCK_DGRAM;
    srvr_hints.ai_protocol = IPPROTO_UDP;
     
    sts = getaddrinfo(NULL, PORT, &srvr_hints, &SrvAddr6); // used for ipv6 socket bind
    fd6 = socket(SrvAddr->ai_family, SrvAddr->ai_socktype, SrvAddr->ai_protocol);
    fd4 = socket(AF_INET, SOCK_DGRAM, PF_UNSPEC);
    bzero(&SrvAddr4, sizeof(SrvAddr4));
    SrvAddr4.sin_family = AF_INET;
    SrvAddr4.sin_port = htons(PORT);
    SrvAddr4.sin_addr.s_addr = htonl(INADDR_ANY);
    sts1 = bind(SrvAddr4, (struct sockaddr *) &SrvAddr4, sizeof(SrvAddr4)); // SUCCESS
    sts2 = bind(fd6, SrvAddr6->ai_addr, SrvAddr6->ai_addrlen); // FAILS WITH ERROR "Address Already in use."
     
    *****Note: Same code is working fine on Linux and Solaris platforms.
    Please suggest if I am doing any wrong or some additional flags needs to be set on sockets.
     
    Regards,
    Tejinder


  • 2.  Re: AIX 7: bind() system call fails with error "Address already in use" if same port number is used for ipv4 socket (AF_INET) and ipv6 socket (AF_INET6)

    Posted Wed December 10, 2014 05:31 AM

    Originally posted by: Wouter Liefting


    Interesting one. It looks like the IPv4 bind call blocks the IPv6 port. I don't have an answer, but I did some searching and maybe you can use the SO_REUSEADDR option when opening the IPv4 port?

    http://utcc.utoronto.ca/~cks/space/blog/programming/ModernSocketsListening

    Alternatively, open the IPv6 port first, and use the IPV6_V6ONLY option?

    More notes here:

    http://utcc.utoronto.ca/~cks/space/blog/linux/Ipv6DualBinding