mirror of
https://github.com/opnsense/src.git
synced 2026-06-11 01:30:30 -04:00
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?)
This commit is contained in:
parent
60743d0a33
commit
ff27d2a474
1 changed files with 41 additions and 12 deletions
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue