22
21
* it under the terms of the GNU General Public License as published by
23
22
* the Free Software Foundation; either version 2 of the License, or
24
23
* (at your option) any later version.
26
25
* This program is distributed in the hope that it will be useful,
27
26
* but WITHOUT ANY WARRANTY; without even the implied warranty of
28
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
28
* GNU General Public License for more details.
31
30
* You should have received a copy of the GNU General Public License
32
31
* along with this program; if not, write to the Free Software
33
32
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
59
struct sockaddr_in serv_addr;
60
int len = sizeof(serv_addr);
61
struct addrinfo *AI = NULL;
63
localhost.SetLocalhost();
65
/* INET6: back-compatible: localhost pipes default to IPv4 unless set otherwise.
66
* it is blocked by untested helpers on many admins configs
67
* if this proves to be wrong it can die easily.
63
71
handles[0] = handles[1] = -1;
65
73
statCounter.syscalls.sock.sockets++;
67
if ((new_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
77
handle0.GetAddrInfo(AI);
79
if ((new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol)) < 0)
70
memset((void *) &serv_addr, 0, sizeof(serv_addr));
72
serv_addr.sin_family = AF_INET;
74
serv_addr.sin_port = htons(0);
76
serv_addr.sin_addr = local_addr;
78
if (bind(new_socket, (SOCKADDR *) & serv_addr, len) < 0 ||
79
listen(new_socket, 1) < 0 || getsockname(new_socket, (SOCKADDR *) & serv_addr, &len) < 0 ||
80
(handles[1] = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
82
if (bind(new_socket, AI->ai_addr, AI->ai_addrlen) < 0 ||
83
listen(new_socket, 1) < 0 || getsockname(new_socket, AI->ai_addr, &(AI->ai_addrlen) ) < 0 ||
84
(handles[1] = socket(AI->ai_family, AI->ai_socktype, 0)) < 0) {
81
85
closesocket(new_socket);
85
handle1_port = ntohs(serv_addr.sin_port);
87
if (connect(handles[1], (SOCKADDR *) & serv_addr, len) < 0 ||
88
(handles[0] = accept(new_socket, (SOCKADDR *) & serv_addr, &len)) < 0) {
89
handle0 = *AI; // retrieve the new details returned by connect()
91
handle1.SetPort(handle1.GetPort());
92
handle1.GetAddrInfo(AI);
94
if (connect(handles[1], AI->ai_addr, AI->ai_addrlen) < 0 ||
95
(handles[0] = accept(new_socket, AI->ai_addr, &(AI->ai_addrlen)) ) < 0) {
89
96
closesocket(handles[1]);
91
98
closesocket(new_socket);
95
102
closesocket(new_socket);
97
104
F = &fd_table[handles[0]];
98
F->local_addr = local_addr;
99
F->local_port = ntohs(serv_addr.sin_port);
105
F->local_addr = handle0;
101
107
F = &fd_table[handles[1]];
102
F->local_addr = local_addr;
103
xstrncpy(F->ipaddr, inet_ntoa(local_addr), 16);
104
F->remote_port = handle1_port;
108
F->local_addr = localhost;
109
handle1.NtoA(F->ipaddr, MAX_IPSTRLEN);
110
F->remote_port = handle1.GetPort();
124
130
FILETIME ftCreate, ftExit, ftKernel, ftUser;
126
132
if (GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser)) {
127
int64_t *ptUser = (int64_t *)&ftUser;
133
int64_t *ptUser = (int64_t *)&ftUser;
128
134
int64_t tUser64 = *ptUser / 10;
129
int64_t *ptKernel = (int64_t *)&ftKernel;
135
int64_t *ptKernel = (int64_t *)&ftKernel;
130
136
int64_t tKernel64 = *ptKernel / 10;
131
137
usage->ru_utime.tv_sec =(long)(tUser64 / 1000000);
132
138
usage->ru_stime.tv_sec =(long)(tKernel64 / 1000000);
157
163
int Win32__WSAFDIsSet(int fd, fd_set FAR * set
160
166
fde *F = &fd_table[fd];
161
167
SOCKET s = F->win32.handle;
163
return __WSAFDIsSet(s, set
169
return __WSAFDIsSet(s, set);
167
172
LONG CALLBACK WIN32_ExceptionHandler(EXCEPTION_POINTERS* ep)