gethostbynis.c:
- Fix problem described in PR #1079: _gethostbynisaddr() doesn't work. Make it accept the same arguments as all the other gethostby*addr() functions and properly convert the supplied IP address into a text string so that yp_match() can find it in the hosts.byaddr map. - Also fix potential memory leak: copy the results of yp_match() to a static buffer and free the result (yp_match() returns dynamically allocated memory). ether_addr.c: - Since I was in the neighborhood, fix ether_ntohost() and ether_hostton() so that they don't bogusly for a free(result) when yp_match() fails.
This commit is contained in:
parent
47ab1071a2
commit
d51d5c3ca5
@ -35,7 +35,7 @@
|
||||
* Center for Telecommunications Research
|
||||
* Columbia University, New York City
|
||||
*
|
||||
* $Id: ether_addr.c,v 1.1 1995/04/02 01:31:17 wpaul Exp $
|
||||
* $Id: ether_addr.c,v 1.2 1995/08/07 03:42:14 wpaul Exp $
|
||||
*/
|
||||
|
||||
|
||||
@ -147,7 +147,6 @@ int ether_ntohost(hostname, e)
|
||||
ether_a = ether_ntoa(e);
|
||||
if (yp_match(yp_domain, "ethers.byaddr", ether_a,
|
||||
strlen(ether_a), &result, &resultlen)) {
|
||||
free(result);
|
||||
continue;
|
||||
}
|
||||
strncpy((char *)&buf, result, resultlen);
|
||||
@ -197,7 +196,6 @@ int ether_hostton(hostname, e)
|
||||
continue;
|
||||
if (yp_match(yp_domain, "ethers.byname", hostname,
|
||||
strlen(hostname), &result, &resultlen)) {
|
||||
free(result);
|
||||
continue;
|
||||
}
|
||||
strncpy((char *)&buf, result, resultlen);
|
||||
|
@ -24,8 +24,8 @@
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)$Id$";
|
||||
static char rcsid[] = "$Id$";
|
||||
static char sccsid[] = "@(#)$Id: gethostbynis.c,v 1.1 1994/09/25 02:12:14 pst Exp $";
|
||||
static char rcsid[] = "$Id: gethostbynis.c,v 1.1 1994/09/25 02:12:14 pst Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -37,6 +37,11 @@ static char rcsid[] = "$Id$";
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#ifdef YP
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpcsvc/yp_prot.h>
|
||||
#include <rpcsvc/ypclnt.h>
|
||||
#endif
|
||||
|
||||
#define MAXALIASES 35
|
||||
#define MAXADDRS 35
|
||||
@ -57,6 +62,7 @@ _gethostbynis(name, map)
|
||||
int resultlen;
|
||||
static struct hostent h;
|
||||
static char *domain = (char *)NULL;
|
||||
static char ypbuf[YPMAXRECORD];
|
||||
|
||||
if (domain == (char *)NULL)
|
||||
if (yp_get_default_domain (&domain))
|
||||
@ -65,6 +71,11 @@ _gethostbynis(name, map)
|
||||
if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
|
||||
return ((struct hostent *)NULL);
|
||||
|
||||
/* avoid potential memory leak */
|
||||
bcopy((char *)result, (char *)&ypbuf, resultlen);
|
||||
free(result);
|
||||
result = (char *)&ypbuf;
|
||||
|
||||
if ((cp = index(result, '\n')))
|
||||
*cp = '\0';
|
||||
|
||||
@ -108,8 +119,10 @@ _gethostbynisname(name)
|
||||
}
|
||||
|
||||
struct hostent *
|
||||
_gethostbynisaddr(name)
|
||||
char *name;
|
||||
_gethostbynisaddr(addr, len, type)
|
||||
char *addr;
|
||||
int len;
|
||||
int type;
|
||||
{
|
||||
return _gethostbynis(name, "hosts.byaddr");
|
||||
return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user