问题
I am writing a SCTP test program in Solaris OS, and use Solaris native SCTP stack. The program likes this:
if ((fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) {
perror("socket");
}
addr.sin_family = AF_INET;
addr.sin_port = htons(9004);
addr.sin_addr.s_addr = inet_addr("192.168.23.117");
if (sctp_bindx(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in), SCTP_BINDX_ADD_ADDR) < 0) {
perror("bind");
}
When running the program, it always return error:"Invalid argument". I have used the gdb to check, and find addr structure is right.
Because Solaris isn't open source, I can only check the assembly code using gdb, and find sctp_bindx calls setsockopt function, and the setsockopt function return error. The calling setsockopt likes this:
setsockopt(fd, SOL_SCTP, SCTP_ADD_ADDR, addrs, addrs_size);
I have checked all the parameters, and find they are right. So I can't figure out the cause of this issue. Could anyone help me? Thanks in advance!
回答1:
You need to call bind first.
From the oracle docs on sctp_bindx
An application can use sctp_bindx(SCTP_BINDX_ADD_ADDR) to associate
additional addresses with an endpoint **after calling the bind() function**.
来源:https://stackoverflow.com/questions/16476770/sctp-bindx-solaris-sctp-library-always-return-invalid-argument