gethostent.c revision 61961e0f20c7637a3846bb39786bb9dffa91dfb9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Ye olde non-reentrant interface (MT-unsafe, caveat utor)
*
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <netdb.h>
#include <stdio.h>
#include <nss_dbdefs.h>
/*
* Still just a global. If you want per-thread h_errno,
* use the reentrant interfaces (gethostbyname_r et al)
*/
int h_errno;
#ifdef NSS_INCLUDE_UNSAFE
/*
* Don't free this, even on an endhostent(), because bitter experience shows
* that there's production code that does getXXXbyYYY(), then endXXXent(),
* and then continues to use the pointer it got back.
*/
static nss_XbyY_buf_t *buffer;
#define GETBUF() \
/* === ?? set ENOMEM on failure? */
struct hostent *
gethostbyname(const char *nam)
{
nss_XbyY_buf_t *b;
if ((b = GETBUF()) == 0)
return (NULL);
&h_errno));
}
struct hostent *
{
nss_XbyY_buf_t *b;
h_errno = 0;
if ((b = GETBUF()) == 0)
return (NULL);
}
struct hostent *
gethostent(void)
{
nss_XbyY_buf_t *b;
if ((b = GETBUF()) == 0)
return (NULL);
}
/*
* Return values: 0 = success, 1 = parse error, 2 = erange ...
* The structure pointer passed in is a structure in the caller's space
* wherein the field pointers would be set to areas in the buffer if
* need be. instring and buffer should be separate areas.
*/
int
int buflen)
{
int naddr, i, aliases_erange = 0;
char **addrvec;
return (NSS_STR_PARSE_PARSE);
/*
* XXX - Returning ERANGE here is completely bogus.
* Unfortunately, there's no error code identifying
* bogus calls from the backend (and nothing the user
* can do about our bugs anyway).
*/
return (NSS_STR_PARSE_ERANGE);
}
/*
* The DNS-via-YP code returns multiple lines for a key.
* Normal YP return values do not contain newlines (nor do
* We count the number of newlines; this should give us
* the number of IP addresses specified.
* We'll also call the aliases code and instruct it to
* stop at the first newline as the remaining lines will
*
* When confronted with a string with embedded newlines,
* and each of the IP addresses at the start of all lines.
* Because the NIS protocol limits return values to 1024 bytes,
* we still do not get all addresses. If you want to fix
* that problem, do not look here.
*/
p = instr;
/* Strip trailing newlines */
lenstr--;
naddr = 1;
naddr++;
/* Allocate space for naddr addresses and h_addr_list */
sizeof (*addrp6));
} else {
sizeof (*addrp));
}
return (NSS_STR_PARSE_ERANGE);
/* For each addr, parse and get it */
p = instr;
for (i = 0; i < naddr; i ++) {
p++;
addrstart = p;
p++;
if (p >= limit)
/* Syntax error - no hostname present or truncated line */
return (NSS_STR_PARSE_PARSE);
/* Syntax error -- supposed IP address is too long */
return (NSS_STR_PARSE_PARSE);
: INET_ADDRSTRLEN))
/* Syntax error -- supposed IP address is too long */
return (NSS_STR_PARSE_PARSE);
/*
* inet_pton() doesn't handle d.d.d, d.d, or d formats,
* so we must use inet_addr() for IPv4 addresses.
*/
0xffffffffU)
/* Syntax error -- bogus IPv4 address */
return (NSS_STR_PARSE_PARSE);
} else {
/*
* In the case of AF_INET6, we can have both v4 and v6
* addresses, so we convert v4's to v4 mapped addresses
* and return them as such.
*/
return (NSS_STR_PARSE_PARSE);
} else {
0xffffffffU)
return (NSS_STR_PARSE_PARSE);
}
}
/* First address, this is where we get the hostname + aliases */
if (i == 0) {
p++;
}
}
break;
else
}
if (aliases_erange)
else
} else {
/* Success */
}
/*
* If i < naddr, we quit the loop early and addrvec[i+1] needs NULL
* otherwise, we ran naddr iterations and addrvec[naddr] needs NULL
*/
} else {
}
return (res);
}
#endif /* NSS_INCLUDE_UNSAFE */