summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/getnetbynis.c
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1996-03-23 22:16:22 +0000
committerwpaul <wpaul@FreeBSD.org>1996-03-23 22:16:22 +0000
commitce5b804dd075dfa57105aaf12534b68a604f49c0 (patch)
tree0b693f5fc763cc94d7b8a3bd40f544a0fc77665b /lib/libc/net/getnetbynis.c
parent4d62e1dae8eabe2df600d0e7f46b88be1b8f6c0e (diff)
downloadFreeBSD-src-ce5b804dd075dfa57105aaf12534b68a604f49c0.zip
FreeBSD-src-ce5b804dd075dfa57105aaf12534b68a604f49c0.tar.gz
Fix other half of problem reported in PR #1079: _getnetbynisaddr() is
broken. The translation from network number to ASCII string was not working correctly (you would sometimes get things like 0.244.0.0 instead of 244.0.0). Also copied results of yp_match() to a static buffer for consistency with gethostbynis.c. Note: _getnetbynisaddr() chops off trailing .0's, i.e. 244.0.0 is truncated to 244. By contrast, getnetbyht.c code (for local /etc/networks lookups) leaves the traling .0's in place. This means that the NIS and local file lookups will match different things when looking up the same network number. I'm not sure which is the correct behavior. (I think the DNS lookup code tries all combinations -- should the NIS and local host lookup routines do that too?)
Diffstat (limited to 'lib/libc/net/getnetbynis.c')
-rw-r--r--lib/libc/net/getnetbynis.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/lib/libc/net/getnetbynis.c b/lib/libc/net/getnetbynis.c
index d87ca0f..ac11aa3 100644
--- a/lib/libc/net/getnetbynis.c
+++ b/lib/libc/net/getnetbynis.c
@@ -24,8 +24,8 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)$Id: getnetbynis.c,v 1.3 1995/05/30 05:40:47 rgrimes Exp $";
-static char rcsid[] = "$Id: getnetbynis.c,v 1.3 1995/05/30 05:40:47 rgrimes Exp $";
+static char sccsid[] = "@(#)$Id: getnetbynis.c,v 1.4 1995/10/22 14:39:06 phk Exp $";
+static char rcsid[] = "$Id: getnetbynis.c,v 1.4 1995/10/22 14:39:06 phk Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -38,6 +38,12 @@ static char rcsid[] = "$Id: getnetbynis.c,v 1.3 1995/05/30 05:40:47 rgrimes Exp
#include <ctype.h>
#include <errno.h>
#include <string.h>
+#include <arpa/nameser.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
#define MAXALIASES 35
#define MAXADDRS 35
@@ -56,19 +62,19 @@ _getnetbynis(name, map)
int resultlen;
static struct netent h;
static char *domain = (char *)NULL;
+ static char ypbuf[YPMAXRECORD];
if (domain == (char *)NULL)
if (yp_get_default_domain (&domain))
return (NULL);
- if (result) {
- free(result);
- result = 0;
- }
-
if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
return (NULL);
+ bcopy((char *)result, (char *)&ypbuf, resultlen);
+ free(result);
+ result = (char *)&ypbuf;
+
if ((cp = index(result, '\n')))
*cp = '\0';
@@ -116,18 +122,41 @@ _getnetbynisaddr(addr, type)
long addr;
int type;
{
- struct in_addr in;
char *str, *cp;
+ unsigned long net2;
+ int nn;
+ unsigned int netbr[4];
+ char buf[MAXDNAME];
if (type != AF_INET)
return (NULL);
- in.s_addr = addr;
- str = inet_ntoa(in);
- cp = str + strlen(str) - 2;
+ for (nn = 4, net2 = addr; net2; net2 >>= 8) {
+ netbr[--nn] = net2 & 0xff;
+ }
+
+ switch (nn) {
+ case 3: /* Class A */
+ sprintf(buf, "%u", netbr[3]);
+ break;
+ case 2: /* Class B */
+ sprintf(buf, "%u.%u", netbr[2], netbr[3]);
+ break;
+ case 1: /* Class C */
+ sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
+ break;
+ case 0: /* Class D - E */
+ sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
+ netbr[2], netbr[3]);
+ break;
+ }
+
+ str = (char *)&buf;
+ cp = str + (strlen(str) - 2);
+
while(!strcmp(cp, ".0")) {
*cp = '\0';
- cp = str + strlen(str) - 2;
+ cp = str + (strlen(str) - 2);
}
return _getnetbynis(str, "networks.byaddr");
OpenPOWER on IntegriCloud