Skip to content

Commit

Permalink
moved setsockopt() in front of bind()
Browse files Browse the repository at this point in the history
  • Loading branch information
achilikin committed Jun 17, 2013
1 parent 68c25b5 commit 47ebb79
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions fmberryd.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,21 @@ void *ListenTCP(void *arg)
syslog(LOG_NOTICE, "Binding to any interface.\n");
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
}

/* Socket an Port binden */
if( bind(lsd, (struct sockaddr*) &saddr, sizeof(saddr)) < 0) {
//whoops. Could not listen
syslog(LOG_ERR, "Could not bind to TCP port! Terminated.\n");
exit(EXIT_FAILURE);
}

//Important! Makes sure you can restart the daemon without any problems!
//Important! Makes sure you can restart the daemon without any problems!
const int optVal = 1;
const socklen_t optLen = sizeof(optVal);

int rtn = setsockopt(lsd, SOL_SOCKET, SO_REUSEADDR, (void*) &optVal, optLen);

//assert(rtn == 0); /* this is optional */

/* Socket an Port binden */
if( bind(lsd, (struct sockaddr*) &saddr, sizeof(saddr)) < 0) {
//whoops. Could not listen
syslog(LOG_ERR, "Could not bind to TCP port! Terminated.\n");
exit(EXIT_FAILURE);
}

syslog(LOG_NOTICE, "Successfully started daemon\n");
/* Auf Socket horchen (Listen) */
Expand Down

0 comments on commit 47ebb79

Please sign in to comment.