258 |
|
|
259 |
|
#ifdef HAVE_LIBCRYPTO |
260 |
|
if (client_p->localClient->fd.ssl) |
261 |
< |
SSL_shutdown(client_p->localClient->fd.ssl); |
261 |
> |
{ |
262 |
> |
SSL_set_shutdown(client_p->localClient->fd.ssl, SSL_RECEIVED_SHUTDOWN); |
263 |
> |
|
264 |
> |
if (!SSL_shutdown(client_p->localClient->fd.ssl)) |
265 |
> |
SSL_shutdown(client_p->localClient->fd.ssl); |
266 |
> |
} |
267 |
|
#endif |
268 |
|
if (client_p->localClient->fd.flags.open) |
269 |
|
fd_close(&client_p->localClient->fd); |
322 |
|
* any client list yet. |
323 |
|
*/ |
324 |
|
void |
325 |
< |
add_connection(struct Listener* listener, int fd) |
325 |
> |
add_connection(struct Listener *listener, struct irc_ssaddr *irn, int fd) |
326 |
|
{ |
327 |
|
struct Client *new_client; |
323 |
– |
socklen_t len = sizeof(struct irc_ssaddr); |
324 |
– |
struct irc_ssaddr irn; |
325 |
– |
assert(NULL != listener); |
328 |
|
|
329 |
< |
/* |
328 |
< |
* get the client socket name from the socket |
329 |
< |
* the client has already been checked out in accept_connection |
330 |
< |
*/ |
331 |
< |
|
332 |
< |
memset(&irn, 0, sizeof(irn)); |
333 |
< |
if (getpeername(fd, (struct sockaddr *)&irn, (socklen_t *)&len)) |
334 |
< |
{ |
335 |
< |
#ifdef _WIN32 |
336 |
< |
errno = WSAGetLastError(); |
337 |
< |
#endif |
338 |
< |
report_error(L_ALL, "Failed in adding new connection %s :%s", |
339 |
< |
get_listener_name(listener), errno); |
340 |
< |
ServerStats->is_ref++; |
341 |
< |
#ifdef _WIN32 |
342 |
< |
closesocket(fd); |
343 |
< |
#else |
344 |
< |
close(fd); |
345 |
< |
#endif |
346 |
< |
return; |
347 |
< |
} |
329 |
> |
assert(NULL != listener); |
330 |
|
|
349 |
– |
#ifdef IPV6 |
350 |
– |
remove_ipv6_mapping(&irn); |
351 |
– |
#else |
352 |
– |
irn.ss_len = len; |
353 |
– |
#endif |
331 |
|
new_client = make_client(NULL); |
332 |
+ |
|
333 |
|
fd_open(&new_client->localClient->fd, fd, 1, |
334 |
|
(listener->flags & LISTENER_SSL) ? |
335 |
|
"Incoming SSL connection" : "Incoming connection"); |
358 |
– |
memset(&new_client->localClient->ip, 0, sizeof(struct irc_ssaddr)); |
336 |
|
|
337 |
|
/* |
338 |
|
* copy address to 'sockhost' as a string, copy it to host too |
339 |
|
* so we have something valid to put into error messages... |
340 |
|
*/ |
341 |
< |
new_client->localClient->port = ntohs(irn.ss_port); |
365 |
< |
memcpy(&new_client->localClient->ip, &irn, sizeof(struct irc_ssaddr)); |
341 |
> |
memcpy(&new_client->localClient->ip, irn, sizeof(struct irc_ssaddr)); |
342 |
|
|
343 |
|
irc_getnameinfo((struct sockaddr*)&new_client->localClient->ip, |
344 |
|
new_client->localClient->ip.ss_len, new_client->sockhost, |
345 |
|
HOSTIPLEN, NULL, 0, NI_NUMERICHOST); |
346 |
|
new_client->localClient->aftype = new_client->localClient->ip.ss.ss_family; |
371 |
– |
|
372 |
– |
*new_client->host = '\0'; |
347 |
|
#ifdef IPV6 |
348 |
< |
if (*new_client->sockhost == ':') |
348 |
> |
if (new_client->sockhost[0] == ':') |
349 |
|
strlcat(new_client->host, "0", HOSTLEN+1); |
350 |
|
|
351 |
|
if (new_client->localClient->aftype == AF_INET6 && |
353 |
|
{ |
354 |
|
strlcat(new_client->host, new_client->sockhost,HOSTLEN+1); |
355 |
|
strlcat(new_client->host, ".", HOSTLEN+1); |
356 |
< |
} else |
356 |
> |
} |
357 |
> |
else |
358 |
|
#endif |
359 |
|
strlcat(new_client->host, new_client->sockhost,HOSTLEN+1); |
360 |
|
|
361 |
+ |
new_client->connect_id = ++connect_id; |
362 |
|
new_client->localClient->listener = listener; |
363 |
|
++listener->ref_count; |
364 |
|
|
389 |
– |
connect_id++; |
390 |
– |
new_client->connect_id = connect_id; |
391 |
– |
|
365 |
|
#ifdef HAVE_LIBCRYPTO |
366 |
< |
if ((listener->flags & LISTENER_SSL)) |
366 |
> |
if (listener->flags & LISTENER_SSL) |
367 |
|
{ |
368 |
|
if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.ctx)) == NULL) |
369 |
|
{ |