IPv6 bind fail - TCP-IP

This is a discussion on IPv6 bind fail - TCP-IP ; Hi, I have the following code. When I test it with ::1, everything is fine. I tested the server and the client. Although I am not on an IPv6 network, when I try to bind the socket to one of ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: IPv6 bind fail

  1. IPv6 bind fail

    Hi,

    I have the following code. When I test it with ::1, everything is
    fine. I tested the server and the client.

    Although I am not on an IPv6 network, when I try to bind the socket to
    one of my "real" interfaces bind() fails...

    struct sockaddr_in6 sin6;
    memset(&sin6,0,sizeof(sin6));

    if(inet_pton(AF_INET6, "fe80::214:a5ff:fe76:f6db", &(sin6.sin6_addr))!
    =1)
    cout<<"pton failed"<
    int fd=socket(PF_INET6, SOCK_STREAM, 0);

    sin6.sin6_port=htons(1234);
    sin6.sin6_family=AF_INET6;

    r = bind (fd, (struct sockaddr*)&sin6, sizeof (sin6));
    if(r<0)
    cout<<"bind failed"< else
    cout<<"bind OK"<
    At first I assumed inet_pton() was giving me the wrong address, but
    when I print sin6.sin6_addr on the screen the numbers seem to be
    correct.

    Any ideas what could be wrong with the code? I assume the TCP/IP stack
    is capable of openning a socket on my interface despite not being
    connected, I tested ping6 on it and it's fine....

    regrads


  2. Re: IPv6 bind fail

    In article <1181307951.139138.121080@k79g2000hse.googlegroups. com>,
    UM wrote:

    > Hi,
    >
    > I have the following code. When I test it with ::1, everything is
    > fine. I tested the server and the client.
    >
    > Although I am not on an IPv6 network, when I try to bind the socket to
    > one of my "real" interfaces bind() fails...
    > [...]
    > "fe80::214:a5ff:fe76:f6db"
    > [...]
    > Any ideas what could be wrong with the code? I assume the TCP/IP stack
    > is capable of openning a socket on my interface despite not being
    > connected, I tested ping6 on it and it's fine....


    That's a link local address. Bind does weird things with link locals. If
    nothing else, you need to specify the sin6_scope_id in the sockaddr_in6.
    Wouldn't hurt to set the sin6_flowinfo to 0 as well; that's probably a
    no-op, but I always do it just to eliminate one variable.

  3. Re: IPv6 bind fail

    On 8 Jun, 14:58, Roy Smith wrote:
    > In article <1181307951.139138.121...@k79g2000hse.googlegroups. com>,
    >
    > UM wrote:
    > > Hi,

    >
    > > I have the following code. When I test it with ::1, everything is
    > > fine. I tested the server and the client.

    >
    > > Although I am not on an IPv6 network, when I try to bind the socket to
    > > one of my "real" interfaces bind() fails...
    > > [...]
    > > "fe80::214:a5ff:fe76:f6db"
    > > [...]
    > > Any ideas what could be wrong with the code? I assume the TCP/IP stack
    > > is capable of openning a socket on my interface despite not being
    > > connected, I tested ping6 on it and it's fine....

    >
    > That's a link local address. Bind does weird things with link locals. If
    > nothing else, you need to specify the sin6_scope_id in the sockaddr_in6.
    > Wouldn't hurt to set the sin6_flowinfo to 0 as well; that's probably a
    > no-op, but I always do it just to eliminate one variable.


    thanks,

    since you mentioned it, I've read a bit on the scope... It looks like
    I will have to statically set it to a specific number for the time
    being...



+ Reply to Thread