Hi,
Em 13-03-2016 23:16, 김영득 escreveu:
Hello.
What are you using to bind the port, sctp_bindx() ?
I don't use sctp bindx().
I use bind().
After I received the e-mail, I tried to use sctp_bindx(). But I have the same error.
Ah ok
And is it the bind or the connect that complains about address in use?
Asking because I couldn't spot any relevant change on sctp_bindx() between those releases while for sctp_connectx() there are quite some.
I have a problem with bind() before connect().
I attach the sample code that I use for test.
Best, Regard.
int main(int argc, char *argv[])
{
struct sockaddr_in addr_in;
unsigned short usPort = atoi(argv[2]);
char strIp[32];
int fd1, fd2, nRet;
strcpy(strIp, argv[1]);
memset(&addr_in, 0x00, sizeof(struct sockaddr_in));
addr_in.sin_family = AF_INET;
addr_in.sin_port = htons(usPort);
nRet = inet_pton(AF_INET, strIp, &addr_in.sin_addr.s_addr);
if (nRet <= 0)
{
printf("inet_pton fail(%d) addr(%s:%d)\n", errno, strIp, usPort);
return -1;
}
/* listen socket */
fd1 = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
if (fd1 < 0)
{
printf("socket fail(%d) addr(%s:%d)\n", errno, strIp, usPort);
return -1;
}
nRet = 1;
setsockopt(fd1, SOL_SOCKET, SO_REUSEADDR, (const void *) &nRet, sizeof(nRet));
if(bind(fd1, (struct sockaddr *) &addr_in, sizeof(struct sockaddr_in)) < 0)
{
printf("bind fail(%d) addr(%s:%d)\n", errno, strIp, usPort);
close(fd1);
return -1;
}
if(listen(fd1, SOMAXCONN) < 0)
{
printf("listen fail(%d) addr(%s:%d)\n", errno, strIp, usPort);
close(fd1);
return -1;
}
/* bind socket */
fd2 = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
if (fd2 < 0)
{
printf("2: socket fail(%d) addr(%s:%d)\n", errno, strIp, usPort);
return -1;
}
nRet = 1;
setsockopt(fd2, SOL_SOCKET, SO_REUSEADDR, (const void *) &nRet, sizeof(nRet));
if(bind(fd2, (struct sockaddr *) &addr_in, sizeof(struct sockaddr_in)) < 0)
{
printf("2: bind fail(%d) addr(%s:%d)\n", errno, strIp, usPort);
close(fd1);
return -1;
}
return 0;
}
This program doesn't use lksctp-tools at all, just syscalls, so it
should be independent of lksctp-tools version. When you tested different
lib versions, did you change your distro/kernel too?
If you changed your kernel version, it may be due to this commit:
commit ce5325c1338acf965f4300f4976eac2129aeb439
Author: Vlad Yasevich <vladislav.yasevich@xxxxxx>
Date: Fri May 4 13:34:49 2007 -0700
[SCTP]: Fix the SO_REUSEADDR handling to be similar to TCP.
Update the SO_REUSEADDR handling to also check for listen state. This
was muliple listening server sockets can't be created and they will
not steal packets from each other.
And it's doing what we currently expect, that's how we can block from
having two listening sockets. I didn't test but after this commit you
should have to disable listening (with listen(sd, 0)) before binding
another socket to the same port, and then enable listening again.
Although the changelog mentions TCP, TCP code grew a lot since then and
both are not very similar anymore.
Marcelo
--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html