1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* s_bsd.c: Network functions. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file s_bsd.c |
23 |
> |
* \brief Network functions. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
106 |
|
} |
107 |
|
|
108 |
|
/* |
109 |
< |
* report_error - report an error from an errno. |
109 |
> |
* report_error - report an error from an errno. |
110 |
|
* Record error to log and also send a copy to all *LOCAL* opers online. |
111 |
|
* |
112 |
|
* text is a *format* string for outputing error. It must |
120 |
|
* Cannot use perror() within daemon. stderr is closed in |
121 |
|
* ircd and cannot be used. And, worse yet, it might have |
122 |
|
* been reassigned to a normal connection... |
123 |
< |
* |
123 |
> |
* |
124 |
|
* Actually stderr is still there IFF ircd was run with -s --Rodder |
125 |
|
*/ |
126 |
|
|
127 |
|
void |
128 |
< |
report_error(int level, const char* text, const char* who, int error) |
128 |
> |
report_error(int level, const char* text, const char* who, int error) |
129 |
|
{ |
130 |
|
who = (who) ? who : ""; |
131 |
|
|
221 |
|
|
222 |
|
dbuf_clear(&client_p->localClient->buf_sendq); |
223 |
|
dbuf_clear(&client_p->localClient->buf_recvq); |
224 |
< |
|
224 |
> |
|
225 |
|
MyFree(client_p->localClient->passwd); |
226 |
|
detach_conf(client_p, CONF_CLIENT|CONF_OPER|CONF_SERVER); |
227 |
|
client_p->from = NULL; /* ...this should catch them! >:) --msa */ |
250 |
|
{ |
251 |
|
case SSL_ERROR_WANT_WRITE: |
252 |
|
comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE, |
253 |
< |
(PF *) ssl_handshake, client_p, 30); |
253 |
> |
(PF *)ssl_handshake, client_p, 30); |
254 |
|
return; |
255 |
|
|
256 |
|
case SSL_ERROR_WANT_READ: |
257 |
|
comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ, |
258 |
< |
(PF *) ssl_handshake, client_p, 30); |
258 |
> |
(PF *)ssl_handshake, client_p, 30); |
259 |
|
return; |
260 |
|
|
261 |
|
default: |
262 |
|
exit_client(client_p, client_p, "Error during SSL handshake"); |
263 |
< |
return; |
263 |
> |
return; |
264 |
|
} |
265 |
|
} |
266 |
|
|
296 |
|
#endif |
297 |
|
|
298 |
|
/* |
299 |
< |
* add_connection - creates a client which has just connected to us on |
299 |
> |
* add_connection - creates a client which has just connected to us on |
300 |
|
* the given fd. The sockhost field is initialized with the ip# of the host. |
301 |
|
* An unique id is calculated now, in case it is needed for auth. |
302 |
|
* The client is sent to the auth module for verification, and not put in |
309 |
|
|
310 |
|
fd_open(&new_client->localClient->fd, fd, 1, |
311 |
|
(listener->flags & LISTENER_SSL) ? |
312 |
< |
"Incoming SSL connection" : "Incoming connection"); |
312 |
> |
"Incoming SSL connection" : "Incoming connection"); |
313 |
|
|
314 |
|
/* |
315 |
|
* copy address to 'sockhost' as a string, copy it to host too |
318 |
|
memcpy(&new_client->localClient->ip, irn, sizeof(struct irc_ssaddr)); |
319 |
|
|
320 |
|
getnameinfo((struct sockaddr *)&new_client->localClient->ip, |
321 |
< |
new_client->localClient->ip.ss_len, new_client->sockhost, |
321 |
> |
new_client->localClient->ip.ss_len, new_client->sockhost, |
322 |
|
sizeof(new_client->sockhost), NULL, 0, NI_NUMERICHOST); |
323 |
|
new_client->localClient->aftype = new_client->localClient->ip.ss.ss_family; |
324 |
|
|
418 |
|
* flush functions, and when comm_close() is implemented correctly |
419 |
|
* with close functions, we _actually_ don't call comm_close() here .. |
420 |
|
* -- originally Adrian's notes |
421 |
< |
* comm_close() is replaced with fd_close() in fdlist.c |
421 |
> |
* comm_close() is replaced with fd_close() in fdlist.c |
422 |
|
*/ |
423 |
|
void |
424 |
|
comm_setflush(fde_t *fd, time_t timeout, PF *callback, void *cbdata) |
510 |
|
* -- adrian |
511 |
|
*/ |
512 |
|
if ((clocal != NULL) && (bind(fd->fd, clocal, socklen) < 0)) |
513 |
< |
{ |
513 |
> |
{ |
514 |
|
/* Failure, call the callback with COMM_ERR_BIND */ |
515 |
|
comm_connect_callback(fd, COMM_ERR_BIND); |
516 |
|
/* ... and quit */ |
607 |
|
/* Copy over the DNS reply info so we can use it in the connect() */ |
608 |
|
/* |
609 |
|
* Note we don't fudge the refcount here, because we aren't keeping |
610 |
< |
* the DNS record around, and the DNS cache is gone anyway.. |
610 |
> |
* the DNS record around, and the DNS cache is gone anyway.. |
611 |
|
* -- adrian |
612 |
|
*/ |
613 |
|
memcpy(&F->connect.hostaddr, addr, addr->ss_len); |
638 |
|
return; |
639 |
|
|
640 |
|
/* Try the connect() */ |
641 |
< |
retval = connect(fd->fd, (struct sockaddr *) &fd->connect.hostaddr, |
641 |
> |
retval = connect(fd->fd, (struct sockaddr *) &fd->connect.hostaddr, |
642 |
|
fd->connect.hostaddr.ss_len); |
643 |
|
|
644 |
|
/* Error? */ |
751 |
|
return newfd; |
752 |
|
} |
753 |
|
|
754 |
< |
/* |
754 |
> |
/* |
755 |
|
* remove_ipv6_mapping() - Removes IPv4-In-IPv6 mapping from an address |
756 |
|
* OSes with IPv6 mapping listening on both |
757 |
|
* AF_INET and AF_INET6 map AF_INET connections inside AF_INET6 structures |
758 |
< |
* |
758 |
> |
* |
759 |
|
*/ |
760 |
|
#ifdef IPV6 |
761 |
|
void |
765 |
|
{ |
766 |
|
if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr)) |
767 |
|
{ |
768 |
< |
struct sockaddr_in6 v6; |
768 |
> |
struct sockaddr_in6 v6; |
769 |
|
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
770 |
|
|
771 |
|
memcpy(&v6, addr, sizeof(v6)); |
775 |
|
addr->ss.ss_family = AF_INET; |
776 |
|
addr->ss_len = sizeof(struct sockaddr_in); |
777 |
|
} |
778 |
< |
else |
778 |
> |
else |
779 |
|
addr->ss_len = sizeof(struct sockaddr_in6); |
780 |
|
} |
781 |
|
else |
782 |
|
addr->ss_len = sizeof(struct sockaddr_in); |
783 |
< |
} |
783 |
> |
} |
784 |
|
#endif |