res_init.c (7257d1b4) res_init.c (bd0e95e6)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2015 Gary Mills
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28/* All Rights Reserved */
29
30/*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29/* All Rights Reserved */
30
31/*
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
35 *
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
39 */
40
40#pragma ident "%Z%%M% %I% %E% SMI"
41
42#include <sys/types.h>
43#include <sys/sockio.h>
44#include <sys/socket.h>
45#include <netinet/in.h>
46#include <stdio.h>
41#include <sys/types.h>
42#include <sys/sockio.h>
43#include <sys/socket.h>
44#include <netinet/in.h>
45#include <stdio.h>
46#include <string.h>
47#include <stdlib.h>
48#include <unistd.h>
49#include <stropts.h>
47#include <arpa/nameser.h>
48#include <resolv.h>
49
50#include <netinet/in.h>
51#include <net/if.h>
52#include <netinet/if_ether.h>
53#include <arpa/inet.h>
54
50#include <arpa/nameser.h>
51#include <resolv.h>
52
53#include <netinet/in.h>
54#include <net/if.h>
55#include <netinet/if_ether.h>
56#include <arpa/inet.h>
57
58/*
59 * Undocumented external function in libnsl
60 */
61extern int
62getdomainname(char *, int);
63
55#define MAXIFS 256
56
57/*
58 * Resolver state default settings
59 */
60
61struct state _res = {
62 RES_TIMEOUT, /* retransmition time interval */

--- 19 unchanged lines hidden (view full) ---

82 */
83int
84res_init(void)
85{
86 register FILE *fp;
87 register char *cp, **pp;
88 register int n;
89 char buf[BUFSIZ];
64#define MAXIFS 256
65
66/*
67 * Resolver state default settings
68 */
69
70struct state _res = {
71 RES_TIMEOUT, /* retransmition time interval */

--- 19 unchanged lines hidden (view full) ---

91 */
92int
93res_init(void)
94{
95 register FILE *fp;
96 register char *cp, **pp;
97 register int n;
98 char buf[BUFSIZ];
90#ifdef SYSV
91 extern char *strchr();
92#else
93 extern char *index();
94#endif
95 extern char *strcpy(), *strncpy();
96 extern char *getenv();
97 int nserv = 0; /* number of nameserver records read from file */
98 int haveenv = 0;
99 int havesearch = 0;
100
101 _res.nsaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); /* INADDR_ANY */
102 _res.nsaddr.sin_family = AF_INET;
103 _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
104 _res.nscount = 1;
105
106#ifdef SIOCGIFNUM
107 { int numifs, s, n, int_up;
108 struct ifconf ifc;
109 register struct ifreq *ifrp;
110 struct ifreq ifr;
111 unsigned bufsize;
112 unsigned int flags;
113 char *buf;
99 int nserv = 0; /* number of nameserver records read from file */
100 int haveenv = 0;
101 int havesearch = 0;
102
103 _res.nsaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); /* INADDR_ANY */
104 _res.nsaddr.sin_family = AF_INET;
105 _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
106 _res.nscount = 1;
107
108#ifdef SIOCGIFNUM
109 { int numifs, s, n, int_up;
110 struct ifconf ifc;
111 register struct ifreq *ifrp;
112 struct ifreq ifr;
113 unsigned bufsize;
114 unsigned int flags;
115 char *buf;
114 extern void *malloc();
115
116 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
117 perror("socket");
118 return (-1);
119 }
120 if (ioctl(s, SIOCGIFNUM, (char *)&numifs) < 0) {
121 numifs = MAXIFS;
122 }
123 bufsize = numifs * sizeof (struct ifreq);
124 buf = (char *)malloc(bufsize);
125 if (buf == NULL) {
126 perror("out of memory");
116
117 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
118 perror("socket");
119 return (-1);
120 }
121 if (ioctl(s, SIOCGIFNUM, (char *)&numifs) < 0) {
122 numifs = MAXIFS;
123 }
124 bufsize = numifs * sizeof (struct ifreq);
125 buf = (char *)malloc(bufsize);
126 if (buf == NULL) {
127 perror("out of memory");
127 close(s);
128 (void) close(s);
128 return (-1);
129 }
130 ifc.ifc_len = bufsize;
131 ifc.ifc_buf = buf;
132 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
133 perror("ifconfig: SIOCGIFCONF");
129 return (-1);
130 }
131 ifc.ifc_len = bufsize;
132 ifc.ifc_buf = buf;
133 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
134 perror("ifconfig: SIOCGIFCONF");
134 close(s);
135 (void) close(s);
135 free(buf);
136 return (-1);
137 }
138
139 int_up = 0;
140 ifrp = ifc.ifc_req;
141 for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0;
142 n--, ifrp++) {
136 free(buf);
137 return (-1);
138 }
139
140 int_up = 0;
141 ifrp = ifc.ifc_req;
142 for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0;
143 n--, ifrp++) {
143 memset((void *) &ifr, 0, sizeof (ifr));
144 (void) memset((void *) &ifr, 0, sizeof (ifr));
144 strncpy(ifr.ifr_name, ifrp->ifr_name,
145 sizeof (ifr.ifr_name));
146 if (ioctl(s, SIOCGIFFLAGS, (char *)&ifr) < 0) {
147 perror("SIOCGIFFLAGS");
145 strncpy(ifr.ifr_name, ifrp->ifr_name,
146 sizeof (ifr.ifr_name));
147 if (ioctl(s, SIOCGIFFLAGS, (char *)&ifr) < 0) {
148 perror("SIOCGIFFLAGS");
148 close(s);
149 (void) close(s);
149 free(buf);
150 return (-1);
151 }
152 flags = ifr.ifr_flags;
153 /* we are looking for a non-loopback interface */
154 if ((flags & IFF_UP) && ((flags & IFF_LOOPBACK) == 0))
155 int_up = 1;
156 }
150 free(buf);
151 return (-1);
152 }
153 flags = ifr.ifr_flags;
154 /* we are looking for a non-loopback interface */
155 if ((flags & IFF_UP) && ((flags & IFF_LOOPBACK) == 0))
156 int_up = 1;
157 }
157 close(s);
158 (void) close(s);
158 free(buf);
159 if (int_up == 0) /* all the non-LOOPBACK interfaces are DOWN */
160 return (-1);
161 }
162#endif /* SIOCGIFNUM */
163
164
165 /*
166 * for the benefit of hidden NIS domains, we use the same procedure
167 * as sendmail: convert leading + to dot, then drop to first dot
168 */
159 free(buf);
160 if (int_up == 0) /* all the non-LOOPBACK interfaces are DOWN */
161 return (-1);
162 }
163#endif /* SIOCGIFNUM */
164
165
166 /*
167 * for the benefit of hidden NIS domains, we use the same procedure
168 * as sendmail: convert leading + to dot, then drop to first dot
169 */
169 getdomainname(buf, BUFSIZ);
170 (void) getdomainname(buf, BUFSIZ);
170 if (buf[0] == '+')
171 if (buf[0] == '+')
171 buf[0] = '.';
172 buf[0] = '.';
172#ifdef SYSV
173 cp = strchr(buf, (int)'.');
174#else
175 cp = index(buf, '.');
176#endif
177 if (cp == NULL)
178 strcpy(_res.defdname, buf);
179 else

--- 124 unchanged lines hidden ---
173#ifdef SYSV
174 cp = strchr(buf, (int)'.');
175#else
176 cp = index(buf, '.');
177#endif
178 if (cp == NULL)
179 strcpy(_res.defdname, buf);
180 else

--- 124 unchanged lines hidden ---