}
/****************************************************************
*
- * Routine sockbind2
+ * Routine sockbindopt
* Return a binded socket given hostname, service, and socket type
- * Issue a SO_REUSEADDR on the socket before binding.
+ * Issue a SO_REUSEADDR on the socket before binding on reuse value.
*
* Author: Simone Piccardi
* Mar. 2005
* $Id$
*
****************************************************************/
-int sockbind2(char *host, char *serv, int prot, int type)
+int sockbindopt(char *host, char *serv, int prot, int type, int reuse)
{
struct addrinfo hint, *addr, *save;
int res;
int sock;
- int opt=1;
char buf[INET6_ADDRSTRLEN];
/* initialize hint structure */
memset(&hint, 0, sizeof(struct addrinfo));
}
}
/* connect the socket */
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ &reuse, sizeof(reuse))) {
printf("error on socket options\n");
return -1;
}