+ if (sp->bind_host)
+ {
+ int r = -1;
+ int ipv6_only = 0;
+ struct addrinfo *ai;
+
+#ifndef WIN32
+ int one = 1;
+ if (setsockopt(h->iofile, SOL_SOCKET, SO_REUSEADDR, (char*)
+ &one, sizeof(one)) < 0)
+ {
+ h->cerrno = CSYSERR;
+ return 0;
+ }
+#endif
+ ai = tcpip_getaddrinfo(sp->bind_host, "0", &ipv6_only);
+ if (!ai)
+ return 0;
+ {
+ struct addrinfo *a;
+ for (a = ai; a; a = a->ai_next)
+ {
+ r = bind(h->iofile, a->ai_addr, a->ai_addrlen);
+ if (!r)
+ break;
+ }
+ }
+ if (r)
+ {
+ h->cerrno = CSYSERR;
+ freeaddrinfo(ai);
+ return 0;
+ }
+ freeaddrinfo(ai);
+ }