Subject: Re: sctp_bindx

From: "Peter Lei (peterlei)" <[email-masked]>
Date: Tue, 08 Jun 2004 19:51:34 -0500

Interesting... not exactly sure why that is the error returned for
this case... my guess is that because the sin_len is missing, the
code can't figure out what the next address is, so is an invalid 
family/proto.  I'll have to double-check that.

see below for a one line addition to fix your problem:

Ryan W. Bickhart wrote:
> Hello!
> 
> I'm not sure if anyone else has experienced this problem, but I am
> currently having trouble with sctp_bindx. Specifically, if I try to bind
> any number of addresses (so far I have tried both a single address and
> two at a time), bindx fails with the error message "Address family not
> supported by protocol family". Below is a small program that causes the
> error. The system being used is FreeBSD 4.9 using the March 31 KAME
> snapshot with SCTP patch 20 applied.
> 
> If you have any insight or suggestions they would be most appreciated.
> 
> Thanks!
> 
> Ryan
> 
> Sample code:
> 
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <arpa/inet.h>
> #include <netinet/sctp.h>
> #include <errno.h>
> #include <stdio.h>
> 
> #define LISTEN_ADDRS 2
> #define LISTEN_PORT 3333
> 
> int main(int argc, char *argv[]) {
> 
>    int sock_fd = 0;
>    int i = 0;
>    struct sockaddr_in listen_addrs[LISTEN_ADDRS];
> 
>    if(--argc != LISTEN_ADDRS) {
>       printf("Usage: %s <addrs>\n", argv[0]);
>       exit(1);
>    }
>    
>    if((sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) {
>       perror("socket");
>       exit(1);
>    }
>    
>    for(i = 0; i < LISTEN_ADDRS; i++) {
>       bzero(&listen_addrs[i], sizeof(struct sockaddr_in));
>       listen_addrs[i].sin_family = AF_INET;
>       inet_pton(AF_INET, argv[i + 1], &listen_addrs[i].sin_addr);
>       listen_addrs[i].sin_port = htons(LISTEN_PORT);

         listen_addrs[i].sin_len = sizeof(struct sockaddr_in);

>    }
>    
>    printf("Binding the following:\n");
>    
>    for(i = 0; i < LISTEN_ADDRS; i++) {
>       printf("Address: %s, ", inet_ntoa(listen_addrs[i].sin_addr));
>       printf("Port: %d\n", ntohs(listen_addrs[i].sin_port));
>    }
> 	
>    if(sctp_bindx(sock_fd, (struct sockaddr *) listen_addrs, LISTEN_ADDRS, SCTP_BINDX_ADD_ADDR) == -1) {
>       perror("sctp_bindx");
>       exit(1);
>    }
> }
> 
> 
>