23 |
*/ |
*/ |
24 |
|
|
25 |
#include "stdinc.h" |
#include "stdinc.h" |
|
#ifndef _WIN32 |
|
26 |
#include <netinet/in_systm.h> |
#include <netinet/in_systm.h> |
27 |
#include <netinet/ip.h> |
#include <netinet/ip.h> |
28 |
#include <netinet/tcp.h> |
#include <netinet/tcp.h> |
|
#endif |
|
29 |
#include "fdlist.h" |
#include "fdlist.h" |
30 |
#include "s_bsd.h" |
#include "s_bsd.h" |
31 |
#include "client.h" |
#include "client.h" |
78 |
else |
else |
79 |
{ |
{ |
80 |
ServerInfo.can_use_v6 = 1; |
ServerInfo.can_use_v6 = 1; |
|
#ifdef _WIN32 |
|
|
closesocket(v6); |
|
|
#else |
|
81 |
close(v6); |
close(v6); |
|
#endif |
|
82 |
} |
} |
83 |
#else |
#else |
84 |
ServerInfo.can_use_v6 = 0; |
ServerInfo.can_use_v6 = 0; |
94 |
int |
int |
95 |
get_sockerr(int fd) |
get_sockerr(int fd) |
96 |
{ |
{ |
|
#ifndef _WIN32 |
|
97 |
int errtmp = errno; |
int errtmp = errno; |
|
#else |
|
|
int errtmp = WSAGetLastError(); |
|
|
#endif |
|
98 |
#ifdef SO_ERROR |
#ifdef SO_ERROR |
99 |
int err = 0; |
int err = 0; |
100 |
socklen_t len = sizeof(err); |
socklen_t len = sizeof(err); |
156 |
setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)); |
setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)); |
157 |
#endif |
#endif |
158 |
|
|
|
#ifndef _WIN32 |
|
159 |
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); |
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); |
|
#endif |
|
160 |
|
|
161 |
return NULL; |
return NULL; |
162 |
} |
} |
646 |
/* Error? */ |
/* Error? */ |
647 |
if (retval < 0) |
if (retval < 0) |
648 |
{ |
{ |
|
#ifdef _WIN32 |
|
|
errno = WSAGetLastError(); |
|
|
#endif |
|
649 |
/* |
/* |
650 |
* If we get EISCONN, then we've already connect()ed the socket, |
* If we get EISCONN, then we've already connect()ed the socket, |
651 |
* which is a good thing. |
* which is a good thing. |
704 |
*/ |
*/ |
705 |
fd = socket(family, sock_type, proto); |
fd = socket(family, sock_type, proto); |
706 |
if (fd < 0) |
if (fd < 0) |
|
{ |
|
|
#ifdef _WIN32 |
|
|
errno = WSAGetLastError(); |
|
|
#endif |
|
707 |
return -1; /* errno will be passed through, yay.. */ |
return -1; /* errno will be passed through, yay.. */ |
|
} |
|
708 |
|
|
709 |
execute_callback(setup_socket_cb, fd); |
execute_callback(setup_socket_cb, fd); |
710 |
|
|
739 |
*/ |
*/ |
740 |
newfd = accept(lptr->fd.fd, (struct sockaddr *)pn, (socklen_t *)&addrlen); |
newfd = accept(lptr->fd.fd, (struct sockaddr *)pn, (socklen_t *)&addrlen); |
741 |
if (newfd < 0) |
if (newfd < 0) |
|
{ |
|
|
#ifdef _WIN32 |
|
|
errno = WSAGetLastError(); |
|
|
#endif |
|
742 |
return -1; |
return -1; |
|
} |
|
743 |
|
|
744 |
#ifdef IPV6 |
#ifdef IPV6 |
745 |
remove_ipv6_mapping(pn); |
remove_ipv6_mapping(pn); |