Commit 16b5ecc6 authored by Mark Andrews's avatar Mark Andrews

glibc getnet*_r()

parent 1336066b
......@@ -18,7 +18,7 @@ AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
esyscmd([sed "s/^/# /" COPYRIGHT])dnl
AC_DIVERT_POP()dnl
AC_REVISION($Revision: 1.70 $)
AC_REVISION($Revision: 1.71 $)
AC_INIT(resolv/herror.c)
AC_PREREQ(2.13)
......@@ -1414,8 +1414,25 @@ NET_R_BAD="#define NET_R_BAD NULL"
NET_R_COPY="#define NET_R_COPY buf, buflen"
NET_R_COPY_ARGS="#define NET_R_COPY_ARGS NET_R_ARGS"
NET_R_OK="#define NET_R_OK nptr"
NET_R_SETANSWER="#undef NET_R_SETANSWER"
NET_R_RETURN="#define NET_R_RETURN struct netent *"
],
AC_TRY_COMPILE(
[#include <netdb.h>
int getnetbyaddr_r (unsigned long int, int, struct netent *,
char *, size_t, struct netent **, int *);
],
[return (0)],
[
NET_R_ARGS="#define NET_R_ARGS char *buf, size_t buflen, struct netent **answerp, int *h_errnop"
NET_R_BAD="#define NET_R_BAD ERANGE"
NET_R_COPY="#define NET_R_COPY buf, buflen"
NET_R_COPY_ARGS="#define NET_R_COPY_ARGS char *buf, size_t buflen"
NET_R_OK="#define NET_R_OK 0"
NET_R_SETANSWER="#define NET_R_SETANSWER 1"
NET_R_RETURN="#define NET_R_RETURN int"
],
)
)
,
NET_R_ARGS="#define NET_R_ARGS char *buf, int buflen"
......@@ -1423,6 +1440,7 @@ NET_R_BAD="#define NET_R_BAD NULL"
NET_R_COPY="#define NET_R_COPY buf, buflen"
NET_R_COPY_ARGS="#define NET_R_COPY_ARGS NET_R_ARGS"
NET_R_OK="#define NET_R_OK nptr"
NET_R_SETANSWER="#undef NET_R_SETANSWER"
NET_R_RETURN="#define NET_R_RETURN struct netent *"
)
AC_SUBST(NET_R_ARGS)
......@@ -1430,6 +1448,7 @@ AC_SUBST(NET_R_BAD)
AC_SUBST(NET_R_COPY)
AC_SUBST(NET_R_COPY_ARGS)
AC_SUBST(NET_R_OK)
AC_SUBST(NET_R_SETANSWER)
AC_SUBST(NET_R_RETURN)
AC_CHECK_FUNC(setnetent_r,
......
......@@ -86,7 +86,7 @@
/*
* @(#)netdb.h 8.1 (Berkeley) 6/2/93
* $Id: netdb.h,v 1.7 2001/07/16 05:23:28 marka Exp $
* $Id: netdb.h,v 1.8 2001/07/16 08:05:19 marka Exp $
*/
#ifndef _NETDB_H_
......@@ -454,11 +454,19 @@ struct hostent *gethostent_r __P((struct hostent *, char *, int, int *));
void sethostent_r __P((int));
void endhostent_r __P((void));
#ifdef __GLIBC__
int getnetbyname_r __P((const char *, struct netent *,
char *, size_t, struct netent **, int*));
int getnetbyaddr_r __P((long, int, struct netent *,
char *, size_t, struct netent **, int*));
int getnetent_r __P((struct netent *, char *, size_t, struct netent **, int*));
#else
struct netent *getnetbyname_r __P((const char *, struct netent *,
char *, int));
struct netent *getnetbyaddr_r __P((long, int, struct netent *,
char *, int));
struct netent *getnetent_r __P((struct netent *, char *, int));
#endif
void setnetent_r __P((int));
void endnetent_r __P((void));
......
......@@ -16,7 +16,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id: getnetent_r.c,v 1.2 2001/07/15 23:29:45 marka Exp $";
static const char rcsid[] = "$Id: getnetent_r.c,v 1.3 2001/07/16 08:05:20 marka Exp $";
#endif /* LIBC_SCCS and not lint */
#include <port_before.h>
......@@ -40,11 +40,22 @@ copy_netent(struct netent *, struct netent *, NET_R_COPY_ARGS);
NET_R_RETURN
getnetbyname_r(const char *name, struct netent *nptr, NET_R_ARGS) {
struct netent *ne = getnetbyname(name);
#ifdef NET_R_SETANSWER
int n = 0;
if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0)
*answerp = NULL;
else
*answerp = ne;
if (ne == NULL)
*h_errnop = h_errno;
return (n);
#else
if (ne == NULL)
return (NET_R_BAD);
return (copy_netent(ne, nptr, NET_R_COPY));
#endif
}
#ifndef GETNETBYADDR_ADDR_T
......@@ -53,11 +64,23 @@ getnetbyname_r(const char *name, struct netent *nptr, NET_R_ARGS) {
NET_R_RETURN
getnetbyaddr_r(GETNETBYADDR_ADDR_T addr, int type, struct netent *nptr, NET_R_ARGS) {
struct netent *ne = getnetbyaddr(addr, type);
#ifdef NET_R_SETANSWER
int n = 0;
if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0)
*answerp = NULL;
else
*answerp = ne;
if (ne == NULL)
*h_errnop = h_errno;
return (n);
#else
if (ne == NULL)
return (NET_R_BAD);
return (copy_netent(ne, nptr, NET_R_COPY));
#endif
}
/*
......@@ -69,11 +92,23 @@ getnetbyaddr_r(GETNETBYADDR_ADDR_T addr, int type, struct netent *nptr, NET_R_AR
NET_R_RETURN
getnetent_r(struct netent *nptr, NET_R_ARGS) {
struct netent *ne = getnetent();
#ifdef NET_R_SETANSWER
int n = 0;
if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0)
*answerp = NULL;
else
*answerp = ne;
if (ne == NULL)
*h_errnop = h_errno;
return (n);
#else
if (ne == NULL)
return (NET_R_BAD);
return (copy_netent(ne, nptr, NET_R_COPY));
#endif
}
NET_R_SET_RETURN
......@@ -118,7 +153,7 @@ copy_netent(struct netent *ne, struct netent *nptr, NET_R_COPY_ARGS) {
len += strlen(ne->n_name) + 1;
len += numptr * sizeof(char*);
if (len > buflen) {
if (len > (int)buflen) {
errno = ERANGE;
return (NET_R_BAD);
}
......
......@@ -35,6 +35,7 @@ struct timezone; /* silence warning */
@NET_R_OK@
@NET_R_RETURN@
@NET_R_SET_RESULT@
@NET_R_SETANSWER@
@NET_R_SET_RETURN@
@GROUP_R_RETURN@
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment