path: root/netsock.c
diff options
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-04-01 22:35:25 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-04-01 22:35:25 +0000
commitb04642f14f66e1ed2764a5140ee683267892c0f2 (patch)
treec5d4c87cd48bc77cfa53ef7927d14ac14fe599de /netsock.c
parent4e302d51366e2f708d06cb923a389189a0323c34 (diff)
Add the SO_REUSEADDR flag to sockets handled by netsock. This is needed by
the patch that went in for issue 7874. chan_iax2 needs to be able to create socket that is lisetning on INADDR_ANY, but also be able to bind sockets to specific addresses. (Thanks to Stevenson on the asterisk-dev mailing list for explaining why this flag was needed.) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2@59608 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'netsock.c')
1 files changed, 3 insertions, 0 deletions
diff --git a/netsock.c b/netsock.c
index bcba51c68..e73598b59 100644
--- a/netsock.c
+++ b/netsock.c
@@ -128,6 +128,7 @@ struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct i
char iabuf[INET_ADDRSTRLEN];
struct ast_netsock *ns;
+ const int reuseFlag = 1;
/* Make a UDP socket */
netsocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
@@ -136,6 +137,8 @@ struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct i
ast_log(LOG_ERROR, "Unable to create network socket: %s\n", strerror(errno));
return NULL;
+ if (setsockopt(netsocket, SOL_SOCKET, SO_REUSEADDR, (char *)&reuseFlag, sizeof reuseFlag) < 0)
+ ast_log(LOG_WARNING, "Error setting SO_REUSEADDR on sockfd '%d'\n", netsocket);
if (bind(netsocket,(struct sockaddr *)bindaddr, sizeof(struct sockaddr_in))) {
ast_log(LOG_ERROR, "Unable to bind to %s port %d: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr->sin_addr), ntohs(bindaddr->sin_port), strerror(errno));