3 /* Copyright 1998 by the Massachusetts Institute of Technology.
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for any purpose and without
7 * fee is hereby granted, provided that the above copyright
8 * notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting
10 * documentation, and that the name of M.I.T. not be used in
11 * advertising or publicity pertaining to distribution of the
12 * software without specific, written prior permission.
13 * M.I.T. makes no representations about the suitability of
14 * this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
19 #include <sys/types.h>
21 #if defined(WIN32) && !defined(WATT32)
27 #include <sys/param.h>
28 #ifdef HAVE_SYS_TIME_H
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
39 #include <arpa/nameser.h>
40 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
41 #include <arpa/nameser_compat.h>
55 #include "ares_private.h"
56 #include "inet_net_pton.h"
59 #undef WIN32 /* Redefined in MingW/MSVC headers */
62 static int init_by_options(ares_channel channel, struct ares_options *options,
64 static int init_by_environment(ares_channel channel);
65 static int init_by_resolv_conf(ares_channel channel);
66 static int init_by_defaults(ares_channel channel);
68 static int config_nameserver(struct server_state **servers, int *nservers,
70 static int set_search(ares_channel channel, const char *str);
71 static int set_options(ares_channel channel, const char *str);
72 static const char *try_option(const char *p, const char *q, const char *opt);
74 static int sortlist_alloc(struct apattern **sortlist, int *nsort, struct apattern *pat);
75 static int ip_addr(const char *s, int len, struct in_addr *addr);
76 static void natural_mask(struct apattern *pat);
77 static int config_domain(ares_channel channel, char *str);
78 static int config_lookup(ares_channel channel, const char *str,
79 const char *bindch, const char *filech);
80 static int config_sortlist(struct apattern **sortlist, int *nsort,
82 static char *try_config(char *s, const char *opt);
85 int ares_init(ares_channel *channelptr)
87 return ares_init_options(channelptr, NULL, 0);
90 int ares_init_options(ares_channel *channelptr, struct ares_options *options,
95 struct server_state *server;
99 const char *env = getenv("CARES_MEMDEBUG");
103 env = getenv("CARES_MEMLIMIT");
105 curl_memlimit(atoi(env));
108 channel = malloc(sizeof(struct ares_channeldata));
112 /* Set everything to distinguished values so we know they haven't
116 channel->timeout = -1;
119 channel->udp_port = -1;
120 channel->tcp_port = -1;
121 channel->nservers = -1;
122 channel->ndomains = -1;
124 channel->lookups = NULL;
125 channel->queries = NULL;
126 channel->domains = NULL;
127 channel->sortlist = NULL;
128 channel->sock_state_cb = NULL;
130 /* Initialize configuration by each of the four sources, from highest
131 * precedence to lowest.
133 status = init_by_options(channel, options, optmask);
134 if (status == ARES_SUCCESS)
135 status = init_by_environment(channel);
136 if (status == ARES_SUCCESS)
137 status = init_by_resolv_conf(channel);
138 if (status == ARES_SUCCESS)
139 status = init_by_defaults(channel);
140 if (status != ARES_SUCCESS)
142 /* Something failed; clean up memory we may have allocated. */
143 if (channel->nservers != -1)
144 free(channel->servers);
145 if (channel->domains)
147 for (i = 0; i < channel->ndomains; i++)
148 free(channel->domains[i]);
149 free(channel->domains);
151 if (channel->sortlist)
152 free(channel->sortlist);
154 free(channel->lookups);
159 /* Trim to one server if ARES_FLAG_PRIMARY is set. */
160 if ((channel->flags & ARES_FLAG_PRIMARY) && channel->nservers > 1)
161 channel->nservers = 1;
163 /* Initialize server states. */
164 for (i = 0; i < channel->nservers; i++)
166 server = &channel->servers[i];
167 server->udp_socket = ARES_SOCKET_BAD;
168 server->tcp_socket = ARES_SOCKET_BAD;
169 server->tcp_lenbuf_pos = 0;
170 server->tcp_buffer = NULL;
171 server->qhead = NULL;
172 server->qtail = NULL;
175 /* Choose a somewhat random query ID. The main point is to avoid
176 * collisions with stale queries. An attacker trying to spoof a DNS
177 * answer also has to guess the query ID, but it's only a 16-bit
178 * field, so there's not much to be done about that.
180 gettimeofday(&tv, NULL);
181 channel->next_id = (unsigned short)
182 (tv.tv_sec ^ tv.tv_usec ^ getpid()) & 0xffff;
184 channel->queries = NULL;
186 *channelptr = channel;
190 static int init_by_options(ares_channel channel, struct ares_options *options,
196 if ((optmask & ARES_OPT_FLAGS) && channel->flags == -1)
197 channel->flags = options->flags;
198 if ((optmask & ARES_OPT_TIMEOUT) && channel->timeout == -1)
199 channel->timeout = options->timeout;
200 if ((optmask & ARES_OPT_TRIES) && channel->tries == -1)
201 channel->tries = options->tries;
202 if ((optmask & ARES_OPT_NDOTS) && channel->ndots == -1)
203 channel->ndots = options->ndots;
204 if ((optmask & ARES_OPT_UDP_PORT) && channel->udp_port == -1)
205 channel->udp_port = options->udp_port;
206 if ((optmask & ARES_OPT_TCP_PORT) && channel->tcp_port == -1)
207 channel->tcp_port = options->tcp_port;
208 if ((optmask & ARES_OPT_SOCK_STATE_CB) && channel->sock_state_cb == NULL)
210 channel->sock_state_cb = options->sock_state_cb;
211 channel->sock_state_cb_data = options->sock_state_cb_data;
214 /* Copy the servers, if given. */
215 if ((optmask & ARES_OPT_SERVERS) && channel->nservers == -1)
218 malloc(options->nservers * sizeof(struct server_state));
219 if (!channel->servers && options->nservers != 0)
221 for (i = 0; i < options->nservers; i++)
222 channel->servers[i].addr = options->servers[i];
223 channel->nservers = options->nservers;
226 /* Copy the domains, if given. Keep channel->ndomains consistent so
227 * we can clean up in case of error.
229 if ((optmask & ARES_OPT_DOMAINS) && channel->ndomains == -1)
231 channel->domains = malloc(options->ndomains * sizeof(char *));
232 if (!channel->domains && options->ndomains != 0)
234 for (i = 0; i < options->ndomains; i++)
236 channel->ndomains = i;
237 channel->domains[i] = strdup(options->domains[i]);
238 if (!channel->domains[i])
241 channel->ndomains = options->ndomains;
244 /* Set lookups, if given. */
245 if ((optmask & ARES_OPT_LOOKUPS) && !channel->lookups)
247 channel->lookups = strdup(options->lookups);
248 if (!channel->lookups)
255 static int init_by_environment(ares_channel channel)
257 const char *localdomain, *res_options;
260 localdomain = getenv("LOCALDOMAIN");
261 if (localdomain && channel->ndomains == -1)
263 status = set_search(channel, localdomain);
264 if (status != ARES_SUCCESS)
268 res_options = getenv("RES_OPTIONS");
271 status = set_options(channel, res_options);
272 if (status != ARES_SUCCESS)
281 * Warning: returns a dynamically allocated buffer, the user MUST
282 * use free() if the function returns 1
284 static int get_res_nt(HKEY hKey, const char *subkey, char **obuf)
286 /* Test for the size we need */
290 result = RegQueryValueEx(hKey, subkey, 0, NULL, NULL, &size);
291 if ((result != ERROR_SUCCESS && result != ERROR_MORE_DATA) || !size)
293 *obuf = malloc(size+1);
297 if (RegQueryValueEx(hKey, subkey, 0, NULL,
298 (LPBYTE)*obuf, &size) != ERROR_SUCCESS)
311 static int get_res_interfaces_nt(HKEY hKey, const char *subkey, char **obuf)
313 char enumbuf[39]; /* GUIDs are 38 chars + 1 for NULL */
314 DWORD enum_size = 39;
318 while (RegEnumKeyEx(hKey, idx++, enumbuf, &enum_size, 0,
319 NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS)
324 if (RegOpenKeyEx(hKey, enumbuf, 0, KEY_QUERY_VALUE, &hVal) !=
327 rc = get_res_nt(hVal, subkey, obuf);
335 static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size)
337 FIXED_INFO *fi = alloca (sizeof(*fi));
338 DWORD size = sizeof (*fi);
339 typedef DWORD (WINAPI* get_net_param_func) (FIXED_INFO*, DWORD*);
340 get_net_param_func GetNetworkParams; /* available only on Win-98/2000+ */
342 IP_ADDR_STRING *ipAddr;
345 size_t ip_size = sizeof("255.255.255.255,")-1;
346 size_t left = ret_size;
353 handle = LoadLibrary ("iphlpapi.dll");
357 GetNetworkParams = (get_net_param_func) GetProcAddress (handle, "GetNetworkParams");
358 if (!GetNetworkParams)
361 res = (*GetNetworkParams) (fi, &size);
362 if ((res != ERROR_BUFFER_OVERFLOW) && (res != ERROR_SUCCESS))
366 if (!fi || (*GetNetworkParams) (fi, &size) != ERROR_SUCCESS)
371 printf ("Host Name: %s\n", fi->HostName);
372 printf ("Domain Name: %s\n", fi->DomainName);
373 printf ("DNS Servers:\n"
374 " %s (primary)\n", fi->DnsServerList.IpAddress.String);
376 if (strlen(fi->DnsServerList.IpAddress.String) > 0 &&
377 inet_addr(fi->DnsServerList.IpAddress.String) != INADDR_NONE &&
380 ret += sprintf (ret, "%s,", fi->DnsServerList.IpAddress.String);
381 left -= ret - ret_buf;
385 for (i = 0, ipAddr = fi->DnsServerList.Next; ipAddr && left > ip_size;
386 ipAddr = ipAddr->Next, i++)
388 if (inet_addr(ipAddr->IpAddress.String) != INADDR_NONE)
390 ret += sprintf (ret, "%s,", ipAddr->IpAddress.String);
391 left -= ret - ret_buf;
395 printf (" %s (secondary %d)\n", ipAddr->IpAddress.String, i+1);
400 FreeLibrary (handle);
402 if (debug && left <= ip_size)
403 printf ("Too many nameservers. Truncating to %d addressess", count);
410 static int init_by_resolv_conf(ares_channel channel)
413 int status = -1, nservers = 0, nsort = 0;
414 struct server_state *servers = NULL;
415 struct apattern *sortlist = NULL;
420 NameServer info via IPHLPAPI (IP helper API):
421 GetNetworkParams() should be the trusted source for this.
422 Available in Win-98/2000 and later. If that fail, fall-back to
423 registry information.
427 On Windows 9X, the DNS server can be found in:
428 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP\NameServer
430 On Windows NT/2000/XP/2003:
431 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer
433 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer
435 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
438 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
449 if (channel->nservers > -1) /* don't override ARES_OPT_SERVER */
452 if (get_iphlpapi_dns_info(buf,sizeof(buf)) > 0)
454 status = config_nameserver(&servers, &nservers, buf);
455 if (status == ARES_SUCCESS)
462 HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0,
466 RegOpenKeyEx(mykey, "Interfaces", 0,
467 KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &subkey);
468 if (get_res_nt(mykey, NAMESERVER, &line))
470 status = config_nameserver(&servers, &nservers, line);
473 else if (get_res_nt(mykey, DHCPNAMESERVER, &line))
475 status = config_nameserver(&servers, &nservers, line);
478 /* Try the interfaces */
479 else if (get_res_interfaces_nt(subkey, NAMESERVER, &line))
481 status = config_nameserver(&servers, &nservers, line);
484 else if (get_res_interfaces_nt(subkey, DHCPNAMESERVER, &line))
486 status = config_nameserver(&servers, &nservers, line);
496 HKEY_LOCAL_MACHINE, WIN_NS_9X, 0,
500 if ((result = RegQueryValueEx(
501 mykey, NAMESERVER, NULL, &data_type,
504 ) == ERROR_SUCCESS ||
505 result == ERROR_MORE_DATA)
509 line = (char *)malloc(bytes+1);
510 if (RegQueryValueEx(mykey, NAMESERVER, NULL, &data_type,
511 (unsigned char *)line, &bytes) ==
514 status = config_nameserver(&servers, &nservers, line);
523 if (status == ARES_SUCCESS)
526 #elif defined(__riscos__)
528 /* Under RISC OS, name servers are listed in the
529 system variable Inet$Resolvers, space separated. */
531 line = getenv("Inet$Resolvers");
534 char *resolvers = strdup(line), *pos, *space;
541 space = strchr(pos, ' ');
544 status = config_nameserver(&servers, &nservers, pos);
545 if (status != ARES_SUCCESS)
550 if (status == ARES_SUCCESS)
556 #elif defined(WATT32)
560 for (i = 0; def_nameservers[i]; i++)
563 return ARES_SUCCESS; /* use localhost DNS server */
566 servers = calloc(sizeof(*servers), i);
570 for (i = 0; def_nameservers[i]; i++)
571 servers[i].addr.s_addr = htonl(def_nameservers[i]);
580 fp = fopen(PATH_RESOLV_CONF, "r");
582 return (errno == ENOENT) ? ARES_SUCCESS : ARES_EFILE;
583 while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
585 if ((p = try_config(line, "domain")))
586 status = config_domain(channel, p);
587 else if ((p = try_config(line, "lookup")) && !channel->lookups)
588 status = config_lookup(channel, p, "bind", "file");
589 else if ((p = try_config(line, "search")))
590 status = set_search(channel, p);
591 else if ((p = try_config(line, "nameserver")) && channel->nservers == -1)
592 status = config_nameserver(&servers, &nservers, p);
593 else if ((p = try_config(line, "sortlist")) && channel->nsort == -1)
594 status = config_sortlist(&sortlist, &nsort, p);
595 else if ((p = try_config(line, "options")))
596 status = set_options(channel, p);
598 status = ARES_SUCCESS;
599 if (status != ARES_SUCCESS)
604 if (!channel->lookups) {
605 /* Many systems (Solaris, Linux, BSD's) use nsswitch.conf */
606 fp = fopen("/etc/nsswitch.conf", "r");
608 while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
610 if ((p = try_config(line, "hosts:")) && !channel->lookups)
611 status = config_lookup(channel, p, "dns", "files");
617 if (!channel->lookups) {
618 /* Linux / GNU libc 2.x and possibly others have host.conf */
619 fp = fopen("/etc/host.conf", "r");
621 while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
623 if ((p = try_config(line, "order")) && !channel->lookups)
624 status = config_lookup(channel, p, "bind", "hosts");
630 if (!channel->lookups) {
631 /* Tru64 uses /etc/svc.conf */
632 fp = fopen("/etc/svc.conf", "r");
634 while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
636 if ((p = try_config(line, "hosts=")) && !channel->lookups)
637 status = config_lookup(channel, p, "bind", "local");
650 if (status != ARES_EOF)
654 if (sortlist != NULL)
659 /* If we got any name server entries, fill them in. */
665 channel->servers = servers;
666 channel->nservers = nservers;
669 /* If we got any sortlist entries, fill them in. */
672 channel->sortlist = sortlist;
673 channel->nsort = nsort;
679 static int init_by_defaults(ares_channel channel)
681 char hostname[MAXHOSTNAMELEN + 1];
683 if (channel->flags == -1)
685 if (channel->timeout == -1)
686 channel->timeout = DEFAULT_TIMEOUT;
687 if (channel->tries == -1)
688 channel->tries = DEFAULT_TRIES;
689 if (channel->ndots == -1)
691 if (channel->udp_port == -1)
692 channel->udp_port = htons(NAMESERVER_PORT);
693 if (channel->tcp_port == -1)
694 channel->tcp_port = htons(NAMESERVER_PORT);
696 if (channel->nservers == -1)
698 /* If nobody specified servers, try a local named. */
699 channel->servers = malloc(sizeof(struct server_state));
700 if (!channel->servers)
702 channel->servers[0].addr.s_addr = htonl(INADDR_LOOPBACK);
703 channel->nservers = 1;
706 if (channel->ndomains == -1)
708 /* Derive a default domain search list from the kernel hostname,
709 * or set it to empty if the hostname isn't helpful.
711 if (gethostname(hostname, sizeof(hostname)) == -1
712 || !strchr(hostname, '.'))
714 channel->domains = malloc(0);
715 channel->ndomains = 0;
719 channel->domains = malloc(sizeof(char *));
720 if (!channel->domains)
722 channel->ndomains = 0;
723 channel->domains[0] = strdup(strchr(hostname, '.') + 1);
724 if (!channel->domains[0])
726 channel->ndomains = 1;
730 if (channel->nsort == -1)
732 channel->sortlist = NULL;
736 if (!channel->lookups)
738 channel->lookups = strdup("fb");
739 if (!channel->lookups)
747 static int config_domain(ares_channel channel, char *str)
751 /* Set a single search domain. */
753 while (*q && !ISSPACE(*q))
756 return set_search(channel, str);
759 static int config_lookup(ares_channel channel, const char *str,
760 const char *bindch, const char *filech)
765 /* Set the lookup order. Only the first letter of each work
766 * is relevant, and it has to be "b" for DNS or "f" for the
767 * host file. Ignore everything else.
773 if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
774 if (*p == *bindch) *l++ = 'b';
777 while (*p && !ISSPACE(*p) && (*p != ','))
779 while (*p && (ISSPACE(*p) || (*p == ',')))
783 channel->lookups = strdup(lookups);
784 return (channel->lookups) ? ARES_SUCCESS : ARES_ENOMEM;
789 static int config_nameserver(struct server_state **servers, int *nservers,
793 struct server_state *newserv;
794 /* On Windows, there may be more than one nameserver specified in the same
795 * registry key, so we parse it as a space or comma seperated list.
804 while (*p && !ISSPACE(*p) && *p != ',')
813 /* Skip multiple spaces or trailing spaces */
820 /* This is the part that actually sets the nameserver */
821 addr.s_addr = inet_addr(begin);
822 if (addr.s_addr == INADDR_NONE)
824 newserv = realloc(*servers, (*nservers + 1) * sizeof(struct server_state));
827 newserv[*nservers].addr = addr;
836 /* Add a nameserver entry, if this is a valid address. */
837 addr.s_addr = inet_addr(str);
838 if (addr.s_addr == INADDR_NONE)
840 newserv = realloc(*servers, (*nservers + 1) * sizeof(struct server_state));
843 newserv[*nservers].addr = addr;
851 static int config_sortlist(struct apattern **sortlist, int *nsort,
857 /* Add sortlist entries. */
858 while (*str && *str != ';')
861 char ipbuf[16], ipbufpfx[32];
862 /* Find just the IP */
864 while (*q && *q != '/' && *q != ';' && !ISSPACE(*q))
866 memcpy(ipbuf, str, (int)(q-str));
867 ipbuf[(int)(q-str)] = 0;
868 /* Find the prefix */
871 const char *str2 = q+1;
872 while (*q && *q != ';' && !ISSPACE(*q))
874 memcpy(ipbufpfx, str, (int)(q-str));
875 ipbufpfx[(int)(q-str)] = 0;
880 /* Lets see if it is CIDR */
881 /* First we'll try IPv6 */
882 if ((bits = ares_inet_net_pton(AF_INET6, ipbufpfx ? ipbufpfx : ipbuf,
884 sizeof(pat.addr.addr6))) > 0)
886 pat.type = PATTERN_CIDR;
887 pat.mask.bits = bits;
888 pat.family = AF_INET6;
889 if (!sortlist_alloc(sortlist, nsort, &pat))
893 (bits = ares_inet_net_pton(AF_INET, ipbufpfx, &pat.addr.addr4,
894 sizeof(pat.addr.addr4))) > 0)
896 pat.type = PATTERN_CIDR;
897 pat.mask.bits = bits;
898 pat.family = AF_INET;
899 if (!sortlist_alloc(sortlist, nsort, &pat))
902 /* See if it is just a regular IP */
903 else if (ip_addr(ipbuf, (int)(q-str), &pat.addr.addr4) == 0)
907 memcpy(ipbuf, str, (int)(q-str));
908 ipbuf[(int)(q-str)] = 0;
909 if (ip_addr(ipbuf, (int)(q - str), &pat.mask.addr.addr4) != 0)
914 pat.family = AF_INET;
915 pat.type = PATTERN_MASK;
916 if (!sortlist_alloc(sortlist, nsort, &pat))
921 while (*q && *q != ';' && !ISSPACE(*q))
925 while (ISSPACE(*str))
933 static int set_search(ares_channel channel, const char *str)
938 if(channel->ndomains != -1) {
939 /* if we already have some domains present, free them first */
940 for(n=0; n < channel->ndomains; n++)
941 free(channel->domains[n]);
942 free(channel->domains);
943 channel->ndomains = -1;
946 /* Count the domains given. */
951 while (*p && !ISSPACE(*p))
958 channel->domains = malloc(n * sizeof(char *));
959 if (!channel->domains && n)
962 /* Now copy the domains. */
967 channel->ndomains = n;
969 while (*q && !ISSPACE(*q))
971 channel->domains[n] = malloc(q - p + 1);
972 if (!channel->domains[n])
974 memcpy(channel->domains[n], p, q - p);
975 channel->domains[n][q - p] = 0;
981 channel->ndomains = n;
986 static int set_options(ares_channel channel, const char *str)
988 const char *p, *q, *val;
994 while (*q && !ISSPACE(*q))
996 val = try_option(p, q, "ndots:");
997 if (val && channel->ndots == -1)
998 channel->ndots = atoi(val);
999 val = try_option(p, q, "retrans:");
1000 if (val && channel->timeout == -1)
1001 channel->timeout = atoi(val);
1002 val = try_option(p, q, "retry:");
1003 if (val && channel->tries == -1)
1004 channel->tries = atoi(val);
1010 return ARES_SUCCESS;
1014 static char *try_config(char *s, const char *opt)
1019 if (strncmp(s, opt, len) != 0 || !ISSPACE(s[len]))
1029 static const char *try_option(const char *p, const char *q, const char *opt)
1031 size_t len = strlen(opt);
1032 return ((size_t)(q - p) > len && !strncmp(p, opt, len)) ? &p[len] : NULL;
1036 static int sortlist_alloc(struct apattern **sortlist, int *nsort,
1037 struct apattern *pat)
1039 struct apattern *newsort;
1040 newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern));
1043 newsort[*nsort] = *pat;
1044 *sortlist = newsort;
1049 static int ip_addr(const char *ipbuf, int len, struct in_addr *addr)
1052 /* Four octets and three periods yields at most 15 characters. */
1056 addr->s_addr = inet_addr(ipbuf);
1057 if (addr->s_addr == INADDR_NONE && strcmp(ipbuf, "255.255.255.255") != 0)
1062 static void natural_mask(struct apattern *pat)
1064 struct in_addr addr;
1066 /* Store a host-byte-order copy of pat in a struct in_addr. Icky,
1069 addr.s_addr = ntohl(pat->addr.addr4.s_addr);
1071 /* This is out of date in the CIDR world, but some people might
1074 if (IN_CLASSA(addr.s_addr))
1075 pat->mask.addr.addr4.s_addr = htonl(IN_CLASSA_NET);
1076 else if (IN_CLASSB(addr.s_addr))
1077 pat->mask.addr.addr4.s_addr = htonl(IN_CLASSB_NET);
1079 pat->mask.addr.addr4.s_addr = htonl(IN_CLASSC_NET);