34 |
|
#include "dbuf.h" |
35 |
|
#include "event.h" |
36 |
|
#include "irc_string.h" |
37 |
– |
#include "irc_getnameinfo.h" |
38 |
– |
#include "irc_getaddrinfo.h" |
37 |
|
#include "ircd.h" |
38 |
|
#include "listener.h" |
39 |
|
#include "numeric.h" |
40 |
|
#include "packet.h" |
41 |
|
#include "irc_res.h" |
44 |
– |
#include "inet_misc.h" |
42 |
|
#include "restart.h" |
43 |
|
#include "s_auth.h" |
44 |
|
#include "s_conf.h" |
195 |
|
send_queued_write(client_p); |
196 |
|
} |
197 |
|
|
198 |
< |
if (IsServer(client_p)) |
198 |
> |
if (IsClient(client_p)) |
199 |
> |
{ |
200 |
> |
++ServerStats.is_cl; |
201 |
> |
ServerStats.is_cbs += client_p->localClient->send.bytes; |
202 |
> |
ServerStats.is_cbr += client_p->localClient->recv.bytes; |
203 |
> |
ServerStats.is_cti += CurrentTime - client_p->firsttime; |
204 |
> |
} |
205 |
> |
else if (IsServer(client_p)) |
206 |
|
{ |
207 |
|
++ServerStats.is_sv; |
208 |
|
ServerStats.is_sbs += client_p->localClient->send.bytes; |
233 |
|
HANGONRETRYDELAY : ConFreq(aclass); |
234 |
|
} |
235 |
|
} |
232 |
– |
else if (IsClient(client_p)) |
233 |
– |
{ |
234 |
– |
++ServerStats.is_cl; |
235 |
– |
ServerStats.is_cbs += client_p->localClient->send.bytes; |
236 |
– |
ServerStats.is_cbr += client_p->localClient->recv.bytes; |
237 |
– |
ServerStats.is_cti += CurrentTime - client_p->firsttime; |
238 |
– |
} |
236 |
|
else |
237 |
|
++ServerStats.is_ni; |
238 |
|
|
304 |
|
void |
305 |
|
add_connection(struct Listener *listener, struct irc_ssaddr *irn, int fd) |
306 |
|
{ |
307 |
< |
struct Client *new_client; |
311 |
< |
|
312 |
< |
assert(NULL != listener); |
313 |
< |
|
314 |
< |
new_client = make_client(NULL); |
307 |
> |
struct Client *new_client = make_client(NULL); |
308 |
|
|
309 |
|
fd_open(&new_client->localClient->fd, fd, 1, |
310 |
|
(listener->flags & LISTENER_SSL) ? |
311 |
|
"Incoming SSL connection" : "Incoming connection"); |
312 |
|
|
313 |
< |
/* |
313 |
> |
/* |
314 |
|
* copy address to 'sockhost' as a string, copy it to host too |
315 |
|
* so we have something valid to put into error messages... |
316 |
|
*/ |
317 |
|
memcpy(&new_client->localClient->ip, irn, sizeof(struct irc_ssaddr)); |
318 |
|
|
319 |
< |
irc_getnameinfo((struct sockaddr*)&new_client->localClient->ip, |
320 |
< |
new_client->localClient->ip.ss_len, new_client->sockhost, |
321 |
< |
sizeof(new_client->sockhost), NULL, 0, NI_NUMERICHOST); |
319 |
> |
getnameinfo((struct sockaddr *)&new_client->localClient->ip, |
320 |
> |
new_client->localClient->ip.ss_len, new_client->sockhost, |
321 |
> |
sizeof(new_client->sockhost), NULL, 0, NI_NUMERICHOST); |
322 |
|
new_client->localClient->aftype = new_client->localClient->ip.ss.ss_family; |
330 |
– |
#ifdef IPV6 |
331 |
– |
if (new_client->sockhost[0] == ':') |
332 |
– |
strlcat(new_client->host, "0", HOSTLEN+1); |
323 |
|
|
324 |
< |
if (new_client->localClient->aftype == AF_INET6 && |
335 |
< |
ConfigFileEntry.dot_in_ip6_addr == 1) |
324 |
> |
if (new_client->sockhost[0] == ':' && new_client->sockhost[1] == ':') |
325 |
|
{ |
326 |
< |
strlcat(new_client->host, new_client->sockhost,HOSTLEN+1); |
327 |
< |
strlcat(new_client->host, ".", HOSTLEN+1); |
326 |
> |
strlcpy(new_client->host, "0", sizeof(new_client->host)); |
327 |
> |
strlcpy(new_client->host+1, new_client->sockhost, sizeof(new_client->host)-1); |
328 |
> |
memmove(new_client->sockhost+1, new_client->sockhost, sizeof(new_client->sockhost)-1); |
329 |
> |
new_client->sockhost[0] = '0'; |
330 |
|
} |
331 |
|
else |
332 |
< |
#endif |
342 |
< |
strlcat(new_client->host, new_client->sockhost,HOSTLEN+1); |
332 |
> |
strlcpy(new_client->host, new_client->sockhost, sizeof(new_client->host)); |
333 |
|
|
334 |
|
new_client->localClient->listener = listener; |
335 |
|
++listener->ref_count; |
516 |
|
|
517 |
|
snprintf(portname, sizeof(portname), "%d", port); |
518 |
|
|
519 |
< |
if (irc_getaddrinfo(host, portname, &hints, &res)) |
519 |
> |
if (getaddrinfo(host, portname, &hints, &res)) |
520 |
|
{ |
521 |
|
/* Send the DNS request, for the next level */ |
522 |
|
if (aftype == AF_INET6) |
532 |
|
memcpy(&fd->connect.hostaddr, res->ai_addr, res->ai_addrlen); |
533 |
|
fd->connect.hostaddr.ss_len = res->ai_addrlen; |
534 |
|
fd->connect.hostaddr.ss.ss_family = res->ai_family; |
535 |
< |
irc_freeaddrinfo(res); |
535 |
> |
freeaddrinfo(res); |
536 |
|
comm_settimeout(fd, timeout*1000, comm_connect_timeout, NULL); |
537 |
|
comm_connect_tryconnect(fd, NULL); |
538 |
|
} |
742 |
|
|
743 |
|
/* |
744 |
|
* remove_ipv6_mapping() - Removes IPv4-In-IPv6 mapping from an address |
745 |
< |
* This function should really inspect the struct itself rather than relying |
756 |
< |
* on inet_pton and inet_ntop. OSes with IPv6 mapping listening on both |
745 |
> |
* OSes with IPv6 mapping listening on both |
746 |
|
* AF_INET and AF_INET6 map AF_INET connections inside AF_INET6 structures |
747 |
|
* |
748 |
|
*/ |
752 |
|
{ |
753 |
|
if (addr->ss.ss_family == AF_INET6) |
754 |
|
{ |
755 |
< |
struct sockaddr_in6 *v6; |
767 |
< |
|
768 |
< |
v6 = (struct sockaddr_in6*)addr; |
769 |
< |
if (IN6_IS_ADDR_V4MAPPED(&v6->sin6_addr)) |
755 |
> |
if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr)) |
756 |
|
{ |
757 |
< |
char v4ip[HOSTIPLEN]; |
758 |
< |
struct sockaddr_in *v4 = (struct sockaddr_in*)addr; |
759 |
< |
inetntop(AF_INET6, &v6->sin6_addr, v4ip, HOSTIPLEN); |
760 |
< |
inet_pton(AF_INET, v4ip, &v4->sin_addr); |
757 |
> |
struct sockaddr_in6 v6; |
758 |
> |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
759 |
> |
|
760 |
> |
memcpy(&v6, addr, sizeof(v6)); |
761 |
> |
memset(v4, 0, sizeof(struct sockaddr_in)); |
762 |
> |
memcpy(&v4->sin_addr, &v6.sin6_addr.s6_addr[12], sizeof(v4->sin_addr)); |
763 |
> |
|
764 |
|
addr->ss.ss_family = AF_INET; |
765 |
|
addr->ss_len = sizeof(struct sockaddr_in); |
766 |
|
} |