ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/s_bsd.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/s_bsd.c (file contents), Revision 896 by michael, Sat Nov 3 08:54:09 2007 UTC vs.
ircd-hybrid-7.3/src/s_bsd.c (file contents), Revision 1029 by michael, Sun Nov 8 13:10:50 2009 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 #ifndef _WIN32
26   #include <netinet/in_systm.h>
27   #include <netinet/ip.h>
28   #include <netinet/tcp.h>
29 < #endif
29 > #include "list.h"
30   #include "fdlist.h"
31   #include "s_bsd.h"
32   #include "client.h"
# Line 38 | Line 37
37   #include "irc_getnameinfo.h"
38   #include "irc_getaddrinfo.h"
39   #include "ircd.h"
41 #include "list.h"
40   #include "listener.h"
41   #include "numeric.h"
42   #include "packet.h"
# Line 60 | Line 58 | static const char *comm_err_str[] = { "C
58  
59   struct Callback *setup_socket_cb = NULL;
60  
61 < static void comm_connect_callback(fde_t *fd, int status);
61 > static void comm_connect_callback(fde_t *, int);
62   static PF comm_connect_timeout;
63 < static void comm_connect_dns_callback(void *vptr, struct DNSReply *reply);
63 > static void comm_connect_dns_callback(void *, const struct irc_ssaddr *, const char *);
64   static PF comm_connect_tryconnect;
65  
68 extern void init_netio(void);
66  
67   /* check_can_use_v6()
68   *  Check if the system can open AF_INET6 sockets
# Line 81 | Line 78 | check_can_use_v6(void)
78    else
79    {
80      ServerInfo.can_use_v6 = 1;
84 #ifdef _WIN32
85    closesocket(v6);
86 #else
81      close(v6);
88 #endif
82    }
83   #else
84    ServerInfo.can_use_v6 = 0;
# Line 101 | Line 94 | check_can_use_v6(void)
94   int
95   get_sockerr(int fd)
96   {
104 #ifndef _WIN32
97    int errtmp = errno;
106 #else
107  int errtmp = WSAGetLastError();
108 #endif
98   #ifdef SO_ERROR
99    int err = 0;
100    socklen_t len = sizeof(err);
101  
102 <  if (-1 < fd && !getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &err, (socklen_t *)&len))
102 >  if (-1 < fd && !getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len))
103    {
104      if (err)
105        errtmp = err;
# Line 160 | Line 149 | setup_socket(va_list args)
149    int fd = va_arg(args, int);
150    int opt = 1;
151  
152 <  setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &opt, sizeof(opt));
152 >  setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
153  
154   #ifdef IPTOS_LOWDELAY
155    opt = IPTOS_LOWDELAY;
156 <  setsockopt(fd, IPPROTO_IP, IP_TOS, (char *) &opt, sizeof(opt));
156 >  setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt));
157   #endif
158  
170 #ifndef _WIN32
159    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
172 #endif
160  
161    return NULL;
162   }
# Line 226 | Line 213 | close_connection(struct Client *client_p
213       * If the connection has been up for a long amount of time, schedule
214       * a 'quick' reconnect, else reset the next-connect cycle.
215       */
216 <    if ((conf = find_conf_exact(SERVER_TYPE,
217 <                                  client_p->name, client_p->username,
231 <                                  client_p->host)))
216 >    if ((conf = find_conf_exact(SERVER_TYPE, client_p->name,
217 >                                client_p->username, client_p->host)))
218      {
219        /*
220         * Reschedule a faster reconnect, if this was a automatically
# Line 236 | Line 222 | close_connection(struct Client *client_p
222         * a rehash in between, the status has been changed to
223         * CONF_ILLEGAL). But only do this if it was a "good" link.
224         */
225 <      aconf = (struct AccessItem *)map_to_conf(conf);
226 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
225 >      aconf  = map_to_conf(conf);
226 >      aclass = map_to_conf(aconf->class_ptr);
227        aconf->hold = time(NULL);
228        aconf->hold += (aconf->hold - client_p->since > HANGONGOODLINK) ?
229          HANGONRETRYDELAY : ConFreq(aclass);
244      if (nextconnect > aconf->hold)
245        nextconnect = aconf->hold;
230      }
231    }
232    else if (IsClient(client_p))
# Line 340 | Line 324 | add_connection(struct Listener *listener
324    memcpy(&new_client->localClient->ip, irn, sizeof(struct irc_ssaddr));
325  
326    irc_getnameinfo((struct sockaddr*)&new_client->localClient->ip,
327 <        new_client->localClient->ip.ss_len,  new_client->sockhost,
328 <        HOSTIPLEN, NULL, 0, NI_NUMERICHOST);
327 >        new_client->localClient->ip.ss_len, new_client->sockhost,
328 >        sizeof(new_client->sockhost), NULL, 0, NI_NUMERICHOST);
329    new_client->localClient->aftype = new_client->localClient->ip.ss.ss_family;
330   #ifdef IPV6
331    if (new_client->sockhost[0] == ':')
# Line 357 | Line 341 | add_connection(struct Listener *listener
341   #endif
342      strlcat(new_client->host, new_client->sockhost,HOSTLEN+1);
343  
360  new_client->connect_id = ++connect_id;
344    new_client->localClient->listener = listener;
345    ++listener->ref_count;
346  
347   #ifdef HAVE_LIBCRYPTO
348    if (listener->flags & LISTENER_SSL)
349    {
350 <    if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.ctx)) == NULL)
350 >    if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.server_ctx)) == NULL)
351      {
352        ilog(L_CRIT, "SSL_new() ERROR! -- %s",
353             ERR_error_string(ERR_get_error(), NULL));
# Line 509 | Line 492 | comm_connect_tcp(fde_t *fd, const char *
492                   void *data, int aftype, int timeout)
493   {
494    struct addrinfo hints, *res;
495 <  char portname[PORTNAMELEN+1];
495 >  char portname[PORTNAMELEN + 1];
496  
497    assert(callback);
498    fd->connect.callback = callback;
# Line 541 | Line 524 | comm_connect_tcp(fde_t *fd, const char *
524    hints.ai_socktype = SOCK_STREAM;
525    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
526  
527 <  snprintf(portname, PORTNAMELEN, "%d", port);
527 >  snprintf(portname, sizeof(portname), "%d", port);
528  
529    if (irc_getaddrinfo(host, portname, &hints, &res))
530    {
531      /* Send the DNS request, for the next level */
549    fd->dns_query = MyMalloc(sizeof(struct DNSQuery));
550    fd->dns_query->ptr = fd;
551    fd->dns_query->callback = comm_connect_dns_callback;
532      if (aftype == AF_INET6)
533 <      gethost_byname_type(host, fd->dns_query, T_AAAA);
533 >      gethost_byname_type(comm_connect_dns_callback, fd, host, T_AAAA);
534      else
535 <      gethost_byname_type(host, fd->dns_query, T_A);
535 >      gethost_byname_type(comm_connect_dns_callback, fd, host, T_A);
536    }
537    else
538    {
# Line 610 | Line 590 | comm_connect_timeout(fde_t *fd, void *no
590   * otherwise we initiate the connect()
591   */
592   static void
593 < comm_connect_dns_callback(void *vptr, struct DNSReply *reply)
593 > comm_connect_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
594   {
595    fde_t *F = vptr;
596  
597 <  if (reply == NULL)
597 >  if (name == NULL)
598    {
619    MyFree(F->dns_query);
620    F->dns_query = NULL;
599      comm_connect_callback(F, COMM_ERR_DNS);
600      return;
601    }
# Line 631 | Line 609 | comm_connect_dns_callback(void *vptr, st
609     * the DNS record around, and the DNS cache is gone anyway..
610     *     -- adrian
611     */
612 <  memcpy(&F->connect.hostaddr, &reply->addr, reply->addr.ss_len);
612 >  memcpy(&F->connect.hostaddr, addr, addr->ss_len);
613    /* The cast is hacky, but safe - port offset is same on v4 and v6 */
614    ((struct sockaddr_in *) &F->connect.hostaddr)->sin_port =
615      F->connect.hostaddr.ss_port;
616 <  F->connect.hostaddr.ss_len = reply->addr.ss_len;
616 >  F->connect.hostaddr.ss_len = addr->ss_len;
617  
618    /* Now, call the tryconnect() routine to try a connect() */
641  MyFree(F->dns_query);
642  F->dns_query = NULL;
619    comm_connect_tryconnect(F, NULL);
620   }
621  
# Line 667 | Line 643 | comm_connect_tryconnect(fde_t *fd, void
643    /* Error? */
644    if (retval < 0)
645    {
670 #ifdef _WIN32
671    errno = WSAGetLastError();
672 #endif
646      /*
647       * If we get EISCONN, then we've already connect()ed the socket,
648       * which is a good thing.
# Line 728 | Line 701 | comm_open(fde_t *F, int family, int sock
701     */
702    fd = socket(family, sock_type, proto);
703    if (fd < 0)
731  {
732 #ifdef _WIN32
733    errno = WSAGetLastError();
734 #endif
704      return -1; /* errno will be passed through, yay.. */
736  }
705  
706    execute_callback(setup_socket_cb, fd);
707  
# Line 766 | Line 734 | comm_accept(struct Listener *lptr, struc
734     * reserved fd limit, but we can deal with that when comm_open()
735     * also does it. XXX -- adrian
736     */
737 <  newfd = accept(lptr->fd.fd, (struct sockaddr *)pn, (socklen_t *)&addrlen);
737 >  newfd = accept(lptr->fd.fd, (struct sockaddr *)pn, &addrlen);
738    if (newfd < 0)
771  {
772 #ifdef _WIN32
773    errno = WSAGetLastError();
774 #endif
739      return -1;
776  }
740  
741   #ifdef IPV6
742    remove_ipv6_mapping(pn);

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)