IPv6, sending packets through a specific NIC

From: marcalcock (marcalcock_at_yahoo.co.uk)
Date: 10/28/03

  • Next message: Floyd Davidson: "Re: 8ms Timer for serial port access"
    Date: 28 Oct 2003 09:42:04 -0800
    
    

    Hi,

    I have searched high and low for information about how to set up a
    IPv6 socket that sends it's packets through a specific NIC, but
    finally have to admit defeat.

    I am new to linux and socket programming, so am hoping that someone
    will be able point me in the right direction.

    My problem is this...
    I have two linus boxes (redhat 9) connected to each other via two NIC
    each (eth0 in LinuxBox1 connected to eth0 on LinuxBox2 and eth1 in
    LinuxBox1 connected to eth1 on LinuxBox2) and they are configured for
    IPv6.

    what I want to do is have some UDP information sent from LinuxBox1 to
    LinuxBox2 via either eth0, or eth1, depending on a program variable.

    Now, I thought that this would be relativley simple...
    ------------------------------------
    //assuming we are on linBox1

    struct sockaddr_in6 route1, route2;
    int fd1 = socket(AF_INET6, SOCK_DGRAM, 0);
    int fd2 = socket(AF_INET6, SOCK_DGRAM, 0);

    bzero(&route1, sizeof(route1);
    bzero(&route2, sizeof(route2);
    route1.sin6_family = AF_INET6;
    route1.sin6_port = htons(5000);
    inet_pton(AF_INET6, "fe80::202:b3ff:fed7:10d0", &route1.sin6_addr);
    //addr of eth0 linBox2
    route2.sin6_family = AF_INET6;
    route2.sin6_port = htons(5001);
    inet_pton(AF_INET6, "fe80::202:b3ff:fed7:1177", &route2.sin6_addr);
    //addr of eth1 linBox2

    for (; ;) {
        pause(500); // wait of half second
        sendto(fd1, "payload1", strLen("payload1"), 0, (const struct
    sockaddr *) &route1, sizeof(route1);

        pause(500); // wait of half second

        sendto(fd2, "payload2", strLen("payload2"), 0, (const struct
    sockaddr *) &route2, sizeof(route2);
    }
    ------------------------------------
    the packets are only sent *some* of the time... ie, when the program
    runs, the packets appear to be sent from linbox1 (by the return val
    for the sandto function being positive- the number of bytes in the UDP
    packet and by using tcpdump on eth0 and eth1 (on LinBox1), we can see
    the packets going. BUT sometimes, we get a positive response from
    sendto (number of bytes sent) but nothing from tcpdump (and nothing on
    the target linBox2). I cannot find any repeative trigger thats causes
    this to happen. any ideas?

    My main problem is the specifying of which NIC to use for the
    socket... The code above works because the NICs can rationalise which
    one needs to send the data because of teh target IPv6 address. But
    what happens if the target address is teh same for both sendto
    function calls, like in the case where LinBox1 is acting as a
    psuedo-router? How would I forced the message down a particular NIC??

    Thanks for any pointers


  • Next message: Floyd Davidson: "Re: 8ms Timer for serial port access"
  • Quantcast