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 967 by michael, Sun Aug 2 18:05:28 2009 UTC vs.
Revision 1013 by michael, Sun Oct 18 14:26:49 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  
66  
# Line 80 | Line 78 | check_can_use_v6(void)
78    else
79    {
80      ServerInfo.can_use_v6 = 1;
83 #ifdef _WIN32
84    closesocket(v6);
85 #else
81      close(v6);
87 #endif
82    }
83   #else
84    ServerInfo.can_use_v6 = 0;
# Line 100 | Line 94 | check_can_use_v6(void)
94   int
95   get_sockerr(int fd)
96   {
103 #ifndef _WIN32
97    int errtmp = errno;
105 #else
106  int errtmp = WSAGetLastError();
107 #endif
98   #ifdef SO_ERROR
99    int err = 0;
100    socklen_t len = sizeof(err);
# Line 166 | Line 156 | setup_socket(va_list args)
156    setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt));
157   #endif
158  
169 #ifndef _WIN32
159    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
171 #endif
160  
161    return NULL;
162   }
# Line 225 | 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,
230 <                                  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 235 | 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);
243      if (nextconnect > aconf->hold)
244        nextconnect = aconf->hold;
230      }
231    }
232    else if (IsClient(client_p))
# Line 339 | 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 507 | 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 539 | 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 */
547    fd->dns_query = MyMalloc(sizeof(struct DNSQuery));
548    fd->dns_query->ptr = fd;
549    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 608 | 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    {
617    MyFree(F->dns_query);
618    F->dns_query = NULL;
599      comm_connect_callback(F, COMM_ERR_DNS);
600      return;
601    }
# Line 629 | 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() */
639  MyFree(F->dns_query);
640  F->dns_query = NULL;
619    comm_connect_tryconnect(F, NULL);
620   }
621  
# Line 665 | Line 643 | comm_connect_tryconnect(fde_t *fd, void
643    /* Error? */
644    if (retval < 0)
645    {
668 #ifdef _WIN32
669    errno = WSAGetLastError();
670 #endif
646      /*
647       * If we get EISCONN, then we've already connect()ed the socket,
648       * which is a good thing.
# Line 726 | Line 701 | comm_open(fde_t *F, int family, int sock
701     */
702    fd = socket(family, sock_type, proto);
703    if (fd < 0)
729  {
730 #ifdef _WIN32
731    errno = WSAGetLastError();
732 #endif
704      return -1; /* errno will be passed through, yay.. */
734  }
705  
706    execute_callback(setup_socket_cb, fd);
707  
# Line 764 | 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)
769  {
770 #ifdef _WIN32
771    errno = WSAGetLastError();
772 #endif
739      return -1;
774  }
740  
741   #ifdef IPV6
742    remove_ipv6_mapping(pn);

Diff Legend

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