Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Introduce allocaddrinfo(3) to make writing getaddrinfo() nss...
details: https://anonhg.NetBSD.org/src/rev/882d36c7a4e2
branches: trunk
changeset: 747770:882d36c7a4e2
user: tsarna <tsarna%NetBSD.org@localhost>
date: Fri Oct 02 02:45:28 2009 +0000
description:
Introduce allocaddrinfo(3) to make writing getaddrinfo() nss plugins easier.
Discussed on tech-net.
diffstat:
distrib/sets/lists/base/md.amd64 | 4 ++--
distrib/sets/lists/base/md.sparc64 | 4 ++--
distrib/sets/lists/base/shl.mi | 6 +++---
distrib/sets/lists/comp/mi | 5 ++++-
include/netdb.h | 3 ++-
lib/libc/net/Makefile.inc | 3 ++-
lib/libc/net/getaddrinfo.3 | 37 ++++++++++++++++++++++++++++++++++---
lib/libc/net/getaddrinfo.c | 33 +++++++++++++++++++++++++--------
lib/libc/shlib_version | 4 ++--
9 files changed, 76 insertions(+), 23 deletions(-)
diffs (278 lines):
diff -r 7cc4b839e77a -r 882d36c7a4e2 distrib/sets/lists/base/md.amd64
--- a/distrib/sets/lists/base/md.amd64 Fri Oct 02 00:00:59 2009 +0000
+++ b/distrib/sets/lists/base/md.amd64 Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.68 2009/09/11 16:01:59 mrg Exp $
+# $NetBSD: md.amd64,v 1.69 2009/10/02 02:45:28 tsarna Exp $
./dev/lms0 base-obsolete obsolete
./dev/mms0 base-obsolete obsolete
./libexec/ld.elf_so-i386 base-sys-shlib compat,pic
@@ -67,7 +67,7 @@
./usr/lib/i386/libbz2.so.1 base-compat-shlib compat,pic
./usr/lib/i386/libbz2.so.1.1 base-compat-shlib compat,pic
./usr/lib/i386/libc.so.12 base-compat-shlib compat,pic
-./usr/lib/i386/libc.so.12.170 base-compat-shlib compat,pic
+./usr/lib/i386/libc.so.12.171 base-compat-shlib compat,pic
./usr/lib/i386/libcom_err.so.6 base-compat-shlib compat,pic,kerberos
./usr/lib/i386/libcom_err.so.6.0 base-compat-shlib compat,pic,kerberos
./usr/lib/i386/libcrypt.so.1 base-compat-shlib compat,pic
diff -r 7cc4b839e77a -r 882d36c7a4e2 distrib/sets/lists/base/md.sparc64
--- a/distrib/sets/lists/base/md.sparc64 Fri Oct 02 00:00:59 2009 +0000
+++ b/distrib/sets/lists/base/md.sparc64 Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.sparc64,v 1.61 2009/09/11 22:36:53 mrg Exp $
+# $NetBSD: md.sparc64,v 1.62 2009/10/02 02:45:28 tsarna Exp $
./libexec/ld.elf_so-sparc base-sysutil-bin compat,pic
./sbin/edlabel base-sysutil-root
./usr/bin/fdformat base-util-bin
@@ -65,7 +65,7 @@
./usr/lib/sparc/libbz2.so.1 base-compat-shlib compat,pic
./usr/lib/sparc/libbz2.so.1.1 base-compat-shlib compat,pic
./usr/lib/sparc/libc.so.12 base-compat-shlib compat,pic
-./usr/lib/sparc/libc.so.12.170 base-compat-shlib compat,pic
+./usr/lib/sparc/libc.so.12.171 base-compat-shlib compat,pic
./usr/lib/sparc/libcom_err.so.6 base-compat-shlib compat,pic
./usr/lib/sparc/libcom_err.so.6.0 base-compat-shlib compat,pic
./usr/lib/sparc/libcrypt.so.1 base-compat-shlib compat,pic
diff -r 7cc4b839e77a -r 882d36c7a4e2 distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi Fri Oct 02 00:00:59 2009 +0000
+++ b/distrib/sets/lists/base/shl.mi Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.493 2009/09/30 03:41:12 tsarna Exp $
+# $NetBSD: shl.mi,v 1.494 2009/10/02 02:45:28 tsarna Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@@ -13,7 +13,7 @@
#
# Note: libtermcap and libtermlib are hardlinked and share the same version.
#
-./lib/libc.so.12.170 base-sys-shlib dynamicroot
+./lib/libc.so.12.171 base-sys-shlib dynamicroot
./lib/libcrypt.so.1.0 base-sys-shlib dynamicroot
./lib/libcrypto.so.6.0 base-crypto-shlib crypto,dynamicroot
./lib/libdevmapper.so.1.0 base-lvm-shlib lvm,dynamicroot
@@ -61,7 +61,7 @@
./usr/lib/libbluetooth.so.4.2 base-sys-shlib
./usr/lib/libbsdmalloc.so.0.0 base-sys-shlib
./usr/lib/libbz2.so.1.1 base-sys-shlib
-./usr/lib/libc.so.12.170 base-sys-shlib
+./usr/lib/libc.so.12.171 base-sys-shlib
./usr/lib/libcom_err.so.6.0 base-krb5-shlib kerberos
./usr/lib/libcrypt.so.1.0 base-sys-shlib
./usr/lib/libcrypto.so.6.0 base-crypto-shlib crypto
diff -r 7cc4b839e77a -r 882d36c7a4e2 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Fri Oct 02 00:00:59 2009 +0000
+++ b/distrib/sets/lists/comp/mi Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1314 2009/09/29 23:56:26 tsarna Exp $
+# $NetBSD: mi,v 1.1315 2009/10/02 02:45:29 tsarna Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4636,6 +4636,7 @@
./usr/share/man/cat3/aio_write.0 comp-c-catman .cat
./usr/share/man/cat3/alarm.0 comp-c-catman .cat
./usr/share/man/cat3/alloca.0 comp-c-catman .cat
+./usr/share/man/cat3/allocaddrinfo.0 comp-c-catman .cat
./usr/share/man/cat3/alphasort.0 comp-c-catman .cat
./usr/share/man/cat3/arc4random.0 comp-c-catman .cat
./usr/share/man/cat3/archive.0 comp-c-catman .cat
@@ -10215,6 +10216,7 @@
./usr/share/man/html3/aio_write.html comp-c-htmlman html
./usr/share/man/html3/alarm.html comp-c-htmlman html
./usr/share/man/html3/alloca.html comp-c-htmlman html
+./usr/share/man/html3/allocaddrinfo.html comp-c-htmlman html
./usr/share/man/html3/alphasort.html comp-c-htmlman html
./usr/share/man/html3/arc4random.html comp-c-htmlman html
./usr/share/man/html3/archive.html comp-c-htmlman html
@@ -15594,6 +15596,7 @@
./usr/share/man/man3/aio_write.3 comp-c-man .man
./usr/share/man/man3/alarm.3 comp-c-man .man
./usr/share/man/man3/alloca.3 comp-c-man .man
+./usr/share/man/man3/allocaddrinfo.3 comp-c-man .man
./usr/share/man/man3/alphasort.3 comp-c-man .man
./usr/share/man/man3/arc4random.3 comp-c-man .man
./usr/share/man/man3/archive.3 comp-c-man .man
diff -r 7cc4b839e77a -r 882d36c7a4e2 include/netdb.h
--- a/include/netdb.h Fri Oct 02 00:00:59 2009 +0000
+++ b/include/netdb.h Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netdb.h,v 1.61 2009/04/12 17:07:33 christos Exp $ */
+/* $NetBSD: netdb.h,v 1.62 2009/10/02 02:45:29 tsarna Exp $ */
/*
* ++Copyright++ 1980, 1983, 1988, 1993
@@ -343,6 +343,7 @@
int getnameinfo(const struct sockaddr * __restrict, socklen_t,
char * __restrict, socklen_t,
char * __restrict, socklen_t, int);
+struct addrinfo *allocaddrinfo(socklen_t);
void freeaddrinfo(struct addrinfo *);
const char *gai_strerror(int);
#endif
diff -r 7cc4b839e77a -r 882d36c7a4e2 lib/libc/net/Makefile.inc
--- a/lib/libc/net/Makefile.inc Fri Oct 02 00:00:59 2009 +0000
+++ b/lib/libc/net/Makefile.inc Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.77 2009/06/08 17:18:11 christos Exp $
+# $NetBSD: Makefile.inc,v 1.78 2009/10/02 02:45:29 tsarna Exp $
# @(#)Makefile.inc 8.2 (Berkeley) 9/5/93
# net sources
@@ -114,6 +114,7 @@
inet6_option_space.3 inet6_rthdr_space.3 \
inet6_opt_init.3 inet6_rth_space.3
MLINKS+=getaddrinfo.3 freeaddrinfo.3 \
+ getaddrinfo.3 allocaddrinfo.3 \
getifaddrs.3 freeifaddrs.3 \
if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \
if_indextoname.3 if_freenameindex.3 \
diff -r 7cc4b839e77a -r 882d36c7a4e2 lib/libc/net/getaddrinfo.3
--- a/lib/libc/net/getaddrinfo.3 Fri Oct 02 00:00:59 2009 +0000
+++ b/lib/libc/net/getaddrinfo.3 Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: getaddrinfo.3,v 1.46 2006/12/23 07:42:30 wiz Exp $
+.\" $NetBSD: getaddrinfo.3,v 1.47 2009/10/02 02:45:29 tsarna Exp $
.\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $
.\" $OpenBSD: getaddrinfo.3,v 1.35 2004/12/21 03:40:31 jaredy Exp $
.\"
@@ -22,7 +22,8 @@
.Os
.Sh NAME
.Nm getaddrinfo ,
-.Nm freeaddrinfo
+.Nm freeaddrinfo ,
+.Nm allocaddrinfo
.Nd host and service name to socket address structure
.Sh SYNOPSIS
.In netdb.h
@@ -32,6 +33,8 @@
"const struct addrinfo * restrict hints" "struct addrinfo ** restrict res"
.Ft void
.Fn freeaddrinfo "struct addrinfo *ai"
+.Ft struct addrinfo *
+.Fn allocaddrinfo "socklen_t len"
.Sh DESCRIPTION
The
.Fn getaddrinfo
@@ -280,7 +283,35 @@
pointer should be a
.Li addrinfo
structure created by a call to
-.Fn getaddrinfo .
+.Fn getaddrinfo
+or
+.Fn allocaddrinfo .
+The
+.Fn allocaddrinfo
+function is intended primarily for authors of
+.Xr nsdispatch 3
+plugins implementing
+.Fn getaddrinfo
+backends.
+.Fn allocaddrinfo
+allocates a
+.Li struct addrinfo
+in a way that is compatible with being returned from
+.Fn getaddrinfo
+and being ultimately freed by
+.Fn freeaddrinfo .
+The returned structure is zeroed, except for the
+.Fa ai_addr
+field, which
+will point to
+.Fa len
+bytes of memory for storage of a socket address.
+It is safe to allocate memory separately for
+.Fa ai_canonname
+with
+.Xr malloc 3 ,
+or in any other way that is compatible with deallocation by
+.Xr free 3 .
.Sh RETURN VALUES
.Fn getaddrinfo
returns zero on success or one of the error codes listed in
diff -r 7cc4b839e77a -r 882d36c7a4e2 lib/libc/net/getaddrinfo.c
--- a/lib/libc/net/getaddrinfo.c Fri Oct 02 00:00:59 2009 +0000
+++ b/lib/libc/net/getaddrinfo.c Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getaddrinfo.c,v 1.92 2009/01/23 00:48:57 tls Exp $ */
+/* $NetBSD: getaddrinfo.c,v 1.93 2009/10/02 02:45:29 tsarna Exp $ */
/* $KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $ */
/*
@@ -55,7 +55,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.92 2009/01/23 00:48:57 tls Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.93 2009/10/02 02:45:29 tsarna Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -847,26 +847,43 @@
return 0;
}
+struct addrinfo *
+allocaddrinfo(socklen_t addrlen)
+{
+ struct addrinfo *ai;
+
+ ai = calloc(sizeof(struct addrinfo) + addrlen, 1);
+ if (ai) {
+ ai->ai_addr = (void *)(ai+1);
+ ai->ai_addrlen = ai->ai_addr->sa_len = addrlen;
+ }
+
+ return ai;
+}
+
static struct addrinfo *
get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr)
{
char *p;
struct addrinfo *ai;
+ struct sockaddr *save;
_DIAGASSERT(pai != NULL);
_DIAGASSERT(afd != NULL);
_DIAGASSERT(addr != NULL);
- ai = (struct addrinfo *)malloc(sizeof(struct addrinfo)
- + (afd->a_socklen));
+ ai = allocaddrinfo((socklen_t)afd->a_socklen);
if (ai == NULL)
return NULL;
+ save = ai->ai_addr;
memcpy(ai, pai, sizeof(struct addrinfo));
- ai->ai_addr = (struct sockaddr *)(void *)(ai + 1);
- memset(ai->ai_addr, 0, (size_t)afd->a_socklen);
- ai->ai_addr->sa_len = afd->a_socklen;
- ai->ai_addrlen = afd->a_socklen;
+
+ /* since we just overwrote all of ai, we have
+ to restore ai_addr and ai_addrlen */
+ ai->ai_addr = save;
+ ai->ai_addrlen = (socklen_t)afd->a_socklen;
+
ai->ai_addr->sa_family = ai->ai_family = afd->a_af;
p = (char *)(void *)(ai->ai_addr);
memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen);
diff -r 7cc4b839e77a -r 882d36c7a4e2 lib/libc/shlib_version
--- a/lib/libc/shlib_version Fri Oct 02 00:00:59 2009 +0000
+++ b/lib/libc/shlib_version Fri Oct 02 02:45:28 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shlib_version,v 1.214 2009/08/16 19:33:38 christos Exp $
+# $NetBSD: shlib_version,v 1.215 2009/10/02 02:45:29 tsarna Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
# things we wish to do on next major version bump:
@@ -35,4 +35,4 @@
# it's insufficient bitwidth to implement all ctype class.
# see isblank's comment in ctype.h.
major=12
-minor=170
+minor=171
Home |
Main Index |
Thread Index |
Old Index