ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/s_bsd.c
Revision: 8265
Committed: Sat Jun 3 20:11:37 2017 UTC (8 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 20933 byte(s)
Log Message:
- s_bsd.c: from p4: add_connection(): clean up logic for ips beginning with :

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2017 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
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file s_bsd.c
23 * \brief Network functions.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include <netinet/in_systm.h>
29 #include <netinet/ip.h>
30 #include <netinet/tcp.h>
31 #include "list.h"
32 #include "fdlist.h"
33 #include "s_bsd.h"
34 #include "client.h"
35 #include "dbuf.h"
36 #include "event.h"
37 #include "irc_string.h"
38 #include "ircd.h"
39 #include "listener.h"
40 #include "numeric.h"
41 #include "packet.h"
42 #include "res.h"
43 #include "restart.h"
44 #include "auth.h"
45 #include "conf.h"
46 #include "log.h"
47 #include "server.h"
48 #include "send.h"
49 #include "memory.h"
50 #include "user.h"
51
52
53 static const char *const comm_err_str[] =
54 {
55 [COMM_OK] = "Comm OK",
56 [COMM_ERR_BIND] = "Error during bind()",
57 [COMM_ERR_DNS] = "Error during DNS lookup",
58 [COMM_ERR_TIMEOUT] = "connect timeout",
59 [COMM_ERR_CONNECT] = "Error during connect()",
60 [COMM_ERROR] = "Comm Error"
61 };
62
63 static void comm_connect_callback(fde_t *, int);
64 static void comm_connect_timeout(fde_t *, void *);
65 static void comm_connect_dns_callback(void *, const struct irc_ssaddr *, const char *, size_t);
66 static void comm_connect_tryconnect(fde_t *, void *);
67
68
69 /* get_sockerr - get the error value from the socket or the current errno
70 *
71 * Get the *real* error from the socket (well try to anyway..).
72 * This may only work when SO_DEBUG is enabled but its worth the
73 * gamble anyway.
74 */
75 int
76 get_sockerr(int fd)
77 {
78 int errtmp = errno;
79 #ifdef SO_ERROR
80 int err = 0;
81 socklen_t len = sizeof(err);
82
83 if (-1 < fd && !getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len))
84 {
85 if (err)
86 errtmp = err;
87 }
88 errno = errtmp;
89 #endif
90 return errtmp;
91 }
92
93 /*
94 * report_error - report an error from an errno.
95 * Record error to log and also send a copy to all *LOCAL* opers online.
96 *
97 * text is a *format* string for outputing error. It must
98 * contain only two '%s', the first will be replaced
99 * by the sockhost from the client_p, and the latter will
100 * be taken from sys_errlist[errno].
101 *
102 * client_p if not NULL, is the *LOCAL* client associated with
103 * the error.
104 *
105 * Cannot use perror() within daemon. stderr is closed in
106 * ircd and cannot be used. And, worse yet, it might have
107 * been reassigned to a normal connection...
108 *
109 * Actually stderr is still there IFF ircd was run with -s --Rodder
110 */
111
112 void
113 report_error(int level, const char* text, const char* who, int error)
114 {
115 who = (who) ? who : "";
116
117 sendto_realops_flags(UMODE_DEBUG, level, SEND_NOTICE,
118 text, who, strerror(error));
119 ilog(LOG_TYPE_IRCD, text, who, strerror(error));
120 }
121
122 /*
123 * setup_socket()
124 *
125 * Set the socket non-blocking, and other wonderful bits.
126 */
127 static void
128 setup_socket(int fd)
129 {
130 int opt = 1;
131
132 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
133
134 #ifdef IPTOS_LOWDELAY
135 opt = IPTOS_LOWDELAY;
136 setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt));
137 #endif
138
139 fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
140 }
141
142 /*
143 * close_connection
144 * Close the physical connection. This function must make
145 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
146 */
147 void
148 close_connection(struct Client *client_p)
149 {
150 assert(client_p);
151
152 if (!IsDead(client_p))
153 {
154 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
155 /* there is still a chance that we might send data to this socket
156 * even if it is marked as blocked (COMM_SELECT_READ handler is called
157 * before COMM_SELECT_WRITE). Let's try, nothing to lose.. -adx
158 */
159 DelFlag(client_p, FLAGS_BLOCKED);
160 send_queued_write(client_p);
161 }
162
163 if (IsClient(client_p))
164 {
165 ++ServerStats.is_cl;
166 ServerStats.is_cbs += client_p->connection->send.bytes;
167 ServerStats.is_cbr += client_p->connection->recv.bytes;
168 ServerStats.is_cti += CurrentTime - client_p->connection->firsttime;
169 }
170 else if (IsServer(client_p))
171 {
172 dlink_node *node = NULL;
173
174 ++ServerStats.is_sv;
175 ServerStats.is_sbs += client_p->connection->send.bytes;
176 ServerStats.is_sbr += client_p->connection->recv.bytes;
177 ServerStats.is_sti += CurrentTime - client_p->connection->firsttime;
178
179 DLINK_FOREACH(node, connect_items.head)
180 {
181 struct MaskItem *conf = node->data;
182
183 if (irccmp(conf->name, client_p->name))
184 continue;
185
186 /*
187 * Reset next-connect cycle of all connect{} blocks that match
188 * this servername.
189 */
190 conf->until = CurrentTime + conf->class->con_freq;
191 }
192 }
193 else
194 ++ServerStats.is_ni;
195
196 if (tls_isusing(&client_p->connection->fd.ssl))
197 tls_shutdown(&client_p->connection->fd.ssl);
198
199 if (client_p->connection->fd.flags.open)
200 fd_close(&client_p->connection->fd);
201
202 dbuf_clear(&client_p->connection->buf_sendq);
203 dbuf_clear(&client_p->connection->buf_recvq);
204
205 xfree(client_p->connection->password);
206 client_p->connection->password = NULL;
207
208 detach_conf(client_p, CONF_CLIENT | CONF_OPER | CONF_SERVER);
209 }
210
211 /*
212 * ssl_handshake - let OpenSSL initialize the protocol. Register for
213 * read/write events if necessary.
214 */
215 static void
216 ssl_handshake(fde_t *fd, void *data)
217 {
218 struct Client *client_p = data;
219
220 tls_handshake_status_t ret = tls_handshake(&client_p->connection->fd.ssl, TLS_ROLE_SERVER, NULL);
221 if (ret != TLS_HANDSHAKE_DONE)
222 {
223 if ((CurrentTime - client_p->connection->firsttime) > CONNECTTIMEOUT)
224 {
225 exit_client(client_p, "Timeout during TLS handshake");
226 return;
227 }
228
229 switch (ret)
230 {
231 case TLS_HANDSHAKE_WANT_WRITE:
232 comm_setselect(&client_p->connection->fd, COMM_SELECT_WRITE,
233 ssl_handshake, client_p, CONNECTTIMEOUT);
234 return;
235 case TLS_HANDSHAKE_WANT_READ:
236 comm_setselect(&client_p->connection->fd, COMM_SELECT_READ,
237 ssl_handshake, client_p, CONNECTTIMEOUT);
238 return;
239 default:
240 exit_client(client_p, "Error during TLS handshake");
241 return;
242 }
243 }
244
245 comm_settimeout(&client_p->connection->fd, 0, NULL, NULL);
246
247 if (!tls_verify_cert(&client_p->connection->fd.ssl, ConfigServerInfo.message_digest_algorithm, &client_p->certfp))
248 ilog(LOG_TYPE_IRCD, "Client %s!%s@%s gave bad TLS client certificate",
249 client_p->name, client_p->username, client_p->host);
250
251 auth_start(client_p);
252 }
253
254 /*
255 * add_connection - creates a client which has just connected to us on
256 * the given fd. The sockhost field is initialized with the ip# of the host.
257 * An unique id is calculated now, in case it is needed for auth.
258 * The client is sent to the auth module for verification, and not put in
259 * any client list yet.
260 */
261 void
262 add_connection(struct Listener *listener, struct irc_ssaddr *irn, int fd)
263 {
264 struct Client *client_p = client_make(NULL);
265
266 fd_open(&client_p->connection->fd, fd, 1,
267 (listener->flags & LISTENER_SSL) ?
268 "Incoming SSL connection" : "Incoming connection");
269
270 /*
271 * copy address to 'sockhost' as a string, copy it to host too
272 * so we have something valid to put into error messages...
273 */
274 memcpy(&client_p->connection->ip, irn, sizeof(struct irc_ssaddr));
275
276 getnameinfo((const struct sockaddr *)&client_p->connection->ip,
277 client_p->connection->ip.ss_len, client_p->sockhost,
278 sizeof(client_p->sockhost), NULL, 0, NI_NUMERICHOST);
279 client_p->connection->aftype = client_p->connection->ip.ss.ss_family;
280
281 #ifdef HAVE_LIBGEOIP
282 if (irn->ss.ss_family == AF_INET && GeoIPv4_ctx)
283 {
284 GeoIPLookup gl;
285 const struct sockaddr_in *const v4 = (const struct sockaddr_in *)&client_p->connection->ip;
286 client_p->connection->country_id = GeoIP_id_by_ipnum_gl(GeoIPv4_ctx, (unsigned long)ntohl(v4->sin_addr.s_addr), &gl);
287 }
288 else if (irn->ss.ss_family == AF_INET6 && GeoIPv6_ctx)
289 {
290 GeoIPLookup gl;
291 const struct sockaddr_in6 *const v6 = (const struct sockaddr_in6 *)&client_p->connection->ip;
292 client_p->connection->country_id = GeoIP_id_by_ipnum_v6_gl(GeoIPv6_ctx, v6->sin6_addr, &gl);
293 }
294 #endif
295
296 if (client_p->sockhost[0] == ':')
297 {
298 client_p->sockhost[0] = '0';
299 memmove(client_p->sockhost + 1, client_p->sockhost, sizeof(client_p->sockhost) - 1);
300 }
301
302 strlcpy(client_p->host, client_p->sockhost, sizeof(client_p->host));
303
304 client_p->connection->listener = listener;
305 ++listener->ref_count;
306
307 if (listener->flags & LISTENER_SSL)
308 {
309 if (!tls_new(&client_p->connection->fd.ssl, fd, TLS_ROLE_SERVER))
310 {
311 SetDead(client_p);
312 exit_client(client_p, "TLS context initialization failed");
313 return;
314 }
315
316 AddFlag(client_p, FLAGS_SSL);
317 ssl_handshake(NULL, client_p);
318 }
319 else
320 auth_start(client_p);
321 }
322
323 /*
324 * stolen from squid - its a neat (but overused! :) routine which we
325 * can use to see whether we can ignore this errno or not. It is
326 * generally useful for non-blocking network IO related errnos.
327 * -- adrian
328 */
329 int
330 ignoreErrno(int ierrno)
331 {
332 switch (ierrno)
333 {
334 case EINPROGRESS:
335 case EWOULDBLOCK:
336 #if EAGAIN != EWOULDBLOCK
337 case EAGAIN:
338 #endif
339 case EALREADY:
340 case EINTR:
341 #ifdef ERESTART
342 case ERESTART:
343 #endif
344 return 1;
345 default:
346 return 0;
347 }
348 }
349
350 /*
351 * comm_settimeout() - set the socket timeout
352 *
353 * Set the timeout for the fd
354 */
355 void
356 comm_settimeout(fde_t *fd, uintmax_t timeout, void (*callback)(fde_t *, void *), void *cbdata)
357 {
358 assert(fd->flags.open);
359
360 fd->timeout = CurrentTime + (timeout / 1000);
361 fd->timeout_handler = callback;
362 fd->timeout_data = cbdata;
363 }
364
365 /*
366 * comm_setflush() - set a flush function
367 *
368 * A flush function is simply a function called if found during
369 * comm_timeouts(). Its basically a second timeout, except in this case
370 * I'm too lazy to implement multiple timeout functions! :-)
371 * its kinda nice to have it separate, since this is designed for
372 * flush functions, and when comm_close() is implemented correctly
373 * with close functions, we _actually_ don't call comm_close() here ..
374 * -- originally Adrian's notes
375 * comm_close() is replaced with fd_close() in fdlist.c
376 */
377 void
378 comm_setflush(fde_t *fd, uintmax_t timeout, void (*callback)(fde_t *, void *), void *cbdata)
379 {
380 assert(fd->flags.open);
381
382 fd->flush_timeout = CurrentTime + (timeout / 1000);
383 fd->flush_handler = callback;
384 fd->flush_data = cbdata;
385 }
386
387 /*
388 * comm_checktimeouts() - check the socket timeouts
389 *
390 * All this routine does is call the given callback/cbdata, without closing
391 * down the file descriptor. When close handlers have been implemented,
392 * this will happen.
393 */
394 void
395 comm_checktimeouts(void *unused)
396 {
397 fde_t *F;
398 void (*hdl)(fde_t *, void *);
399 void *data;
400
401 for (unsigned int i = 0; i < FD_HASH_SIZE; i++)
402 {
403 for (F = fd_hash[i]; F != NULL; F = fd_next_in_loop)
404 {
405 assert(F->flags.open);
406 fd_next_in_loop = F->hnext;
407
408 /* check flush functions */
409 if (F->flush_handler && F->flush_timeout > 0 &&
410 F->flush_timeout < CurrentTime)
411 {
412 hdl = F->flush_handler;
413 data = F->flush_data;
414 comm_setflush(F, 0, NULL, NULL);
415 hdl(F, data);
416 }
417
418 /* check timeouts */
419 if (F->timeout_handler && F->timeout > 0 &&
420 F->timeout < CurrentTime)
421 {
422 /* Call timeout handler */
423 hdl = F->timeout_handler;
424 data = F->timeout_data;
425 comm_settimeout(F, 0, NULL, NULL);
426 hdl(F, data);
427 }
428 }
429 }
430 }
431
432 /*
433 * void comm_connect_tcp(int fd, const char *host, unsigned short port,
434 * struct sockaddr *clocal, int socklen,
435 * CNCB *callback, void *data, int aftype, int timeout)
436 * Input: An fd to connect with, a host and port to connect to,
437 * a local sockaddr to connect from + length(or NULL to use the
438 * default), a callback, the data to pass into the callback, the
439 * address family.
440 * Output: None.
441 * Side-effects: A non-blocking connection to the host is started, and
442 * if necessary, set up for selection. The callback given
443 * may be called now, or it may be called later.
444 */
445 void
446 comm_connect_tcp(fde_t *fd, const char *host, unsigned short port, struct sockaddr *clocal,
447 int socklen, void (*callback)(fde_t *, int, void *), void *data,
448 int aftype, uintmax_t timeout)
449 {
450 struct addrinfo hints, *res;
451 char portname[PORTNAMELEN + 1];
452
453 assert(callback);
454 fd->connect.callback = callback;
455 fd->connect.data = data;
456
457 fd->connect.hostaddr.ss.ss_family = aftype;
458 fd->connect.hostaddr.ss_port = htons(port);
459
460 /* Note that we're using a passed sockaddr here. This is because
461 * generally you'll be bind()ing to a sockaddr grabbed from
462 * getsockname(), so this makes things easier.
463 * XXX If NULL is passed as local, we should later on bind() to the
464 * virtual host IP, for completeness.
465 * -- adrian
466 */
467 if (clocal && bind(fd->fd, clocal, socklen) < 0)
468 {
469 /* Failure, call the callback with COMM_ERR_BIND */
470 comm_connect_callback(fd, COMM_ERR_BIND);
471 return; /* ... and quit */
472 }
473
474 memset(&hints, 0, sizeof(hints));
475
476 hints.ai_family = AF_UNSPEC;
477 hints.ai_socktype = SOCK_STREAM;
478 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
479
480 snprintf(portname, sizeof(portname), "%d", port);
481
482 /*
483 * Next, if we have been given an IP address, get the address and skip the
484 * DNS check (and head direct to comm_connect_tryconnect()).
485 */
486 if (getaddrinfo(host, portname, &hints, &res))
487 {
488 /* Send the DNS request, for the next level */
489 if (aftype == AF_INET6)
490 gethost_byname_type(comm_connect_dns_callback, fd, host, T_AAAA);
491 else
492 gethost_byname_type(comm_connect_dns_callback, fd, host, T_A);
493 }
494 else
495 {
496 /* We have a valid IP, so we just call tryconnect */
497 /* Make sure we actually set the timeout here .. */
498 assert(res);
499
500 memcpy(&fd->connect.hostaddr, res->ai_addr, res->ai_addrlen);
501 fd->connect.hostaddr.ss_len = res->ai_addrlen;
502 fd->connect.hostaddr.ss.ss_family = res->ai_family;
503 freeaddrinfo(res);
504
505 comm_settimeout(fd, timeout * 1000, comm_connect_timeout, NULL);
506 comm_connect_tryconnect(fd, NULL);
507 }
508 }
509
510 /*
511 * comm_connect_callback() - call the callback, and continue with life
512 */
513 static void
514 comm_connect_callback(fde_t *fd, int status)
515 {
516 void (*hdl)(fde_t *, int, void *);
517
518 /* This check is gross..but probably necessary */
519 if (fd->connect.callback == NULL)
520 return;
521
522 /* Clear the connect flag + handler */
523 hdl = fd->connect.callback;
524 fd->connect.callback = NULL;
525
526 /* Clear the timeout handler */
527 comm_settimeout(fd, 0, NULL, NULL);
528
529 /* Call the handler */
530 hdl(fd, status, fd->connect.data);
531 }
532
533 /*
534 * comm_connect_timeout() - this gets called when the socket connection
535 * times out. This *only* can be called once connect() is initially
536 * called ..
537 */
538 static void
539 comm_connect_timeout(fde_t *fd, void *unused)
540 {
541 /* error! */
542 comm_connect_callback(fd, COMM_ERR_TIMEOUT);
543 }
544
545 /*
546 * comm_connect_dns_callback() - called at the completion of the DNS request
547 *
548 * The DNS request has completed, so if we've got an error, return it,
549 * otherwise we initiate the connect()
550 */
551 static void
552 comm_connect_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
553 {
554 fde_t *const F = vptr;
555
556 if (!addr)
557 {
558 comm_connect_callback(F, COMM_ERR_DNS);
559 return;
560 }
561
562 /* No error, set a 10 second timeout */
563 comm_settimeout(F, 30*1000, comm_connect_timeout, NULL);
564
565 /* Copy over the DNS reply info so we can use it in the connect() */
566 /*
567 * Note we don't fudge the refcount here, because we aren't keeping
568 * the DNS record around, and the DNS cache is gone anyway..
569 * -- adrian
570 */
571 memcpy(&F->connect.hostaddr, addr, addr->ss_len);
572
573 /* The cast is hacky, but safe - port offset is same on v4 and v6 */
574 ((struct sockaddr_in *)&F->connect.hostaddr)->sin_port = F->connect.hostaddr.ss_port;
575 F->connect.hostaddr.ss_len = addr->ss_len;
576
577 /* Now, call the tryconnect() routine to try a connect() */
578 comm_connect_tryconnect(F, NULL);
579 }
580
581 /* static void comm_connect_tryconnect(int fd, void *unused)
582 * Input: The fd, the handler data(unused).
583 * Output: None.
584 * Side-effects: Try and connect with pending connect data for the FD. If
585 * we succeed or get a fatal error, call the callback.
586 * Otherwise, it is still blocking or something, so register
587 * to select for a write event on this FD.
588 */
589 static void
590 comm_connect_tryconnect(fde_t *fd, void *unused)
591 {
592 /* This check is needed or re-entrant s_bsd_* like sigio break it. */
593 if (fd->connect.callback == NULL)
594 return;
595
596 /* Try the connect() */
597 int retval = connect(fd->fd, (struct sockaddr *)&fd->connect.hostaddr, fd->connect.hostaddr.ss_len);
598
599 /* Error? */
600 if (retval < 0)
601 {
602 /*
603 * If we get EISCONN, then we've already connect()ed the socket,
604 * which is a good thing.
605 * -- adrian
606 */
607 if (errno == EISCONN)
608 comm_connect_callback(fd, COMM_OK);
609 else if (ignoreErrno(errno))
610 /* Ignore error? Reschedule */
611 comm_setselect(fd, COMM_SELECT_WRITE, comm_connect_tryconnect, NULL, 0);
612 else
613 /* Error? Fail with COMM_ERR_CONNECT */
614 comm_connect_callback(fd, COMM_ERR_CONNECT);
615 return;
616 }
617
618 /* If we get here, we've suceeded, so call with COMM_OK */
619 comm_connect_callback(fd, COMM_OK);
620 }
621
622 /*
623 * comm_errorstr() - return an error string for the given error condition
624 */
625 const char *
626 comm_errstr(int error)
627 {
628 if (error < 0 || error >= COMM_ERR_MAX)
629 return "Invalid error number!";
630 return comm_err_str[error];
631 }
632
633 /*
634 * comm_open() - open a socket
635 *
636 * This is a highly highly cut down version of squid's comm_open() which
637 * for the most part emulates socket(), *EXCEPT* it fails if we're about
638 * to run out of file descriptors.
639 */
640 int
641 comm_open(fde_t *F, int family, int sock_type, int proto, const char *note)
642 {
643 /* First, make sure we aren't going to run out of file descriptors */
644 if (number_fd >= hard_fdlimit)
645 {
646 errno = ENFILE;
647 return -1;
648 }
649
650 /*
651 * Next, we try to open the socket. We *should* drop the reserved FD
652 * limit if/when we get an error, but we can deal with that later.
653 * XXX !!! -- adrian
654 */
655 int fd = socket(family, sock_type, proto);
656 if (fd < 0)
657 return -1; /* errno will be passed through, yay.. */
658
659 setup_socket(fd);
660
661 /* update things in our fd tracking */
662 fd_open(F, fd, 1, note);
663 return 0;
664 }
665
666 /*
667 * comm_accept() - accept an incoming connection
668 *
669 * This is a simple wrapper for accept() which enforces FD limits like
670 * comm_open() does. Returned fd must be either closed or tagged with
671 * fd_open (this function no longer does it).
672 */
673 int
674 comm_accept(fde_t *F, struct irc_ssaddr *addr)
675 {
676 socklen_t addrlen = sizeof(struct irc_ssaddr);
677
678 if (number_fd >= hard_fdlimit)
679 {
680 errno = ENFILE;
681 return -1;
682 }
683
684 memset(addr, 0, sizeof(struct irc_ssaddr));
685
686 /*
687 * Next, do the accept(). if we get an error, we should drop the
688 * reserved fd limit, but we can deal with that when comm_open()
689 * also does it. XXX -- adrian
690 */
691 int fd = accept(F->fd, (struct sockaddr *)addr, &addrlen);
692 if (fd < 0)
693 return -1;
694
695 remove_ipv6_mapping(addr);
696
697 setup_socket(fd);
698
699 /* .. and return */
700 return fd;
701 }
702
703 /*
704 * remove_ipv6_mapping() - Removes IPv4-In-IPv6 mapping from an address
705 * OSes with IPv6 mapping listening on both
706 * AF_INET and AF_INET6 map AF_INET connections inside AF_INET6 structures
707 *
708 */
709 void
710 remove_ipv6_mapping(struct irc_ssaddr *addr)
711 {
712 if (addr->ss.ss_family == AF_INET6)
713 {
714 if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr))
715 {
716 struct sockaddr_in6 v6;
717 struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
718
719 memcpy(&v6, addr, sizeof(v6));
720 memset(v4, 0, sizeof(struct sockaddr_in));
721 memcpy(&v4->sin_addr, &v6.sin6_addr.s6_addr[12], sizeof(v4->sin_addr));
722
723 addr->ss.ss_family = AF_INET;
724 addr->ss_len = sizeof(struct sockaddr_in);
725 }
726 else
727 addr->ss_len = sizeof(struct sockaddr_in6);
728 }
729 else
730 addr->ss_len = sizeof(struct sockaddr_in);
731 }

Properties

Name Value
svn:eol-style native
svn:keywords Id