Deleted Added
full compact
getnetbynis.c (8870) getnetbynis.c (11661)
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.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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.2 1994/09/26 02:50:43 wollman Exp $";
28static char rcsid[] = "$Id: getnetbynis.c,v 1.2 1994/09/26 02:50:43 wollman Exp $";
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 $";
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>
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>
37#include <ctype.h>
38#include <errno.h>
39#include <string.h>
40
41#define MAXALIASES 35
42#define MAXADDRS 35
43
44#ifdef YP
45static char *host_aliases[MAXALIASES];
46#endif /* YP */
47
48static struct netent *
49_getnetbynis(name, map)
50 char *name, *map;
51{
52#ifdef YP
53 register char *cp, **q;
54 static char *result;
55 int resultlen;
56 static struct netent h;
57 static char *domain = (char *)NULL;
58
59 if (domain == (char *)NULL)
60 if (yp_get_default_domain (&domain))
61 return (NULL);
62
63 if (result) {
64 free(result);
65 result = 0;
66 }
67
68 if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
69 return (NULL);
70
71 if ((cp = index(result, '\n')))
72 *cp = '\0';
73
74 cp = strpbrk(result, " \t");
75 *cp++ = '\0';
76 h.n_name = result;
77
78 while (*cp == ' ' || *cp == '\t')
79 cp++;
80
81 h.n_net = inet_network(cp);
82 h.n_addrtype = AF_INET;
83
84 q = h.n_aliases = host_aliases;
85 cp = strpbrk(cp, " \t");
86 if (cp != NULL)
87 *cp++ = '\0';
88 while (cp && *cp) {
89 if (*cp == ' ' || *cp == '\t') {
90 cp++;
91 continue;
92 }
93 if (q < &host_aliases[MAXALIASES - 1])
94 *q++ = cp;
95 cp = strpbrk(cp, " \t");
96 if (cp != NULL)
97 *cp++ = '\0';
98 }
99 *q = NULL;
100 return (&h);
101#else
102 return (NULL);
103#endif
104}
105
106struct netent *
107_getnetbynisname(name)
108 char *name;
109{
110 return _getnetbynis(name, "networks.byname");
111}
112
113struct netent *
114_getnetbynisaddr(addr, type)
115 long addr;
116 int type;
117{
118 struct in_addr in;
119 char *str, *cp;
38#include <ctype.h>
39#include <errno.h>
40#include <string.h>
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;
59
60 if (domain == (char *)NULL)
61 if (yp_get_default_domain (&domain))
62 return (NULL);
63
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
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')
80 cp++;
81
82 h.n_net = inet_network(cp);
83 h.n_addrtype = AF_INET;
84
85 q = h.n_aliases = host_aliases;
86 cp = strpbrk(cp, " \t");
87 if (cp != NULL)
88 *cp++ = '\0';
89 while (cp && *cp) {
90 if (*cp == ' ' || *cp == '\t') {
91 cp++;
92 continue;
93 }
94 if (q < &host_aliases[MAXALIASES - 1])
95 *q++ = cp;
96 cp = strpbrk(cp, " \t");
97 if (cp != NULL)
98 *cp++ = '\0';
99 }
100 *q = NULL;
101 return (&h);
102#else
103 return (NULL);
104#endif
105}
106
107struct netent *
108_getnetbynisname(name)
109 char *name;
110{
111 return _getnetbynis(name, "networks.byname");
112}
113
114struct netent *
115_getnetbynisaddr(addr, type)
116 long addr;
117 int type;
118{
119 struct in_addr in;
120 char *str, *cp;
120 struct netent *np;
121
122 if (type != AF_INET)
123 return (NULL);
124
125 in.s_addr = addr;
126 str = inet_ntoa(in);
127 cp = str + strlen(str) - 2;
128 while(!strcmp(cp, ".0")) {
129 *cp = '\0';
130 cp = str + strlen(str) - 2;
131 }
132
133 return _getnetbynis(str, "networks.byaddr");
134}
121
122 if (type != AF_INET)
123 return (NULL);
124
125 in.s_addr = addr;
126 str = inet_ntoa(in);
127 cp = str + strlen(str) - 2;
128 while(!strcmp(cp, ".0")) {
129 *cp = '\0';
130 cp = str + strlen(str) - 2;
131 }
132
133 return _getnetbynis(str, "networks.byaddr");
134}