Hello,

I am not able to get a behavior similar to SO_BINDTODEVICE (on linux) using the 
IP_BOUND_IF option on

SunOS dev-224 5.10 Generic_127127-11 sun4v sparc SUNW,SPARC-Enterprise-T5220

Below is a piece of some sample connect code I am testing with. I was expecting 
the SYNs to go out on the specified interface, but it seems like the kernel 
makes a choice based on the dest IP addr. Binding to specific IP (assigned to 
an interface) doesn't seem to help either.

On the other hand, this code work just fine on linux, irrespective of dest IP 
or the local bind address, I can specify 0.0.0.0 as the local bind address and 
it will still send the pkt out of the specified interface.

What am I missing here? 

I would appreciate any help I can get.

Thanks for your time.

-- Pranav


------------------------- code ---------------------------------
    //socket
    if ((sock = socket(AF_INET, SOCK_STREAM, 0) ) < 0) {
        perror("socket()");
    }

    //bind
    memset(&from, 0, sizeof(from));
    from.sin_family = AF_INET;
    from.sin_addr.s_addr = inet_addr(argv[1]);
    from.sin_port = htons(0);

    if(bind(sock, (struct sockaddr *)&from, sizeof(from)) < 0) {
        perror("bind()");
    }

    //bound
#ifdef LINUX
    fprintf(stdout, "interface %s\n", argv[2]);
    strncpy( interface.ifr_ifrn.ifrn_name, argv[2], 20);
    if(setsockopt (sock, SOL_SOCKET, SO_BINDTODEVICE, (char *)&interface, 
sizeof(interface)) < 0) {
        perror("setsockopt");
    }
#elif SOLARIS
    index = if_nametoindex(argv[2]);
    fprintf(stdout, "index for %s=%d\n", argv[2], index);
    if(setsockopt (sock, IPPROTO_IP, IP_BOUND_IF, &index, sizeof(index)) < 0){
        perror("setsockopt");
    }
#endif

    //connect
    memset(&sin, 0, sizeof(sin));
    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = inet_addr(argv[3]);
    sin.sin_port = htons(5000);
 
 
This message posted from opensolaris.org

Reply via email to