1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-26 14:11:53 +02:00

atrf-proxy.c (loop): use SO_REUSEADDR to avoid "address already in use"

This commit is contained in:
Werner Almesberger 2011-04-12 06:58:55 -03:00
parent 8c5d21b0d7
commit 02b80879bf

View File

@ -239,6 +239,7 @@ static void loop(const char *driver, int port)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
int s; int s;
int one = 1;
s = socket(PF_INET, SOCK_STREAM, 0); s = socket(PF_INET, SOCK_STREAM, 0);
if (s < 0) { if (s < 0) {
@ -246,6 +247,11 @@ static void loop(const char *driver, int port)
exit(1); exit(1);
} }
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) {
perror("setsockopt");
exit(1);
}
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(port); addr.sin_port = htons(port);