Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I am trying to assign an IPV6 address to the interface using SIOCSIFADDR ioctl call. After that trying to bind to that particular IPV6 address added. Bind fails with ...
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    2

    bind() fails with EADDRNOTAVAIL after calling an SIOCSIFADDR ioctl for IPV6 address

    Hi,

    I am trying to assign an IPV6 address to the interface using SIOCSIFADDR ioctl call. After that trying to bind to that particular IPV6 address added. Bind fails with errno 99 (EADDRNOTAVAIL).
    Tried introducing some sleep after ioctl and before bind() call, the same error is returned.

    Linux kernel version is 2.6.28.9.

    Does anyone know how to fix this??

    The program is below:
    OUTPUT:

    fed1::81
    Error: 0
    Return of Bind: -1, errno: 99


    struct sockaddr_in6 in_addr;
    void setIP()
    {
    struct ifreq ifr;
    struct in6_ifreq ifr6;
    int socv6;
    char ip[50]={0};

    memset(&in_addr, 0, sizeof(in_addr));

    socv6=socket(AF_INET6, SOCK_DGRAM, 0);
    strcpy(ifr.ifr_name,"eth0");
    ioctl(socv6, SIOGIFINDEX, &ifr);

    ifr6.ifr6_ifindex = ifr.ifr_ifindex;
    ifr6.ifr6_prefixlen = 64;

    inet_pton(AF_INET6, "fed1::81", &in_addr);
    inet_pton(AF_INET6, "fed1::81", &ifr6.ifr6_addr);
    inet_ntop(AF_INET6, &in_addr, &ip, sizeof(ip) );

    inet_ntop(AF_INET6, &ifr6.ifr6_addr, &ip, sizeof(ip) );
    printf("%s:\n", ip);

    ioctl(socv6,SIOCSIFADDR,&ifr6);
    printf("Error: %d\n",errno);
    }
    int main()
    {
    int sockFd=0, ret =0;

    setIP();

    sockFd = socket(AF_INET6, SOCK_STREAM, 0);
    inet_pton(AF_INET6, "fed1::81", &(in_addr.sin6_addr));

    int one = 1;

    if (setsockopt(sockFd, SOL_SOCKET, SO_REUSEADDR, &one,
    sizeof(one)) < 0)
    {
    printf("ERROR in set_sockopt(): %d\n", errno);
    return 0;
    }

    in_addr.sin6_port = htons(8888 );
    in_addr.sin6_family = AF_INET6;

    ret = bind(sockFd, (struct sockaddr *)&in_addr, sizeof(in_addr));
    printf("Return of Bind: %d, errno: %d\n", ret, errno);

    getchar();
    return 0;
    }

    thanks in advance,
    Lakshmi

  2. #2
    Just Joined!
    Join Date
    Oct 2010
    Posts
    2
    Hi,

    Found a workaround at "mwnnlin.blogspot.com/2010/05/ipv6-address-assignment-bind-issues.html"

    If anyone knows of another solution other than modifying the Kernel source and disabling DAD requests, please reply..

    thanks

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Unfortunately my ISP (AT&T) doesn't yet support IPv6 on their DSL links, so I haven't had a chance to test this stuff out. At least you found a solution, and thanks for the link. It may come in handy for some users as they migrate to IPv6 over time.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...