Deleted Added
full compact
getnetbynis.c (11661) getnetbynis.c (14775)
1/*-
2 * Copyright (c) 1994, Garrett Wollman
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

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

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#if defined(LIBC_SCCS) && !defined(lint)
1/*-
2 * Copyright (c) 1994, Garrett Wollman
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

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

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#if defined(LIBC_SCCS) && !defined(lint)
27static char sccsid[] = "@(#)$Id: getnetbynis.c,v 1.3 1995/05/30 05:40:47 rgrimes Exp $";
28static char rcsid[] = "$Id: getnetbynis.c,v 1.3 1995/05/30 05:40:47 rgrimes Exp $";
27static char sccsid[] = "@(#)$Id: getnetbynis.c,v 1.4 1995/10/22 14:39:06 phk Exp $";
28static char rcsid[] = "$Id: getnetbynis.c,v 1.4 1995/10/22 14:39:06 phk Exp $";
29#endif /* LIBC_SCCS and not lint */
30
31#include <sys/param.h>
32#include <sys/socket.h>
33#include <netinet/in.h>
34#include <arpa/inet.h>
35#include <netdb.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <ctype.h>
39#include <errno.h>
40#include <string.h>
29#endif /* LIBC_SCCS and not lint */
30
31#include <sys/param.h>
32#include <sys/socket.h>
33#include <netinet/in.h>
34#include <arpa/inet.h>
35#include <netdb.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <ctype.h>
39#include <errno.h>
40#include <string.h>
41#include <arpa/nameser.h>
42#ifdef YP
43#include <rpc/rpc.h>
44#include <rpcsvc/yp_prot.h>
45#include <rpcsvc/ypclnt.h>
46#endif
41
42#define MAXALIASES 35
43#define MAXADDRS 35
44
45#ifdef YP
46static char *host_aliases[MAXALIASES];
47#endif /* YP */
48
49static struct netent *
50_getnetbynis(name, map)
51 char *name, *map;
52{
53#ifdef YP
54 register char *cp, **q;
55 static char *result;
56 int resultlen;
57 static struct netent h;
58 static char *domain = (char *)NULL;
47
48#define MAXALIASES 35
49#define MAXADDRS 35
50
51#ifdef YP
52static char *host_aliases[MAXALIASES];
53#endif /* YP */
54
55static struct netent *
56_getnetbynis(name, map)
57 char *name, *map;
58{
59#ifdef YP
60 register char *cp, **q;
61 static char *result;
62 int resultlen;
63 static struct netent h;
64 static char *domain = (char *)NULL;
65 static char ypbuf[YPMAXRECORD];
59
60 if (domain == (char *)NULL)
61 if (yp_get_default_domain (&domain))
62 return (NULL);
63
66
67 if (domain == (char *)NULL)
68 if (yp_get_default_domain (&domain))
69 return (NULL);
70
64 if (result) {
65 free(result);
66 result = 0;
67 }
68
69 if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
70 return (NULL);
71
71 if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
72 return (NULL);
73
74 bcopy((char *)result, (char *)&ypbuf, resultlen);
75 free(result);
76 result = (char *)&ypbuf;
77
72 if ((cp = index(result, '\n')))
73 *cp = '\0';
74
75 cp = strpbrk(result, " \t");
76 *cp++ = '\0';
77 h.n_name = result;
78
79 while (*cp == ' ' || *cp == '\t')

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

111 return _getnetbynis(name, "networks.byname");
112}
113
114struct netent *
115_getnetbynisaddr(addr, type)
116 long addr;
117 int type;
118{
78 if ((cp = index(result, '\n')))
79 *cp = '\0';
80
81 cp = strpbrk(result, " \t");
82 *cp++ = '\0';
83 h.n_name = result;
84
85 while (*cp == ' ' || *cp == '\t')

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

117 return _getnetbynis(name, "networks.byname");
118}
119
120struct netent *
121_getnetbynisaddr(addr, type)
122 long addr;
123 int type;
124{
119 struct in_addr in;
120 char *str, *cp;
125 char *str, *cp;
126 unsigned long net2;
127 int nn;
128 unsigned int netbr[4];
129 char buf[MAXDNAME];
121
122 if (type != AF_INET)
123 return (NULL);
124
130
131 if (type != AF_INET)
132 return (NULL);
133
125 in.s_addr = addr;
126 str = inet_ntoa(in);
127 cp = str + strlen(str) - 2;
134 for (nn = 4, net2 = addr; net2; net2 >>= 8) {
135 netbr[--nn] = net2 & 0xff;
136 }
137
138 switch (nn) {
139 case 3: /* Class A */
140 sprintf(buf, "%u", netbr[3]);
141 break;
142 case 2: /* Class B */
143 sprintf(buf, "%u.%u", netbr[2], netbr[3]);
144 break;
145 case 1: /* Class C */
146 sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
147 break;
148 case 0: /* Class D - E */
149 sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
150 netbr[2], netbr[3]);
151 break;
152 }
153
154 str = (char *)&buf;
155 cp = str + (strlen(str) - 2);
156
128 while(!strcmp(cp, ".0")) {
129 *cp = '\0';
157 while(!strcmp(cp, ".0")) {
158 *cp = '\0';
130 cp = str + strlen(str) - 2;
159 cp = str + (strlen(str) - 2);
131 }
132
133 return _getnetbynis(str, "networks.byaddr");
134}
160 }
161
162 return _getnetbynis(str, "networks.byaddr");
163}