+static void set_nolinger(int fd)
+{
+ struct linger lng;
+ lng.l_onoff = 1;
+ lng.l_linger = 0;
+ setsockopt(fd, SOL_SOCKET, SO_LINGER, &lng, sizeof(lng));
+}
+
+#ifdef HAVE_NETINET_TCP_H
+int set_tcp_sockopt(int sockfd, int optname, int value)
+{
+ int level;
+
+ #if defined(__FreeBSD__) || defined(__sun) || (defined(__APPLE__) && defined(__MACH__))
+ struct protoent *buf;
+
+ if ((buf = getprotobyname("tcp")) != NULL)
+ level = buf->p_proto;
+ else
+ return -1;
+ #else
+ level = SOL_TCP;
+ #endif
+
+ return setsockopt(sockfd, level, optname, (char *)&value, sizeof(value));
+}
+#endif
+