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->servers = NULL;
129 channel->sock_state_cb = NULL;
130 channel->sock_state_cb_data = NULL;
132 /* Initialize configuration by each of the four sources, from highest
133 * precedence to lowest.
135 status = init_by_options(channel, options, optmask);
136 if (status == ARES_SUCCESS)
137 status = init_by_environment(channel);
138 if (status == ARES_SUCCESS)
139 status = init_by_resolv_conf(channel);
140 if (status == ARES_SUCCESS)
141 status = init_by_defaults(channel);
142 if (status != ARES_SUCCESS)
144 /* Something failed; clean up memory we may have allocated. */
145 if (channel->servers)
146 free(channel->servers);
147 if (channel->domains)
149 for (i = 0; i < channel->ndomains; i++)
150 free(channel->domains[i]);
151 free(channel->domains);
153 if (channel->sortlist)
154 free(channel->sortlist);
156 free(channel->lookups);
161 /* Trim to one server if ARES_FLAG_PRIMARY is set. */
162 if ((channel->flags & ARES_FLAG_PRIMARY) && channel->nservers > 1)
163 channel->nservers = 1;
165 /* Initialize server states. */
166 for (i = 0; i < channel->nservers; i++)
168 server = &channel->servers[i];
169 server->udp_socket = ARES_SOCKET_BAD;
170 server->tcp_socket = ARES_SOCKET_BAD;
171 server->tcp_lenbuf_pos = 0;
172 server->tcp_buffer = NULL;
173 server->qhead = NULL;
174 server->qtail = NULL;
177 /* Choose a somewhat random query ID. The main point is to avoid
178 * collisions with stale queries. An attacker trying to spoof a DNS
179 * answer also has to guess the query ID, but it's only a 16-bit
180 * field, so there's not much to be done about that.
182 gettimeofday(&tv, NULL);
183 channel->next_id = (unsigned short)
184 ((tv.tv_sec ^ tv.tv_usec ^ getpid()) & 0xffff);
186 channel->queries = NULL;
188 *channelptr = channel;
192 static int init_by_options(ares_channel channel, struct ares_options *options,
198 if ((optmask & ARES_OPT_FLAGS) && channel->flags == -1)
199 channel->flags = options->flags;
200 if ((optmask & ARES_OPT_TIMEOUT) && channel->timeout == -1)
201 channel->timeout = options->timeout;
202 if ((optmask & ARES_OPT_TRIES) && channel->tries == -1)
203 channel->tries = options->tries;
204 if ((optmask & ARES_OPT_NDOTS) && channel->ndots == -1)
205 channel->ndots = options->ndots;
206 if ((optmask & ARES_OPT_UDP_PORT) && channel->udp_port == -1)
207 channel->udp_port = options->udp_port;
208 if ((optmask & ARES_OPT_TCP_PORT) && channel->tcp_port == -1)
209 channel->tcp_port = options->tcp_port;
210 if ((optmask & ARES_OPT_SOCK_STATE_CB) && channel->sock_state_cb == NULL)
212 channel->sock_state_cb = options->sock_state_cb;
213 channel->sock_state_cb_data = options->sock_state_cb_data;
216 /* Copy the servers, if given. */
217 if ((optmask & ARES_OPT_SERVERS) && channel->nservers == -1)
219 /* Avoid zero size allocations at any cost */
220 if (options->nservers > 0)
223 malloc(options->nservers * sizeof(struct server_state));
224 if (!channel->servers)
226 for (i = 0; i < options->nservers; i++)
227 channel->servers[i].addr = options->servers[i];
229 channel->nservers = options->nservers;
232 /* Copy the domains, if given. Keep channel->ndomains consistent so
233 * we can clean up in case of error.
235 if ((optmask & ARES_OPT_DOMAINS) && channel->ndomains == -1)
237 /* Avoid zero size allocations at any cost */
238 if (options->ndomains > 0)
240 channel->domains = malloc(options->ndomains * sizeof(char *));
241 if (!channel->domains)
243 for (i = 0; i < options->ndomains; i++)
245 channel->ndomains = i;
246 channel->domains[i] = strdup(options->domains[i]);
247 if (!channel->domains[i])
251 channel->ndomains = options->ndomains;
254 /* Set lookups, if given. */
255 if ((optmask & ARES_OPT_LOOKUPS) && !channel->lookups)
257 channel->lookups = strdup(options->lookups);
258 if (!channel->lookups)
265 static int init_by_environment(ares_channel channel)
267 const char *localdomain, *res_options;
270 localdomain = getenv("LOCALDOMAIN");
271 if (localdomain && channel->ndomains == -1)
273 status = set_search(channel, localdomain);
274 if (status != ARES_SUCCESS)
278 res_options = getenv("RES_OPTIONS");
281 status = set_options(channel, res_options);
282 if (status != ARES_SUCCESS)
291 * Warning: returns a dynamically allocated buffer, the user MUST
292 * use free() if the function returns 1
294 static int get_res_nt(HKEY hKey, const char *subkey, char **obuf)
296 /* Test for the size we need */
300 result = RegQueryValueEx(hKey, subkey, 0, NULL, NULL, &size);
301 if ((result != ERROR_SUCCESS && result != ERROR_MORE_DATA) || !size)
303 *obuf = malloc(size+1);
307 if (RegQueryValueEx(hKey, subkey, 0, NULL,
308 (LPBYTE)*obuf, &size) != ERROR_SUCCESS)
321 static int get_res_interfaces_nt(HKEY hKey, const char *subkey, char **obuf)
323 char enumbuf[39]; /* GUIDs are 38 chars + 1 for NULL */
324 DWORD enum_size = 39;
328 while (RegEnumKeyEx(hKey, idx++, enumbuf, &enum_size, 0,
329 NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS)
334 if (RegOpenKeyEx(hKey, enumbuf, 0, KEY_QUERY_VALUE, &hVal) !=
337 rc = get_res_nt(hVal, subkey, obuf);
345 static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size)
347 FIXED_INFO *fi = alloca (sizeof(*fi));
348 DWORD size = sizeof (*fi);
349 typedef DWORD (WINAPI* get_net_param_func) (FIXED_INFO*, DWORD*);
350 get_net_param_func GetNetworkParams; /* available only on Win-98/2000+ */
352 IP_ADDR_STRING *ipAddr;
355 size_t ip_size = sizeof("255.255.255.255,")-1;
356 size_t left = ret_size;
363 handle = LoadLibrary ("iphlpapi.dll");
367 GetNetworkParams = (get_net_param_func) GetProcAddress (handle, "GetNetworkParams");
368 if (!GetNetworkParams)
371 res = (*GetNetworkParams) (fi, &size);
372 if ((res != ERROR_BUFFER_OVERFLOW) && (res != ERROR_SUCCESS))
376 if (!fi || (*GetNetworkParams) (fi, &size) != ERROR_SUCCESS)
381 printf ("Host Name: %s\n", fi->HostName);
382 printf ("Domain Name: %s\n", fi->DomainName);
383 printf ("DNS Servers:\n"
384 " %s (primary)\n", fi->DnsServerList.IpAddress.String);
386 if (strlen(fi->DnsServerList.IpAddress.String) > 0 &&
387 inet_addr(fi->DnsServerList.IpAddress.String) != INADDR_NONE &&
390 ret += sprintf (ret, "%s,", fi->DnsServerList.IpAddress.String);
391 left -= ret - ret_buf;
395 for (i = 0, ipAddr = fi->DnsServerList.Next; ipAddr && left > ip_size;
396 ipAddr = ipAddr->Next, i++)
398 if (inet_addr(ipAddr->IpAddress.String) != INADDR_NONE)
400 ret += sprintf (ret, "%s,", ipAddr->IpAddress.String);
401 left -= ret - ret_buf;
405 printf (" %s (secondary %d)\n", ipAddr->IpAddress.String, i+1);
410 FreeLibrary (handle);
412 if (debug && left <= ip_size)
413 printf ("Too many nameservers. Truncating to %d addressess", count);
420 static int init_by_resolv_conf(ares_channel channel)
423 int status = -1, nservers = 0, nsort = 0;
424 struct server_state *servers = NULL;
425 struct apattern *sortlist = NULL;
430 NameServer info via IPHLPAPI (IP helper API):
431 GetNetworkParams() should be the trusted source for this.
432 Available in Win-98/2000 and later. If that fail, fall-back to
433 registry information.
437 On Windows 9X, the DNS server can be found in:
438 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP\NameServer
440 On Windows NT/2000/XP/2003:
441 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer
443 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer
445 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
448 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
459 if (channel->nservers > -1) /* don't override ARES_OPT_SERVER */
462 if (get_iphlpapi_dns_info(buf,sizeof(buf)) > 0)
464 status = config_nameserver(&servers, &nservers, buf);
465 if (status == ARES_SUCCESS)
472 HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0,
476 RegOpenKeyEx(mykey, "Interfaces", 0,
477 KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &subkey);
478 if (get_res_nt(mykey, NAMESERVER, &line))
480 status = config_nameserver(&servers, &nservers, line);
483 else if (get_res_nt(mykey, DHCPNAMESERVER, &line))
485 status = config_nameserver(&servers, &nservers, line);
488 /* Try the interfaces */
489 else if (get_res_interfaces_nt(subkey, NAMESERVER, &line))
491 status = config_nameserver(&servers, &nservers, line);
494 else if (get_res_interfaces_nt(subkey, DHCPNAMESERVER, &line))
496 status = config_nameserver(&servers, &nservers, line);
506 HKEY_LOCAL_MACHINE, WIN_NS_9X, 0,
510 if ((result = RegQueryValueEx(
511 mykey, NAMESERVER, NULL, &data_type,
514 ) == ERROR_SUCCESS ||
515 result == ERROR_MORE_DATA)
519 line = (char *)malloc(bytes+1);
520 if (RegQueryValueEx(mykey, NAMESERVER, NULL, &data_type,
521 (unsigned char *)line, &bytes) ==
524 status = config_nameserver(&servers, &nservers, line);
533 if (status == ARES_SUCCESS)
536 #elif defined(__riscos__)
538 /* Under RISC OS, name servers are listed in the
539 system variable Inet$Resolvers, space separated. */
541 line = getenv("Inet$Resolvers");
544 char *resolvers = strdup(line), *pos, *space;
551 space = strchr(pos, ' ');
554 status = config_nameserver(&servers, &nservers, pos);
555 if (status != ARES_SUCCESS)
560 if (status == ARES_SUCCESS)
566 #elif defined(WATT32)
570 for (i = 0; def_nameservers[i]; i++)
573 return ARES_SUCCESS; /* use localhost DNS server */
576 servers = calloc(sizeof(*servers), i);
580 for (i = 0; def_nameservers[i]; i++)
581 servers[i].addr.s_addr = htonl(def_nameservers[i]);
590 fp = fopen(PATH_RESOLV_CONF, "r");
592 return (errno == ENOENT) ? ARES_SUCCESS : ARES_EFILE;
593 while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
595 if ((p = try_config(line, "domain")) && channel->ndomains == -1)
596 status = config_domain(channel, p);
597 else if ((p = try_config(line, "lookup")) && !channel->lookups)
598 status = config_lookup(channel, p, "bind", "file");
599 else if ((p = try_config(line, "search")) && channel->ndomains == -1)
600 status = set_search(channel, p);
601 else if ((p = try_config(line, "nameserver")) && channel->nservers == -1)
602 status = config_nameserver(&servers, &nservers, p);
603 else if ((p = try_config(line, "sortlist")) && channel->nsort == -1)
604 status = config_sortlist(&sortlist, &nsort, p);
605 else if ((p = try_config(line, "options")))
606 status = set_options(channel, p);
608 status = ARES_SUCCESS;
609 if (status != ARES_SUCCESS)
614 if (!channel->lookups) {
615 /* Many systems (Solaris, Linux, BSD's) use nsswitch.conf */
616 fp = fopen("/etc/nsswitch.conf", "r");
618 while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
620 if ((p = try_config(line, "hosts:")) && !channel->lookups)
621 status = config_lookup(channel, p, "dns", "files");
627 if (!channel->lookups) {
628 /* Linux / GNU libc 2.x and possibly others have host.conf */
629 fp = fopen("/etc/host.conf", "r");
631 while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
633 if ((p = try_config(line, "order")) && !channel->lookups)
634 status = config_lookup(channel, p, "bind", "hosts");
640 if (!channel->lookups) {
641 /* Tru64 uses /etc/svc.conf */
642 fp = fopen("/etc/svc.conf", "r");
644 while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
646 if ((p = try_config(line, "hosts=")) && !channel->lookups)
647 status = config_lookup(channel, p, "bind", "local");
660 if (status != ARES_EOF)
664 if (sortlist != NULL)
669 /* If we got any name server entries, fill them in. */
675 channel->servers = servers;
676 channel->nservers = nservers;
679 /* If we got any sortlist entries, fill them in. */
682 channel->sortlist = sortlist;
683 channel->nsort = nsort;
689 static int init_by_defaults(ares_channel channel)
691 char hostname[MAXHOSTNAMELEN + 1];
693 if (channel->flags == -1)
695 if (channel->timeout == -1)
696 channel->timeout = DEFAULT_TIMEOUT;
697 if (channel->tries == -1)
698 channel->tries = DEFAULT_TRIES;
699 if (channel->ndots == -1)
701 if (channel->udp_port == -1)
702 channel->udp_port = htons(NAMESERVER_PORT);
703 if (channel->tcp_port == -1)
704 channel->tcp_port = htons(NAMESERVER_PORT);
706 if (channel->nservers == -1)
708 /* If nobody specified servers, try a local named. */
709 channel->servers = malloc(sizeof(struct server_state));
710 if (!channel->servers)
712 channel->servers[0].addr.s_addr = htonl(INADDR_LOOPBACK);
713 channel->nservers = 1;
716 if (channel->ndomains == -1)
718 /* Derive a default domain search list from the kernel hostname,
719 * or set it to empty if the hostname isn't helpful.
721 if (gethostname(hostname, sizeof(hostname)) == -1
722 || !strchr(hostname, '.'))
724 channel->ndomains = 0;
728 channel->domains = malloc(sizeof(char *));
729 if (!channel->domains)
731 channel->ndomains = 0;
732 channel->domains[0] = strdup(strchr(hostname, '.') + 1);
733 if (!channel->domains[0])
735 channel->ndomains = 1;
739 if (channel->nsort == -1)
741 channel->sortlist = NULL;
745 if (!channel->lookups)
747 channel->lookups = strdup("fb");
748 if (!channel->lookups)
756 static int config_domain(ares_channel channel, char *str)
760 /* Set a single search domain. */
762 while (*q && !ISSPACE(*q))
765 return set_search(channel, str);
768 static int config_lookup(ares_channel channel, const char *str,
769 const char *bindch, const char *filech)
774 /* Set the lookup order. Only the first letter of each work
775 * is relevant, and it has to be "b" for DNS or "f" for the
776 * host file. Ignore everything else.
782 if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
783 if (*p == *bindch) *l++ = 'b';
786 while (*p && !ISSPACE(*p) && (*p != ','))
788 while (*p && (ISSPACE(*p) || (*p == ',')))
792 channel->lookups = strdup(lookups);
793 return (channel->lookups) ? ARES_SUCCESS : ARES_ENOMEM;
798 static int config_nameserver(struct server_state **servers, int *nservers,
802 struct server_state *newserv;
803 /* On Windows, there may be more than one nameserver specified in the same
804 * registry key, so we parse it as a space or comma seperated list.
813 while (*p && !ISSPACE(*p) && *p != ',')
822 /* Skip multiple spaces or trailing spaces */
829 /* This is the part that actually sets the nameserver */
830 addr.s_addr = inet_addr(begin);
831 if (addr.s_addr == INADDR_NONE)
833 newserv = realloc(*servers, (*nservers + 1) * sizeof(struct server_state));
836 newserv[*nservers].addr = addr;
845 /* Add a nameserver entry, if this is a valid address. */
846 addr.s_addr = inet_addr(str);
847 if (addr.s_addr == INADDR_NONE)
849 newserv = realloc(*servers, (*nservers + 1) * sizeof(struct server_state));
852 newserv[*nservers].addr = addr;
860 static int config_sortlist(struct apattern **sortlist, int *nsort,
866 /* Add sortlist entries. */
867 while (*str && *str != ';')
870 char ipbuf[16], ipbufpfx[32];
871 /* Find just the IP */
873 while (*q && *q != '/' && *q != ';' && !ISSPACE(*q))
875 memcpy(ipbuf, str, (int)(q-str));
876 ipbuf[(int)(q-str)] = 0;
877 /* Find the prefix */
880 const char *str2 = q+1;
881 while (*q && *q != ';' && !ISSPACE(*q))
883 memcpy(ipbufpfx, str, (int)(q-str));
884 ipbufpfx[(int)(q-str)] = 0;
889 /* Lets see if it is CIDR */
890 /* First we'll try IPv6 */
891 if ((bits = ares_inet_net_pton(AF_INET6, ipbufpfx ? ipbufpfx : ipbuf,
893 sizeof(pat.addr.addr6))) > 0)
895 pat.type = PATTERN_CIDR;
896 pat.mask.bits = (unsigned short)bits;
897 pat.family = AF_INET6;
898 if (!sortlist_alloc(sortlist, nsort, &pat))
902 (bits = ares_inet_net_pton(AF_INET, ipbufpfx, &pat.addr.addr4,
903 sizeof(pat.addr.addr4))) > 0)
905 pat.type = PATTERN_CIDR;
906 pat.mask.bits = (unsigned short)bits;
907 pat.family = AF_INET;
908 if (!sortlist_alloc(sortlist, nsort, &pat))
911 /* See if it is just a regular IP */
912 else if (ip_addr(ipbuf, (int)(q-str), &pat.addr.addr4) == 0)
916 memcpy(ipbuf, str, (int)(q-str));
917 ipbuf[(int)(q-str)] = 0;
918 if (ip_addr(ipbuf, (int)(q - str), &pat.mask.addr.addr4) != 0)
923 pat.family = AF_INET;
924 pat.type = PATTERN_MASK;
925 if (!sortlist_alloc(sortlist, nsort, &pat))
930 while (*q && *q != ';' && !ISSPACE(*q))
934 while (ISSPACE(*str))
942 static int set_search(ares_channel channel, const char *str)
947 if(channel->ndomains != -1) {
948 /* if we already have some domains present, free them first */
949 for(n=0; n < channel->ndomains; n++)
950 free(channel->domains[n]);
951 free(channel->domains);
952 channel->domains = NULL;
953 channel->ndomains = -1;
956 /* Count the domains given. */
961 while (*p && !ISSPACE(*p))
970 channel->ndomains = 0;
974 channel->domains = malloc(n * sizeof(char *));
975 if (!channel->domains)
978 /* Now copy the domains. */
983 channel->ndomains = n;
985 while (*q && !ISSPACE(*q))
987 channel->domains[n] = malloc(q - p + 1);
988 if (!channel->domains[n])
990 memcpy(channel->domains[n], p, q - p);
991 channel->domains[n][q - p] = 0;
997 channel->ndomains = n;
1002 static int set_options(ares_channel channel, const char *str)
1004 const char *p, *q, *val;
1010 while (*q && !ISSPACE(*q))
1012 val = try_option(p, q, "ndots:");
1013 if (val && channel->ndots == -1)
1014 channel->ndots = atoi(val);
1015 val = try_option(p, q, "retrans:");
1016 if (val && channel->timeout == -1)
1017 channel->timeout = atoi(val);
1018 val = try_option(p, q, "retry:");
1019 if (val && channel->tries == -1)
1020 channel->tries = atoi(val);
1026 return ARES_SUCCESS;
1030 static char *try_config(char *s, const char *opt)
1035 if (strncmp(s, opt, len) != 0 || !ISSPACE(s[len]))
1045 static const char *try_option(const char *p, const char *q, const char *opt)
1047 size_t len = strlen(opt);
1048 return ((size_t)(q - p) > len && !strncmp(p, opt, len)) ? &p[len] : NULL;
1052 static int sortlist_alloc(struct apattern **sortlist, int *nsort,
1053 struct apattern *pat)
1055 struct apattern *newsort;
1056 newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern));
1059 newsort[*nsort] = *pat;
1060 *sortlist = newsort;
1065 static int ip_addr(const char *ipbuf, int len, struct in_addr *addr)
1068 /* Four octets and three periods yields at most 15 characters. */
1072 addr->s_addr = inet_addr(ipbuf);
1073 if (addr->s_addr == INADDR_NONE && strcmp(ipbuf, "255.255.255.255") != 0)
1078 static void natural_mask(struct apattern *pat)
1080 struct in_addr addr;
1082 /* Store a host-byte-order copy of pat in a struct in_addr. Icky,
1085 addr.s_addr = ntohl(pat->addr.addr4.s_addr);
1087 /* This is out of date in the CIDR world, but some people might
1090 if (IN_CLASSA(addr.s_addr))
1091 pat->mask.addr.addr4.s_addr = htonl(IN_CLASSA_NET);
1092 else if (IN_CLASSB(addr.s_addr))
1093 pat->mask.addr.addr4.s_addr = htonl(IN_CLASSB_NET);
1095 pat->mask.addr.addr4.s_addr = htonl(IN_CLASSC_NET);