CVS commit: src/lib/libc/net

2020-06-05 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Jun  5 11:16:15 UTC 2020

Modified Files:
src/lib/libc/net: getnetent.c getnetnamadr.c

Log Message:
Remove more bogus tests for 64-bit i386 and SuperH.

These are always false.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/net/getnetent.c
cvs rdiff -u -r1.44 -r1.45 src/lib/libc/net/getnetnamadr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnetent.c
diff -u src/lib/libc/net/getnetent.c:1.21 src/lib/libc/net/getnetent.c:1.22
--- src/lib/libc/net/getnetent.c:1.21	Tue Mar 20 17:44:18 2012
+++ src/lib/libc/net/getnetent.c	Fri Jun  5 11:16:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnetent.c,v 1.21 2012/03/20 17:44:18 matt Exp $	*/
+/*	$NetBSD: getnetent.c,v 1.22 2020/06/05 11:16:15 nia Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -44,7 +44,7 @@
 static char sccsid[] = "@(#)getnetent.c	8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: getnetent.c,v 1.21 2012/03/20 17:44:18 matt Exp $");
+__RCSID("$NetBSD: getnetent.c,v 1.22 2020/06/05 11:16:15 nia Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -121,9 +121,7 @@ getnetent(void)
 	if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "re")) == NULL)
 		return (NULL);
 #if (defined(__sparc__) && defined(_LP64)) ||		\
-defined(__alpha__) ||\
-(defined(__i386__) && defined(_LP64)) ||		\
-(defined(__sh__) && defined(_LP64))
+defined(__alpha__)
 	net.__n_pad0 = 0;
 #endif
 again:

Index: src/lib/libc/net/getnetnamadr.c
diff -u src/lib/libc/net/getnetnamadr.c:1.44 src/lib/libc/net/getnetnamadr.c:1.45
--- src/lib/libc/net/getnetnamadr.c:1.44	Mon Oct 26 19:41:19 2015
+++ src/lib/libc/net/getnetnamadr.c	Fri Jun  5 11:16:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnetnamadr.c,v 1.44 2015/10/26 19:41:19 christos Exp $	*/
+/*	$NetBSD: getnetnamadr.c,v 1.45 2020/06/05 11:16:15 nia Exp $	*/
 
 /* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
  *	Dep. Matematica Universidade de Coimbra, Portugal, Europe
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)getnetbyaddr
 static char sccsid_[] = "from getnetnamadr.c	1.4 (Coimbra) 93/06/03";
 static char rcsid[] = "Id: getnetnamadr.c,v 8.8 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: getnetnamadr.c,v 1.44 2015/10/26 19:41:19 christos Exp $");
+__RCSID("$NetBSD: getnetnamadr.c,v 1.45 2020/06/05 11:16:15 nia Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -267,9 +267,7 @@ getnetanswer(res_state res, querybuf *an
 		}
 		net_entry.n_aliases++;
 #if (defined(__sparc__) && defined(_LP64)) ||		\
-defined(__alpha__) ||\
-(defined(__i386__) && defined(_LP64)) ||		\
-(defined(__sh__) && defined(_LP64))
+defined(__alpha__)
 		net_entry.__n_pad0 = 0;
 #endif
 		return _entry;
@@ -627,9 +625,7 @@ _ypnetent(char *line)
 		*p++ = '\0';
 	net_entry.n_net = inet_network(cp);
 #if (defined(__sparc__) && defined(_LP64)) ||		\
-defined(__alpha__) ||\
-(defined(__i386__) && defined(_LP64)) ||		\
-(defined(__sh__) && defined(_LP64))
+defined(__alpha__)
 	net_entry.__n_pad0 = 0;
 #endif
 	net_entry.n_addrtype = AF_INET;



CVS commit: src/lib/libc/net

2020-06-04 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Jun  4 11:28:00 UTC 2020

Modified Files:
src/lib/libc/net: getaddrinfo.3

Log Message:
getaddrinfo.3: order of the struct members is wrong, correct it


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/lib/libc/net/getaddrinfo.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.3
diff -u src/lib/libc/net/getaddrinfo.3:1.59 src/lib/libc/net/getaddrinfo.3:1.60
--- src/lib/libc/net/getaddrinfo.3:1.59	Mon Jul  3 21:32:49 2017
+++ src/lib/libc/net/getaddrinfo.3	Thu Jun  4 11:28:00 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getaddrinfo.3,v 1.59 2017/07/03 21:32:49 wiz Exp $
+.\"	$NetBSD: getaddrinfo.3,v 1.60 2020/06/04 11:28:00 nia 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 $
 .\"
@@ -17,7 +17,7 @@
 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 .\" PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd December 13, 2015
+.Dd June 4, 2020
 .Dt GETADDRINFO 3
 .Os
 .Sh NAME
@@ -81,8 +81,8 @@ struct addrinfo {
 	int ai_socktype;	/* socket type */
 	int ai_protocol;	/* protocol for socket */
 	socklen_t ai_addrlen;	/* length of socket-address */
-	struct sockaddr *ai_addr; /* socket-address for socket */
 	char *ai_canonname;	/* canonical name for service location */
+	struct sockaddr *ai_addr; /* socket-address for socket */
 	struct addrinfo *ai_next; /* pointer to next in list */
 };
 .Ed



CVS commit: src/lib/libc/net

2018-12-12 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Dec 13 04:41:41 UTC 2018

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
Adjust English usage in message for EAI_NONAME.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.118 src/lib/libc/net/getaddrinfo.c:1.119
--- src/lib/libc/net/getaddrinfo.c:1.118	Thu Dec 13 04:30:55 2018
+++ src/lib/libc/net/getaddrinfo.c	Thu Dec 13 04:41:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.118 2018/12/13 04:30:55 dholland Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.119 2018/12/13 04:41:41 dholland Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.118 2018/12/13 04:30:55 dholland Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.119 2018/12/13 04:41:41 dholland Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -302,7 +302,7 @@ static const char * const ai_errlist[] =
 	"ai_family not supported",			/* EAI_FAMILY	  */
 	"Memory allocation failure",			/* EAI_MEMORY	  */
 	"No address associated with hostname",		/* EAI_NODATA	  */
-	"hostname nor servname provided, or not known", /* EAI_NONAME	  */
+	"hostname or servname not provided or not known", /* EAI_NONAME	  */
 	"servname not supported for ai_socktype",	/* EAI_SERVICE	  */
 	"ai_socktype not supported",			/* EAI_SOCKTYPE	  */
 	"System error returned in errno",		/* EAI_SYSTEM	  */



CVS commit: src/lib/libc/net

2018-12-12 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Dec 13 04:30:56 UTC 2018

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
Return EAI_NODATA, not EAI_NONAME, for nonexistent hosts.

This causes e.g. "ssh nosuchname" to print "No address associated with
hostname", which is correct, rather than "hostname nor servname
provided, or not known", which is not.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.117 src/lib/libc/net/getaddrinfo.c:1.118
--- src/lib/libc/net/getaddrinfo.c:1.117	Thu Dec 28 15:12:15 2017
+++ src/lib/libc/net/getaddrinfo.c	Thu Dec 13 04:30:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.117 2017/12/28 15:12:15 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.118 2018/12/13 04:30:55 dholland Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.117 2017/12/28 15:12:15 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.118 2018/12/13 04:30:55 dholland Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -1188,7 +1188,7 @@ explore_fqdn(const struct addrinfo *pai,
 		error = EAI_FAIL;
 		goto free;
 	case NS_NOTFOUND:
-		error = EAI_NONAME;
+		error = EAI_NODATA;
 		goto free;
 	case NS_SUCCESS:
 		error = 0;



CVS commit: src/lib/libc/net

2018-08-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Aug 22 03:12:31 UTC 2018

Modified Files:
src/lib/libc/net: if_nametoindex.c

Log Message:
- SIOCGIFINDEX was added in 2013, but if_freenameindex(3) have not used it
  for years. Use it to improve performance. Same as FreeBSD.
- KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/net/if_nametoindex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/if_nametoindex.c
diff -u src/lib/libc/net/if_nametoindex.c:1.5 src/lib/libc/net/if_nametoindex.c:1.6
--- src/lib/libc/net/if_nametoindex.c:1.5	Tue Sep  1 09:54:34 2015
+++ src/lib/libc/net/if_nametoindex.c	Wed Aug 22 03:12:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_nametoindex.c,v 1.5 2015/09/01 09:54:34 ozaki-r Exp $	*/
+/*	$NetBSD: if_nametoindex.c,v 1.6 2018/08/22 03:12:31 msaitoh Exp $	*/
 /*	$KAME: if_nametoindex.c,v 1.6 2000/11/24 08:18:54 itojun Exp $	*/
 
 /*-
@@ -28,19 +28,21 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: if_nametoindex.c,v 1.5 2015/09/01 09:54:34 ozaki-r Exp $");
+__RCSID("$NetBSD: if_nametoindex.c,v 1.6 2018/08/22 03:12:31 msaitoh Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
 #include "namespace.h"
 #endif
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifndef RUMP_ACTION
@@ -71,11 +73,24 @@ __weak_alias(if_nametoindex,_if_nametoin
 unsigned int
 if_nametoindex(const char *ifname)
 {
+	int s;
+	struct ifreq ifr;
 	struct ifaddrs *ifaddrs, *ifa;
 	unsigned int ni;
 
+	s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (s != -1) {
+		memset(, 0, sizeof(ifr));
+		strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+		if (ioctl(s, SIOCGIFINDEX, ) != -1) {
+			close(s);
+			return (ifr.ifr_index);
+		}
+		close(s);
+	}
+
 	if (getifaddrs() < 0)
-		return(0);
+		return 0;
 
 	ni = 0;
 
@@ -92,5 +107,5 @@ if_nametoindex(const char *ifname)
 	freeifaddrs(ifaddrs);
 	if (!ni)
 		errno = ENXIO;
-	return(ni);
+	return ni;
 }



CVS commit: src/lib/libc/net

2018-08-13 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Aug 13 06:00:21 UTC 2018

Modified Files:
src/lib/libc/net: sctp_bindx.3 sctp_connectx.3 sctp_freepaddrs.3
sctp_getaddrlen.3 sctp_getassocid.3 sctp_getpaddrs.3
sctp_opt_info.3 sctp_peeloff.3 sctp_recvmsg.3 sctp_send.3
sctp_sendmsg.3

Log Message:
Various improvements.
More markup, sort errors, fix -1.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/net/sctp_bindx.3 \
src/lib/libc/net/sctp_connectx.3 src/lib/libc/net/sctp_freepaddrs.3 \
src/lib/libc/net/sctp_getaddrlen.3 src/lib/libc/net/sctp_getassocid.3 \
src/lib/libc/net/sctp_getpaddrs.3 src/lib/libc/net/sctp_opt_info.3 \
src/lib/libc/net/sctp_peeloff.3 src/lib/libc/net/sctp_recvmsg.3 \
src/lib/libc/net/sctp_send.3 src/lib/libc/net/sctp_sendmsg.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/sctp_bindx.3
diff -u src/lib/libc/net/sctp_bindx.3:1.1 src/lib/libc/net/sctp_bindx.3:1.2
--- src/lib/libc/net/sctp_bindx.3:1.1	Thu Aug  2 08:40:48 2018
+++ src/lib/libc/net/sctp_bindx.3	Mon Aug 13 06:00:21 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sctp_bindx.3,v 1.1 2018/08/02 08:40:48 rjs Exp $
+.\"	$NetBSD: sctp_bindx.3,v 1.2 2018/08/13 06:00:21 wiz Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -34,7 +34,7 @@
 .Os
 .Sh NAME
 .Nm sctp_bindx
-.Nd bind or unbind an SCTP socket to a list of addresses.
+.Nd bind or unbind an SCTP socket to a list of addresses
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
@@ -83,12 +83,16 @@ is enabled any associations in the endpo
 have the address(es) added dynamically to the existing
 association.
 .Sh RETURN VALUES
-The call returns 0 on success and -1 upon failure.
+The call returns 0 on success and \-1 upon failure.
 .Sh ERRORS
 The
 .Fn sctp_bindx
 function can return the following errors:
 .Bl -tag -width Er
+.It Bq Er EBADF
+The argument
+.Fa s
+is not a valid descriptor.
 .It Bq Er EINVAL
 This value is returned if the
 .Fa type
@@ -97,10 +101,6 @@ field is not one of the allowed values (
 This value is returned if the number of addresses
 being added causes a memory allocation failure in
 the call.
-.It Bq Er EBADF
-The argument
-.Fa s
-is not a valid descriptor.
 .It Bq Er ENOTSOCK
 The argument
 .Fa s
@@ -114,7 +114,7 @@ is not a socket.
 .%N 6458
 .%T "Sockets API Extensions for the Stream Control Transmission Protocol (SCTP)"
 .%D December 2011
-.Re 
+.Re
 .Sh HISTORY
 This function first appeared in
 .Nx 9.0 .
Index: src/lib/libc/net/sctp_connectx.3
diff -u src/lib/libc/net/sctp_connectx.3:1.1 src/lib/libc/net/sctp_connectx.3:1.2
--- src/lib/libc/net/sctp_connectx.3:1.1	Thu Aug  2 08:40:48 2018
+++ src/lib/libc/net/sctp_connectx.3	Mon Aug 13 06:00:21 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sctp_connectx.3,v 1.1 2018/08/02 08:40:48 rjs Exp $
+.\"	$NetBSD: sctp_connectx.3,v 1.2 2018/08/13 06:00:21 wiz Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -76,15 +76,12 @@ will be
 filled in with the association identification of the newly
 forming association.
 .Sh RETURN VALUES
-The call returns 0 on success and -1 upon failure.
+The call returns 0 on success and \-1 upon failure.
 .Sh ERRORS
 The
 .Fn sctp_connectx
 function can return the following errors:
 .Bl -tag -width Er
-.It Bq Er EINVAL
-An address listed has an invalid family or no
-addresses were provided.
 .It Bq Er E2BIG
 The size of the address list exceeds the amount of
 data provided.
@@ -92,6 +89,9 @@ data provided.
 The argument
 .Fa s
 is not a valid descriptor.
+.It Bq Er EINVAL
+An address listed has an invalid family or no
+addresses were provided.
 .It Bq Er ENOTSOCK
 The argument
 .Fa s
@@ -105,7 +105,7 @@ is not a socket.
 .%N 6458
 .%T "Sockets API Extensions for the Stream Control Transmission Protocol (SCTP)"
 .%D December 2011
-.Re 
+.Re
 .Sh HISTORY
 This function first appeared in
 .Nx 9.0 .
Index: src/lib/libc/net/sctp_freepaddrs.3
diff -u src/lib/libc/net/sctp_freepaddrs.3:1.1 src/lib/libc/net/sctp_freepaddrs.3:1.2
--- src/lib/libc/net/sctp_freepaddrs.3:1.1	Thu Aug  2 08:40:48 2018
+++ src/lib/libc/net/sctp_freepaddrs.3	Mon Aug 13 06:00:21 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sctp_freepaddrs.3,v 1.1 2018/08/02 08:40:48 rjs Exp $
+.\"	$NetBSD: sctp_freepaddrs.3,v 1.2 2018/08/13 06:00:21 wiz Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -53,9 +53,9 @@ and
 .Fn sctp_freeladdrs
 functions are used to release the memory allocated by previous
 calls to
-.Fn sctp_getpaddrs
+.Xr sctp_getpaddrs 3
 or
-.Fn sctp_getladdrs
+.Xr sctp_getladdrs 3
 respectively.
 .Sh RETURN VALUES
 none.
@@ -68,8 +68,7 @@ none.
 .%N 6458
 .%T "Sockets API Extensions for the Stream Control Transmission Protocol (SCTP)"
 .%D 

CVS commit: src/lib/libc/net

2018-08-02 Thread Robert Swindells
Module Name:src
Committed By:   rjs
Date:   Thu Aug  2 10:18:19 UTC 2018

Added Files:
src/lib/libc/net: sctp_recvmsg.3

Log Message:
Add missing SCTP manpage.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/libc/net/sctp_recvmsg.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/lib/libc/net/sctp_recvmsg.3
diff -u /dev/null src/lib/libc/net/sctp_recvmsg.3:1.1
--- /dev/null	Thu Aug  2 10:18:19 2018
+++ src/lib/libc/net/sctp_recvmsg.3	Thu Aug  2 10:18:19 2018
@@ -0,0 +1,303 @@
+.\"	$NetBSD: sctp_recvmsg.3,v 1.1 2018/08/02 10:18:19 rjs Exp $
+.\"
+.\" Copyright (c) 1983, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\"may be used to endorse or promote products derived from this software
+.\"without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd August 1, 2018
+.Dt SCTP_RECVMSG 3
+.Os
+.Sh NAME
+.Nm sctp_recvmsg
+.Nd receive a message from an SCTP socket
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/socket.h
+.In netinet/sctp.h
+.Ft ssize_t
+.Fo sctp_recvmsg
+.Fa "int s" "void *msg" "size_t len" "struct sockaddr * restrict from"
+.Fa "socklen_t * restrict fromlen" "struct sctp_sndrcvinfo *sinfo" "int *flags"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn sctp_recvmsg
+system call
+is used to receive a message from another SCTP endpoint.
+The
+.Fn sctp_recvmsg
+call is used by one-to-one (SOCK_STREAM) type sockets after a
+successful
+.Fn connect
+call or after the application has performed a
+.Fn listen
+followed by a successful
+.Fn accept .
+For a one-to-many (SOCK_SEQPACKET) type socket, an endpoint may call
+.Fn sctp_recvmsg
+after having implicitly started an association via one
+of the send calls including
+.Fn sctp_sendmsg ,
+.Fn sendto
+and
+.Fn sendmsg .
+Or, an application may also receive a message after having
+called
+.Fn listen
+with a positive backlog to enable the reception of new associations.
+.Pp
+The address of the sender is held in the
+.Fa from
+argument with
+.Fa fromlen
+specifying its size.
+At the completion of a successful
+.Fn sctp_recvmsg
+call
+.Fa from
+will hold the address of the peer and
+.Fa fromlen
+will hold the length of that address.
+Note that
+the address is bounded by the initial value of
+.Fa fromlen
+which is used as an in/out variable.
+.Pp
+The length of the message
+.Fa msg
+to be received is bounded by
+.Fa len .
+If the message is too long to fit in the users
+receive buffer, then the
+.Fa flags
+argument will
+.Em not
+have the
+.Dv MSG_EOF
+flag applied.
+If the message is a complete message then
+the
+.Fa flags
+argument will have
+.Dv MSG_EOF
+set.
+Locally detected errors are
+indicated by a return value of -1 with
+.Va errno
+set accordingly.
+The
+.Fa flags
+argument may also hold the value
+.Dv MSG_NOTIFICATION .
+When this
+occurs it indicates that the message received is
+.Em not
+from
+the peer endpoint, but instead is a notification from the
+SCTP stack (see
+.Xr sctp 4
+for more details).
+Note that no notifications are ever
+given unless the user subscribes to such notifications using
+the
+.Dv SCTP_EVENTS
+socket option.
+.Pp
+If no messages are available at the socket then
+.Fn sctp_recvmsg
+normally blocks on the reception of a message or NOTIFICATION, unless the
+socket has been placed in non-blocking I/O mode.
+The
+.Xr select 2
+system call may be used to determine when it is possible to
+receive a message.
+.Pp
+The
+.Fa sinfo
+argument is defined as follows.
+.Bd -literal
+struct 

CVS commit: src/lib/libc/net

2018-02-21 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Feb 21 14:11:09 UTC 2018

Modified Files:
src/lib/libc/net: getnetent.3

Log Message:
Consistenly use "host byte order".


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/net/getnetent.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnetent.3
diff -u src/lib/libc/net/getnetent.3:1.15 src/lib/libc/net/getnetent.3:1.16
--- src/lib/libc/net/getnetent.3:1.15	Wed Feb 21 09:47:37 2018
+++ src/lib/libc/net/getnetent.3	Wed Feb 21 14:11:09 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getnetent.3,v 1.15 2018/02/21 09:47:37 wiz Exp $
+.\"	$NetBSD: getnetent.3,v 1.16 2018/02/21 14:11:09 uwe Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -83,7 +83,7 @@ The type of the network number returned;
 .Dv AF_INET .
 .It Fa n_net
 The network number.
-Network numbers are returned in machine byte order.
+Network numbers are returned in host byte order.
 .El
 .Pp
 The
@@ -113,7 +113,7 @@ functions sequentially search from the b
 a matching net name or net address and type is found, or until
 .Dv EOF
 is encountered.
-Network numbers are supplied in host order.
+Network numbers are supplied in host byte order.
 .Sh FILES
 .Bl -tag -width /etc/networks -compact
 .It Pa /etc/networks



CVS commit: src/lib/libc/net

2018-02-21 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Feb 21 09:47:37 UTC 2018

Modified Files:
src/lib/libc/net: getnetent.3

Log Message:
Fix endnetent prototype. Fix NULL. New sentence, new line.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/net/getnetent.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnetent.3
diff -u src/lib/libc/net/getnetent.3:1.14 src/lib/libc/net/getnetent.3:1.15
--- src/lib/libc/net/getnetent.3:1.14	Wed Feb 21 03:13:50 2018
+++ src/lib/libc/net/getnetent.3	Wed Feb 21 09:47:37 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getnetent.3,v 1.14 2018/02/21 03:13:50 kamil Exp $
+.\"	$NetBSD: getnetent.3,v 1.15 2018/02/21 09:47:37 wiz Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -52,18 +52,16 @@
 .Ft void
 .Fn setnetent "int stayopen"
 .Ft void
-.Fn endnetent
+.Fn endnetent void
 .Sh DESCRIPTION
 The
 .Fn getnetent ,
 .Fn getnetbyname ,
 and
 .Fn getnetbyaddr
-functions
-each return a pointer to an object with the
-following structure
-containing the broken-out
-fields of a line in the network data base as described in
+functions each return a pointer to an object with the following
+structure containing the broken-out fields of a line in the network
+data base as described in
 .Xr networks 5 .
 .Bd -literal -offset indent
 struct	netent {
@@ -81,43 +79,38 @@ The official name of the network.
 .It Fa n_aliases
 A zero terminated list of alternative names for the network.
 .It Fa n_addrtype
-The type of the network number returned; currently only AF_INET.
+The type of the network number returned; currently only
+.Dv AF_INET .
 .It Fa n_net
-The network number.  Network numbers are returned in machine byte
-order.
+The network number.
+Network numbers are returned in machine byte order.
 .El
 .Pp
 The
 .Fn getnetent
-function
-reads the next line of the file, opening the file if necessary.
+function reads the next line of the file, opening the file if necessary.
 .Pp
 The
 .Fn setnetent
-function
-opens and rewinds the file.  If the
+function opens and rewinds the file.
+If the
 .Fa stayopen
-flag is non-zero,
-the net data base will not be closed after each call to
+flag is non-zero, the net data base will not be closed after each
+call to
 .Fn getnetbyname
 or
 .Fn getnetbyaddr .
 .Pp
 The
 .Fn endnetent
-function
-closes the file.
+function closes the file.
 .Pp
 The
 .Fn getnetbyname
-function
 and
 .Fn getnetbyaddr
-sequentially search from the beginning
-of the file until a matching
-net name or
-net address and type is found,
-or until
+functions sequentially search from the beginning of the file until
+a matching net name or net address and type is found, or until
 .Dv EOF
 is encountered.
 Network numbers are supplied in host order.
@@ -127,7 +120,8 @@ Network numbers are supplied in host ord
 .El
 .Sh DIAGNOSTICS
 Null pointer
-(0) returned on
+.Dv ( NULL )
+returned on
 .Dv EOF
 or error.
 .Sh SEE ALSO
@@ -144,11 +138,9 @@ and
 functions appeared in
 .Bx 4.2 .
 .Sh BUGS
-The data space used by
-these functions is static; if future use requires the data, it should be
-copied before any subsequent calls to these functions overwrite it.
-Only Internet network
-numbers are currently understood.
-Expecting network numbers to fit
-in no more than 32 bits is probably
+The data space used by these functions is static; if future use
+requires the data, it should be copied before any subsequent calls
+to these functions overwrite it.
+Only Internet network numbers are currently understood.
+Expecting network numbers to fit in no more than 32 bits is probably
 naive.



CVS commit: src/lib/libc/net

2018-02-20 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Feb 21 03:13:50 UTC 2018

Modified Files:
src/lib/libc/net: getnetent.3

Log Message:
Improve the getnetent(3) man-page

Document return type of setnetent(3) and endnetent(3). Both "void".

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/net/getnetent.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnetent.3
diff -u src/lib/libc/net/getnetent.3:1.13 src/lib/libc/net/getnetent.3:1.14
--- src/lib/libc/net/getnetent.3:1.13	Sat May  8 18:52:15 2004
+++ src/lib/libc/net/getnetent.3	Wed Feb 21 03:13:50 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getnetent.3,v 1.13 2004/05/08 18:52:15 kleink Exp $
+.\"	$NetBSD: getnetent.3,v 1.14 2018/02/21 03:13:50 kamil Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)getnetent.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd May 8, 2004
+.Dd February 21, 2018
 .Dt GETNETENT 3
 .Os
 .Sh NAME
@@ -49,7 +49,9 @@
 .Fn getnetbyname "const char *name"
 .Ft struct netent *
 .Fn getnetbyaddr "uint32_t net" "int type"
+.Ft void
 .Fn setnetent "int stayopen"
+.Ft void
 .Fn endnetent
 .Sh DESCRIPTION
 The



CVS commit: src/lib/libc/net

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 19:21:49 UTC 2018

Modified Files:
src/lib/libc/net: getpeereid.c

Log Message:
Enforce that getpeereid only returns success on AF_LOCAL sockets, instead
of returning garbage for other socket types.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/net/getpeereid.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getpeereid.c
diff -u src/lib/libc/net/getpeereid.c:1.2 src/lib/libc/net/getpeereid.c:1.3
--- src/lib/libc/net/getpeereid.c:1.2	Tue Apr 29 02:53:01 2008
+++ src/lib/libc/net/getpeereid.c	Fri Feb 16 14:21:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: getpeereid.c,v 1.2 2008/04/29 06:53:01 martin Exp $ */
+/* $NetBSD: getpeereid.c,v 1.3 2018/02/16 19:21:49 christos Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -31,27 +31,38 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getpeereid.c,v 1.2 2008/04/29 06:53:01 martin Exp $");
+__RCSID("$NetBSD: getpeereid.c,v 1.3 2018/02/16 19:21:49 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
-#include 
 #include 
 #include 
+#include 
+#include 
 
 
 int
 getpeereid(int s, uid_t *euid, gid_t *egid)
 {
 	struct unpcbid cred;
-	socklen_t len = sizeof(cred);
-	if (getsockopt(s, 0, LOCAL_PEEREID, , ) < 0) {
+	struct sockaddr_storage ss;
+	socklen_t len;
+
+	len = sizeof(ss);
+	if (getsockname(s, (void *), ) == -1)
+		return -1;
+	if (ss.ss_family != AF_LOCAL) {
+		errno = EOPNOTSUPP;
 		return -1;
-	} else {
-		if (euid != NULL)
-			*euid = cred.unp_euid;
-		if (egid != NULL)
-			*egid = cred.unp_egid;
-		return 0;
 	}
+
+	len = sizeof(cred);
+	if (getsockopt(s, 0, LOCAL_PEEREID, , ) == -1)
+		return -1;
+
+	if (euid != NULL)
+		*euid = cred.unp_euid;
+	if (egid != NULL)
+		*egid = cred.unp_egid;
+	return 0;
 }



CVS commit: src/lib/libc/net

2017-12-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Dec 28 15:12:16 UTC 2017

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
PR/52837: Michael Kaufmann: getaddrinfo() resolves "127.0.0.1 www.example.com"
to 127.0.0.1. Apply the patch from FreeBSD and explain the rationale.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.116 src/lib/libc/net/getaddrinfo.c:1.117
--- src/lib/libc/net/getaddrinfo.c:1.116	Thu Sep 28 20:04:33 2017
+++ src/lib/libc/net/getaddrinfo.c	Thu Dec 28 10:12:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.116 2017/09/29 00:04:33 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.117 2017/12/28 15:12:15 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.116 2017/09/29 00:04:33 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.117 2017/12/28 15:12:15 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -1322,8 +1322,15 @@ explore_numeric(const struct addrinfo *p
 		* check for errors. inet_pton() only accepts addresses
 		* in the dotted quad format and only in base 10, so we
 		* need to treat AF_INET specially.
+		*
+		* We also check for trailing characters and fail if there
+		* are any. This matches the inet_pton6(), but not the
+		* inet_pton4() behavior. We choose to make the protocol
+		* behavior consistent.
 		*/
-		if (inet_aton(hostname, (void *)pton) == 1) {
+		if (inet_aton(hostname, (void *)pton) == 1 &&
+		hostname[strspn(hostname, "0123456789.xabcdefXABCDEF")]
+		== '\0') {
 			if (pai->ai_family == afd->a_af ||
 			pai->ai_family == PF_UNSPEC /*?*/) {
 GET_AI(cur->ai_next, afd, pton);



CVS commit: src/lib/libc/net

2017-10-30 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Oct 30 15:46:38 UTC 2017

Modified Files:
src/lib/libc/net: ethers.3 resolver.3

Log Message:
Fix Bl argument.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/net/ethers.3
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/ethers.3
diff -u src/lib/libc/net/ethers.3:1.14 src/lib/libc/net/ethers.3:1.15
--- src/lib/libc/net/ethers.3:1.14	Wed Oct 25 16:13:04 2017
+++ src/lib/libc/net/ethers.3	Mon Oct 30 15:46:38 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ethers.3,v 1.14 2017/10/25 16:13:04 abhinav Exp $
+.\"	$NetBSD: ethers.3,v 1.15 2017/10/30 15:46:38 wiz Exp $
 .\"
 .\" Written by rol...@frob.com.  Public domain.
 .\"
@@ -113,9 +113,7 @@ The
 .Fn ether_hostton ,
 and
 .Fn ether_line
-functions were adopted from
-.Tn SunOS
-and appeared in
+functions were adopted from SunOS and appeared in
 .Nx 1.0 .
 .Sh BUGS
 The data space used by these functions is static; if future use

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.32 src/lib/libc/net/resolver.3:1.33
--- src/lib/libc/net/resolver.3:1.32	Wed Oct 25 16:26:42 2017
+++ src/lib/libc/net/resolver.3	Mon Oct 30 15:46:38 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: resolver.3,v 1.32 2017/10/25 16:26:42 abhinav Exp $
+.\"	$NetBSD: resolver.3,v 1.33 2017/10/30 15:46:38 wiz Exp $
 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
 .\"
 .\" Permission to use, copy, modify, and distribute this software for any
@@ -590,7 +590,7 @@ and construct an UPDATE message in
 .Fn res_mkupdate
 return the length of the constructed message on no error or one of the
 following error values.
-.Bl -inset -width "-5"
+.Bl -inset -offset "-5"
 .It \-1
 An error occurred parsing
 .Fa rrecp_in .



CVS commit: src/lib/libc/net

2017-10-25 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Wed Oct 25 16:29:21 UTC 2017

Modified Files:
src/lib/libc/net: getifaddrs.3

Log Message:
Add freeifaddrs to the NAME section


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/net/getifaddrs.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getifaddrs.3
diff -u src/lib/libc/net/getifaddrs.3:1.18 src/lib/libc/net/getifaddrs.3:1.19
--- src/lib/libc/net/getifaddrs.3:1.18	Mon Jul  3 21:32:49 2017
+++ src/lib/libc/net/getifaddrs.3	Wed Oct 25 16:29:20 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getifaddrs.3,v 1.18 2017/07/03 21:32:49 wiz Exp $
+.\"	$NetBSD: getifaddrs.3,v 1.19 2017/10/25 16:29:20 abhinav Exp $
 .\"	BSDI	getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp
 .\"
 .\" Copyright (c) 1995, 1999
@@ -25,7 +25,8 @@
 .Dt GETIFADDRS 3
 .Os
 .Sh NAME
-.Nm getifaddrs
+.Nm getifaddrs ,
+.Nm freeifaddrs
 .Nd get interface addresses
 .Sh SYNOPSIS
 .In sys/types.h



CVS commit: src/lib/libc/net

2017-10-25 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Wed Oct 25 16:26:42 UTC 2017

Modified Files:
src/lib/libc/net: resolver.3

Log Message:
Remove comma after last Nm entry


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.31 src/lib/libc/net/resolver.3:1.32
--- src/lib/libc/net/resolver.3:1.31	Sun Dec 18 17:34:36 2016
+++ src/lib/libc/net/resolver.3	Wed Oct 25 16:26:42 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: resolver.3,v 1.31 2016/12/18 17:34:36 christos Exp $
+.\"	$NetBSD: resolver.3,v 1.32 2017/10/25 16:26:42 abhinav Exp $
 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
 .\"
 .\" Permission to use, copy, modify, and distribute this software for any
@@ -69,7 +69,7 @@
 .Nm res_mkquery ,
 .Nm res_send ,
 .Nm res_update ,
-.Nm res_close ,
+.Nm res_close
 .\" .Nm herror
 .Nd resolver routines
 .Sh LIBRARY



CVS commit: src/lib/libc/net

2017-10-25 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Wed Oct 25 16:13:04 UTC 2017

Modified Files:
src/lib/libc/net: ethers.3

Log Message:
Remove comma after last Nm entry.
New sentence, new line


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/net/ethers.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/ethers.3
diff -u src/lib/libc/net/ethers.3:1.13 src/lib/libc/net/ethers.3:1.14
--- src/lib/libc/net/ethers.3:1.13	Wed Apr 16 13:34:41 2003
+++ src/lib/libc/net/ethers.3	Wed Oct 25 16:13:04 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ethers.3,v 1.13 2003/04/16 13:34:41 wiz Exp $
+.\"	$NetBSD: ethers.3,v 1.14 2017/10/25 16:13:04 abhinav Exp $
 .\"
 .\" Written by rol...@frob.com.  Public domain.
 .\"
@@ -10,7 +10,7 @@
 .Nm ether_aton ,
 .Nm ether_ntohost ,
 .Nm ether_hostton ,
-.Nm ether_line ,
+.Nm ether_line
 .Nd get ethers entry
 .Sh LIBRARY
 .Lb libc
@@ -42,12 +42,14 @@ The
 .Fn ether_ntoa
 function converts this structure into an ASCII string of the form
 ``xx:xx:xx:xx:xx:xx'', consisting of 6 hexadecimal numbers separated
-by colons.  It returns a pointer to a static buffer that is reused for
+by colons.
+It returns a pointer to a static buffer that is reused for
 each call.
 The
 .Fn ether_aton
 converts an ASCII string of the same form and to a structure
-containing the 6 octets of the address.  It returns a pointer to a
+containing the 6 octets of the address.
+It returns a pointer to a
 static structure that is reused for each call.
 .Pp
 The
@@ -64,7 +66,8 @@ host name into the character buffer pass
 The
 .Fn ether_hostton
 function looks up the given host name and writes the associated
-Ethernet address into the structure passed.  Both functions return
+Ethernet address into the structure passed.
+Both functions return
 zero if they find the requested host name or address, and -1 if not.
 Each call reads
 .Pa /etc/ethers
@@ -83,8 +86,8 @@ The
 function parses a line from the
 .Pa /etc/ethers
 file and fills in the passed ``struct ether_addr'' and character
-buffer with the Ethernet address and host name on the line.  It
-returns zero if the line was successfully parsed and -1 if not.
+buffer with the Ethernet address and host name on the line.
+It returns zero if the line was successfully parsed and -1 if not.
 .Pp
 The
 .Fa hostname



CVS commit: src/lib/libc/net

2017-09-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Sep 29 00:04:33 UTC 2017

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
PR/52578: Benjamin M. Schwartz: sync the internal copy of res_nquery for
getaddrinfo, with the real version so that we handle EDNS fallback.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.115 src/lib/libc/net/getaddrinfo.c:1.116
--- src/lib/libc/net/getaddrinfo.c:1.115	Tue Jan 10 12:51:01 2017
+++ src/lib/libc/net/getaddrinfo.c	Thu Sep 28 20:04:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.115 2017/01/10 17:51:01 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.116 2017/09/29 00:04:33 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.115 2017/01/10 17:51:01 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.116 2017/09/29 00:04:33 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -2539,13 +2539,14 @@ _yp_getaddrinfo(void *rv, void *cb_data,
  */
 static int
 res_queryN(const char *name, /* domain name */ struct res_target *target,
-res_state res)
+res_state statp)
 {
 	u_char buf[MAXPACKET];
 	HEADER *hp;
 	int n;
 	struct res_target *t;
 	int rcode;
+	u_char *rdata;
 	int ancount;
 
 	_DIAGASSERT(name != NULL);
@@ -2558,8 +2559,12 @@ res_queryN(const char *name, /* domain n
 		int class, type;
 		u_char *answer;
 		int anslen;
+		u_int oflags;
 
 		hp = (HEADER *)(void *)t->answer;
+		oflags = statp->_flags;
+
+again:
 		hp->rcode = NOERROR;	/* default */
 
 		/* make it easier... */
@@ -2568,42 +2573,63 @@ res_queryN(const char *name, /* domain n
 		answer = t->answer;
 		anslen = t->anslen;
 #ifdef DEBUG
-		if (res->options & RES_DEBUG)
+		if (statp->options & RES_DEBUG)
 			printf(";; res_nquery(%s, %d, %d)\n", name, class, type);
 #endif
 
-		n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL,
+		n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL,
 		buf, (int)sizeof(buf));
 #ifdef RES_USE_EDNS0
-		if (n > 0 && (res->options & RES_USE_EDNS0) != 0)
-			n = res_nopt(res, n, buf, (int)sizeof(buf), anslen);
+		if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
+		(statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0) {
+			n = res_nopt(statp, n, buf, (int)sizeof(buf), anslen);
+			rdata = [n];
+			if (n > 0 && (statp->options & RES_NSID) != 0U) {
+n = res_nopt_rdata(statp, n, buf,
+(int)sizeof(buf),
+rdata, NS_OPT_NSID, 0, NULL);
+			}
+		}
 #endif
 		if (n <= 0) {
 #ifdef DEBUG
-			if (res->options & RES_DEBUG)
+			if (statp->options & RES_DEBUG)
 printf(";; res_nquery: mkquery failed\n");
 #endif
 			h_errno = NO_RECOVERY;
 			return n;
 		}
-		n = res_nsend(res, buf, n, answer, anslen);
-#if 0
+		n = res_nsend(statp, buf, n, answer, anslen);
 		if (n < 0) {
+#ifdef RES_USE_EDNS0
+			/* if the query choked with EDNS0, retry without EDNS0 */
+			if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U &&
+			((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) {
+statp->_flags |= RES_F_EDNS0ERR;
+if (statp->options & RES_DEBUG)
+	printf(";; res_nquery: retry without EDNS0\n");
+goto again;
+			}
+#endif
+#if 0
 #ifdef DEBUG
-			if (res->options & RES_DEBUG)
+			if (statp->options & RES_DEBUG)
 printf(";; res_query: send error\n");
 #endif
 			h_errno = TRY_AGAIN;
 			return n;
-		}
 #endif
+		}
 
 		if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
 			rcode = hp->rcode;	/* record most recent error */
 #ifdef DEBUG
-			if (res->options & RES_DEBUG)
-printf(";; rcode = %u, ancount=%u\n", hp->rcode,
-ntohs(hp->ancount));
+			if (statp->options & RES_DEBUG)
+printf(";; rcode = (%s), counts = an:%d ns:%d ar:%d\n",
+   p_rcode(hp->rcode),
+   ntohs(hp->ancount),
+   ntohs(hp->nscount),
+   ntohs(hp->arcount));
 #endif
 			continue;
 		}



CVS commit: src/lib/libc/net

2017-06-17 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Jun 18 04:03:44 UTC 2017

Modified Files:
src/lib/libc/net: Makefile.inc

Log Message:
Include IPv6 global variable in USE_INET6=no libc

This ensures a binary built with USE_INET6=yes libc can still link at
runtime with a USE_INET6=no libc. Of course IPv6 functionnality is not
available, but dynamic linking is not killed by missing symbols such
as in6addr_any.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/lib/libc/net/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/Makefile.inc
diff -u src/lib/libc/net/Makefile.inc:1.86 src/lib/libc/net/Makefile.inc:1.87
--- src/lib/libc/net/Makefile.inc:1.86	Wed Apr 15 19:13:46 2015
+++ src/lib/libc/net/Makefile.inc	Sun Jun 18 04:03:44 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.86 2015/04/15 19:13:46 mrg Exp $
+#	$NetBSD: Makefile.inc,v 1.87 2017/06/18 04:03:44 manu Exp $
 #	@(#)Makefile.inc	8.2 (Berkeley) 9/5/93
 
 # net sources
@@ -21,8 +21,9 @@ SRCS+=	hesiod.c
 
 SRCS+=	getaddrinfo.c getnameinfo.c
 .if (${USE_INET6} != "no")
-SRCS+=	ip6opt.c rthdr.c vars6.c inet6_scopeid.c
+SRCS+=	ip6opt.c rthdr.c inet6_scopeid.c
 .endif
+SRCS+=	vars6.c
 SRCS+=	if_indextoname.c if_nameindex.c if_nametoindex.c
 
 LPREFIX=_nsyy



CVS commit: src/lib/libc/net

2017-03-10 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Mar 10 18:02:32 UTC 2017

Modified Files:
src/lib/libc/net: hesiod.c

Log Message:
Remove entirely redundant free right after declaration.

This block existed because the original code used bindname as a global.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/lib/libc/net/hesiod.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/hesiod.c
diff -u src/lib/libc/net/hesiod.c:1.29 src/lib/libc/net/hesiod.c:1.30
--- src/lib/libc/net/hesiod.c:1.29	Fri Mar 10 17:47:20 2017
+++ src/lib/libc/net/hesiod.c	Fri Mar 10 18:02:32 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: hesiod.c,v 1.29 2017/03/10 17:47:20 maya Exp $	*/
+/*	$NetBSD: hesiod.c,v 1.30 2017/03/10 18:02:32 maya Exp $	*/
 
 /* Copyright (c) 1996 by Internet Software Consortium.
  *
@@ -51,7 +51,7 @@ __IDSTRING(rcsid_hesiod_p_h,
 "#Id: hesiod_p.h,v 1.1 1996/12/08 21:39:37 ghudson Exp #");
 __IDSTRING(rcsid_hescompat_c,
 "#Id: hescompat.c,v 1.1.2.1 1996/12/16 08:37:45 ghudson Exp #");
-__RCSID("$NetBSD: hesiod.c,v 1.29 2017/03/10 17:47:20 maya Exp $");
+__RCSID("$NetBSD: hesiod.c,v 1.30 2017/03/10 18:02:32 maya Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -553,8 +553,7 @@ hes_to_bind(const char *name, const char
 
 	if (init_context() < 0)
 		return NULL;
-	if (bindname)
-		free(bindname);
+
 	bindname = hesiod_to_bind(context, name, type);
 	if (!bindname)
 		translate_errors();



CVS commit: src/lib/libc/net

2017-03-10 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Mar 10 17:47:20 UTC 2017

Modified Files:
src/lib/libc/net: hesiod.c

Log Message:
Drop redundant null checks.

this doesn't increase diff to upstream, the whole block differs already.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/net/hesiod.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/hesiod.c
diff -u src/lib/libc/net/hesiod.c:1.28 src/lib/libc/net/hesiod.c:1.29
--- src/lib/libc/net/hesiod.c:1.28	Thu Sep 18 13:58:20 2014
+++ src/lib/libc/net/hesiod.c	Fri Mar 10 17:47:20 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: hesiod.c,v 1.28 2014/09/18 13:58:20 christos Exp $	*/
+/*	$NetBSD: hesiod.c,v 1.29 2017/03/10 17:47:20 maya Exp $	*/
 
 /* Copyright (c) 1996 by Internet Software Consortium.
  *
@@ -51,7 +51,7 @@ __IDSTRING(rcsid_hesiod_p_h,
 "#Id: hesiod_p.h,v 1.1 1996/12/08 21:39:37 ghudson Exp #");
 __IDSTRING(rcsid_hescompat_c,
 "#Id: hescompat.c,v 1.1.2.1 1996/12/16 08:37:45 ghudson Exp #");
-__RCSID("$NetBSD: hesiod.c,v 1.28 2014/09/18 13:58:20 christos Exp $");
+__RCSID("$NetBSD: hesiod.c,v 1.29 2017/03/10 17:47:20 maya Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -152,10 +152,8 @@ hesiod_init(void **context)
 
 	serrno = errno;
 	if (ctx) {
-		if (ctx->lhs)
-			free(ctx->lhs);
-		if (ctx->rhs)
-			free(ctx->rhs);
+		free(ctx->lhs);
+		free(ctx->rhs);
 		free(ctx);
 	}
 	errno = serrno;



CVS commit: src/lib/libc/net

2017-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 10 17:51:01 UTC 2017

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
KNF, simplify expressions for readability.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.114 src/lib/libc/net/getaddrinfo.c:1.115
--- src/lib/libc/net/getaddrinfo.c:1.114	Sat Feb  6 14:33:07 2016
+++ src/lib/libc/net/getaddrinfo.c	Tue Jan 10 12:51:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.114 2016/02/06 19:33:07 riastradh Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.115 2017/01/10 17:51:01 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.114 2016/02/06 19:33:07 riastradh Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.115 2017/01/10 17:51:01 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -109,6 +109,9 @@ __weak_alias(gai_strerror,_gai_strerror)
 #define YES 1
 #define NO  0
 
+#define sa4addr(sa) ((void *)&((struct sockaddr_in *)(void *)sa)->sin_addr)
+#define sa6addr(sa) ((void *)&((struct sockaddr_in6 *)(void *)sa)->sin6_addr)
+
 static const char in_addrany[] = { 0, 0, 0, 0 };
 static const char in_loopback[] = { 127, 0, 0, 1 };
 #ifdef INET6
@@ -711,11 +714,11 @@ reorder(struct addrinfo *sentinel, struc
 	 * If the number is small enough, we can skip the reordering process.
 	 */
 	if (n <= 1)
-		return(n);
+		return n;
 
 	/* allocate a temporary array for sort and initialization of it. */
 	if ((aio = malloc(sizeof(*aio) * n)) == NULL)
-		return(n);	/* give up reordering */
+		return n;	/* give up reordering */
 	memset(aio, 0, sizeof(*aio) * n);
 
 	/* retrieve address selection policy from the kernel */
@@ -723,7 +726,7 @@ reorder(struct addrinfo *sentinel, struc
 	if (!get_addrselectpolicy()) {
 		/* no policy is installed into kernel, we don't sort. */
 		free(aio);
-		return (n);
+		return n;
 	}
 
 	for (i = 0, ai = sentinel->ai_next; i < n; ai = ai->ai_next, i++) {
@@ -747,31 +750,33 @@ reorder(struct addrinfo *sentinel, struc
 	/* cleanup and return */
 	free(aio);
 	free_addrselectpolicy();
-	return(n);
+	return n;
 }
 
 static int
 get_addrselectpolicy(struct policyhead *head)
 {
 #ifdef INET6
-	int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_ADDRCTLPOLICY };
+	static const int mib[] = { 
+	CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_ADDRCTLPOLICY };
+	static const u_int miblen = (u_int)__arraycount(mib);
 	size_t l;
 	char *buf;
 	struct in6_addrpolicy *pol, *ep;
 
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, , NULL, 0) < 0)
-		return (0);
+	if (sysctl(mib, miblen, NULL, , NULL, 0) < 0)
+		return 0;
 	if (l == 0)
-		return (0);
+		return 0;
 	if ((buf = malloc(l)) == NULL)
-		return (0);
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, , NULL, 0) < 0) {
+		return 0;
+	if (sysctl(mib, miblen, buf, , NULL, 0) < 0) {
 		free(buf);
-		return (0);
+		return 0;
 	}
 
-	ep = (struct in6_addrpolicy *)(buf + l);
-	for (pol = (struct in6_addrpolicy *)buf; pol + 1 <= ep; pol++) {
+	ep = (void *)(buf + l);
+	for (pol = (void *)buf; pol + 1 <= ep; pol++) {
 		struct policyqueue *new;
 
 		if ((new = malloc(sizeof(*new))) == NULL) {
@@ -783,9 +788,9 @@ get_addrselectpolicy(struct policyhead *
 	}
 
 	free(buf);
-	return (1);
+	return 1;
 #else
-	return (0);
+	return 0;
 #endif
 }
 
@@ -808,12 +813,13 @@ match_addrselectpolicy(struct sockaddr *
 	struct policyqueue *ent, *bestent = NULL;
 	struct in6_addrpolicy *pol;
 	int curmatchlen, bestmatchlen = -1;
-	u_char *mp, *ep, *k, *p, m;
+	u_char *mp, *ep, *k, *p;
+	u_int m;
 	struct sockaddr_in6 key;
 
 	switch(addr->sa_family) {
 	case AF_INET6:
-		key = *(struct sockaddr_in6 *)addr;
+		memcpy(, addr, sizeof(key));
 		break;
 	case AF_INET:
 		/* convert the address into IPv4-mapped IPv6 address. */
@@ -822,21 +828,20 @@ match_addrselectpolicy(struct sockaddr *
 		key.sin6_len = sizeof(key);
 		key.sin6_addr.s6_addr[10] = 0xff;
 		key.sin6_addr.s6_addr[11] = 0xff;
-		memcpy(_addr.s6_addr[12],
-		   &((struct sockaddr_in *)addr)->sin_addr, 4);
+		memcpy(_addr.s6_addr[12], sa4addr(addr), 4);
 		break;
 	default:
-		return(NULL);
+		return NULL;
 	}
 
 	for (ent = TAILQ_FIRST(head); ent; ent = TAILQ_NEXT(ent, pc_entry)) {
 		pol = >pc_policy;
 		curmatchlen = 0;
 
-		mp = (u_char *)>addrmask.sin6_addr;
+		mp = (void *)>addrmask.sin6_addr;
 		ep = mp + 16;	/* XXX: scope field? */
-		k = (u_char *)_addr;
-		p = (u_char *)>addr.sin6_addr;
+		k = (void *)_addr;
+		p = (void *)>addr.sin6_addr;
 		for (; mp < ep && *mp; mp++, k++, p++) {
 			m = *mp;
 			if ((*k & m) != *p)
@@ -861,9 +866,9 @@ match_addrselectpolicy(struct sockaddr *
 		

CVS commit: src/lib/libc/net

2016-12-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 18 17:34:36 UTC 2016

Modified Files:
src/lib/libc/net: resolver.3

Log Message:
clarify res_nclose and res_ndestroy.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.30 src/lib/libc/net/resolver.3:1.31
--- src/lib/libc/net/resolver.3:1.30	Fri Jan 22 05:58:39 2016
+++ src/lib/libc/net/resolver.3	Sun Dec 18 12:34:36 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: resolver.3,v 1.30 2016/01/22 10:58:39 wiz Exp $
+.\"	$NetBSD: resolver.3,v 1.31 2016/12/18 17:34:36 christos Exp $
 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
 .\"
 .\" Permission to use, copy, modify, and distribute this software for any
@@ -33,7 +33,7 @@
 .\"	@(#)resolver.3	6.5 (Berkeley) 6/23/90
 .\"	Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
 .\"
-.Dd January 22, 2016
+.Dd December 18, 2016
 .Dt RESOLVER 3
 .Os
 .Sh NAME
@@ -611,10 +611,16 @@ The functions
 .Fn res_nclose
 /
 .Fn res_close
-close any open files referenced through
+close any open socket file descriptors referenced through
 .Fa statp
 /
 .Fa _res .
+These functions were designed to be used to emulate
+.Xr endhostent 3 ,
+and don't release other resources held in
+.Ft res_state ;
+to free all_resources, call
+.Fn res_ndestroy .
 .Pp
 The function
 .Fn res_ndestroy



CVS commit: src/lib/libc/net

2016-12-07 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Dec  7 10:03:29 UTC 2016

Modified Files:
src/lib/libc/net: linkaddr.c

Log Message:
Fix comment:  s/ACCD/ADDC/


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/net/linkaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/linkaddr.c
diff -u src/lib/libc/net/linkaddr.c:1.21 src/lib/libc/net/linkaddr.c:1.22
--- src/lib/libc/net/linkaddr.c:1.21	Wed Dec  7 09:52:34 2016
+++ src/lib/libc/net/linkaddr.c	Wed Dec  7 10:03:29 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: linkaddr.c,v 1.21 2016/12/07 09:52:34 kre Exp $	*/
+/*	$NetBSD: linkaddr.c,v 1.22 2016/12/07 10:03:29 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: linkaddr.c,v 1.21 2016/12/07 09:52:34 kre Exp $");
+__RCSID("$NetBSD: linkaddr.c,v 1.22 2016/12/07 10:03:29 pgoyette Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -163,7 +163,7 @@ link_ntoa(const struct sockaddr_dl *sdl)
 	 *  complex:
 	 *	if (out < obuf + sizeof(obuf) - ((ch) != '\0'))
 	 *		*out++ = (ch);
-	 *  so it never returns, and the final ACCD(0) always works
+	 *  so it never returns, and the final ADDC(0) always works
 	 *  but that evaluates 'ch' twice, and is slower, so ...)
 	 */
 	obuf[sizeof(obuf) - 1] = '\0';



CVS commit: src/lib/libc/net

2016-12-07 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Dec  7 09:52:34 UTC 2016

Modified Files:
src/lib/libc/net: linkaddr.c

Log Message:
Actually guarantee that the returned buffer from link_ntoa() is always
NUL terminated, even when called by malicious/broken applications.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/net/linkaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/linkaddr.c
diff -u src/lib/libc/net/linkaddr.c:1.20 src/lib/libc/net/linkaddr.c:1.21
--- src/lib/libc/net/linkaddr.c:1.20	Wed Dec  7 03:16:45 2016
+++ src/lib/libc/net/linkaddr.c	Wed Dec  7 09:52:34 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: linkaddr.c,v 1.20 2016/12/07 03:16:45 christos Exp $	*/
+/*	$NetBSD: linkaddr.c,v 1.21 2016/12/07 09:52:34 kre Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: linkaddr.c,v 1.20 2016/12/07 03:16:45 christos Exp $");
+__RCSID("$NetBSD: linkaddr.c,v 1.21 2016/12/07 09:52:34 kre Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -153,6 +153,21 @@ link_ntoa(const struct sockaddr_dl *sdl)
 		*out++ = (ch); \
 	} while (/*CONSTCOND*/0)
 
+	/*
+	 * This is not needed on the first call, as the static
+	 * obuf wil be fully init'd to 0 by default.   But after
+	 * obuf has been returned to userspace the first time,
+	 * anything may have been written to it, so, let's be safe.
+	 *
+	 * (An alternative method would be to make ADDC() more
+	 *  complex:
+	 *	if (out < obuf + sizeof(obuf) - ((ch) != '\0'))
+	 *		*out++ = (ch);
+	 *  so it never returns, and the final ACCD(0) always works
+	 *  but that evaluates 'ch' twice, and is slower, so ...)
+	 */
+	obuf[sizeof(obuf) - 1] = '\0';
+
 	if (sdl->sdl_nlen) {
 		if (sdl->sdl_nlen >= sizeof(obuf))
 			i = sizeof(obuf) - 1;



CVS commit: src/lib/libc/net

2016-12-06 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Dec  7 03:48:05 UTC 2016

Modified Files:
src/lib/libc/net: linkaddr.3

Log Message:
More tweaking...


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/net/linkaddr.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/linkaddr.3
diff -u src/lib/libc/net/linkaddr.3:1.11 src/lib/libc/net/linkaddr.3:1.12
--- src/lib/libc/net/linkaddr.3:1.11	Wed Dec  7 03:22:14 2016
+++ src/lib/libc/net/linkaddr.3	Wed Dec  7 03:48:05 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: linkaddr.3,v 1.11 2016/12/07 03:22:14 pgoyette Exp $
+.\"	$NetBSD: linkaddr.3,v 1.12 2016/12/07 03:48:05 pgoyette Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -112,13 +112,12 @@ and
 functions appeared in
 .Bx 4.3 Reno .
 .Sh BUGS
-The returned values for
+The returned string for
 .Fn link_ntoa
-reside in a static memory area.
-If the returned value would overflow this area,
+resides in a static memory area.
+If it would overflow this area,
 .Fn link_ntoa
-truncates the returned string.
-There is no provision for detecting a truncated return value.
+silently truncates the result.
 .Pp
 The function
 .Fn link_addr



CVS commit: src/lib/libc/net

2016-12-06 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Dec  7 03:22:14 UTC 2016

Modified Files:
src/lib/libc/net: linkaddr.3

Log Message:
Update BUGS section to note the possibility of a truncated return value.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/net/linkaddr.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/linkaddr.3
diff -u src/lib/libc/net/linkaddr.3:1.10 src/lib/libc/net/linkaddr.3:1.11
--- src/lib/libc/net/linkaddr.3:1.10	Thu Aug  7 16:43:11 2003
+++ src/lib/libc/net/linkaddr.3	Wed Dec  7 03:22:14 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: linkaddr.3,v 1.10 2003/08/07 16:43:11 agc Exp $
+.\"	$NetBSD: linkaddr.3,v 1.11 2016/12/07 03:22:14 pgoyette Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -32,7 +32,7 @@
 .\"
 .\" @(#)linkaddr.3	8.1 (Berkeley) 7/28/93
 .\"
-.Dd July 28, 1993
+.Dd December 7, 2016
 .Dt LINK_ADDR 3
 .Os
 .Sh NAME
@@ -115,6 +115,10 @@ functions appeared in
 The returned values for
 .Fn link_ntoa
 reside in a static memory area.
+If the returned value would overflow this area,
+.Fn link_ntoa
+truncates the returned string.
+There is no provision for detecting a truncated return value.
 .Pp
 The function
 .Fn link_addr



CVS commit: src/lib/libc/net

2016-12-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec  7 03:16:45 UTC 2016

Modified Files:
src/lib/libc/net: linkaddr.c

Log Message:
make it always return a NUL terminated string instead of NULL when the address
is truncated for compatibility with others.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/net/linkaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/linkaddr.c
diff -u src/lib/libc/net/linkaddr.c:1.19 src/lib/libc/net/linkaddr.c:1.20
--- src/lib/libc/net/linkaddr.c:1.19	Tue Dec  6 21:48:54 2016
+++ src/lib/libc/net/linkaddr.c	Tue Dec  6 22:16:45 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: linkaddr.c,v 1.19 2016/12/07 02:48:54 christos Exp $	*/
+/*	$NetBSD: linkaddr.c,v 1.20 2016/12/07 03:16:45 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: linkaddr.c,v 1.19 2016/12/07 02:48:54 christos Exp $");
+__RCSID("$NetBSD: linkaddr.c,v 1.20 2016/12/07 03:16:45 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -148,16 +148,18 @@ link_ntoa(const struct sockaddr_dl *sdl)
 
 #define ADDC(ch) \
 	do { \
-		if (out >= obuf + sizeof(obuf)) \
-			return NULL; \
+		if (out >= obuf + sizeof(obuf) - 1) \
+			return obuf; \
 		*out++ = (ch); \
 	} while (/*CONSTCOND*/0)
 
 	if (sdl->sdl_nlen) {
 		if (sdl->sdl_nlen >= sizeof(obuf))
-			return NULL;
-		(void)memcpy(obuf, sdl->sdl_data, (size_t)sdl->sdl_nlen);
-		out += sdl->sdl_nlen;
+			i = sizeof(obuf) - 1;
+		else
+			i = sdl->sdl_nlen;
+		(void)memcpy(obuf, sdl->sdl_data, i);
+		out += i;
 		if (sdl->sdl_alen)
 			ADDC(':');
 	}
@@ -176,5 +178,5 @@ link_ntoa(const struct sockaddr_dl *sdl)
 			ADDC(hexlist[i]);
 	}
 	ADDC('\0');
-	return (obuf);
+	return obuf;
 }



CVS commit: src/lib/libc/net

2016-12-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec  7 02:48:54 UTC 2016

Modified Files:
src/lib/libc/net: linkaddr.c

Log Message:
Add the terminating NUL as a regular character addition.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/net/linkaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/linkaddr.c
diff -u src/lib/libc/net/linkaddr.c:1.18 src/lib/libc/net/linkaddr.c:1.19
--- src/lib/libc/net/linkaddr.c:1.18	Tue Dec  6 21:36:41 2016
+++ src/lib/libc/net/linkaddr.c	Tue Dec  6 21:48:54 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: linkaddr.c,v 1.18 2016/12/07 02:36:41 dholland Exp $	*/
+/*	$NetBSD: linkaddr.c,v 1.19 2016/12/07 02:48:54 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: linkaddr.c,v 1.18 2016/12/07 02:36:41 dholland Exp $");
+__RCSID("$NetBSD: linkaddr.c,v 1.19 2016/12/07 02:48:54 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -148,7 +148,7 @@ link_ntoa(const struct sockaddr_dl *sdl)
 
 #define ADDC(ch) \
 	do { \
-		if (out >= obuf + sizeof(obuf) - 1) \
+		if (out >= obuf + sizeof(obuf)) \
 			return NULL; \
 		*out++ = (ch); \
 	} while (/*CONSTCOND*/0)
@@ -175,6 +175,6 @@ link_ntoa(const struct sockaddr_dl *sdl)
 		} else
 			ADDC(hexlist[i]);
 	}
-	*out = 0;
+	ADDC('\0');
 	return (obuf);
 }



CVS commit: src/lib/libc/net

2016-12-06 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Dec  7 02:36:41 UTC 2016

Modified Files:
src/lib/libc/net: linkaddr.c

Log Message:
Leave room for the null terminator. Spotted by DuClare on freenode.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/net/linkaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/linkaddr.c
diff -u src/lib/libc/net/linkaddr.c:1.17 src/lib/libc/net/linkaddr.c:1.18
--- src/lib/libc/net/linkaddr.c:1.17	Tue Dec  6 18:41:02 2016
+++ src/lib/libc/net/linkaddr.c	Wed Dec  7 02:36:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: linkaddr.c,v 1.17 2016/12/06 18:41:02 christos Exp $	*/
+/*	$NetBSD: linkaddr.c,v 1.18 2016/12/07 02:36:41 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: linkaddr.c,v 1.17 2016/12/06 18:41:02 christos Exp $");
+__RCSID("$NetBSD: linkaddr.c,v 1.18 2016/12/07 02:36:41 dholland Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -148,7 +148,7 @@ link_ntoa(const struct sockaddr_dl *sdl)
 
 #define ADDC(ch) \
 	do { \
-		if (out >= obuf + sizeof(obuf)) \
+		if (out >= obuf + sizeof(obuf) - 1) \
 			return NULL; \
 		*out++ = (ch); \
 	} while (/*CONSTCOND*/0)



CVS commit: src/lib/libc/net

2016-12-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec  6 18:41:03 UTC 2016

Modified Files:
src/lib/libc/net: linkaddr.c

Log Message:
Fix buffer copy without checking the size of input:
https://www.kb.cert.org/vuls/id/548487


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/net/linkaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/linkaddr.c
diff -u src/lib/libc/net/linkaddr.c:1.16 src/lib/libc/net/linkaddr.c:1.17
--- src/lib/libc/net/linkaddr.c:1.16	Tue Mar 20 13:44:18 2012
+++ src/lib/libc/net/linkaddr.c	Tue Dec  6 13:41:02 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: linkaddr.c,v 1.16 2012/03/20 17:44:18 matt Exp $	*/
+/*	$NetBSD: linkaddr.c,v 1.17 2016/12/06 18:41:02 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: linkaddr.c,v 1.16 2012/03/20 17:44:18 matt Exp $");
+__RCSID("$NetBSD: linkaddr.c,v 1.17 2016/12/06 18:41:02 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -59,7 +59,7 @@ __RCSID("$NetBSD: linkaddr.c,v 1.16 2012
 void
 link_addr(const char *addr, struct sockaddr_dl *sdl)
 {
-	register char *cp = sdl->sdl_data;
+	char *cp = sdl->sdl_data;
 	char *cplim = sdl->sdl_len + (char *)(void *)sdl;
 	int byte = 0, state = NAMING;
 	size_t newaddr = 0;	/* pacify gcc */
@@ -138,33 +138,42 @@ char *
 link_ntoa(const struct sockaddr_dl *sdl)
 {
 	static char obuf[64];
-	register char *out = obuf; 
-	register size_t i;
+	char *out = obuf; 
+	size_t i;
 	const u_char *in = (const u_char *)CLLADDR(sdl);
 	const u_char *inlim = in + sdl->sdl_alen;
 	int firsttime = 1;
 
 	_DIAGASSERT(sdl != NULL);
 
+#define ADDC(ch) \
+	do { \
+		if (out >= obuf + sizeof(obuf)) \
+			return NULL; \
+		*out++ = (ch); \
+	} while (/*CONSTCOND*/0)
+
 	if (sdl->sdl_nlen) {
+		if (sdl->sdl_nlen >= sizeof(obuf))
+			return NULL;
 		(void)memcpy(obuf, sdl->sdl_data, (size_t)sdl->sdl_nlen);
 		out += sdl->sdl_nlen;
 		if (sdl->sdl_alen)
-			*out++ = ':';
+			ADDC(':');
 	}
 	while (in < inlim) {
 		if (firsttime)
 			firsttime = 0;
 		else
-			*out++ = '.';
+			ADDC('.');
 		i = *in++;
 		if (i > 0xf) {
-			out[1] = hexlist[i & 0xf];
+			size_t j = i & 0xf;
 			i >>= 4;
-			out[0] = hexlist[i];
-			out += 2;
+			ADDC(hexlist[i]);
+			ADDC(hexlist[j]);
 		} else
-			*out++ = hexlist[i];
+			ADDC(hexlist[i]);
 	}
 	*out = 0;
 	return (obuf);



CVS commit: src/lib/libc/net

2016-09-21 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Sep 21 10:53:24 UTC 2016

Modified Files:
src/lib/libc/net: getifaddrs.3 getifaddrs.c

Log Message:
Add ifa_addrflags to ifaddrs.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/net/getifaddrs.3
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/net/getifaddrs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getifaddrs.3
diff -u src/lib/libc/net/getifaddrs.3:1.16 src/lib/libc/net/getifaddrs.3:1.17
--- src/lib/libc/net/getifaddrs.3:1.16	Sat Jan 23 07:21:18 2016
+++ src/lib/libc/net/getifaddrs.3	Wed Sep 21 10:53:24 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getifaddrs.3,v 1.16 2016/01/23 07:21:18 wiz Exp $
+.\"	$NetBSD: getifaddrs.3,v 1.17 2016/09/21 10:53:24 roy Exp $
 .\"	BSDI	getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp
 .\"
 .\" Copyright (c) 1995, 1999
@@ -21,7 +21,7 @@
 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
-.Dd April 7, 2013
+.Dd September 15, 2016
 .Dt GETIFADDRS 3
 .Os
 .Sh NAME
@@ -57,6 +57,7 @@ structure contains at least the followin
 struct sockaddr  *ifa_broadaddr;/* Interface broadcast address */
 struct sockaddr  *ifa_dstaddr;  /* P2P interface destination */
 void *ifa_data;		/* Address specific data */
+unsigned int  ifa_addrflags;/* Address flags */
 .Ed
 .Pp
 The
@@ -123,6 +124,10 @@ which contains various interface attribu
 For all other address families, it is
 .Dv NULL .
 .Pp
+The
+.Li ifa_addrflags
+field contains the address flags, which are specific to the address family.
+.Pp
 The data returned by
 .Fn getifaddrs
 is dynamically allocated and should be freed using
@@ -185,6 +190,10 @@ The
 .Nm
 implementation first appeared in
 .Bsx .
+.Pp
+.Li ifa_addrflags
+was added in
+.Nx 8.0 .
 .Sh BUGS
 If both
 .In net/if.h

Index: src/lib/libc/net/getifaddrs.c
diff -u src/lib/libc/net/getifaddrs.c:1.15 src/lib/libc/net/getifaddrs.c:1.16
--- src/lib/libc/net/getifaddrs.c:1.15	Tue Mar 13 21:13:40 2012
+++ src/lib/libc/net/getifaddrs.c	Wed Sep 21 10:53:24 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: getifaddrs.c,v 1.15 2012/03/13 21:13:40 christos Exp $	*/
+/*	$NetBSD: getifaddrs.c,v 1.16 2016/09/21 10:53:24 roy Exp $	*/
 
 /*
  * Copyright (c) 1995, 1999
@@ -27,7 +27,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getifaddrs.c,v 1.15 2012/03/13 21:13:40 christos Exp $");
+__RCSID("$NetBSD: getifaddrs.c,v 1.16 2016/09/21 10:53:24 roy Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -225,6 +225,7 @@ getifaddrs(struct ifaddrs **pif)
 			ift->ifa_name = cif.ifa_name;
 			ift->ifa_flags = cif.ifa_flags;
 			ift->ifa_data = NULL;
+			ift->ifa_addrflags = ifam->ifam_addrflags;
 			p = (char *)(void *)(ifam + 1);
 			/* Scan to look for length of address */
 			alen = 0;



CVS commit: src/lib/libc/net

2016-02-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb  6 19:33:07 UTC 2016

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
Avoid shadowing global.


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.113 src/lib/libc/net/getaddrinfo.c:1.114
--- src/lib/libc/net/getaddrinfo.c:1.113	Mon Dec 14 22:07:37 2015
+++ src/lib/libc/net/getaddrinfo.c	Sat Feb  6 19:33:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.113 2015/12/14 22:07:37 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.114 2016/02/06 19:33:07 riastradh Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.113 2015/12/14 22:07:37 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.114 2016/02/06 19:33:07 riastradh Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -807,7 +807,7 @@ match_addrselectpolicy(struct sockaddr *
 #ifdef INET6
 	struct policyqueue *ent, *bestent = NULL;
 	struct in6_addrpolicy *pol;
-	int matchlen, bestmatchlen = -1;
+	int curmatchlen, bestmatchlen = -1;
 	u_char *mp, *ep, *k, *p, m;
 	struct sockaddr_in6 key;
 
@@ -831,7 +831,7 @@ match_addrselectpolicy(struct sockaddr *
 
 	for (ent = TAILQ_FIRST(head); ent; ent = TAILQ_NEXT(ent, pc_entry)) {
 		pol = >pc_policy;
-		matchlen = 0;
+		curmatchlen = 0;
 
 		mp = (u_char *)>addrmask.sin6_addr;
 		ep = mp + 16;	/* XXX: scope field? */
@@ -842,19 +842,19 @@ match_addrselectpolicy(struct sockaddr *
 			if ((*k & m) != *p)
 goto next; /* not match */
 			if (m == 0xff) /* short cut for a typical case */
-matchlen += 8;
+curmatchlen += 8;
 			else {
 while (m >= 0x80) {
-	matchlen++;
+	curmatchlen++;
 	m <<= 1;
 }
 			}
 		}
 
 		/* matched.  check if this is better than the current best. */
-		if (matchlen > bestmatchlen) {
+		if (curmatchlen > bestmatchlen) {
 			bestent = ent;
-			bestmatchlen = matchlen;
+			bestmatchlen = curmatchlen;
 		}
 
 	  next:



CVS commit: src/lib/libc/net

2016-01-22 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Jan 22 10:58:39 UTC 2016

Modified Files:
src/lib/libc/net: resolver.3

Log Message:
Try to reduce singular/plural confusion. Use more markup.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.29 src/lib/libc/net/resolver.3:1.30
--- src/lib/libc/net/resolver.3:1.29	Fri Jan 22 03:38:57 2016
+++ src/lib/libc/net/resolver.3	Fri Jan 22 10:58:39 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: resolver.3,v 1.29 2016/01/22 03:38:57 zafer Exp $
+.\"	$NetBSD: resolver.3,v 1.30 2016/01/22 10:58:39 wiz Exp $
 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
 .\"
 .\" Permission to use, copy, modify, and distribute this software for any
@@ -33,7 +33,7 @@
 .\"	@(#)resolver.3	6.5 (Berkeley) 6/23/90
 .\"	Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
 .\"
-.Dd November 13, 2013
+.Dd January 22, 2016
 .Dt RESOLVER 3
 .Os
 .Sh NAME
@@ -217,8 +217,7 @@ are initialized on the first call to
 /
 .Fn res_init
 to reasonable defaults and can be ignored.
-Options
-stored in
+Options stored in
 .Ft statp->options
 /
 .Ft _res.options
@@ -299,7 +298,7 @@ the
 environment variable.
 Network daemons should set this option.
 .It Dv RES_ROTATE
-This options causes the
+This options causes
 .Fn res_nsend
 /
 .Fn res_send
@@ -323,15 +322,15 @@ This option has no effect if neither
 .Dv RES_DEFNAMES
 or
 .Dv RES_DNSRCH
-is set.
+are set.
 .El
 .Pp
 The
 .Fn res_ninit
 /
 .Fn res_init
-routine
-reads the configuration file (if any; see
+routines
+read the configuration file (if any; see
 .Xr resolv.conf 5 )
 to get the default domain name, search list and
 the Internet address of the local name server(s).
@@ -397,9 +396,9 @@ The
 .Fn res_nquery
 /
 .Fn res_query
-functions provides interfaces to the server query mechanism.
-They constructs a query, sends it to the local server,
-awaits a response, and makes preliminary checks on the reply.
+functions provide interfaces to the server query mechanism.
+They construct a query, send it to the local server,
+await a response, and make preliminary checks on the reply.
 The query requests information of the specified
 .Fa type
 and
@@ -424,13 +423,13 @@ routines make a query and awaits a respo
 .Fn res_nquery
 /
 .Fn res_query ,
-but in addition, it implements the default and search rules
+but in addition, they implement the default and search rules
 controlled by the
 .Dv RES_DEFNAMES
 and
 .Dv RES_DNSRCH
 options.
-It returns the length of the first successful reply which is stored in
+They return the length of the first successful reply which is stored in
 .Ft answer
 or \-1 on error.
 .Pp
@@ -442,10 +441,9 @@ The
 .Fn res_nmkquery
 /
 .Fn res_mkquery
-functions
-constructs a standard query message and places it in
+functions construct a standard query message and place it in
 .Fa buf .
-It returns the size of the query, or \-1 if the query is
+They return the size of the query, or \-1 if the query is
 larger than
 .Fa buflen .
 The query type
@@ -466,8 +464,8 @@ The
 /
 .Fn res_nsendsigned
 routines
-sends a pre-formatted query and returns an answer.
-It will call
+send a pre-formatted query and return an answer.
+They will call
 .Fn res_ninit
 /
 .Fn res_init
@@ -495,12 +493,14 @@ and
 return a length that may be bigger than
 .Fa anslen .
 In that case the query should be retried with a bigger buffer.
-NOTE the answer to the second query may be larger still so supplying
+.Em NOTE :
+The answer to the second query may be larger still so supplying
 a buffer that bigger that the answer returned by the previous
 query is recommended.
 .Pp
 .Fa answer
-MUST be big enough to receive a maximum UDP response from the server or
+.Em MUST
+be big enough to receive a maximum UDP response from the server or
 parts of the answer will be silently discarded.
 The default maximum UDP response size is 512 bytes.
 .Pp
@@ -539,10 +539,11 @@ The functions
 .Fn res_hostalias
 /
 .Fn hostalias
-lookup up name in the file referred to by the
+look up name in the file referred to by the
 .Ev HOSTALIASES
-files return a fully qualified hostname if found or NULL if
-not found or an error occurred.
+files and return a fully qualified hostname if found or
+.Dv NULL
+if not found or an error occurred.
 .Fn res_hostalias
 uses
 .Fa buf
@@ -562,14 +563,14 @@ The functions
 .Fn res_update
 take a list of ns_updrec
 .Fa rrecp_in .
-Identifies the containing zone for each record and groups the records
-according to containing zone maintaining in zone order then sends and update
+They identify the containing zone for each record and group the records
+according to containing zone maintaining in zone order then send an update
 request to the servers for these zones.
 The number of zones updated is returned or 

CVS commit: src/lib/libc/net

2015-12-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 14 22:07:37 UTC 2015

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
PR/50552: Kyle Amon: RFC3493 section 6.1 wants us to accept non-dotted-quad
INET4 addresses.
XXX: pullup-7


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.112 src/lib/libc/net/getaddrinfo.c:1.113
--- src/lib/libc/net/getaddrinfo.c:1.112	Sat Dec 12 21:02:59 2015
+++ src/lib/libc/net/getaddrinfo.c	Mon Dec 14 17:07:37 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.112 2015/12/13 02:02:59 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.113 2015/12/14 22:07:37 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.112 2015/12/13 02:02:59 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.113 2015/12/14 22:07:37 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -1312,8 +1312,15 @@ explore_numeric(const struct addrinfo *p
 		return 0;
 
 	switch (afd->a_af) {
-#if 0 /*X/Open spec*/
 	case AF_INET:
+	   /*
+		* RFC3493 section 6.1, requires getaddrinfo() to accept
+		* AF_INET formats that are accepted by inet_addr(); here
+		* we use the equivalent inet_aton() function so we can
+		* check for errors. inet_pton() only accepts addresses
+		* in the dotted quad format and only in base 10, so we
+		* need to treat AF_INET specially.
+		*/
 		if (inet_aton(hostname, (struct in_addr *)pton) == 1) {
 			if (pai->ai_family == afd->a_af ||
 			pai->ai_family == PF_UNSPEC /*?*/) {
@@ -1333,7 +1340,6 @@ explore_numeric(const struct addrinfo *p
 ERR(EAI_FAMILY);	/*xxx*/
 		}
 		break;
-#endif
 	default:
 		if (inet_pton(afd->a_af, hostname, pton) == 1) {
 			if (pai->ai_family == afd->a_af ||



CVS commit: src/lib/libc/net

2015-12-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 13 14:54:17 UTC 2015

Modified Files:
src/lib/libc/net: getaddrinfo.3

Log Message:
mention ip6addrctl


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/lib/libc/net/getaddrinfo.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.3
diff -u src/lib/libc/net/getaddrinfo.3:1.57 src/lib/libc/net/getaddrinfo.3:1.58
--- src/lib/libc/net/getaddrinfo.3:1.57	Fri May  3 17:13:34 2013
+++ src/lib/libc/net/getaddrinfo.3	Sun Dec 13 09:54:17 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getaddrinfo.3,v 1.57 2013/05/03 21:13:34 wiz Exp $
+.\"	$NetBSD: getaddrinfo.3,v 1.58 2015/12/13 14:54:17 christos 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 $
 .\"
@@ -17,7 +17,7 @@
 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 .\" PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd April 30, 2013
+.Dd December 13, 2015
 .Dt GETADDRINFO 3
 .Os
 .Sh NAME
@@ -251,6 +251,10 @@ structure in the list, the
 member points to a filled-in socket address structure of length
 .Fa ai_addrlen .
 .Pp
+By default IPv6 address entries are ordered before IPv4 ones, but
+the order of the entries in the list can be controlled using
+.Xr ip6addrctl 8 .
+.Pp
 This implementation of
 .Fn getaddrinfo
 allows numeric IPv6 address notation with scope identifier,
@@ -450,6 +454,7 @@ freeaddrinfo(res0);
 .Xr resolv.conf 5 ,
 .Xr services 5 ,
 .Xr hostname 7 ,
+.Xr ip6addrctl 8 ,
 .Xr named 8
 .Rs
 .%A R. Gilligan



CVS commit: src/lib/libc/net

2015-12-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Dec 14 03:49:54 UTC 2015

Modified Files:
src/lib/libc/net: inet6_scopeid.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/net/inet6_scopeid.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/inet6_scopeid.c
diff -u src/lib/libc/net/inet6_scopeid.c:1.2 src/lib/libc/net/inet6_scopeid.c:1.3
--- src/lib/libc/net/inet6_scopeid.c:1.2	Sat Oct 19 15:47:02 2013
+++ src/lib/libc/net/inet6_scopeid.c	Mon Dec 14 03:49:54 2015
@@ -34,7 +34,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: inet6_scopeid.c,v 1.2 2013/10/19 15:47:02 christos Exp $");
+__RCSID("$NetBSD: inet6_scopeid.c,v 1.3 2015/12/14 03:49:54 ozaki-r Exp $");
 
 #include 
 #include 
@@ -71,7 +71,7 @@ inet6_putscopeid(struct sockaddr_in6 *si
 	(flags & INET6_IS_ADDR_MC_LINKLOCAL)) ||
 	(IN6_IS_ADDR_SITELOCAL(>sin6_addr) &&
 	(flags & INET6_IS_ADDR_SITELOCAL))) {
-	uint16_t scope = htons(sin6->sin6_scope_id);
+		uint16_t scope = htons(sin6->sin6_scope_id);
 		memcpy(>sin6_addr.s6_addr[2], , sizeof(scope));
 		sin6->sin6_scope_id = 0;
 	}



CVS commit: src/lib/libc/net

2015-12-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 13 02:02:59 UTC 2015

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
Implement the address selection policy; from FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.111 src/lib/libc/net/getaddrinfo.c:1.112
--- src/lib/libc/net/getaddrinfo.c:1.111	Wed Dec  2 13:09:53 2015
+++ src/lib/libc/net/getaddrinfo.c	Sat Dec 12 21:02:59 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.111 2015/12/02 18:09:53 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.112 2015/12/13 02:02:59 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.111 2015/12/02 18:09:53 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.112 2015/12/13 02:02:59 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -64,8 +64,11 @@ __RCSID("$NetBSD: getaddrinfo.c,v 1.111 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -117,6 +120,14 @@ static const char in6_loopback[] = {
 };
 #endif
 
+struct policyqueue {
+	TAILQ_ENTRY(policyqueue) pc_entry;
+#ifdef INET6
+	struct in6_addrpolicy pc_policy;
+#endif
+};
+TAILQ_HEAD(policyhead, policyqueue);
+
 static const struct afd {
 	int a_af;
 	int a_addrlen;
@@ -174,6 +185,23 @@ static const struct explore explore[] = 
 #define PTON_MAX	4
 #endif
 
+#define AIO_SRCFLAG_DEPRECATED	0x1
+
+struct ai_order {
+	union {
+		struct sockaddr_storage aiou_ss;
+		struct sockaddr aiou_sa;
+	} aio_src_un;
+#define aio_srcsa aio_src_un.aiou_sa
+	u_int32_t aio_srcflag;
+	int aio_srcscope;
+	int aio_dstscope;
+	struct policyqueue *aio_srcpolicy;
+	struct policyqueue *aio_dstpolicy;
+	struct addrinfo *aio_ai;
+	int aio_matchlen;
+};
+
 static const ns_src default_dns_files[] = {
 	{ NSSRC_FILES,	NS_SUCCESS },
 	{ NSSRC_DNS,	NS_SUCCESS },
@@ -222,9 +250,20 @@ static int get_port(const struct addrinf
 struct servent_data *);
 static const struct afd *find_afd(int);
 static int addrconfig(uint64_t *);
+static void set_source(struct ai_order *, struct policyhead *,
+struct servent_data *);
+static int comp_dst(const void *, const void *);
 #ifdef INET6
 static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *);
 #endif
+static int gai_addr2scopetype(struct sockaddr *);
+
+static int reorder(struct addrinfo *, struct servent_data *);
+static int get_addrselectpolicy(struct policyhead *);
+static void free_addrselectpolicy(struct policyhead *);
+static struct policyqueue *match_addrselectpolicy(struct sockaddr *,
+	struct policyhead *);
+static int matchlen(struct sockaddr *, struct sockaddr *);
 
 static struct addrinfo *getanswer(res_state, const querybuf *, int,
 const char *, int, const struct addrinfo *);
@@ -421,6 +460,7 @@ getaddrinfo(const char *hostname, const 
 	const struct explore *ex;
 	struct servent_data svd;
 	uint64_t mask = (uint64_t)~0ULL;
+	int numeric = 0;
 
 	/* hostname is allowed to be NULL */
 	/* servname is allowed to be NULL */
@@ -557,8 +597,10 @@ getaddrinfo(const char *hostname, const 
 	 * If numeric representation of AF1 can be interpreted as FQDN
 	 * representation of AF2, we need to think again about the code below.
 	 */
-	if (sentinel.ai_next)
+	if (sentinel.ai_next) {
+		numeric = 1;
 		goto good;
+	}
 
 	if (hostname == NULL)
 		ERR(EAI_NODATA);
@@ -614,6 +656,31 @@ getaddrinfo(const char *hostname, const 
 
 	if (sentinel.ai_next) {
  good:
+		/*
+		 * If the returned entry is for an active connection,
+		 * and the given name is not numeric, reorder the
+		 * list, so that the application would try the list
+		 * in the most efficient order.  Since the head entry
+		 * of the original list may contain ai_canonname and
+		 * that entry may be moved elsewhere in the new list,
+		 * we keep the pointer and will  restore it in the new
+		 * head entry.  (Note that RFC3493 requires the head
+		 * entry store it when requested by the caller).
+		 */
+		if (hints == NULL || !(hints->ai_flags & AI_PASSIVE)) {
+			if (!numeric) {
+char *canonname;
+
+canonname = sentinel.ai_next->ai_canonname;
+sentinel.ai_next->ai_canonname = NULL;
+(void)reorder(, );
+if (sentinel.ai_next->ai_canonname == NULL) {
+	sentinel.ai_next->ai_canonname
+	= canonname;
+} else if (canonname != NULL)
+	free(canonname);
+			}
+		}
 		endservent_r();
 		*res = sentinel.ai_next;
 		return SUCCESS;
@@ -628,6 +695,458 @@ getaddrinfo(const char *hostname, const 
 	return error;
 }
 
+static int
+reorder(struct addrinfo *sentinel, struct servent_data *svd)
+{
+	

CVS commit: src/lib/libc/net

2015-12-02 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec  2 18:09:53 UTC 2015

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
PR/44915: Havard Eidnes:
- Convert NS_NOTFOUND to EAI_NONAME instead
  of EAI_NODATA which more inline with what other OS's do.
- Convert NO_DATA to NS_NOTFOUND since there is no equivalent mapping
  for nsswitch (perhaps we could add one so what we could recover the exact
  error and return EAI_NODATA?)
- If we end up following a CNAME chain that does not find any data return that
  instead of internal error.

XXX: pullup-7


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.110 src/lib/libc/net/getaddrinfo.c:1.111
--- src/lib/libc/net/getaddrinfo.c:1.110	Mon Oct 26 10:48:04 2015
+++ src/lib/libc/net/getaddrinfo.c	Wed Dec  2 13:09:53 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.110 2015/10/26 14:48:04 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.111 2015/12/02 18:09:53 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.110 2015/10/26 14:48:04 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.111 2015/12/02 18:09:53 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -667,7 +667,7 @@ explore_fqdn(const struct addrinfo *pai,
 		error = EAI_FAIL;
 		goto free;
 	case NS_NOTFOUND:
-		error = EAI_NODATA;
+		error = EAI_NONAME;
 		goto free;
 	case NS_SUCCESS:
 		error = 0;
@@ -1453,7 +1453,9 @@ getanswer(res_state res, const querybuf 
 		return sentinel.ai_next;
 	}
 
-	h_errno = NO_RECOVERY;
+	/* We could have walked a CNAME chain, */
+	/* but the ultimate target may not have what we looked for */
+	h_errno = ntohs(hp->ancount) > 0? NO_DATA : NO_RECOVERY;
 	return NULL;
 }
 
@@ -1724,6 +1726,8 @@ _dns_getaddrinfo(void *rv, void *cb_data
 		if (ai == NULL) {
 			switch (h_errno) {
 			case HOST_NOT_FOUND:
+			case NO_DATA:	// XXX: Perhaps we could differentiate
+	// So that we could return EAI_NODATA?
 return NS_NOTFOUND;
 			case TRY_AGAIN:
 return NS_TRYAGAIN;



CVS commit: src/lib/libc/net

2015-10-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 26 19:28:53 UTC 2015

Modified Files:
src/lib/libc/net: getnetnamadr.c

Log Message:
PR/50367: Stefan Schaeckeler: Apply fix to obey RES_CHECKNAME to getnetbyaddr
and getnetbyname.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/lib/libc/net/getnetnamadr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnetnamadr.c
diff -u src/lib/libc/net/getnetnamadr.c:1.42 src/lib/libc/net/getnetnamadr.c:1.43
--- src/lib/libc/net/getnetnamadr.c:1.42	Tue Mar 13 17:13:41 2012
+++ src/lib/libc/net/getnetnamadr.c	Mon Oct 26 15:28:53 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnetnamadr.c,v 1.42 2012/03/13 21:13:41 christos Exp $	*/
+/*	$NetBSD: getnetnamadr.c,v 1.43 2015/10/26 19:28:53 christos Exp $	*/
 
 /* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
  *	Dep. Matematica Universidade de Coimbra, Portugal, Europe
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)getnetbyaddr
 static char sccsid_[] = "from getnetnamadr.c	1.4 (Coimbra) 93/06/03";
 static char rcsid[] = "Id: getnetnamadr.c,v 8.8 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: getnetnamadr.c,v 1.42 2012/03/13 21:13:41 christos Exp $");
+__RCSID("$NetBSD: getnetnamadr.c,v 1.43 2015/10/26 19:28:53 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -77,6 +77,12 @@ __weak_alias(getnetbyaddr,_getnetbyaddr)
 __weak_alias(getnetbyname,_getnetbyname)
 #endif
 
+#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || \
+   (ok)(nm) != 0)
+#define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
+#define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
+
+
 extern int _net_stayopen;
 
 #define BYADDR 0
@@ -105,7 +111,7 @@ static	struct netent net_entry;
 static	char *net_aliases[MAXALIASES];
 
 static int		parse_reversed_addr(const char *, in_addr_t *);
-static struct netent	*getnetanswer(querybuf *, int, int);
+static struct netent	*getnetanswer(res_state, querybuf *, int, int);
 static int		_files_getnetbyaddr(void *, void *, va_list);
 static int		_files_getnetbyname(void *, void *, va_list);
 static int		_dns_getnetbyaddr(void *, void *, va_list);
@@ -159,7 +165,7 @@ parse_reversed_addr(const char *str, in_
 }
 
 static struct netent *
-getnetanswer(querybuf *answer, int anslen, int net_i)
+getnetanswer(res_state res, querybuf *answer, int anslen, int net_i)
 {
 	static char	n_name[MAXDNAME];
 	static char	netbuf[PACKETSZ];
@@ -172,6 +178,7 @@ getnetanswer(querybuf *answer, int ansle
 	char		*in, *bp, **ap, *ep;
 
 	_DIAGASSERT(answer != NULL);
+	_DIAGASSERT(res != NULL);
 
 	/*
 	 * find first satisfactory answer
@@ -216,7 +223,7 @@ getnetanswer(querybuf *answer, int ansle
 	n_name[0] = '\0';
 	while (--ancount >= 0 && cp < eom) {
 		n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
-		if ((n < 0) || !res_dnok(bp))
+		if ((n < 0) || !maybe_dnok(res, bp))
 			break;
 		cp += n;
 		(void)strlcpy(n_name, bp, sizeof(n_name));
@@ -226,7 +233,7 @@ getnetanswer(querybuf *answer, int ansle
 		GETSHORT(n, cp);
 		if (class == C_IN && type == T_PTR) {
 			n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
-			if ((n < 0) || !res_hnok(bp)) {
+			if ((n < 0) || !maybe_hnok(res, bp)) {
 cp += n;
 return NULL;
 			}
@@ -359,7 +366,7 @@ _dns_getnetbyaddr(void *cbrv, void *cbda
 		return NS_NOTFOUND;
 	}
 	__res_put_state(res);
-	np = getnetanswer(buf, anslen, BYADDR);
+	np = getnetanswer(res, buf, anslen, BYADDR);
 	free(buf);
 	if (np) {
 		/* maybe net should be unsigned? */
@@ -471,7 +478,7 @@ _dns_getnetbyname(void *cbrv, void *cbda
 		return NS_NOTFOUND;
 	}
 	__res_put_state(res);
-	np = getnetanswer(buf, anslen, BYNAME);
+	np = getnetanswer(res, buf, anslen, BYNAME);
 	free(buf);
 
 	if (np != NULL) {



CVS commit: src/lib/libc/net

2015-10-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 26 19:41:19 UTC 2015

Modified Files:
src/lib/libc/net: getnetnamadr.c

Log Message:
put the state back after it is used.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/lib/libc/net/getnetnamadr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnetnamadr.c
diff -u src/lib/libc/net/getnetnamadr.c:1.43 src/lib/libc/net/getnetnamadr.c:1.44
--- src/lib/libc/net/getnetnamadr.c:1.43	Mon Oct 26 15:28:53 2015
+++ src/lib/libc/net/getnetnamadr.c	Mon Oct 26 15:41:19 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnetnamadr.c,v 1.43 2015/10/26 19:28:53 christos Exp $	*/
+/*	$NetBSD: getnetnamadr.c,v 1.44 2015/10/26 19:41:19 christos Exp $	*/
 
 /* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
  *	Dep. Matematica Universidade de Coimbra, Portugal, Europe
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)getnetbyaddr
 static char sccsid_[] = "from getnetnamadr.c	1.4 (Coimbra) 93/06/03";
 static char rcsid[] = "Id: getnetnamadr.c,v 8.8 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: getnetnamadr.c,v 1.43 2015/10/26 19:28:53 christos Exp $");
+__RCSID("$NetBSD: getnetnamadr.c,v 1.44 2015/10/26 19:41:19 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -365,8 +365,8 @@ _dns_getnetbyaddr(void *cbrv, void *cbda
 		__res_put_state(res);
 		return NS_NOTFOUND;
 	}
-	__res_put_state(res);
 	np = getnetanswer(res, buf, anslen, BYADDR);
+	__res_put_state(res);
 	free(buf);
 	if (np) {
 		/* maybe net should be unsigned? */
@@ -477,8 +477,8 @@ _dns_getnetbyname(void *cbrv, void *cbda
 		__res_put_state(res);
 		return NS_NOTFOUND;
 	}
-	__res_put_state(res);
 	np = getnetanswer(res, buf, anslen, BYNAME);
+	__res_put_state(res);
 	free(buf);
 
 	if (np != NULL) {



CVS commit: src/lib/libc/net

2015-10-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 26 14:48:04 UTC 2015

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
PR/50367: Stefan Schaeckeler: libc resolver library does not resolve host
names with underscores ("_"). According to resolv.conf(5) RES_NOCHECKNAME
is on by default; well, it is and gethostbyname(3) obeys it
(gethnamaddr.c:maybe_ok), but getaddrinfo(3) up till this commit not.
XXX: pullup-7, pullup-6


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.109 src/lib/libc/net/getaddrinfo.c:1.110
--- src/lib/libc/net/getaddrinfo.c:1.109	Thu Sep 10 10:05:06 2015
+++ src/lib/libc/net/getaddrinfo.c	Mon Oct 26 10:48:04 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.109 2015/09/10 14:05:06 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.110 2015/10/26 14:48:04 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.109 2015/09/10 14:05:06 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.110 2015/10/26 14:48:04 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -226,8 +226,8 @@ static int addrconfig(uint64_t *);
 static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *);
 #endif
 
-static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
-const struct addrinfo *);
+static struct addrinfo *getanswer(res_state, const querybuf *, int,
+const char *, int, const struct addrinfo *);
 static void aisort(struct addrinfo *s, res_state res);
 static struct addrinfo * _dns_query(struct res_target *,
 const struct addrinfo *, res_state, int);
@@ -1162,9 +1162,11 @@ ip6_str2scopeid(char *scope, struct sock
 static const char AskedForGot[] =
 	"gethostby*.getanswer: asked for \"%s\", got \"%s\"";
 
+#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || \
+   (ok)(nm) != 0)
 static struct addrinfo *
-getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
-const struct addrinfo *pai)
+getanswer(res_state res, const querybuf *answer, int anslen, const char *qname,
+int qtype, const struct addrinfo *pai)
 {
 	struct addrinfo sentinel, *cur;
 	struct addrinfo ai, *aip;
@@ -1186,6 +1188,7 @@ getanswer(const querybuf *answer, int an
 	_DIAGASSERT(answer != NULL);
 	_DIAGASSERT(qname != NULL);
 	_DIAGASSERT(pai != NULL);
+	_DIAGASSERT(res != NULL);
 
 	memset(, 0, sizeof(sentinel));
 	cur = 
@@ -1218,7 +1221,7 @@ getanswer(const querybuf *answer, int an
 		return (NULL);
 	}
 	n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
-	if ((n < 0) || !(*name_ok)(bp)) {
+	if ((n < 0) || !maybe_ok(res, bp, name_ok)) {
 		h_errno = NO_RECOVERY;
 		return (NULL);
 	}
@@ -1243,7 +1246,7 @@ getanswer(const querybuf *answer, int an
 	srvlist = NULL;
 	while (ancount-- > 0 && cp < eom && !had_error) {
 		n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
-		if ((n < 0) || !(*name_ok)(bp)) {
+		if ((n < 0) || !maybe_ok(res, bp, name_ok)) {
 			had_error++;
 			continue;
 		}
@@ -1262,7 +1265,7 @@ getanswer(const querybuf *answer, int an
 		if ((qtype == T_A || qtype == T_ || qtype == T_ANY) &&
 		type == T_CNAME) {
 			n = dn_expand(answer->buf, eom, cp, tbuf, (int)sizeof tbuf);
-			if ((n < 0) || !(*name_ok)(tbuf)) {
+			if ((n < 0) || !maybe_ok(res, tbuf, name_ok)) {
 had_error++;
 continue;
 			}
@@ -1353,7 +1356,7 @@ getanswer(const querybuf *answer, int an
 			cp += INT16SZ;
 			n = dn_expand(answer->buf, eom, cp, tbuf,
 			(int)sizeof(tbuf));
-			if ((n < 0) || !res_hnok(tbuf)) {
+			if ((n < 0) || !maybe_ok(res, tbuf, res_hnok)) {
 had_error++;
 continue;
 			}
@@ -1399,7 +1402,6 @@ getanswer(const querybuf *answer, int an
 	}
 
 	if (srvlist) {
-		res_state res;
 		/*
 		 * Check for explicit rejection.
 		 */
@@ -1408,16 +1410,6 @@ getanswer(const querybuf *answer, int an
 			h_errno = HOST_NOT_FOUND;
 			return NULL;
 		}
-		res = __res_get_state();
-		if (res == NULL) {
-			while (srvlist != NULL) {
-srv = srvlist;
-srvlist = srvlist->next;
-free(srv);
-			}
-			h_errno = NETDB_INTERNAL;
-			return NULL;
-		}
 
 		while (srvlist) {
 			struct res_target q, q2;
@@ -1452,7 +1444,6 @@ getanswer(const querybuf *answer, int an
 			}
 			free(srv);
 		}
-		__res_put_state(res);
 	}
 	if (haveanswer) {
 		if (!sentinel.ai_next->ai_canonname)
@@ -1541,14 +1532,14 @@ _dns_query(struct res_target *q, const s
 			goto out;
 	}
 
-	ai = getanswer(buf, q->n, q->name, q->qtype, pai);
+	ai = getanswer(res, buf, q->n, q->name, q->qtype, pai);
 	if (ai) {
 		cur->ai_next = ai;
 		while (cur && 

CVS commit: src/lib/libc/net

2015-09-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 22 16:15:08 UTC 2015

Modified Files:
src/lib/libc/net: getnameinfo.c

Log Message:
be more forgiving, and don't abort on unexpected errors.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/lib/libc/net/getnameinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnameinfo.c
diff -u src/lib/libc/net/getnameinfo.c:1.58 src/lib/libc/net/getnameinfo.c:1.59
--- src/lib/libc/net/getnameinfo.c:1.58	Tue Sep 22 10:46:09 2015
+++ src/lib/libc/net/getnameinfo.c	Tue Sep 22 12:15:08 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnameinfo.c,v 1.58 2015/09/22 14:46:09 christos Exp $	*/
+/*	$NetBSD: getnameinfo.c,v 1.59 2015/09/22 16:15:08 christos Exp $	*/
 /*	$KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $	*/
 
 /*
@@ -47,7 +47,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getnameinfo.c,v 1.58 2015/09/22 14:46:09 christos Exp $");
+__RCSID("$NetBSD: getnameinfo.c,v 1.59 2015/09/22 16:15:08 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -64,7 +64,6 @@ __RCSID("$NetBSD: getnameinfo.c,v 1.58 2
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -406,9 +405,6 @@ getnameinfo_inet(const struct sockaddr *
 			strlcpy(host, hp->h_name, hostlen);
 		} else {
 			switch (he) {
-			case NETDB_INTERNAL:
-			case NO_RECOVERY:
-return EAI_SYSTEM;
 			case NO_DATA:
 			case HOST_NOT_FOUND:
 if (flags & NI_NAMEREQD)
@@ -417,9 +413,11 @@ getnameinfo_inet(const struct sockaddr *
 			case TRY_AGAIN:
 return EAI_AGAIN;
 			case NETDB_SUCCESS:
+			case NETDB_INTERNAL:
+			case NO_RECOVERY:
 /*FALLTHROUGH*/
 			default:
-abort();
+return EAI_SYSTEM;
 			}
 			switch(afd->a_af) {
 #ifdef INET6



CVS commit: src/lib/libc/net

2015-09-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 22 16:16:02 UTC 2015

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
- fix various leaks on error
- don't use the wrong error variable in switch
- always set the error return code
- return consistent errors when the input data cannot be handled.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.91 src/lib/libc/net/gethnamaddr.c:1.92
--- src/lib/libc/net/gethnamaddr.c:1.91	Thu Jun 19 11:08:18 2014
+++ src/lib/libc/net/gethnamaddr.c	Tue Sep 22 12:16:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.91 2014/06/19 15:08:18 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.92 2015/09/22 16:16:02 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = "@(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: gethnamaddr.c,v 1.91 2014/06/19 15:08:18 christos Exp $");
+__RCSID("$NetBSD: gethnamaddr.c,v 1.92 2015/09/22 16:16:02 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -244,6 +244,7 @@ getanswer(const querybuf *answer, int an
 		name_ok = res_dnok;
 		break;
 	default:
+		*he = NO_RECOVERY;
 		return NULL;	/* XXX should be abort(); */
 	}
 
@@ -964,6 +965,7 @@ _dns_gethtbyname(void *rv, void *cb_data
 	res = __res_get_state();
 	if (res == NULL) {
 		free(buf);
+		*info->he = NETDB_INTERNAL;
 		return NS_NOTFOUND;
 	}
 	n = res_nsearch(res, name, C_IN, type, buf->buf, (int)sizeof(buf->buf));
@@ -978,7 +980,7 @@ _dns_gethtbyname(void *rv, void *cb_data
 	free(buf);
 	__res_put_state(res);
 	if (hp == NULL)
-		switch (h_errno) {
+		switch (*info->he) {
 		case HOST_NOT_FOUND:
 			return NS_NOTFOUND;
 		case TRY_AGAIN:
@@ -1026,35 +1028,31 @@ _dns_gethtbyaddr(void *rv, void	*cb_data
 			((unsigned int)uaddr[n] >> 4) & 0xf);
 			if (advance > 0 && qp + advance < ep)
 qp += advance;
-			else {
-*info->he = NETDB_INTERNAL;
-return NS_NOTFOUND;
-			}
-		}
-		if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) {
-			*info->he = NETDB_INTERNAL;
-			return NS_NOTFOUND;
+			else
+goto norecovery;
 		}
+		if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf))
+			goto norecovery;
 		break;
 	default:
-		return NS_UNAVAIL;
+		goto norecovery;
 	}
 
 	buf = malloc(sizeof(*buf));
 	if (buf == NULL) {
-		*info->he = NETDB_INTERNAL;
-		return NS_NOTFOUND;
+		goto nospc;
 	}
 	res = __res_get_state();
 	if (res == NULL) {
 		free(buf);
-		return NS_NOTFOUND;
+		goto nospc;
 	}
 	n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf));
 	if (n < 0) {
 		free(buf);
 		debugprintf("res_nquery failed (%d)\n", res, n);
 		__res_put_state(res);
+		*info->he = HOST_NOT_FOUND;
 		return NS_NOTFOUND;
 	}
 	hp = getanswer(buf, n, qbuf, T_PTR, res, info->hp, info->buf,
@@ -1080,8 +1078,10 @@ _dns_gethtbyaddr(void *rv, void	*cb_data
 	hp->h_addr_list[1] = NULL;
 	(void)memcpy(bf, uaddr, (size_t)info->hp->h_length);
 	if (info->hp->h_addrtype == AF_INET && (res->options & RES_USE_INET6)) {
-		if (blen + NS_IN6ADDRSZ > info->buflen)
+		if (blen + NS_IN6ADDRSZ > info->buflen) {
+			__res_put_state(res);
 			goto nospc;
+		}
 		map_v4v6_address(bf, bf);
 		hp->h_addrtype = AF_INET6;
 		hp->h_length = NS_IN6ADDRSZ;
@@ -1093,6 +1093,9 @@ _dns_gethtbyaddr(void *rv, void	*cb_data
 nospc:
 	*info->he = NETDB_INTERNAL;
 	return NS_UNAVAIL;
+norecovery:
+	*info->he = NO_RECOVERY;
+	return NS_UNAVAIL;
 }
 
 #ifdef YP



CVS commit: src/lib/libc/net

2015-09-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 22 14:46:09 UTC 2015

Modified Files:
src/lib/libc/net: getnameinfo.c

Log Message:
Handle herrors properly so that postfix can return 4XX codes when appropriate.
Pointed out by Viktor Dukhovni.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/lib/libc/net/getnameinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnameinfo.c
diff -u src/lib/libc/net/getnameinfo.c:1.57 src/lib/libc/net/getnameinfo.c:1.58
--- src/lib/libc/net/getnameinfo.c:1.57	Thu Sep  3 11:01:19 2015
+++ src/lib/libc/net/getnameinfo.c	Tue Sep 22 10:46:09 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnameinfo.c,v 1.57 2015/09/03 15:01:19 christos Exp $	*/
+/*	$NetBSD: getnameinfo.c,v 1.58 2015/09/22 14:46:09 christos Exp $	*/
 /*	$KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $	*/
 
 /*
@@ -47,7 +47,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getnameinfo.c,v 1.57 2015/09/03 15:01:19 christos Exp $");
+__RCSID("$NetBSD: getnameinfo.c,v 1.58 2015/09/22 14:46:09 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -64,6 +64,7 @@ __RCSID("$NetBSD: getnameinfo.c,v 1.57 2
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -404,8 +405,22 @@ getnameinfo_inet(const struct sockaddr *
 			}
 			strlcpy(host, hp->h_name, hostlen);
 		} else {
-			if (flags & NI_NAMEREQD)
-return EAI_NONAME;
+			switch (he) {
+			case NETDB_INTERNAL:
+			case NO_RECOVERY:
+return EAI_SYSTEM;
+			case NO_DATA:
+			case HOST_NOT_FOUND:
+if (flags & NI_NAMEREQD)
+	return EAI_NONAME;
+break;
+			case TRY_AGAIN:
+return EAI_AGAIN;
+			case NETDB_SUCCESS:
+/*FALLTHROUGH*/
+			default:
+abort();
+			}
 			switch(afd->a_af) {
 #ifdef INET6
 			case AF_INET6:



CVS commit: src/lib/libc/net

2015-09-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep 10 11:33:27 UTC 2015

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
mke allocaddrinfo static.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.107 src/lib/libc/net/getaddrinfo.c:1.108
--- src/lib/libc/net/getaddrinfo.c:1.107	Wed Sep  9 06:06:05 2015
+++ src/lib/libc/net/getaddrinfo.c	Thu Sep 10 07:33:27 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.107 2015/09/09 10:06:05 ozaki-r Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.108 2015/09/10 11:33:27 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.107 2015/09/09 10:06:05 ozaki-r Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.108 2015/09/10 11:33:27 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -935,7 +935,7 @@ get_canonname(const struct addrinfo *pai
 	return 0;
 }
 
-struct addrinfo *
+static struct addrinfo *
 allocaddrinfo(socklen_t addrlen)
 {
 	struct addrinfo *ai;



CVS commit: src/lib/libc/net

2015-09-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep  3 15:01:19 UTC 2015

Modified Files:
src/lib/libc/net: getnameinfo.c

Log Message:
PR/50195: Henning Petersen: Incorrect check in getnameinfo_link.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/lib/libc/net/getnameinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnameinfo.c
diff -u src/lib/libc/net/getnameinfo.c:1.56 src/lib/libc/net/getnameinfo.c:1.57
--- src/lib/libc/net/getnameinfo.c:1.56	Fri May 15 10:26:02 2015
+++ src/lib/libc/net/getnameinfo.c	Thu Sep  3 11:01:19 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnameinfo.c,v 1.56 2015/05/15 14:26:02 joerg Exp $	*/
+/*	$NetBSD: getnameinfo.c,v 1.57 2015/09/03 15:01:19 christos Exp $	*/
 /*	$KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $	*/
 
 /*
@@ -47,7 +47,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getnameinfo.c,v 1.56 2015/05/15 14:26:02 joerg Exp $");
+__RCSID("$NetBSD: getnameinfo.c,v 1.57 2015/09/03 15:01:19 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -536,11 +536,7 @@ getnameinfo_link(const struct sockaddr *
 
 	if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) {
 		n = snprintf(host, hostlen, "link#%u", sdl->sdl_index);
-		if (n < 0 || (socklen_t) n > hostlen) {
-			*host = '\0';
-			return EAI_MEMORY;
-		}
-		return 0;
+		goto out;
 	}
 
 	switch (sdl->sdl_type) {
@@ -553,11 +549,7 @@ getnameinfo_link(const struct sockaddr *
 		else
 			n = snprintf(host, hostlen, "%u.%u",
 			CLLADDR(sdl)[1], CLLADDR(sdl)[0]);
-		if (n < 0 || (socklen_t) n >= hostlen) {
-			*host = '\0';
-			return EAI_MEMORY;
-		} else
-			return 0;
+		goto out;
 #endif
 	case IFT_IEEE1394:
 		if (sdl->sdl_alen < sizeof(iha->iha_uid))
@@ -591,6 +583,12 @@ getnameinfo_link(const struct sockaddr *
 		return hexname((const uint8_t *)CLLADDR(sdl),
 		(size_t)sdl->sdl_alen, host, hostlen);
 	}
+out:
+	if (n < 0 || (socklen_t) n >= hostlen) {
+		*host = '\0';
+		return EAI_MEMORY;
+	}
+	return 0;
 }
 
 static int



CVS commit: src/lib/libc/net

2015-05-15 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri May 15 14:26:02 UTC 2015

Modified Files:
src/lib/libc/net: getnameinfo.c

Log Message:
Don't create a weak alias in the !RUMPACTION case.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/lib/libc/net/getnameinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnameinfo.c
diff -u src/lib/libc/net/getnameinfo.c:1.55 src/lib/libc/net/getnameinfo.c:1.56
--- src/lib/libc/net/getnameinfo.c:1.55	Fri May 15 06:58:59 2015
+++ src/lib/libc/net/getnameinfo.c	Fri May 15 14:26:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnameinfo.c,v 1.55 2015/05/15 06:58:59 ozaki-r Exp $	*/
+/*	$NetBSD: getnameinfo.c,v 1.56 2015/05/15 14:26:02 joerg Exp $	*/
 /*	$KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $	*/
 
 /*
@@ -47,7 +47,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: getnameinfo.c,v 1.55 2015/05/15 06:58:59 ozaki-r Exp $);
+__RCSID($NetBSD: getnameinfo.c,v 1.56 2015/05/15 14:26:02 joerg Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -74,9 +74,11 @@ __RCSID($NetBSD: getnameinfo.c,v 1.55 2
 #include servent.h
 #include hostent.h
 
+#ifndef RUMP_ACTION
 #ifdef __weak_alias
 __weak_alias(getnameinfo,_getnameinfo)
 #endif
+#endif
 
 static const struct afd {
 	int		a_af;



CVS commit: src/lib/libc/net

2015-01-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan  4 16:06:29 UTC 2015

Modified Files:
src/lib/libc/net: nsdispatch.3

Log Message:
Correct API for the gethostby{name,addr}


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/libc/net/nsdispatch.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/nsdispatch.3
diff -u src/lib/libc/net/nsdispatch.3:1.31 src/lib/libc/net/nsdispatch.3:1.32
--- src/lib/libc/net/nsdispatch.3:1.31	Thu Apr 28 12:16:23 2011
+++ src/lib/libc/net/nsdispatch.3	Sun Jan  4 11:06:29 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: nsdispatch.3,v 1.31 2011/04/28 16:16:23 wiz Exp $
+.\	$NetBSD: nsdispatch.3,v 1.32 2015/01/04 16:06:29 christos Exp $
 .\
 .\ Copyright (c) 1997, 1998, 1999, 2004, 2005, 2008
 .\ The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd May 8, 2008
+.Dd January 4, 2015
 .Dt NSDISPATCH 3
 .Os
 .Sh NAME
@@ -434,8 +434,6 @@ The callback function names and
 organization for various standard database callback functions are:
 .\
 .Ss Methods for hosts database
-.Sy NOTE:
-The method APIs for this database will be changing in the near future.
 .Bl -tag -width 3n
 .It Sy getaddrinfo
 .Ft char *name ,
@@ -451,7 +449,7 @@ via
 .Ft int af
 .Pp
 Returns
-.Ft struct hostent *
+.Ft struct getnamaddr *
 via
 .Ft void *cbrv .
 .It Sy gethostbyname
@@ -460,10 +458,22 @@ via
 .Ft int af
 .Pp
 Returns
-.Ft struct hostent *
+.Ft struct getnamaddr *
 via
 .Ft void *cbrv .
 .El
+.Pp
+The
+.Ft struct getnamaddr
+is defined internally in libc as:
+.Bd -literal
+struct getnamaddr { 
+struct hostent *hp;
+char *buf; 
+size_t buflen;
+int *he; 
+}; 
+.Ed
 .\
 .Ss Methods for group and group_compat databases
 .Bl -tag -width 3n



CVS commit: src/lib/libc/net

2015-01-04 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jan  4 21:38:58 UTC 2015

Modified Files:
src/lib/libc/net: nsdispatch.3

Log Message:
Add more markup.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/net/nsdispatch.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/nsdispatch.3
diff -u src/lib/libc/net/nsdispatch.3:1.32 src/lib/libc/net/nsdispatch.3:1.33
--- src/lib/libc/net/nsdispatch.3:1.32	Sun Jan  4 16:06:29 2015
+++ src/lib/libc/net/nsdispatch.3	Sun Jan  4 21:38:58 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: nsdispatch.3,v 1.32 2015/01/04 16:06:29 christos Exp $
+.\	$NetBSD: nsdispatch.3,v 1.33 2015/01/04 21:38:58 wiz Exp $
 .\
 .\ Copyright (c) 1997, 1998, 1999, 2004, 2005, 2008
 .\ The NetBSD Foundation, Inc.
@@ -941,8 +941,8 @@ routines first appeared in
 Support for dynamically-loaded modules first appeared in
 .Nx 3.0 .
 .Sh AUTHORS
-Luke Mewburn
-.Aq lu...@netbsd.org
+.An Luke Mewburn
+.Aq Mt lu...@netbsd.org
 wrote this freely distributable name-service switch implementation,
 using ideas from the
 .Tn ULTRIX
@@ -951,8 +951,9 @@ and
 .Tn Solaris
 .Xr nsswitch.conf 4
 manual pages.
-Support for dynamically-loaded modules was added by Jason Thorpe
-.Aq thor...@netbsd.org ,
+Support for dynamically-loaded modules was added by
+.An Jason Thorpe
+.Aq Mt thor...@netbsd.org ,
 based on code developed by the
 .Fx
 Project.



CVS commit: src/lib/libc/net

2014-11-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Nov 24 15:41:18 UTC 2014

Modified Files:
src/lib/libc/net: base64.c

Log Message:
Don't read past the end when the data is exactly the right size. Reported
by tedu @ openbsd in tech-userlevel. Thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/net/base64.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/base64.c
diff -u src/lib/libc/net/base64.c:1.14 src/lib/libc/net/base64.c:1.15
--- src/lib/libc/net/base64.c:1.14	Mon Jun 25 18:32:44 2012
+++ src/lib/libc/net/base64.c	Mon Nov 24 10:41:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: base64.c,v 1.14 2012/06/25 22:32:44 abs Exp $	*/
+/*	$NetBSD: base64.c,v 1.15 2014/11/24 15:41:18 christos Exp $	*/
 
 /*
  * Copyright (c) 2004 by Internet Systems Consortium, Inc. (ISC)
@@ -47,7 +47,7 @@
 #if 0
 static const char rcsid[] = Id: base64.c,v 1.4 2005/04/27 04:56:34 sra Exp;
 #else
-__RCSID($NetBSD: base64.c,v 1.14 2012/06/25 22:32:44 abs Exp $);
+__RCSID($NetBSD: base64.c,v 1.15 2014/11/24 15:41:18 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -218,6 +218,7 @@ b64_pton(char const *src, u_char *target
 {
 	size_t tarindex;
 	int state, ch;
+	u_char nextbyte;
 	char *pos;
 
 	_DIAGASSERT(src != NULL);
@@ -242,33 +243,36 @@ b64_pton(char const *src, u_char *target
 			if (target) {
 if ((size_t)tarindex = targsize)
 	return (-1);
-target[tarindex] =
-(unsigned char)(pos - Base64)  2;
+target[tarindex] = (u_char)(pos - Base64)  2;
 			}
 			state = 1;
 			break;
 		case 1:
 			if (target) {
-if ((size_t)tarindex + 1 = targsize)
+if ((size_t)tarindex = targsize)
 	return (-1);
 target[tarindex] |= 
 (u_int32_t)(pos - Base64)  4;
-target[tarindex+1]  = 
-(unsigned char)
-(((pos - Base64)  0x0f)  4);
+nextbyte = (u_char)((pos - Base64)  0x0f)  4;
+if (tarindex + 1  targsize)
+	target[tarindex + 1] = nextbyte;
+else if (nextbyte)
+	return (-1);
 			}
 			tarindex++;
 			state = 2;
 			break;
 		case 2:
 			if (target) {
-if ((size_t)tarindex + 1 = targsize)
+if ((size_t)tarindex = targsize)
 	return (-1);
 target[tarindex] |= 
 	(u_int32_t)(pos - Base64)  2;
-target[tarindex+1] =
-(unsigned char)
-(((pos - Base64)  0x03)  6);
+nextbyte = (u_char)((pos - Base64)  0x03)  6;
+if (tarindex + 1  targsize)
+	target[tarindex + 1] = nextbyte;
+else if (nextbyte)
+	return (-1);
 			}
 			tarindex++;
 			state = 3;
@@ -327,7 +331,8 @@ b64_pton(char const *src, u_char *target
 			 * zeros.  If we don't check them, they become a
 			 * subliminal channel.
 			 */
-			if (target  target[tarindex] != 0)
+			if (target  tarindex  targsize 
+			target[tarindex] != 0)
 return (-1);
 		}
 	} else {



CVS commit: src/lib/libc/net

2014-11-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Nov 24 15:43:21 UTC 2014

Modified Files:
src/lib/libc/net: base64.c

Log Message:
knf, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/net/base64.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/base64.c
diff -u src/lib/libc/net/base64.c:1.15 src/lib/libc/net/base64.c:1.16
--- src/lib/libc/net/base64.c:1.15	Mon Nov 24 10:41:18 2014
+++ src/lib/libc/net/base64.c	Mon Nov 24 10:43:21 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: base64.c,v 1.15 2014/11/24 15:41:18 christos Exp $	*/
+/*	$NetBSD: base64.c,v 1.16 2014/11/24 15:43:21 christos Exp $	*/
 
 /*
  * Copyright (c) 2004 by Internet Systems Consortium, Inc. (ISC)
@@ -47,7 +47,7 @@
 #if 0
 static const char rcsid[] = Id: base64.c,v 1.4 2005/04/27 04:56:34 sra Exp;
 #else
-__RCSID($NetBSD: base64.c,v 1.15 2014/11/24 15:41:18 christos Exp $);
+__RCSID($NetBSD: base64.c,v 1.16 2014/11/24 15:43:21 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -155,11 +155,11 @@ b64_ntop(u_char const *src, size_t srcle
 		input[2] = *src++;
 		srclength -= 3;
 
-		output[0] = (u_int32_t)input[0]  2;
-		output[1] = ((u_int32_t)(input[0]  0x03)  4) +
-		((u_int32_t)input[1]  4);
-		output[2] = ((u_int32_t)(input[1]  0x0f)  2) +
-		((u_int32_t)input[2]  6);
+		output[0] = (uint32_t)input[0]  2;
+		output[1] = ((uint32_t)(input[0]  0x03)  4) +
+		((uint32_t)input[1]  4);
+		output[2] = ((uint32_t)(input[1]  0x0f)  2) +
+		((uint32_t)input[2]  6);
 		output[3] = input[2]  0x3f;
 		Assert(output[0]  64);
 		Assert(output[1]  64);
@@ -167,7 +167,7 @@ b64_ntop(u_char const *src, size_t srcle
 		Assert(output[3]  64);
 
 		if (datalength + 4  targsize)
-			return (-1);
+			return -1;
 		target[datalength++] = Base64[output[0]];
 		target[datalength++] = Base64[output[1]];
 		target[datalength++] = Base64[output[2]];
@@ -181,17 +181,17 @@ b64_ntop(u_char const *src, size_t srcle
 		for (i = 0; i  srclength; i++)
 			input[i] = *src++;
 	
-		output[0] = (u_int32_t)input[0]  2;
-		output[1] = ((u_int32_t)(input[0]  0x03)  4) +
-		((u_int32_t)input[1]  4);
-		output[2] = ((u_int32_t)(input[1]  0x0f)  2) +
-		((u_int32_t)input[2]  6);
+		output[0] = (uint32_t)input[0]  2;
+		output[1] = ((uint32_t)(input[0]  0x03)  4) +
+		((uint32_t)input[1]  4);
+		output[2] = ((uint32_t)(input[1]  0x0f)  2) +
+		((uint32_t)input[2]  6);
 		Assert(output[0]  64);
 		Assert(output[1]  64);
 		Assert(output[2]  64);
 
 		if (datalength + 4  targsize)
-			return (-1);
+			return -1;
 		target[datalength++] = Base64[output[0]];
 		target[datalength++] = Base64[output[1]];
 		if (srclength == 1U)
@@ -201,7 +201,7 @@ b64_ntop(u_char const *src, size_t srcle
 		target[datalength++] = Pad64;
 	}
 	if (datalength = targsize)
-		return (-1);
+		return -1;
 	target[datalength] = '\0';	/*% Returned value doesn't count \\0. */
 	_DIAGASSERT(__type_fit(int, datalength));
 	return (int)datalength;
@@ -235,44 +235,44 @@ b64_pton(char const *src, u_char *target
 			break;
 
 		pos = strchr(Base64, ch);
-		if (pos == 0) 		/*% A non-base64 character. */
-			return (-1);
+		if (pos == NULL) 	/*% A non-base64 character. */
+			return -1;
 
 		switch (state) {
 		case 0:
 			if (target) {
-if ((size_t)tarindex = targsize)
-	return (-1);
+if (tarindex = targsize)
+	return -1;
 target[tarindex] = (u_char)(pos - Base64)  2;
 			}
 			state = 1;
 			break;
 		case 1:
 			if (target) {
-if ((size_t)tarindex = targsize)
-	return (-1);
+if (tarindex = targsize)
+	return -1;
 target[tarindex] |= 
-(u_int32_t)(pos - Base64)  4;
+(uint32_t)(pos - Base64)  4;
 nextbyte = (u_char)((pos - Base64)  0x0f)  4;
 if (tarindex + 1  targsize)
 	target[tarindex + 1] = nextbyte;
 else if (nextbyte)
-	return (-1);
+	return -1;
 			}
 			tarindex++;
 			state = 2;
 			break;
 		case 2:
 			if (target) {
-if ((size_t)tarindex = targsize)
-	return (-1);
+if (tarindex = targsize)
+	return -1;
 target[tarindex] |= 
-	(u_int32_t)(pos - Base64)  2;
+	(uint32_t)(pos - Base64)  2;
 nextbyte = (u_char)((pos - Base64)  0x03)  6;
 if (tarindex + 1  targsize)
 	target[tarindex + 1] = nextbyte;
 else if (nextbyte)
-	return (-1);
+	return -1;
 			}
 			tarindex++;
 			state = 3;
@@ -280,9 +280,8 @@ b64_pton(char const *src, u_char *target
 		case 3:
 			if (target) {
 if ((size_t)tarindex = targsize)
-	return (-1);
-target[tarindex] |=
-(unsigned char)(pos - Base64);
+	return -1;
+target[tarindex] |= (u_char)(pos - Base64);
 			}
 			tarindex++;
 			state = 0;
@@ -302,7 +301,7 @@ b64_pton(char const *src, u_char *target
 		switch (state) {
 		case 0:		/*% Invalid = in first position */
 		case 1:		/*% Invalid = in second position */
-			

CVS commit: src/lib/libc/net

2014-06-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 19 15:08:18 UTC 2014

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
use fparseln() instead of abusing fgetln(), so that the last line that
might not have a terminating newline is processed.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.90 src/lib/libc/net/gethnamaddr.c:1.91
--- src/lib/libc/net/gethnamaddr.c:1.90	Fri Jan 24 12:26:18 2014
+++ src/lib/libc/net/gethnamaddr.c	Thu Jun 19 11:08:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.90 2014/01/24 17:26:18 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.91 2014/06/19 15:08:18 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.90 2014/01/24 17:26:18 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.91 2014/06/19 15:08:18 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -741,7 +741,7 @@ gethostent_r(FILE *hf, struct hostent *h
 	char *p, *name;
 	char *cp, **q;
 	int af, len;
-	size_t llen, anum;
+	size_t anum;
 	char **aliases;
 	size_t maxaliases;
 	struct in6_addr host_addr;
@@ -751,62 +751,61 @@ gethostent_r(FILE *hf, struct hostent *h
 		errno = EINVAL;
 		return NULL;
 	}
+	p = NULL;
 	setup(aliases, maxaliases);
- again:
-	if ((p = fgetln(hf, llen)) == NULL) {
-		free(aliases);
-		*he = HOST_NOT_FOUND;
-		return NULL;
-	}
-	if (llen  1)
-		goto again;
-	if (*p == '#')
-		goto again;
-	p[llen] = '\0';
-	if (!(cp = strpbrk(p, #\n)))
-		goto again;
-	*cp = '\0';
-	if (!(cp = strpbrk(p,  \t)))
-		goto again;
-	*cp++ = '\0';
-	if (inet_pton(AF_INET6, p, host_addr)  0) {
-		af = AF_INET6;
-		len = NS_IN6ADDRSZ;
-	} else if (inet_pton(AF_INET, p, host_addr)  0) {
-		res_state res = __res_get_state();
-		if (res == NULL)
-			goto nospc;
-		if (res-options  RES_USE_INET6) {
-			map_v4v6_address(buf, buf);
+	for (;;) {
+		free(p);
+		p = fparseln(hf, NULL, NULL, NULL, FPARSELN_UNESCALL);
+		if (p == NULL) {
+			free(aliases);
+			*he = HOST_NOT_FOUND;
+			return NULL;
+		}
+		if (!(cp = strpbrk(p,  \t)))
+			continue;
+		*cp++ = '\0';
+		if (inet_pton(AF_INET6, p, host_addr)  0) {
 			af = AF_INET6;
 			len = NS_IN6ADDRSZ;
 		} else {
-			af = AF_INET;
-			len = NS_INADDRSZ;
+			if (inet_pton(AF_INET, p, host_addr) = 0)
+continue;
+
+			res_state res = __res_get_state();
+			if (res == NULL)
+goto nospc;
+			if (res-options  RES_USE_INET6) {
+map_v4v6_address(buf, buf);
+af = AF_INET6;
+len = NS_IN6ADDRSZ;
+			} else {
+af = AF_INET;
+len = NS_INADDRSZ;
+			}
+			__res_put_state(res);
 		}
-		__res_put_state(res);
-	} else {
-		goto again;
-	}
-	/* if this is not something we're looking for, skip it. */
-	if (hent-h_addrtype != 0  hent-h_addrtype != af)
-		goto again;
-	if (hent-h_length != 0  hent-h_length != len)
-		goto again;
 
-	while (*cp == ' ' || *cp == '\t')
-		cp++;
-	if ((cp = strpbrk(name = cp,  \t)) != NULL)
-		*cp++ = '\0';
-	q = aliases;
-	while (cp  *cp) {
-		if (*cp == ' ' || *cp == '\t') {
-			cp++;
+		/* if this is not something we're looking for, skip it. */
+		if (hent-h_addrtype != 0  hent-h_addrtype != af)
 			continue;
-		}
-		addalias(q, cp, aliases, maxaliases);
-		if ((cp = strpbrk(cp,  \t)) != NULL)
+		if (hent-h_length != 0  hent-h_length != len)
+			continue;
+
+		while (*cp == ' ' || *cp == '\t')
+			cp++;
+		if ((cp = strpbrk(name = cp,  \t)) != NULL)
 			*cp++ = '\0';
+		q = aliases;
+		while (cp  *cp) {
+			if (*cp == ' ' || *cp == '\t') {
+cp++;
+continue;
+			}
+			addalias(q, cp, aliases, maxaliases);
+			if ((cp = strpbrk(cp,  \t)) != NULL)
+*cp++ = '\0';
+		}
+		break;
 	}
 	hent-h_length = len;
 	hent-h_addrtype = af;
@@ -823,9 +822,11 @@ gethostent_r(FILE *hf, struct hostent *h
 	hent-h_aliases[anum] = NULL;
 
 	*he = NETDB_SUCCESS;
+	free(p);
 	free(aliases);
 	return hent;
 nospc:
+	free(p);
 	free(aliases);
 	errno = ENOSPC;
 	*he = NETDB_INTERNAL;



CVS commit: src/lib/libc/net

2014-06-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 19 15:09:07 UTC 2014

Modified Files:
src/lib/libc/net: ethers.c

Log Message:
use fparseln() instead of fgetln() for consistency (this was the last fgetln()
using parser in net/.
cVS: --


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/net/ethers.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/ethers.c
diff -u src/lib/libc/net/ethers.c:1.23 src/lib/libc/net/ethers.c:1.24
--- src/lib/libc/net/ethers.c:1.23	Tue Mar 20 13:44:18 2012
+++ src/lib/libc/net/ethers.c	Thu Jun 19 11:09:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ethers.c,v 1.23 2012/03/20 17:44:18 matt Exp $	*/
+/*	$NetBSD: ethers.c,v 1.24 2014/06/19 15:09:07 christos Exp $	*/
 
 /* 
  * ethers(3N) a la Sun.
@@ -9,7 +9,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: ethers.c,v 1.23 2012/03/20 17:44:18 matt Exp $);
+__RCSID($NetBSD: ethers.c,v 1.24 2014/06/19 15:09:07 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -83,17 +83,14 @@ ether_ntohost(char *hostname, const stru
 {
 	FILE *f; 
 	char *p;
-	size_t len;
 	struct ether_addr try;
-#ifdef YP
-	char trybuf[sizeof xx:xx:xx:xx:xx:xx];
-	int trylen;
-#endif
 
 	_DIAGASSERT(hostname != NULL);
 	_DIAGASSERT(e != NULL);
 
 #ifdef YP
+	char trybuf[sizeof xx:xx:xx:xx:xx:xx];
+	int trylen;
 	trylen = snprintf(trybuf, sizeof trybuf, %x:%x:%x:%x:%x:%x, 
 	e-ether_addr_octet[0], e-ether_addr_octet[1],
 	e-ether_addr_octet[2], e-ether_addr_octet[3],
@@ -103,13 +100,14 @@ ether_ntohost(char *hostname, const stru
 	f = fopen(_PATH_ETHERS, r);
 	if (f == NULL)
 		return -1;
-	while ((p = fgetln(f, len)) != NULL) {
-		if (p[len - 1] != '\n')
-			continue;		/* skip lines w/o \n */
-		p[--len] = '\0';
+	for (p = NULL;;) {
+		free(p);
+		p = fparseln(f, NULL, NULL, NULL, FPARSELN_UNESCALL);
+		if (p == NULL)
+			break;
 #ifdef YP
 		/* A + in the file means try YP now.  */
-		if (len == 1  *p == '+') {
+		if (strcmp(p, +) == 0) {
 			char *ypbuf, *ypdom;
 			int ypbuflen;
 
@@ -118,24 +116,25 @@ ether_ntohost(char *hostname, const stru
 			if (yp_match(ypdom, ethers.byaddr, trybuf,
 			trylen, ypbuf, ypbuflen))
 continue;
-			if (ether_line(ypbuf, try, hostname) == 0) {
-free(ypbuf);
-(void)fclose(f);
-return 0;
-			}
+			ypbuflen = ether_line(ypbuf, try, hostname);
 			free(ypbuf);
+			if (ypbuflen == 0)
+goto done;
 			continue;
 		}
 #endif
 		if (ether_line(p, try, hostname) == 0 
-		memcmp(try, e, sizeof try) == 0) {
-			(void)fclose(f);
-			return 0;
-		} 
+		memcmp(try, e, sizeof try) == 0)
+			goto done;
 	}
+	free(p);
 	(void)fclose(f);
 	errno = ENOENT;
 	return -1;
+done:
+	free(p);
+	(void)fclose(f);
+	return 0;
 }
 
 int
@@ -143,7 +142,6 @@ ether_hostton(const char *hostname, stru
 {
 	FILE *f;
 	char *p;
-	size_t len;
 	char try[MAXHOSTNAMELEN + 1];
 #ifdef YP
 	int hostlen = (int)strlen(hostname);
@@ -153,16 +151,17 @@ ether_hostton(const char *hostname, stru
 	_DIAGASSERT(e != NULL);
 
 	f = fopen(_PATH_ETHERS, r);
-	if (f==NULL)
+	if (f == NULL)
 		return -1;
 
-	while ((p = fgetln(f, len)) != NULL) {
-		if (p[len - 1] != '\n')
-			continue;		/* skip lines w/o \n */
-		p[--len] = '\0';
+	for (p = NULL;;) {
+		free(p);
+		p = fparseln(f, NULL, NULL, NULL, FPARSELN_UNESCALL);
+		if (p == NULL)
+			break;
 #ifdef YP
 		/* A + in the file means try YP now.  */
-		if (len == 1  *p == '+') {
+		if (strcmp(p, +) == 0) {
 			char *ypbuf, *ypdom;
 			int ypbuflen;
 
@@ -171,23 +170,24 @@ ether_hostton(const char *hostname, stru
 			if (yp_match(ypdom, ethers.byname, hostname, hostlen,
 			ypbuf, ypbuflen))
 continue;
-			if (ether_line(ypbuf, e, try) == 0) {
-free(ypbuf);
-(void)fclose(f);
-return 0;
-			}
+			ypbuflen = ether_line(ypbuf, e, try);
 			free(ypbuf);
+			if (ypbuflen == 0)
+goto done;
 			continue;
 		}
 #endif
-		if (ether_line(p, e, try) == 0  strcmp(hostname, try) == 0) {
-			(void)fclose(f);
-			return 0;
-		}
+		if (ether_line(p, e, try) == 0  strcmp(hostname, try) == 0)
+			goto done;
 	}
+	free(p);
 	(void)fclose(f);
 	errno = ENOENT;
 	return -1;
+done:
+	free(p);
+	(void)fclose(f);
+	return 0;
 }
 
 int



CVS commit: src/lib/libc/net

2014-05-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 28 14:39:02 UTC 2014

Modified Files:
src/lib/libc/net: rcmd.c

Log Message:
CID 975111: Ignore return value from initgroups(). If we failed, then
the failure would be that we could not open the .rhosts file so we fail
closed.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/lib/libc/net/rcmd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/rcmd.c
diff -u src/lib/libc/net/rcmd.c:1.68 src/lib/libc/net/rcmd.c:1.69
--- src/lib/libc/net/rcmd.c:1.68	Sat Jul 14 11:06:26 2012
+++ src/lib/libc/net/rcmd.c	Wed May 28 10:39:02 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rcmd.c,v 1.68 2012/07/14 15:06:26 darrenr Exp $	*/
+/*	$NetBSD: rcmd.c,v 1.69 2014/05/28 14:39:02 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = @(#)rcmd.c	8.3 (Berkeley) 3/26/94;
 #else
-__RCSID($NetBSD: rcmd.c,v 1.68 2012/07/14 15:06:26 darrenr Exp $);
+__RCSID($NetBSD: rcmd.c,v 1.69 2014/05/28 14:39:02 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -698,7 +698,7 @@ iruserok_sa(const void *raddr, int rlen,
 		uid = geteuid();
 		gid = getegid();
 		(void)setegid(pwd-pw_gid);
-		initgroups(pwd-pw_name, pwd-pw_gid);
+		(void)initgroups(pwd-pw_name, pwd-pw_gid);
 		(void)seteuid(pwd-pw_uid);
 		hostf = fopen(pbuf, r);
 



CVS commit: src/lib/libc/net

2014-03-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar 17 13:24:23 UTC 2014

Modified Files:
src/lib/libc/net: sethostent.c

Log Message:
fix memory leak
XXX: pullup 6


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/net/sethostent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/sethostent.c
diff -u src/lib/libc/net/sethostent.c:1.19 src/lib/libc/net/sethostent.c:1.20
--- src/lib/libc/net/sethostent.c:1.19	Tue Aug 27 05:56:12 2013
+++ src/lib/libc/net/sethostent.c	Mon Mar 17 09:24:23 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sethostent.c,v 1.19 2013/08/27 09:56:12 christos Exp $	*/
+/*	$NetBSD: sethostent.c,v 1.20 2014/03/17 13:24:23 christos Exp $	*/
 
 /*
  * Copyright (c) 1985, 1993
@@ -35,7 +35,7 @@
 static char sccsid[] = @(#)sethostent.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: sethostent.c,v 8.5 1996/09/28 06:51:07 vixie Exp ;
 #else
-__RCSID($NetBSD: sethostent.c,v 1.19 2013/08/27 09:56:12 christos Exp $);
+__RCSID($NetBSD: sethostent.c,v 1.20 2014/03/17 13:24:23 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -223,6 +223,7 @@ _hf_gethtbyname2(const char *name, int a
 
 	if (num == 0) {
 		*info-he = HOST_NOT_FOUND;
+		free(buf);
 		return NULL;
 	}
 
@@ -247,9 +248,11 @@ _hf_gethtbyname2(const char *name, int a
 		HENT_SCOPY(hp-h_aliases[i], aliases[i], ptr, len);
 	hp-h_aliases[anum] = NULL;
 
+	free(buf);
 	return hp;
 nospc:
 	*info-he = NETDB_INTERNAL;
+	free(buf);
 	errno = ENOSPC;
 	return NULL;
 }



CVS commit: src/lib/libc/net

2014-02-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb  7 02:36:06 UTC 2014

Modified Files:
src/lib/libc/net: ip6opt.c

Log Message:
RFC 3542 (section 10.1) states that optlen should only be checked when
opt != NULL (Eitan Adler)


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/net/ip6opt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/ip6opt.c
diff -u src/lib/libc/net/ip6opt.c:1.14 src/lib/libc/net/ip6opt.c:1.15
--- src/lib/libc/net/ip6opt.c:1.14	Tue Mar 20 13:44:18 2012
+++ src/lib/libc/net/ip6opt.c	Thu Feb  6 21:36:06 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6opt.c,v 1.14 2012/03/20 17:44:18 matt Exp $	*/
+/*	$NetBSD: ip6opt.c,v 1.15 2014/02/07 02:36:06 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: ip6opt.c,v 1.14 2012/03/20 17:44:18 matt Exp $);
+__RCSID($NetBSD: ip6opt.c,v 1.15 2014/02/07 02:36:06 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -442,11 +442,8 @@ inet6_opt_init(void *extbuf, socklen_t e
 {
 	struct ip6_ext *ext = (struct ip6_ext *)extbuf;
 
-	if (extlen % 8)
-		return (-1);
-
 	if (ext) {
-		if (extlen == 0)
+		if (extlen == 0 || (extlen % 8))
 			return (-1);
 		ext-ip6e_len = (extlen  3) - 1;
 	}



CVS commit: src/lib/libc/net

2014-01-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 24 17:26:18 UTC 2014

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
CID 1163170, 1164171, resource leak
CID 1161172 double free


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.89 src/lib/libc/net/gethnamaddr.c:1.90
--- src/lib/libc/net/gethnamaddr.c:1.89	Fri Jan 17 07:39:47 2014
+++ src/lib/libc/net/gethnamaddr.c	Fri Jan 24 12:26:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.89 2014/01/17 12:39:47 drochner Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.90 2014/01/24 17:26:18 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.89 2014/01/17 12:39:47 drochner Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.90 2014/01/24 17:26:18 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -199,18 +199,14 @@ debugprintf(const char *msg, res_state r
 #define BOUNDED_INCR(x) \
 	do { \
 		cp += (x); \
-		if (cp  eom) { \
-			h_errno = NO_RECOVERY; \
-			return NULL; \
-		} \
+		if (cp  eom) \
+			goto no_recovery; \
 	} while (/*CONSTCOND*/0)
 
 #define BOUNDS_CHECK(ptr, count) \
 	do { \
-		if ((ptr) + (count)  eom) { \
-			h_errno = NO_RECOVERY; \
-			return NULL; \
-		} \
+		if ((ptr) + (count)  eom) \
+			goto no_recovery; \
 	} while (/*CONSTCOND*/0)
 
 static struct hostent *
@@ -503,6 +499,7 @@ success:
 	hent-h_aliases = (void *)bp;
 	memcpy(bp, aliases, qlen);
 	free(aliases);
+	aliases = NULL;
 
 	bp += qlen;
 	n = (int)(hap - addr_ptrs);



CVS commit: src/lib/libc/net

2014-01-17 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Fri Jan 17 12:39:47 UTC 2014

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
fix memory allocation, and an off-by-one


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.88 src/lib/libc/net/gethnamaddr.c:1.89
--- src/lib/libc/net/gethnamaddr.c:1.88	Fri Jan 17 02:08:44 2014
+++ src/lib/libc/net/gethnamaddr.c	Fri Jan 17 12:39:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.88 2014/01/17 02:08:44 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.89 2014/01/17 12:39:47 drochner Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.88 2014/01/17 02:08:44 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.89 2014/01/17 12:39:47 drochner Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -109,8 +109,8 @@ __weak_alias(gethostent,_gethostent)
 #define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
 
 #define addalias(d, s, arr, siz) do {			\
-	if (d = arr[siz - 1]) {			\
-		char **xptr = realloc(arr, siz + 10); 	\
+	if (d = arr[siz]) {\
+		char **xptr = realloc(arr, (siz + 10) * sizeof(*arr)); \
 		if (xptr == NULL)			\
 			goto nospc;			\
 		d = xptr + (d - arr);			\
@@ -121,7 +121,7 @@ __weak_alias(gethostent,_gethostent)
 } while (/*CONSTCOND*/0)
 
 #define setup(arr, siz) do {\
-	arr = malloc(siz = 10); 			\
+	arr = malloc((siz = 10) * sizeof(*arr)); 	\
 	if (arr == NULL)\
 		goto nospc;\
 } while (/*CONSTCOND*/0)



CVS commit: src/lib/libc/net

2014-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 16 20:59:21 UTC 2014

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
Remove MAXALIASES limit


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.85 src/lib/libc/net/gethnamaddr.c:1.86
--- src/lib/libc/net/gethnamaddr.c:1.85	Sat Dec 21 21:45:16 2013
+++ src/lib/libc/net/gethnamaddr.c	Thu Jan 16 15:59:21 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.85 2013/12/22 02:45:16 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.86 2014/01/16 20:59:21 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.85 2013/12/22 02:45:16 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.86 2014/01/16 20:59:21 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -108,6 +108,20 @@ __weak_alias(gethostent,_gethostent)
 #define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
 #define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
 
+#define grow(arr, siz) do {			\
+	void *xptr = realloc(arr, siz + 10); 	\
+	if (xptr == NULL)			\
+		goto nospc;			\
+	arr = xptr;\
+	siz += 10;\
+} while (/*CONSTCOND*/0)
+
+#define setup(arr, siz) do {			\
+	arr = malloc(siz = 10); 		\
+	if (arr == NULL)			\
+		goto nospc;			\
+} while (/*CONSTCOND*/0)
+
 
 static const char AskedForGot[] =
 gethostby*.getanswer: asked for \%s\, got \%s\;
@@ -209,7 +223,8 @@ getanswer(const querybuf *answer, int an
 	int haveanswer, had_error;
 	int toobig = 0;
 	char tbuf[MAXDNAME];
-	char *aliases[MAXALIASES];
+	char **aliases;
+	size_t maxaliases;
 	char *addr_ptrs[MAXADDRS];
 	const char *tname;
 	int (*name_ok)(const char *);
@@ -231,6 +246,8 @@ getanswer(const querybuf *answer, int an
 	default:
 		return NULL;	/* XXX should be abort(); */
 	}
+
+	setup(aliases, maxaliases);
 	/*
 	 * find first satisfactory answer
 	 */
@@ -290,8 +307,8 @@ getanswer(const querybuf *answer, int an
 			continue;		/* XXX - had_error++ ? */
 		}
 		if ((qtype == T_A || qtype == T_)  type == T_CNAME) {
-			if (ap = aliases[MAXALIASES-1])
-continue;
+			if (ap = aliases[maxaliases - 1])
+grow(aliases, maxaliases);
 			n = dn_expand(answer-buf, eom, cp, tbuf,
 			(int)sizeof tbuf);
 			if ((n  0) || !maybe_ok(res, tbuf, name_ok)) {
@@ -369,10 +386,11 @@ getanswer(const querybuf *answer, int an
 goto no_recovery;
 			if (!haveanswer)
 hent-h_name = bp;
-			else if (ap  aliases[MAXALIASES-1])
+			else {
+if (ap = aliases[maxaliases - 1])
+	grow(aliases, maxaliases);
 *ap++ = bp;
-			else
-n = -1;
+			}
 			if (n != -1) {
 n = (int)strlen(bp) + 1;	/* for the \0 */
 if (n = MAXHOSTNAMELEN) {
@@ -474,6 +492,7 @@ getanswer(const querybuf *answer, int an
 		goto success;
 	}
 no_recovery:
+	free(aliases);
 	*he = NO_RECOVERY;
 	return NULL;
 success:
@@ -484,6 +503,7 @@ success:
 		goto nospc;
 	hent-h_aliases = (void *)bp;
 	memcpy(bp, aliases, qlen);
+	free(aliases);
 
 	bp += qlen;
 	n = (int)(hap - addr_ptrs);
@@ -495,6 +515,7 @@ success:
 	*he = NETDB_SUCCESS;
 	return hent;
 nospc:
+	free(aliases);
 	errno = ENOSPC;
 	*he = NETDB_INTERNAL;
 	return NULL;
@@ -725,7 +746,8 @@ gethostent_r(FILE *hf, struct hostent *h
 	char *cp, **q;
 	int af, len;
 	size_t llen, anum;
-	char *aliases[MAXALIASES];
+	char **aliases;
+	size_t maxaliases;
 	struct in6_addr host_addr;
 
 	if (hf == NULL) {
@@ -733,8 +755,10 @@ gethostent_r(FILE *hf, struct hostent *h
 		errno = EINVAL;
 		return NULL;
 	}
+	setup(aliases, maxaliases);
  again:
 	if ((p = fgetln(hf, llen)) == NULL) {
+		free(aliases);
 		*he = HOST_NOT_FOUND;
 		return NULL;
 	}
@@ -755,7 +779,7 @@ gethostent_r(FILE *hf, struct hostent *h
 	} else if (inet_pton(AF_INET, p, host_addr)  0) {
 		res_state res = __res_get_state();
 		if (res == NULL)
-			return NULL;
+			goto nospc;
 		if (res-options  RES_USE_INET6) {
 			map_v4v6_address(buf, buf);
 			af = AF_INET6;
@@ -784,8 +808,8 @@ gethostent_r(FILE *hf, struct hostent *h
 			cp++;
 			continue;
 		}
-		if (q = aliases[__arraycount(aliases)])
-			goto nospc;
+		if (q = aliases[maxaliases - 1])
+			grow(aliases, maxaliases);
 		*q++ = cp;
 		if ((cp = strpbrk(cp,  \t)) != NULL)
 			*cp++ = '\0';
@@ -805,8 +829,10 @@ gethostent_r(FILE *hf, struct hostent *h
 	hent-h_aliases[anum] = NULL;
 
 	*he = NETDB_SUCCESS;
+	free(aliases);
 	return hent;
 nospc:
+	free(aliases);
 	errno = ENOSPC;
 	*he = NETDB_INTERNAL;
 	return NULL;
@@ -1080,7 +1106,8 @@ static struct hostent *
 _yp_hostent(char *line, int af, struct getnamaddr *info)
 {
 	struct in6_addr 

CVS commit: src/lib/libc/net

2014-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 17 02:03:44 UTC 2014

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
Move more code into the macro, and fix the bug where realloc would cause
a dangling pointer and memory corruption.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.86 src/lib/libc/net/gethnamaddr.c:1.87
--- src/lib/libc/net/gethnamaddr.c:1.86	Thu Jan 16 15:59:21 2014
+++ src/lib/libc/net/gethnamaddr.c	Thu Jan 16 21:03:44 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.86 2014/01/16 20:59:21 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.87 2014/01/17 02:03:44 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.86 2014/01/16 20:59:21 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.87 2014/01/17 02:03:44 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -108,18 +108,22 @@ __weak_alias(gethostent,_gethostent)
 #define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
 #define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
 
-#define grow(arr, siz) do {			\
-	void *xptr = realloc(arr, siz + 10); 	\
-	if (xptr == NULL)			\
-		goto nospc;			\
-	arr = xptr;\
-	siz += 10;\
+#define addalias(d, s, arr, siz) do {			\
+	if (d = arr[siz - 1]) {			\
+		char **xptr = realloc(arr, siz + 10); 	\
+		if (xptr == NULL)			\
+			goto nospc;			\
+		d = xptr + (d - arr);			\
+		arr = xptr;\
+		siz += 10;\
+	}		\
+	*d++ = s;	\
 } while (/*CONSTCOND*/0)
 
-#define setup(arr, siz) do {			\
-	arr = malloc(siz = 10); 		\
-	if (arr == NULL)			\
-		goto nospc;			\
+#define setup(arr, siz) do {\
+	arr = malloc(siz = 10); 			\
+	if (arr == NULL)\
+		goto nospc;\
 } while (/*CONSTCOND*/0)
 
 
@@ -307,8 +311,6 @@ getanswer(const querybuf *answer, int an
 			continue;		/* XXX - had_error++ ? */
 		}
 		if ((qtype == T_A || qtype == T_)  type == T_CNAME) {
-			if (ap = aliases[maxaliases - 1])
-grow(aliases, maxaliases);
 			n = dn_expand(answer-buf, eom, cp, tbuf,
 			(int)sizeof tbuf);
 			if ((n  0) || !maybe_ok(res, tbuf, name_ok)) {
@@ -319,7 +321,7 @@ getanswer(const querybuf *answer, int an
 			if (cp != erdata)
 goto no_recovery;
 			/* Store alias. */
-			*ap++ = bp;
+			addalias(ap, bp, aliases, maxaliases);
 			n = (int)strlen(bp) + 1;	/* for the \0 */
 			if (n = MAXHOSTNAMELEN) {
 had_error++;
@@ -386,11 +388,8 @@ getanswer(const querybuf *answer, int an
 goto no_recovery;
 			if (!haveanswer)
 hent-h_name = bp;
-			else {
-if (ap = aliases[maxaliases - 1])
-	grow(aliases, maxaliases);
-*ap++ = bp;
-			}
+			else
+addalias(ap, bp, aliases, maxaliases);
 			if (n != -1) {
 n = (int)strlen(bp) + 1;	/* for the \0 */
 if (n = MAXHOSTNAMELEN) {
@@ -808,8 +807,7 @@ gethostent_r(FILE *hf, struct hostent *h
 			cp++;
 			continue;
 		}
-		if (q = aliases[maxaliases - 1])
-			grow(aliases, maxaliases);
+		addalias(q, cp, aliases, maxaliases);
 		*q++ = cp;
 		if ((cp = strpbrk(cp,  \t)) != NULL)
 			*cp++ = '\0';
@@ -1173,11 +1171,8 @@ nextline:
 		hp-h_name = p;
 	else if (strcmp(hp-h_name, p) == 0)
 		;
-	else {
-		if (q = aliases[maxaliases - 1])
-			grow(aliases, maxaliases);
-		*q++ = p;
-	}
+	else
+		addalias(q, p, aliases, maxaliases);
 	p = cp;
 	if (more)
 		goto nextline;
@@ -1191,8 +1186,7 @@ nextline:
 			cp++;
 			goto nextline;
 		}
-		if (q = aliases[maxaliases - 1])
-			grow(aliases, maxaliases);
+		addalias(q, cp, aliases, maxaliases);
 		*q++ = cp;
 		cp = strpbrk(cp,  \t);
 		if (cp != NULL)



CVS commit: src/lib/libc/net

2014-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 17 02:08:44 UTC 2014

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
the addition is handled in the alias.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.87 src/lib/libc/net/gethnamaddr.c:1.88
--- src/lib/libc/net/gethnamaddr.c:1.87	Thu Jan 16 21:03:44 2014
+++ src/lib/libc/net/gethnamaddr.c	Thu Jan 16 21:08:44 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.87 2014/01/17 02:03:44 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.88 2014/01/17 02:08:44 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.87 2014/01/17 02:03:44 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.88 2014/01/17 02:08:44 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -808,7 +808,6 @@ gethostent_r(FILE *hf, struct hostent *h
 			continue;
 		}
 		addalias(q, cp, aliases, maxaliases);
-		*q++ = cp;
 		if ((cp = strpbrk(cp,  \t)) != NULL)
 			*cp++ = '\0';
 	}
@@ -1187,7 +1186,6 @@ nextline:
 			goto nextline;
 		}
 		addalias(q, cp, aliases, maxaliases);
-		*q++ = cp;
 		cp = strpbrk(cp,  \t);
 		if (cp != NULL)
 			*cp++ = '\0';



CVS commit: src/lib/libc/net

2014-01-04 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Jan  4 15:37:26 UTC 2014

Modified Files:
src/lib/libc/net: inet6_opt_init.3

Log Message:
Sort sections. Punctuation formatting nits.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/net/inet6_opt_init.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/inet6_opt_init.3
diff -u src/lib/libc/net/inet6_opt_init.3:1.1 src/lib/libc/net/inet6_opt_init.3:1.2
--- src/lib/libc/net/inet6_opt_init.3:1.1	Fri May  5 00:03:21 2006
+++ src/lib/libc/net/inet6_opt_init.3	Sat Jan  4 15:37:26 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: inet6_opt_init.3,v 1.1 2006/05/05 00:03:21 rpaulo Exp $
+.\	$NetBSD: inet6_opt_init.3,v 1.2 2014/01/04 15:37:26 wiz Exp $
 .\	$KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 itojun Exp $
 .\
 .\ Copyright (C) 2004 WIDE Project.
@@ -237,7 +237,7 @@ The option is returned in the arguments
 .Fa typep , lenp ,
 and
 .Fa databufp .
-.Fa typep, lenp,
+.Fa typep , lenp ,
 and
 .Fa databufp
 point to the 8-bit option type, the 8-bit option length and the option
@@ -299,11 +299,6 @@ by calculating
 which can be used when extracting option content with multiple fields.
 Robust receivers must verify alignment before calling this function.
 .\
-.Sh DIAGNOSTICS
-All the functions return
-\-1
-on an error.
-.\
 .Sh EXAMPLES
 RFC3542 gives comprehensive examples in Section 23.
 .Pp
@@ -311,6 +306,11 @@ KAME also provides examples in the
 .Pa advapitest
 directory of its kit.
 .\
+.Sh DIAGNOSTICS
+All the functions return
+\-1
+on an error.
+.\
 .Sh SEE ALSO
 .Rs
 .%A W. Stevens
@@ -328,10 +328,10 @@ directory of its kit.
 .%N RFC2460
 .%D December 1998
 .Re
-.Sh HISTORY
-The implementation first appeared in KAME advanced networking kit.
 .Sh STANDARDS
 The functions are documented in
 .Dq Advanced Sockets API for IPv6
 .Pq RFC3542 .
 .\
+.Sh HISTORY
+The implementation first appeared in KAME advanced networking kit.



CVS commit: src/lib/libc/net

2014-01-04 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Jan  4 15:37:46 UTC 2014

Modified Files:
src/lib/libc/net: inet6_rth_space.3

Log Message:
Sort sections. Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/net/inet6_rth_space.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/inet6_rth_space.3
diff -u src/lib/libc/net/inet6_rth_space.3:1.1 src/lib/libc/net/inet6_rth_space.3:1.2
--- src/lib/libc/net/inet6_rth_space.3:1.1	Fri May  5 00:03:21 2006
+++ src/lib/libc/net/inet6_rth_space.3	Sat Jan  4 15:37:46 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: inet6_rth_space.3,v 1.1 2006/05/05 00:03:21 rpaulo Exp $
+.\	$NetBSD: inet6_rth_space.3,v 1.2 2014/01/04 15:37:46 wiz Exp $
 .\	$KAME: inet6_rth_space.3,v 1.7 2005/01/05 03:00:44 itojun Exp $
 .\
 .\ Copyright (C) 2004 WIDE Project.
@@ -60,7 +60,7 @@
 The IPv6 Advanced API, RFC 3542, defines the functions that an
 application calls to build and examine IPv6 Routing headers.
 Routing headers are used to perform source routing in IPv6 networks.
-The RFC uses the word 
+The RFC uses the word
 .Dq segments
 to describe addresses and that is the term used here as well.
 All of the functions are defined in the
@@ -81,14 +81,14 @@ The
 .Fn inet6_rth_space
 function returns the number of bytes required to hold a Routing Header
 of the type, specified in the
-.Fa type 
+.Fa type
 argument and containing the number of addresses specified in the
 .Fa segments
 argumment.
-When the type is 
+When the type is
 .Dv IPV6_RTHDR_TYPE_0
 the number of segments must be from 0 through 127.
-Routing headers of type 
+Routing headers of type
 .Dv IPV6_RTHDR_TYPE_2
 contain only one segment, and are only used with Mobile IPv6.
 The return value from this function is the number of bytes required to
@@ -165,20 +165,25 @@ The
 .Fa index
 is the location in the routing header from which the application wants
 to retrieve an address.
-The 
-.Fa index 
+The
+.Fa index
 parameter must have a value between 0 and one less than the number of
 segments present in the routing header.
 The
-.Fn inet6_rth_segments 
+.Fn inet6_rth_segments
 function, described in the last section, should be used to determine
 the total number of segments in the routing header.
 The
 .Fn inet6_rth_getaddr
-function returns a pointer to an IPv6 address on success or 
+function returns a pointer to an IPv6 address on success or
 .Dv NULL
 when an error has occurred.
 .\
+.Sh EXAMPLES
+RFC 3542 gives extensive examples in Section 21, Appendix B.
+.Pp
+KAME also provides examples in the advapitest directory of its kit.
+.\
 .Sh DIAGNOSTICS
 The
 .Fn inet6_rth_space
@@ -197,11 +202,6 @@ and
 .Fn inet6_rth_reverse
 functions return 0 on success, or \-1 upon an error.
 .\
-.Sh EXAMPLES
-RFC 3542 gives extensive examples in Section 21, Appendix B.
-.Pp
-KAME also provides examples in the advapitest directory of its kit.
-.\
 .Sh SEE ALSO
 .Rs
 .%A W. Stevens



CVS commit: src/lib/libc/net

2013-12-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 22 02:40:48 UTC 2013

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
this is supposed to be re-entrant, call don't call __hostalias that uses
a static buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.105 src/lib/libc/net/getaddrinfo.c:1.106
--- src/lib/libc/net/getaddrinfo.c:1.105	Mon May 13 13:54:55 2013
+++ src/lib/libc/net/getaddrinfo.c	Sat Dec 21 21:40:48 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.105 2013/05/13 17:54:55 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.106 2013/12/22 02:40:48 christos 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.105 2013/05/13 17:54:55 christos Exp $);
+__RCSID($NetBSD: getaddrinfo.c,v 1.106 2013/12/22 02:40:48 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -2121,6 +2121,7 @@ res_searchN(const char *name, struct res
 	const char *cp, * const *domain;
 	HEADER *hp;
 	u_int dots;
+	char buf[MAXHOSTNAMELEN];
 	int trailing_dot, ret, saved_herrno;
 	int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
 
@@ -2141,7 +2142,7 @@ res_searchN(const char *name, struct res
 	/*
 	 * if there aren't any dots, it could be a user-level alias
 	 */
-	if (!dots  (cp = __hostalias(name)) != NULL) {
+	if (!dots  (cp = res_hostalias(res, name, buf, sizeof(buf))) != NULL) {
 		ret = res_queryN(cp, target, res);
 		return ret;
 	}



CVS commit: src/lib/libc/net

2013-12-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 22 02:45:16 UTC 2013

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
- don't clobber hp in the RES_USE_INET6 case
- increment naddrs in the yp case
- don't use __hostalias(), it is not thread-safe.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.84 src/lib/libc/net/gethnamaddr.c:1.85
--- src/lib/libc/net/gethnamaddr.c:1.84	Tue Aug 27 05:56:12 2013
+++ src/lib/libc/net/gethnamaddr.c	Sat Dec 21 21:45:16 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.84 2013/08/27 09:56:12 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.85 2013/12/22 02:45:16 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.84 2013/08/27 09:56:12 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.85 2013/12/22 02:45:16 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -514,11 +514,11 @@ gethostbyname_r(const char *name, struct
 	_DIAGASSERT(name != NULL);
 
 	if (res-options  RES_USE_INET6) {
-		hp = gethostbyname_internal(name, AF_INET6, res, hp, buf,
-		buflen, he);
-		if (hp) {
+		struct hostent *nhp = gethostbyname_internal(name, AF_INET6,
+		res, hp, buf, buflen, he);
+		if (nhp) {
 			__res_put_state(res);
-			return hp;
+			return nhp;
 		}
 	}
 	hp = gethostbyname_internal(name, AF_INET, res, hp, buf, buflen, he);
@@ -547,6 +547,7 @@ gethostbyname_internal(const char *name,
 {
 	const char *cp;
 	struct getnamaddr info;
+	char hbuf[MAXHOSTNAMELEN];
 	size_t size;
 	static const ns_dtab dtab[] = {
 		NS_FILES_CB(_hf_gethtbyname, NULL)
@@ -580,7 +581,8 @@ gethostbyname_internal(const char *name,
 	 * this is also done in res_nquery() since we are not the only
 	 * function that looks up host names.
 	 */
-	if (!strchr(name, '.')  (cp = __hostalias(name)))
+	if (!strchr(name, '.')  (cp = res_hostalias(res, name,
+	hbuf, sizeof(hbuf
 		name = cp;
 
 	/*
@@ -1128,6 +1130,7 @@ nextline:
 		}
 		goto done;
 	}
+	naddrs++;
 
 	while (*cp == ' ' || *cp == '\t')
 		cp++;



CVS commit: src/lib/libc/net

2013-11-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov 13 23:58:51 UTC 2013

Modified Files:
src/lib/libc/net: resolver.3

Log Message:
PR/48379: mention kqueue functionality


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.26 src/lib/libc/net/resolver.3:1.27
--- src/lib/libc/net/resolver.3:1.26	Wed May  8 14:18:32 2013
+++ src/lib/libc/net/resolver.3	Wed Nov 13 18:58:51 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: resolver.3,v 1.26 2013/05/08 18:18:32 wiz Exp $
+.\	$NetBSD: resolver.3,v 1.27 2013/11/13 23:58:51 christos Exp $
 .\ Copyright (c) 2004 by Internet Systems Consortium, Inc. (ISC)
 .\
 .\ Permission to use, copy, modify, and distribute this software for any
@@ -33,7 +33,7 @@
 .\	@(#)resolver.3	6.5 (Berkeley) 6/23/90
 .\	Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
 .\
-.Dd May 8, 2013
+.Dd November 13, 2013
 .Dt RESOLVER 3
 .Os
 .Sh NAME
@@ -364,6 +364,26 @@ environment variable is explained in
 Initialization normally occurs on the first call
 to one of the other resolver routines.
 .Pp
+In
+.Nx
+the initialization code also sets up a
+.Xr kqueue 2
+and creates a
+.Xr kevent 2
+watching a file descriptor that points to the resolver file.
+Every resolver function, calls the internal function
+.Fn __res_check
+which checks for a new
+.Xr kevent 2
+related to the
+.Xr resolv.conf 5
+file, and reloads the file if necessary.
+This does not work if the file is accessed through a symlink and the symlink
+changes to point to a different file.
+To fix the symlink issue one could add a system call per resolver call to
+get the current time, and reload every so often.
+This is not done currently, but it is under consideration.
+.Pp
 The memory referred to by
 .Ft statp
 must be set to all zeros prior to the first call to



CVS commit: src/lib/libc/net

2013-11-13 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Nov 14 00:13:41 UTC 2013

Modified Files:
src/lib/libc/net: resolver.3

Log Message:
Remove annoying comma and sort SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.27 src/lib/libc/net/resolver.3:1.28
--- src/lib/libc/net/resolver.3:1.27	Wed Nov 13 23:58:51 2013
+++ src/lib/libc/net/resolver.3	Thu Nov 14 00:13:41 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: resolver.3,v 1.27 2013/11/13 23:58:51 christos Exp $
+.\	$NetBSD: resolver.3,v 1.28 2013/11/14 00:13:41 wiz Exp $
 .\ Copyright (c) 2004 by Internet Systems Consortium, Inc. (ISC)
 .\
 .\ Permission to use, copy, modify, and distribute this software for any
@@ -371,7 +371,7 @@ the initialization code also sets up a
 and creates a
 .Xr kevent 2
 watching a file descriptor that points to the resolver file.
-Every resolver function, calls the internal function
+Every resolver function calls the internal function
 .Fn __res_check
 which checks for a new
 .Xr kevent 2
@@ -733,11 +733,11 @@ The configuration file, see
 .El
 .Sh SEE ALSO
 .Xr getaddrinfo 3 ,
-.Xr getnameinfo 3 ,
 .Xr gethostbyaddr 3 ,
 .Xr gethostbyname 3 ,
-.Xr hostname 7 ,
+.Xr getnameinfo 3 ,
 .Xr resolv.conf 5 ,
+.Xr hostname 7 ,
 .Xr named 8
 .Pp
 .%T RFC 974 ,



CVS commit: src/lib/libc/net

2013-10-30 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Oct 31 00:30:14 UTC 2013

Modified Files:
src/lib/libc/net: inet6_getscopeid.3

Log Message:
Try improving the description.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/net/inet6_getscopeid.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/inet6_getscopeid.3
diff -u src/lib/libc/net/inet6_getscopeid.3:1.2 src/lib/libc/net/inet6_getscopeid.3:1.3
--- src/lib/libc/net/inet6_getscopeid.3:1.2	Sat Oct 19 23:34:48 2013
+++ src/lib/libc/net/inet6_getscopeid.3	Thu Oct 31 00:30:14 2013
@@ -1,6 +1,6 @@
-.\	$NetBSD: inet6_getscopeid.3,v 1.2 2013/10/19 23:34:48 wiz Exp $
+.\	$NetBSD: inet6_getscopeid.3,v 1.3 2013/10/31 00:30:14 wiz Exp $
 .\-
-.\ Copyright (c) 2003 The NetBSD Foundation, Inc.
+.\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
 .\
 .\ This code is derived from software contributed to The NetBSD Foundation
@@ -28,7 +28,7 @@
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
 .\
-.Dd October 19, 2013
+.Dd October 31, 2013
 .Dt INET6_GETSCOPEID 3
 .Os
 .\
@@ -48,6 +48,9 @@
 These functions implement a KAME-specific extension that encodes and
 decodes the scope id inside in the 3rd and 4th byte of the address,
 for link-local, site-local, and multicast-link-local addresses.
+The scope id helps deciding which interface is used for packets of
+that type.
+.Pp
 Typically those two bytes are
 .Dv 0
 for these kinds of addresses.
@@ -55,7 +58,11 @@ The scope id is stored in network byte o
 .Pp
 The
 .Fn inet6_getscopeid
-function retrieves the scope id from the 3rd and the 4th address bytes,
+function retrieves the scope id from the 3rd and the 4th address bytes
+(from the
+.Va sin6_addr
+member of
+.Fa sin6 ) ,
 and sets the
 .Ft sin6_scope_id
 from them.
@@ -65,19 +72,28 @@ The
 .Fn inet6putscopeid
 function stores the scope id found in
 .Ft sin6_scope_id
-into the 3rd and 4th byte of the address.
+into the 3rd and 4th byte of the address
+(into the
+.Va sin6_addr
+member of
+.Fa sin6 ) .
 It then clears the
-.Ft sin6_scope_id .
+.Va sin6_scope_id
+member of
+.Fa sin6 .
 .Pp
 The
 .Fa flags
 argument controls for which addresses this action is performed.
 It
 can be a combination of:
-.Bl -tag -width INET6_IS_ADDR_MC_LINKLOCAL
-.It Dv INET6_IS_ADDR_LINKLOCAL
-.It Dv INET6_IS_ADDR_MC_LINKLOCAL
-.It Dv INET6_IS_ADDR_SITELOCAL
+.Bl -bullet
+.It
+.Dv INET6_IS_ADDR_LINKLOCAL
+.It
+.Dv INET6_IS_ADDR_MC_LINKLOCAL
+.It
+.Dv INET6_IS_ADDR_SITELOCAL
 .El
 .Sh HISTORY
 These functions first appeared in



CVS commit: src/lib/libc/net

2013-10-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 19 15:47:02 UTC 2013

Modified Files:
src/lib/libc/net: inet6_scopeid.c

Log Message:
use new constants


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/net/inet6_scopeid.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/inet6_scopeid.c
diff -u src/lib/libc/net/inet6_scopeid.c:1.1 src/lib/libc/net/inet6_scopeid.c:1.2
--- src/lib/libc/net/inet6_scopeid.c:1.1	Fri Oct 18 20:08:34 2013
+++ src/lib/libc/net/inet6_scopeid.c	Sat Oct 19 11:47:02 2013
@@ -34,7 +34,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: inet6_scopeid.c,v 1.1 2013/10/19 00:08:34 christos Exp $);
+__RCSID($NetBSD: inet6_scopeid.c,v 1.2 2013/10/19 15:47:02 christos Exp $);
 
 #include sys/endian.h
 #include string.h
@@ -47,8 +47,12 @@ void
 inet6_getscopeid(struct sockaddr_in6 *sin6, int flags)
 {
 #if defined(__KAME__)
-	if ((IN6_IS_ADDR_LINKLOCAL(sin6-sin6_addr)  (flags  1)) ||
-	(IN6_IS_ADDR_MC_LINKLOCAL(sin6-sin6_addr)  (flags  2))) {
+	if ((IN6_IS_ADDR_LINKLOCAL(sin6-sin6_addr) 
+	(flags  INET6_IS_ADDR_LINKLOCAL)) ||
+	(IN6_IS_ADDR_MC_LINKLOCAL(sin6-sin6_addr) 
+	(flags  INET6_IS_ADDR_MC_LINKLOCAL)) ||
+	(IN6_IS_ADDR_SITELOCAL(sin6-sin6_addr) 
+	(flags  INET6_IS_ADDR_SITELOCAL))) {
 		uint16_t scope;
 		memcpy(scope, sin6-sin6_addr.s6_addr[2], sizeof(scope));
 		sin6-sin6_scope_id = ntohs(scope);
@@ -61,8 +65,12 @@ void
 inet6_putscopeid(struct sockaddr_in6 *sin6, int flags)
 {
 #if defined(__KAME__)
-	if ((IN6_IS_ADDR_LINKLOCAL(sin6-sin6_addr)  (flags  1)) ||
-	(IN6_IS_ADDR_MC_LINKLOCAL(sin6-sin6_addr)  (flags  2))) {
+	if ((IN6_IS_ADDR_LINKLOCAL(sin6-sin6_addr) 
+	(flags  INET6_IS_ADDR_LINKLOCAL)) ||
+	(IN6_IS_ADDR_MC_LINKLOCAL(sin6-sin6_addr) 
+	(flags  INET6_IS_ADDR_MC_LINKLOCAL)) ||
+	(IN6_IS_ADDR_SITELOCAL(sin6-sin6_addr) 
+	(flags  INET6_IS_ADDR_SITELOCAL))) {
 	uint16_t scope = htons(sin6-sin6_scope_id);
 		memcpy(sin6-sin6_addr.s6_addr[2], scope, sizeof(scope));
 		sin6-sin6_scope_id = 0;



CVS commit: src/lib/libc/net

2013-10-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 19 19:56:56 UTC 2013

Modified Files:
src/lib/libc/net: Makefile.inc
Added Files:
src/lib/libc/net: inet6_getscopeid.3

Log Message:
document the scopeid functions


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/lib/libc/net/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/net/inet6_getscopeid.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/Makefile.inc
diff -u src/lib/libc/net/Makefile.inc:1.84 src/lib/libc/net/Makefile.inc:1.85
--- src/lib/libc/net/Makefile.inc:1.84	Fri Oct 18 20:08:34 2013
+++ src/lib/libc/net/Makefile.inc	Sat Oct 19 15:56:56 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.84 2013/10/19 00:08:34 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.85 2013/10/19 19:56:56 christos Exp $
 #	@(#)Makefile.inc	8.2 (Berkeley) 9/5/93
 
 # net sources
@@ -120,12 +120,13 @@ MLINKS+=resolver.3 dn_comp.3 \
 # IPv6
 MAN+=	gai_strerror.3 getaddrinfo.3 getnameinfo.3 if_indextoname.3 \
 	inet6_option_space.3 inet6_rthdr_space.3 \
-	inet6_opt_init.3 inet6_rth_space.3
+	inet6_opt_init.3 inet6_rth_space.3 inet6_getscopeid.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 \
+	inet6_getscopeid.3 inet6_putscopeid.3 \
 	inet6_option_space.3 inet6_option_init.3 \
 	inet6_option_space.3 inet6_option_append.3 \
 	inet6_option_space.3 inet6_option_alloc.3 \

Added files:

Index: src/lib/libc/net/inet6_getscopeid.3
diff -u /dev/null src/lib/libc/net/inet6_getscopeid.3:1.1
--- /dev/null	Sat Oct 19 15:56:56 2013
+++ src/lib/libc/net/inet6_getscopeid.3	Sat Oct 19 15:56:56 2013
@@ -0,0 +1,83 @@
+.\	$NetBSD: inet6_getscopeid.3,v 1.1 2013/10/19 19:56:56 christos Exp $
+.\-
+.\ Copyright (c) 2003 The NetBSD Foundation, Inc.
+.\ All rights reserved.
+.\
+.\ This code is derived from software contributed to The NetBSD Foundation
+.\ by Christos Zoulas.
+.\
+.\ Redistribution and use in source and binary forms, with or without
+.\ modification, are permitted provided that the following conditions
+.\ are met:
+.\ 1. Redistributions of source code must retain the above copyright
+.\notice, this list of conditions and the following disclaimer.
+.\ 2. Redistributions in binary form must reproduce the above copyright
+.\notice, this list of conditions and the following disclaimer in the
+.\documentation and/or other materials provided with the distribution.
+.\
+.\ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\ PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\ POSSIBILITY OF SUCH DAMAGE.
+.\
+.\
+.Dd October 19, 2013
+.Dt INET6_GETSCOPEID 3
+.Os
+.\
+.Sh NAME
+.Nm inet6_getscopeid ,
+.Nm inet6_putscopeid 
+.Nd IPv6 scope id encoding and decoding functions
+.\
+.Sh SYNOPSIS
+.In netinet/in.h
+.Ft void
+.Fn inet6_getscopeid struct sockaddr_in6 *sin6 int flags
+.Ft void
+.Fn inet6_putscopeid struct sockaddr_in6 *sin6 int flags
+.\
+.Sh DESCRIPTION
+These functions implement a KAME-specific extension that encodes and
+decodes the scope id inside in the 3rd and 4th byte of the address,
+for link-local, site-local, and multicast-link-local addresses.
+Typically those two bytes are
+.Dv 0
+for these kinds of addresses.
+The scope id is stored in network byte order.
+.Pp
+The
+.Fn inet6_getscopeid
+function retrieves the scope id from the 3rd and the 4th address bytes,
+and sets the
+.Ft sin6_scope_id
+from them.
+It then clears the two address bytes.
+.Pp
+The
+.Fn inet6putscopeid
+function stores the scope id found in
+.Ft sin6_scope_id
+into the 3rd and 4th byte of the address.
+It then clears the
+.Ft sin6_scope_id
+.Pp
+The
+.Fa flags
+argument controls for which addresses this action is performed. It
+can be a combination of:
+.Bl -tag -width INET6_IS_ADDR_MC_LINKLOCAL
+.It Dv INET6_IS_ADDR_LINKLOCAL
+.It Dv INET6_IS_ADDR_MC_LINKLOCAL
+.It Dv INET6_IS_ADDR_SITELOCAL
+.El
+.Sh HISTORY
+These functions first appeared in
+.Nx 7 .



CVS commit: src/lib/libc/net

2013-10-19 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Oct 19 23:34:48 UTC 2013

Modified Files:
src/lib/libc/net: inet6_getscopeid.3

Log Message:
Minor fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/net/inet6_getscopeid.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/inet6_getscopeid.3
diff -u src/lib/libc/net/inet6_getscopeid.3:1.1 src/lib/libc/net/inet6_getscopeid.3:1.2
--- src/lib/libc/net/inet6_getscopeid.3:1.1	Sat Oct 19 19:56:56 2013
+++ src/lib/libc/net/inet6_getscopeid.3	Sat Oct 19 23:34:48 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: inet6_getscopeid.3,v 1.1 2013/10/19 19:56:56 christos Exp $
+.\	$NetBSD: inet6_getscopeid.3,v 1.2 2013/10/19 23:34:48 wiz Exp $
 .\-
 .\ Copyright (c) 2003 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -34,7 +34,7 @@
 .\
 .Sh NAME
 .Nm inet6_getscopeid ,
-.Nm inet6_putscopeid 
+.Nm inet6_putscopeid
 .Nd IPv6 scope id encoding and decoding functions
 .\
 .Sh SYNOPSIS
@@ -67,11 +67,12 @@ function stores the scope id found in
 .Ft sin6_scope_id
 into the 3rd and 4th byte of the address.
 It then clears the
-.Ft sin6_scope_id
+.Ft sin6_scope_id .
 .Pp
 The
 .Fa flags
-argument controls for which addresses this action is performed. It
+argument controls for which addresses this action is performed.
+It
 can be a combination of:
 .Bl -tag -width INET6_IS_ADDR_MC_LINKLOCAL
 .It Dv INET6_IS_ADDR_LINKLOCAL
@@ -80,4 +81,4 @@ can be a combination of:
 .El
 .Sh HISTORY
 These functions first appeared in
-.Nx 7 .
+.Nx 7.0 .



CVS commit: src/lib/libc/net

2013-10-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 19 00:08:34 UTC 2013

Modified Files:
src/lib/libc/net: Makefile.inc
Added Files:
src/lib/libc/net: inet6_scopeid.c

Log Message:
add inet6_scopeid


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/lib/libc/net/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/net/inet6_scopeid.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/Makefile.inc
diff -u src/lib/libc/net/Makefile.inc:1.83 src/lib/libc/net/Makefile.inc:1.84
--- src/lib/libc/net/Makefile.inc:1.83	Fri Mar  1 13:25:16 2013
+++ src/lib/libc/net/Makefile.inc	Fri Oct 18 20:08:34 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.83 2013/03/01 18:25:16 joerg Exp $
+#	$NetBSD: Makefile.inc,v 1.84 2013/10/19 00:08:34 christos Exp $
 #	@(#)Makefile.inc	8.2 (Berkeley) 9/5/93
 
 # net sources
@@ -24,7 +24,7 @@ COPTS.hesiod.c+=	${${ACTIVE_CC} == gcc
 
 SRCS+=	getaddrinfo.c getnameinfo.c
 .if (${USE_INET6} != no)
-SRCS+=	ip6opt.c rthdr.c vars6.c
+SRCS+=	ip6opt.c rthdr.c vars6.c inet6_scopeid.c
 .endif
 SRCS+=	if_indextoname.c if_nameindex.c if_nametoindex.c
 

Added files:

Index: src/lib/libc/net/inet6_scopeid.c
diff -u /dev/null src/lib/libc/net/inet6_scopeid.c:1.1
--- /dev/null	Fri Oct 18 20:08:34 2013
+++ src/lib/libc/net/inet6_scopeid.c	Fri Oct 18 20:08:34 2013
@@ -0,0 +1,71 @@
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *must display the following acknowledgement:
+ *This product includes software developed by the NetBSD
+ *Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include sys/cdefs.h
+__RCSID($NetBSD: inet6_scopeid.c,v 1.1 2013/10/19 00:08:34 christos Exp $);
+
+#include sys/endian.h
+#include string.h
+#include stdint.h
+#include netinet/in.h
+#include netinet6/in6.h
+
+/* KAME idiosyncrasy */
+void
+inet6_getscopeid(struct sockaddr_in6 *sin6, int flags)
+{
+#if defined(__KAME__)
+	if ((IN6_IS_ADDR_LINKLOCAL(sin6-sin6_addr)  (flags  1)) ||
+	(IN6_IS_ADDR_MC_LINKLOCAL(sin6-sin6_addr)  (flags  2))) {
+		uint16_t scope;
+		memcpy(scope, sin6-sin6_addr.s6_addr[2], sizeof(scope));
+		sin6-sin6_scope_id = ntohs(scope);
+		sin6-sin6_addr.s6_addr[2] = sin6-sin6_addr.s6_addr[3] = 0;
+	}
+#endif
+}
+
+void
+inet6_putscopeid(struct sockaddr_in6 *sin6, int flags)
+{
+#if defined(__KAME__)
+	if ((IN6_IS_ADDR_LINKLOCAL(sin6-sin6_addr)  (flags  1)) ||
+	(IN6_IS_ADDR_MC_LINKLOCAL(sin6-sin6_addr)  (flags  2))) {
+	uint16_t scope = htons(sin6-sin6_scope_id);
+		memcpy(sin6-sin6_addr.s6_addr[2], scope, sizeof(scope));
+		sin6-sin6_scope_id = 0;
+	}
+#endif
+}



CVS commit: src/lib/libc/net

2013-08-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 27 09:56:12 UTC 2013

Modified Files:
src/lib/libc/net: gethnamaddr.c hostent.h sethostent.c

Log Message:
move the host file getbyname and getbyaddr functions to sethostent.c so
that they are in a separate file from the dns ones in order for libhack
to use them.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/lib/libc/net/gethnamaddr.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/net/hostent.h
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/net/sethostent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.83 src/lib/libc/net/gethnamaddr.c:1.84
--- src/lib/libc/net/gethnamaddr.c:1.83	Thu Aug 22 06:04:28 2013
+++ src/lib/libc/net/gethnamaddr.c	Tue Aug 27 05:56:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.83 2013/08/22 10:04:28 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.84 2013/08/27 09:56:12 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.83 2013/08/22 10:04:28 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.84 2013/08/27 09:56:12 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -109,9 +109,6 @@ __weak_alias(gethostent,_gethostent)
 #define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
 
 
-#define	MAXALIASES	35
-#define	MAXADDRS	35
-
 static const char AskedForGot[] =
 gethostby*.getanswer: asked for \%s\, got \%s\;
 
@@ -146,8 +143,6 @@ void dns_service(void);
 #undef dn_skipname
 int dn_skipname(const u_char *, const u_char *);
 
-static struct hostent *_hf_gethtbyname2(const char *, int, struct getnamaddr *);
-
 #ifdef YP
 static struct hostent *_yp_hostent(char *, int, struct getnamaddr *);
 #endif
@@ -162,33 +157,6 @@ static const ns_src default_dns_files[] 
 };
 
 
-#define ARRAY(dst, anum, ptr, len) \
-	do { \
-		size_t _len = (anum + 1) * sizeof(*dst); \
-		if (_len  len) \
-			goto nospc; \
-		dst = (void *)ptr; \
-		ptr += _len; \
-		len -= _len; \
-	} while (/*CONSTCOND*/0)
-
-#define COPY(dst, src, slen, ptr, len) \
-	do { \
-		if ((size_t)slen  len) \
-			goto nospc; \
-		memcpy(ptr, src, (size_t)slen); \
-		dst = ptr; \
-		ptr += slen; \
-		len -= slen; \
-	} while (/* CONSTCOND */0)
-
-#define SCOPY(dst, src, ptr, len) \
-	do { \
-		size_t _len = strlen(src) + 1; \
-		COPY(dst, src, _len, ptr, len); \
-	} while (/* CONSTCOND */0)
-
-
 #ifdef DEBUG
 static void
 debugprintf(const char *msg, res_state res, ...)
@@ -666,8 +634,8 @@ nospc:
 	errno = ENOSPC;
 	return NULL;
 fake:
-	ARRAY(hp-h_addr_list, 1, buf, buflen);
-	ARRAY(hp-h_aliases, 0, buf, buflen);
+	HENT_ARRAY(hp-h_addr_list, 1, buf, buflen);
+	HENT_ARRAY(hp-h_aliases, 0, buf, buflen);
 
 	hp-h_aliases[0] = NULL;
 	if (size  buflen)
@@ -681,7 +649,7 @@ fake:
 	hp-h_addr_list[1] = NULL;
 	buf += size;
 	buflen -= size;
-	SCOPY(hp-h_name, name, buf, buflen);
+	HENT_SCOPY(hp-h_name, name, buf, buflen);
 	if (res-options  RES_USE_INET6)
 		map_v4v6_hostent(hp, buf, buf + buflen);
 	*he = NETDB_SUCCESS;
@@ -748,31 +716,6 @@ gethostbyaddr_r(const void *addr, sockle
 	return hp;
 }
 
-static const char *_h_hosts = _PATH_HOSTS;
-
-void
-_hf_sethostsfile(const char *f) {
-	_h_hosts = f;
-}
-
-void
-sethostent_r(FILE **hf)
-{
-	if (!*hf)
-		*hf = fopen(_h_hosts, re);
-	else
-		rewind(*hf);
-}
-
-void
-endhostent_r(FILE **hf)
-{
-	if (*hf) {
-		(void)fclose(*hf);
-		*hf = NULL;
-	}
-}
-
 struct hostent *
 gethostent_r(FILE *hf, struct hostent *hent, char *buf, size_t buflen, int *he)
 {
@@ -847,15 +790,16 @@ gethostent_r(FILE *hf, struct hostent *h
 	}
 	hent-h_length = len;
 	hent-h_addrtype = af;
-	ARRAY(hent-h_addr_list, 1, buf, buflen);
+	HENT_ARRAY(hent-h_addr_list, 1, buf, buflen);
 	anum = (size_t)(q - aliases);
-	ARRAY(hent-h_aliases, anum, buf, buflen);
-	COPY(hent-h_addr_list[0], host_addr, hent-h_length, buf, buflen);
+	HENT_ARRAY(hent-h_aliases, anum, buf, buflen);
+	HENT_COPY(hent-h_addr_list[0], host_addr, hent-h_length, buf,
+	buflen);
 	hent-h_addr_list[1] = NULL;
 
-	SCOPY(hent-h_name, name, buf, buflen);
+	HENT_SCOPY(hent-h_name, name, buf, buflen);
 	for (size_t i = 0; i  anum; i++)
-		SCOPY(hent-h_aliases[i], aliases[i], buf, buflen);
+		HENT_SCOPY(hent-h_aliases[i], aliases[i], buf, buflen);
 	hent-h_aliases[anum] = NULL;
 
 	*he = NETDB_SUCCESS;
@@ -866,181 +810,6 @@ nospc:
 	return NULL;
 }
 
-/*ARGSUSED*/
-int
-_hf_gethtbyname(void *rv, void *cb_data, va_list ap)
-{
-	struct hostent *hp;
-	const char *name;
-	int af;
-	struct getnamaddr *info = rv;
-
-	_DIAGASSERT(rv != NULL);
-
-	name = va_arg(ap, char *);
-	/* NOSTRICT skip string len */(void)va_arg(ap, int);
-	af = va_arg(ap, int);
-
-#if 0
-	{
-		res_state res = 

CVS commit: src/lib/libc/net

2013-08-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Aug 22 10:04:28 UTC 2013

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
get rid of bogus + 1


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.82 src/lib/libc/net/gethnamaddr.c:1.83
--- src/lib/libc/net/gethnamaddr.c:1.82	Mon Aug 19 03:18:42 2013
+++ src/lib/libc/net/gethnamaddr.c	Thu Aug 22 06:04:28 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.82 2013/08/19 07:18:42 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.83 2013/08/22 10:04:28 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.82 2013/08/19 07:18:42 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.83 2013/08/22 10:04:28 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -242,7 +242,7 @@ getanswer(const querybuf *answer, int an
 	int toobig = 0;
 	char tbuf[MAXDNAME];
 	char *aliases[MAXALIASES];
-	char *addr_ptrs[MAXADDRS + 1];
+	char *addr_ptrs[MAXADDRS];
 	const char *tname;
 	int (*name_ok)(const char *);
 
@@ -912,7 +912,7 @@ _hf_gethtbyname2(const char *name, int a
 	size_t len, anum, num, i;
 	FILE *hf;
 	char *aliases[MAXALIASES];
-	char *addr_ptrs[MAXADDRS + 1];
+	char *addr_ptrs[MAXADDRS];
 
 	_DIAGASSERT(name != NULL);
 



CVS commit: src/lib/libc/net

2013-08-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Aug 18 09:57:16 UTC 2013

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
appease lint.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.80 src/lib/libc/net/gethnamaddr.c:1.81
--- src/lib/libc/net/gethnamaddr.c:1.80	Fri Aug 16 11:27:12 2013
+++ src/lib/libc/net/gethnamaddr.c	Sun Aug 18 05:57:16 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.80 2013/08/16 15:27:12 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.81 2013/08/18 09:57:16 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.80 2013/08/16 15:27:12 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.81 2013/08/18 09:57:16 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -1030,7 +1030,7 @@ _hf_gethtbyaddr(void *rv, void *cb_data,
 	}
 	while ((hp = gethostent_r(hf, info-hp, info-buf, info-buflen,
 	info-he)) != NULL)
-		if (!memcmp(hp-h_addr_list[0], addr, hp-h_length))
+		if (!memcmp(hp-h_addr_list[0], addr, (size_t)hp-h_length))
 			break;
 	endhostent_r(hf);
 



CVS commit: src/lib/libc/net

2013-08-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Aug 18 10:00:58 UTC 2013

Modified Files:
src/lib/libc/net: getnameinfo.3

Log Message:
getnameinfo is now thread-safe so remove bugs section.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/lib/libc/net/getnameinfo.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnameinfo.3
diff -u src/lib/libc/net/getnameinfo.3:1.39 src/lib/libc/net/getnameinfo.3:1.40
--- src/lib/libc/net/getnameinfo.3:1.39	Wed Sep 26 19:13:00 2012
+++ src/lib/libc/net/getnameinfo.3	Sun Aug 18 06:00:57 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: getnameinfo.3,v 1.39 2012/09/26 23:13:00 christos Exp $
+.\	$NetBSD: getnameinfo.3,v 1.40 2013/08/18 10:00:57 christos Exp $
 .\	$KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $
 .\	$OpenBSD: getnameinfo.3,v 1.36 2004/12/21 09:48:20 jmc Exp $
 .\
@@ -17,7 +17,7 @@
 .\ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 .\ PERFORMANCE OF THIS SOFTWARE.
 .\
-.Dd September 26, 2012
+.Dd August 18, 2013
 .Dt GETNAMEINFO 3
 .Os
 .Sh NAME
@@ -263,10 +263,6 @@ if (error == 0) {
 	NULL, 0, NI_NUMERICHOST);
 }
 .Ed
-.Sh BUGS
-The implementation of
-.Fn getnameinfo
-is not thread-safe.
 .\.Pp
 .\.Ox
 .\intentionally uses a different



CVS commit: src/lib/libc/net

2013-08-18 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Aug 18 10:40:06 UTC 2013

Modified Files:
src/lib/libc/net: getnameinfo.3

Log Message:
Update comment.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/lib/libc/net/getnameinfo.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnameinfo.3
diff -u src/lib/libc/net/getnameinfo.3:1.40 src/lib/libc/net/getnameinfo.3:1.41
--- src/lib/libc/net/getnameinfo.3:1.40	Sun Aug 18 10:00:57 2013
+++ src/lib/libc/net/getnameinfo.3	Sun Aug 18 10:40:06 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: getnameinfo.3,v 1.40 2013/08/18 10:00:57 christos Exp $
+.\	$NetBSD: getnameinfo.3,v 1.41 2013/08/18 10:40:06 wiz Exp $
 .\	$KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $
 .\	$OpenBSD: getnameinfo.3,v 1.36 2004/12/21 09:48:20 jmc Exp $
 .\
@@ -263,7 +263,7 @@ if (error == 0) {
 	NULL, 0, NI_NUMERICHOST);
 }
 .Ed
-.\.Pp
+.\.Sh BUGS
 .\.Ox
 .\intentionally uses a different
 .\.Dv NI_MAXHOST



CVS commit: src/lib/libc/net

2013-08-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Aug 16 15:27:12 UTC 2013

Modified Files:
src/lib/libc/net: gethnamaddr.c getnameinfo.c sethostent.c
Added Files:
src/lib/libc/net: hostent.h

Log Message:
Add not advertised reentrant functions: {get,set,end}hostent_r,
gethostbyname{,2}_r, gethostbyaddr_r. Make getnameinfo(3) use
gethostbyaddr_r(3) so it is re-entrant (ahem __ypdomain). These
are not being advertised because there is a bunch of different
implementation of them that have a variety of type signatures.

If people want to follow someone's implementation, it is now easy.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/lib/libc/net/gethnamaddr.c
cvs rdiff -u -r1.53 -r1.54 src/lib/libc/net/getnameinfo.c
cvs rdiff -u -r0 -r1.1 src/lib/libc/net/hostent.h
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/net/sethostent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.79 src/lib/libc/net/gethnamaddr.c:1.80
--- src/lib/libc/net/gethnamaddr.c:1.79	Sun Sep  9 12:42:23 2012
+++ src/lib/libc/net/gethnamaddr.c	Fri Aug 16 11:27:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.79 2012/09/09 16:42:23 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.80 2013/08/16 15:27:12 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.79 2012/09/09 16:42:23 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.80 2013/08/16 15:27:12 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -95,6 +95,8 @@ __RCSID($NetBSD: gethnamaddr.c,v 1.79 2
 #include rpcsvc/ypclnt.h
 #endif
 
+#include hostent.h
+
 #if defined(_LIBC)  defined(__weak_alias)
 __weak_alias(gethostbyaddr,_gethostbyaddr)
 __weak_alias(gethostbyname,_gethostbyname)
@@ -111,31 +113,23 @@ __weak_alias(gethostent,_gethostent)
 #define	MAXADDRS	35
 
 static const char AskedForGot[] =
-			  gethostby*.getanswer: asked for \%s\, got \%s\;
+gethostby*.getanswer: asked for \%s\, got \%s\;
 
-static char *h_addr_ptrs[MAXADDRS + 1];
 
 #ifdef YP
 static char *__ypdomain;
 #endif
 
-static struct hostent host;
-static char *host_aliases[MAXALIASES];
-static char hostbuf[8*1024];
-static u_int32_t host_addr[16 / sizeof(u_int32_t)];	/* IPv4 or IPv6 */
-static FILE *hostf = NULL;
-static int stayopen = 0;
-
 #define	MAXPACKET	(64*1024)
 
 typedef union {
-HEADER hdr;
-u_char buf[MAXPACKET];
+	HEADER hdr;
+	u_char buf[MAXPACKET];
 } querybuf;
 
 typedef union {
-int32_t al;
-char ac;
+	int32_t al;
+	char ac;
 } align;
 
 #ifdef DEBUG
@@ -143,33 +137,23 @@ static void debugprintf(const char *, re
 	__attribute__((__format__(__printf__, 1, 3)));
 #endif
 static struct hostent *getanswer(const querybuf *, int, const char *, int,
-res_state);
+res_state, struct hostent *, char *, size_t, int *);
 static void map_v4v6_address(const char *, char *);
 static void map_v4v6_hostent(struct hostent *, char **, char *);
 static void addrsort(char **, int, res_state);
 
-void _sethtent(int);
-void _endhtent(void);
-struct hostent *_gethtent(void);
-void ht_sethostent(int);
-void ht_endhostent(void);
-struct hostent *ht_gethostbyname(char *);
-struct hostent *ht_gethostbyaddr(const char *, int, int);
 void dns_service(void);
 #undef dn_skipname
 int dn_skipname(const u_char *, const u_char *);
-int _gethtbyaddr(void *, void *, va_list);
-int _gethtbyname(void *, void *, va_list);
-struct hostent *_gethtbyname2(const char *, int);
-int _dns_gethtbyaddr(void *, void *, va_list);
-int _dns_gethtbyname(void *, void *, va_list);
+
+static struct hostent *_hf_gethtbyname2(const char *, int, struct getnamaddr *);
+
 #ifdef YP
-struct hostent *_yphostent(char *, int);
-int _yp_gethtbyaddr(void *, void *, va_list);
-int _yp_gethtbyname(void *, void *, va_list);
+static struct hostent *_yp_hostent(char *, int, struct getnamaddr *);
 #endif
 
-static struct hostent *gethostbyname_internal(const char *, int, res_state);
+static struct hostent *gethostbyname_internal(const char *, int, res_state,
+struct hostent *, char *, size_t, int *);
 
 static const ns_src default_dns_files[] = {
 	{ NSSRC_FILES, 	NS_SUCCESS },
@@ -178,6 +162,33 @@ static const ns_src default_dns_files[] 
 };
 
 
+#define ARRAY(dst, anum, ptr, len) \
+	do { \
+		size_t _len = (anum + 1) * sizeof(*dst); \
+		if (_len  len) \
+			goto nospc; \
+		dst = (void *)ptr; \
+		ptr += _len; \
+		len -= _len; \
+	} while (/*CONSTCOND*/0)
+
+#define COPY(dst, src, slen, ptr, len) \
+	do { \
+		if ((size_t)slen  len) \
+			goto nospc; \
+		memcpy(ptr, src, (size_t)slen); \
+		dst = ptr; \
+		ptr += slen; \
+		len -= slen; \
+	} while (/* CONSTCOND */0)
+
+#define SCOPY(dst, src, ptr, 

CVS commit: src/lib/libc/net

2013-05-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon May 13 13:59:39 UTC 2013

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
CVE 1020938: Fix memory leak


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.103 src/lib/libc/net/getaddrinfo.c:1.104
--- src/lib/libc/net/getaddrinfo.c:1.103	Fri May  3 15:31:13 2013
+++ src/lib/libc/net/getaddrinfo.c	Mon May 13 09:59:39 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.103 2013/05/03 19:31:13 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.104 2013/05/13 13:59:39 christos 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.103 2013/05/03 19:31:13 christos Exp $);
+__RCSID($NetBSD: getaddrinfo.c,v 1.104 2013/05/13 13:59:39 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -1405,6 +1405,11 @@ getanswer(const querybuf *answer, int an
 		}
 		res = __res_get_state();
 		if (res == NULL) {
+			while (srvlist != NULL) {
+srv = srvlist;
+srvlist = srvlist-next;
+free(srv);
+			}
 			h_errno = NETDB_INTERNAL;
 			return NULL;
 		}



CVS commit: src/lib/libc/net

2013-05-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon May 13 17:54:55 UTC 2013

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
CVE 1020946: Fix res leak.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.104 src/lib/libc/net/getaddrinfo.c:1.105
--- src/lib/libc/net/getaddrinfo.c:1.104	Mon May 13 09:59:39 2013
+++ src/lib/libc/net/getaddrinfo.c	Mon May 13 13:54:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.104 2013/05/13 13:59:39 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.105 2013/05/13 17:54:55 christos 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.104 2013/05/13 13:59:39 christos Exp $);
+__RCSID($NetBSD: getaddrinfo.c,v 1.105 2013/05/13 17:54:55 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -1669,6 +1669,7 @@ _dns_host_lookup(const char *name, const
 		q.qtype = T_;
 		break;
 	default:
+		__res_put_state(res);
 		h_errno = NETDB_INTERNAL;
 		return NULL;
 	}



CVS commit: src/lib/libc/net

2013-05-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May  8 18:06:46 UTC 2013

Modified Files:
src/lib/libc/net: resolver.3

Log Message:
Clarify which functions are only in libresolv.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.24 src/lib/libc/net/resolver.3:1.25
--- src/lib/libc/net/resolver.3:1.24	Wed Nov  7 10:48:13 2012
+++ src/lib/libc/net/resolver.3	Wed May  8 14:06:46 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: resolver.3,v 1.24 2012/11/07 15:48:13 christos Exp $
+.\	$NetBSD: resolver.3,v 1.25 2013/05/08 18:06:46 christos Exp $
 .\ Copyright (c) 2004 by Internet Systems Consortium, Inc. (ISC)
 .\
 .\ Permission to use, copy, modify, and distribute this software for any
@@ -33,7 +33,7 @@
 .\	@(#)resolver.3	6.5 (Berkeley) 6/23/90
 .\	Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
 .\
-.Dd November 7, 2012
+.Dd May 8, 2013
 .Dt RESOLVER 3 
 .Os
 .Sh NAME
@@ -74,6 +74,7 @@
 .Nd resolver routines
 .Sh LIBRARY
 .Lb libc
+.Lb libresolv
 .Sh SYNOPSIS
 .In resolv.h
 .In res_update.h
@@ -685,14 +686,28 @@ definitions are given in
 .\ value of the
 .\ .Fa err
 .\ parameter.
+.Pp
+The following functions are only in
+.Dv libresolv :
+.Fn res_findzonecut ,
+.Fn res_nmkupdate ,
+.Fn res_nsendsigned , 
+and
+.Fn res_nupdate .
+All the rest are in both
+.Dv libc
+and
+.Dv libresolv .
 .Sh FILES
 .Bl -tag -width /etc/resolv.conf
-.It Pa
-/etc/resolv.conf
+.It Pa /etc/resolv.conf
 The configuration file, see
 .Xr resolv.conf 5 .
 .El
 .Sh SEE ALSO
+.Xr getaddrinfo 3 , 
+.Xr getnameinfo 3 , 
+.Xr gethostbyaddr 3 , 
 .Xr gethostbyname 3 , 
 .Xr hostname 7 ,
 .Xr resolv.conf 5 ,



CVS commit: src/lib/libc/net

2013-05-08 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed May  8 18:18:32 UTC 2013

Modified Files:
src/lib/libc/net: resolver.3

Log Message:
New sentence, new line. Fix minus. Avoid .
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.25 src/lib/libc/net/resolver.3:1.26
--- src/lib/libc/net/resolver.3:1.25	Wed May  8 18:06:46 2013
+++ src/lib/libc/net/resolver.3	Wed May  8 18:18:32 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: resolver.3,v 1.25 2013/05/08 18:06:46 christos Exp $
+.\	$NetBSD: resolver.3,v 1.26 2013/05/08 18:18:32 wiz Exp $
 .\ Copyright (c) 2004 by Internet Systems Consortium, Inc. (ISC)
 .\
 .\ Permission to use, copy, modify, and distribute this software for any
@@ -34,7 +34,7 @@
 .\	Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
 .\
 .Dd May 8, 2013
-.Dt RESOLVER 3 
+.Dt RESOLVER 3
 .Os
 .Sh NAME
 .Nm res_ninit ,
@@ -208,7 +208,7 @@ kept in the structure
 rather than that referenced through
 .Ft statp .
 .Pp
-Most of the values in 
+Most of the values in
 .Ft statp
 and
 .Ft _res
@@ -225,7 +225,7 @@ stored in
 are defined in
 .Pa resolv.h
 and are as follows.
-Options are stored as a simple bit mask containing the bitwise 
+Options are stored as a simple bit mask containing the bitwise
 .Dq OR
 of the options enabled.
 .Bl -tag -width RES_USE_INET6
@@ -245,8 +245,8 @@ Currently this is not implemented.
 .It Dv RES_USEVC
 Use TCP connections for queries instead of UDP datagrams.
 .It Dv RES_STAYOPEN
-Used with 
-.Dv RES_USEVC 
+Used with
+.Dv RES_USEVC
 to keep the TCP connection open between queries.
 This is useful only in programs that regularly do many queries.
 UDP should be the normal mode used.
@@ -294,8 +294,8 @@ DNS query packets with EDNS0 extension i
 non-EDNS0 DNS servers.
 .It Dv RES_NOALIASES
 This option turns off the user level aliasing feature controlled by
-the 
-.Ev HOSTALIASES 
+the
+.Ev HOSTALIASES
 environment variable.
 Network daemons should set this option.
 .It Dv RES_ROTATE
@@ -338,16 +338,17 @@ the Internet address of the local name s
 If no server is configured, the host running the resolver is tried.
 The current domain name is defined by the hostname
 if not specified in the configuration file;
-it can be overridden by the environment variable 
+it can be overridden by the environment variable
 .Ev LOCALDOMAIN .
 This environment variable may contain several blank-separated
 tokens if you wish to override the
 .Fa search list
-on a per-process basis.  This is similar to the
+on a per-process basis.
+This is similar to the
 .Fa search
 command in the configuration file.
-Another environment variable 
-.Ev RES_OPTIONS 
+Another environment variable
+.Ev RES_OPTIONS
 can be set to override certain internal resolver options which are otherwise
 set by changing fields in the
 .Ft statp
@@ -356,8 +357,8 @@ set by changing fields in the
 structure or are inherited from the configuration file's
 .Fa options
 command.
-The syntax of the 
-.Ev RES_OPTIONS 
+The syntax of the
+.Ev RES_OPTIONS
 environment variable is explained in
 .Xr resolv.conf 5 .
 Initialization normally occurs on the first call
@@ -369,7 +370,7 @@ must be set to all zeros prior to the fi
 .Fn res_ninit .
 .Fn res_ndestroy
 should be call to free memory allocated by
-.Fn res_ninit 
+.Fn res_ninit
 after last use.
 .Pp
 The
@@ -393,7 +394,7 @@ supplied by the caller.
 .Fn res_nquery
 /
 .Fn res_query
-return -1 on error or the length of the answer.
+return \-1 on error or the length of the answer.
 .Pp
 The
 .Fn res_nsearch
@@ -404,14 +405,14 @@ routines make a query and awaits a respo
 /
 .Fn res_query ,
 but in addition, it implements the default and search rules
-controlled by the 
-.Dv RES_DEFNAMES 
-and 
-.Dv RES_DNSRCH 
+controlled by the
+.Dv RES_DEFNAMES
+and
+.Dv RES_DNSRCH
 options.
 It returns the length of the first successful reply which is stored in
 .Ft answer
-or -1 on error.
+or \-1 on error.
 .Pp
 The remaining routines are lower-level routines used by
 .Fn res_nquery
@@ -429,10 +430,10 @@ larger than
 .Fa buflen .
 The query type
 .Fa op
-is usually 
-.Dv QUERY , 
+is usually
+.Dv QUERY ,
 but can be any of the query types defined in
-.Pa arpa/nameser.h .
+.Aq Pa arpa/nameser.h .
 The domain name for the query is given by
 .Fa dname .
 .Fa newrr
@@ -450,13 +451,15 @@ It will call
 .Fn res_ninit
 /
 .Fn res_init
-if 
-.Dv RES_INIT 
+if
+.Dv RES_INIT
 is not set, send the query to the local name server, and
-handle timeouts and retries.  Additionally,
+handle timeouts and retries.
+Additionally,
 .Fn res_nsendsigned
 will use TSIG signatures to add authentication to the query and verify the
-response.  In this case, only one nameserver will be contacted.
+response.
+In this case, only one nameserver will be 

CVS commit: src/lib/libc/net

2013-05-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May  3 19:24:53 UTC 2013

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
KNF, whitespace police -- no code changes


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.101 src/lib/libc/net/getaddrinfo.c:1.102
--- src/lib/libc/net/getaddrinfo.c:1.101	Fri Jun  8 03:54:14 2012
+++ src/lib/libc/net/getaddrinfo.c	Fri May  3 15:24:52 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.101 2012/06/08 07:54:14 martin Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.102 2013/05/03 19:24:52 christos 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.101 2012/06/08 07:54:14 martin Exp $);
+__RCSID($NetBSD: getaddrinfo.c,v 1.102 2013/05/03 19:24:52 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -118,7 +118,7 @@ static const struct afd {
 	int a_socklen;
 	int a_off;
 	const char *a_addrany;
-	const char *a_loopback;	
+	const char *a_loopback;
 	int a_scoped;
 } afdl [] = {
 #ifdef INET6
@@ -170,8 +170,8 @@ static const struct explore explore[] = 
 #endif
 
 static const ns_src default_dns_files[] = {
-	{ NSSRC_FILES, 	NS_SUCCESS },
-	{ NSSRC_DNS, 	NS_SUCCESS },
+	{ NSSRC_FILES,	NS_SUCCESS },
+	{ NSSRC_DNS,	NS_SUCCESS },
 	{ 0, 0 }
 };
 
@@ -193,17 +193,17 @@ struct res_target {
 
 static int str2number(const char *);
 static int explore_fqdn(const struct addrinfo *, const char *,
-	const char *, struct addrinfo **, struct servent_data *);
+const char *, struct addrinfo **, struct servent_data *);
 static int explore_null(const struct addrinfo *,
-	const char *, struct addrinfo **, struct servent_data *);
+const char *, struct addrinfo **, struct servent_data *);
 static int explore_numeric(const struct addrinfo *, const char *,
-	const char *, struct addrinfo **, const char *, struct servent_data *);
+const char *, struct addrinfo **, const char *, struct servent_data *);
 static int explore_numeric_scope(const struct addrinfo *, const char *,
-	const char *, struct addrinfo **, struct servent_data *);
+const char *, struct addrinfo **, struct servent_data *);
 static int get_canonname(const struct addrinfo *,
-	struct addrinfo *, const char *);
+struct addrinfo *, const char *);
 static struct addrinfo *get_ai(const struct addrinfo *,
-	const struct afd *, const char *);
+const struct afd *, const char *);
 static int get_portmatch(const struct addrinfo *, const char *,
 struct servent_data *);
 static int get_port(const struct addrinfo *, const char *, int,
@@ -215,7 +215,7 @@ static int ip6_str2scopeid(char *, struc
 #endif
 
 static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
-	const struct addrinfo *);
+const struct addrinfo *);
 static void aisort(struct addrinfo *s, res_state res);
 static int _dns_getaddrinfo(void *, void *, va_list);
 static void _sethtent(FILE **);
@@ -231,67 +231,67 @@ static int _yp_getaddrinfo(void *, void 
 static int res_queryN(const char *, struct res_target *, res_state);
 static int res_searchN(const char *, struct res_target *, res_state);
 static int res_querydomainN(const char *, const char *,
-	struct res_target *, res_state);
+struct res_target *, res_state);
 
 static const char * const ai_errlist[] = {
 	Success,
 	Address family for hostname not supported,	/* EAI_ADDRFAMILY */
-	Temporary failure in name resolution,		/* EAI_AGAIN  */
-	Invalid value for ai_flags,		   	/* EAI_BADFLAGS   */
-	Non-recoverable failure in name resolution, 	/* EAI_FAIL   */
-	ai_family not supported,			/* EAI_FAMILY */
-	Memory allocation failure, 			/* EAI_MEMORY */
-	No address associated with hostname, 		/* EAI_NODATA */
-	hostname nor servname provided, or not known,	/* EAI_NONAME */
-	servname not supported for ai_socktype,	/* EAI_SERVICE*/
-	ai_socktype not supported, 			/* EAI_SOCKTYPE   */
-	System error returned in errno, 		/* EAI_SYSTEM */
+	Temporary failure in name resolution,		/* EAI_AGAIN	  */
+	Invalid value for ai_flags,			/* EAI_BADFLAGS	  */
+	Non-recoverable failure in name resolution,	/* EAI_FAIL	  */
+	ai_family not supported,			/* EAI_FAMILY	  */
+	Memory allocation failure,			/* EAI_MEMORY	  */
+	No address associated with hostname,		/* EAI_NODATA	  */
+	hostname nor servname provided, or not known, /* EAI_NONAME	  */
+	servname not supported for ai_socktype,	/* EAI_SERVICE	  */
+	ai_socktype not supported,			/* EAI_SOCKTYPE	  */
+	System error returned in errno,		/* EAI_SYSTEM	  */
 	Invalid value for hints,			/* EAI_BADHINTS	  */
-	Resolved protocol is unknown,			/* 

CVS commit: src/lib/libc/net

2013-05-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May  3 19:31:13 UTC 2013

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
PR/32373, PR/25827: Add SRV lookup in getaddrinfo(3)
Per DNS-SD (RFC 2782), but only enabled if AI_SRV is set.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.102 src/lib/libc/net/getaddrinfo.c:1.103
--- src/lib/libc/net/getaddrinfo.c:1.102	Fri May  3 15:24:52 2013
+++ src/lib/libc/net/getaddrinfo.c	Fri May  3 15:31:13 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.102 2013/05/03 19:24:52 christos Exp $ */
+/*	$NetBSD: getaddrinfo.c,v 1.103 2013/05/03 19:31:13 christos 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.102 2013/05/03 19:24:52 christos Exp $);
+__RCSID($NetBSD: getaddrinfo.c,v 1.103 2013/05/03 19:31:13 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -191,6 +191,13 @@ struct res_target {
 	int n;			/* result length */
 };
 
+struct srvinfo {
+   struct srvinfo *next;
+   char name[MAXDNAME];
+   int port, pri, weight;
+};
+
+static int gai_srvok(const char *);
 static int str2number(const char *);
 static int explore_fqdn(const struct addrinfo *, const char *,
 const char *, struct addrinfo **, struct servent_data *);
@@ -217,6 +224,12 @@ static int ip6_str2scopeid(char *, struc
 static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
 const struct addrinfo *);
 static void aisort(struct addrinfo *s, res_state res);
+static struct addrinfo * _dns_query(struct res_target *,
+const struct addrinfo *, res_state, int);
+static struct addrinfo * _dns_srv_lookup(const char *, const char *,
+const struct addrinfo *);
+static struct addrinfo * _dns_host_lookup(const char *,
+const struct addrinfo *);
 static int _dns_getaddrinfo(void *, void *, va_list);
 static void _sethtent(FILE **);
 static void _endhtent(FILE **);
@@ -319,6 +332,58 @@ freeaddrinfo(struct addrinfo *ai)
 	} while (ai);
 }
 
+/*
+ * We don't want localization to affect us
+ */
+#define PERIOD '.'
+#define hyphenchar(c) ((c) == '-')
+#define periodchar(c) ((c) == PERIOD)
+#define underschar(c) ((c) == '_')
+#define alphachar(c) (((c) = 'a'  (c) = 'z') || ((c) = 'A'  (c) = 'Z'))
+#define digitchar(c) ((c) = '0'  (c) = '9')
+
+#define firstchar(c)  (alphachar(c) || digitchar(c) || underschar(c))
+#define lastchar(c)   (alphachar(c) || digitchar(c))
+#define middlechar(c) (lastchar(c) || hyphenchar(c))
+
+static int
+gai_srvok(const char *dn)
+{
+	int nch, pch, ch;
+
+	for (pch = PERIOD, nch = ch = *dn++; ch != '\0'; pch = ch, ch = nch) {
+		if (periodchar(ch))
+			continue;
+		if (periodchar(pch)) {
+			if (!firstchar(ch))
+return 0;
+		} else if (periodchar(nch) || nch == '\0') {
+			if (!lastchar(ch))
+return 0;
+		} else if (!middlechar(ch))
+			return 0;
+   }
+   return 1;
+}
+
+static in_port_t *
+getport(struct addrinfo *ai) {
+	static in_port_t p;
+
+	switch (ai-ai_family) {
+	case AF_INET:
+		return ((struct sockaddr_in *)(void *)ai-ai_addr)-sin_port;
+#ifdef INET6
+	case AF_INET6:
+		return ((struct sockaddr_in6 *)(void *)ai-ai_addr)-sin6_port;
+#endif
+	default:
+		p = 0;
+		/* XXX: abort()? */
+		return p;
+	}
+}
+
 static int
 str2number(const char *p)
 {
@@ -589,7 +654,7 @@ explore_fqdn(const struct addrinfo *pai,
 		return 0;
 
 	switch (nsdispatch(result, dtab, NSDB_HOSTS, getaddrinfo,
-			default_dns_files, hostname, pai)) {
+	default_dns_files, hostname, pai, servname)) {
 	case NS_TRYAGAIN:
 		error = EAI_AGAIN;
 		goto free;
@@ -602,6 +667,9 @@ explore_fqdn(const struct addrinfo *pai,
 	case NS_SUCCESS:
 		error = 0;
 		for (cur = result; cur; cur = cur-ai_next) {
+			/* Check for already filled port. */
+			if (*getport(cur))
+continue;
 			GET_PORT(cur, servname, svd);
 			/* canonname should be filled already */
 		}
@@ -990,21 +1058,8 @@ get_port(const struct addrinfo *ai, cons
 		port = sp-s_port;
 	}
 
-	if (!matchonly) {
-		switch (ai-ai_family) {
-		case AF_INET:
-			((struct sockaddr_in *)(void *)
-			ai-ai_addr)-sin_port = port;
-			break;
-#ifdef INET6
-		case AF_INET6:
-			((struct sockaddr_in6 *)(void *)
-			ai-ai_addr)-sin6_port = port;
-			break;
-#endif
-		}
-	}
-
+	if (!matchonly)
+		*getport(__UNCONST(ai)) = port;
 	return 0;
 }
 
@@ -1107,7 +1162,7 @@ getanswer(const querybuf *answer, int an
 const struct addrinfo *pai)
 {
 	struct addrinfo sentinel, *cur;
-	struct addrinfo ai;
+	struct addrinfo ai, *aip;
 	const struct afd *afd;
 	char *canonname;
 	const HEADER *hp;
@@ -1120,6 +1175,8 @@ getanswer(const 

CVS commit: src/lib/libc/net

2013-05-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May  3 19:34:55 UTC 2013

Modified Files:
src/lib/libc/net: getaddrinfo.3

Log Message:
document AI_SRV


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/lib/libc/net/getaddrinfo.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.3
diff -u src/lib/libc/net/getaddrinfo.3:1.55 src/lib/libc/net/getaddrinfo.3:1.56
--- src/lib/libc/net/getaddrinfo.3:1.55	Sat Apr 17 16:28:47 2010
+++ src/lib/libc/net/getaddrinfo.3	Fri May  3 15:34:54 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: getaddrinfo.3,v 1.55 2010/04/17 20:28:47 wiz Exp $
+.\	$NetBSD: getaddrinfo.3,v 1.56 2013/05/03 19:34:54 christos 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 $
 .\
@@ -17,7 +17,7 @@
 .\ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 .\ PERFORMANCE OF THIS SOFTWARE.
 .\
-.Dd April 17, 2010
+.Dd April 30, 2013
 .Dt GETADDRINFO 3
 .Os
 .Sh NAME
@@ -199,6 +199,9 @@ loopback address if
 is the null pointer and
 .Dv AI_PASSIVE
 is not set.
+.It Dv AI_SRV
+Perform SRV (RFC 2782) record lookups first. This is a non-portable
+extension.
 .El
 .El
 .Pp



CVS commit: src/lib/libc/net

2013-05-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri May  3 21:13:34 UTC 2013

Modified Files:
src/lib/libc/net: getaddrinfo.3

Log Message:
New sentence, new line.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/lib/libc/net/getaddrinfo.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.3
diff -u src/lib/libc/net/getaddrinfo.3:1.56 src/lib/libc/net/getaddrinfo.3:1.57
--- src/lib/libc/net/getaddrinfo.3:1.56	Fri May  3 19:34:54 2013
+++ src/lib/libc/net/getaddrinfo.3	Fri May  3 21:13:34 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: getaddrinfo.3,v 1.56 2013/05/03 19:34:54 christos Exp $
+.\	$NetBSD: getaddrinfo.3,v 1.57 2013/05/03 21:13:34 wiz 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 $
 .\
@@ -200,8 +200,8 @@ is the null pointer and
 .Dv AI_PASSIVE
 is not set.
 .It Dv AI_SRV
-Perform SRV (RFC 2782) record lookups first. This is a non-portable
-extension.
+Perform SRV (RFC 2782) record lookups first.
+This is a non-portable extension.
 .El
 .El
 .Pp



CVS commit: src/lib/libc/net

2013-04-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr  7 22:54:26 UTC 2013

Modified Files:
src/lib/libc/net: getifaddrs.3

Log Message:
Add a small example.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/net/getifaddrs.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getifaddrs.3
diff -u src/lib/libc/net/getifaddrs.3:1.12 src/lib/libc/net/getifaddrs.3:1.13
--- src/lib/libc/net/getifaddrs.3:1.12	Mon Mar 22 15:30:54 2010
+++ src/lib/libc/net/getifaddrs.3	Sun Apr  7 18:54:26 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: getifaddrs.3,v 1.12 2010/03/22 19:30:54 joerg Exp $
+.\	$NetBSD: getifaddrs.3,v 1.13 2013/04/07 22:54:26 christos Exp $
 .\	BSDI	getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp
 .\
 .\ Copyright (c) 1995, 1999
@@ -21,7 +21,7 @@
 .\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
-.Dd April 21, 2009
+.Dd April 7, 2013
 .Dt GETIFADDRS 3
 .Os
 .Sh NAME
@@ -133,6 +133,36 @@ Upon successful completion, a value of 0
 Otherwise, a value of -1 is returned and
 .Va errno
 is set to indicate the error.
+.Sh EXAMPLES
+The following example program prints a list of all addresses configured
+on the system.
+.Bd -literal -offset indent
+#include \*[Lt]sys/types.h\*[Gt]
+#include \*[Lt]sys/socket.h\*[Gt]
+#include \*[Lt]stdio.h\*[Gt]
+#include \*[Lt]ifaddrs.h\*[Gt]
+#include \*[Lt]util.h\*[Gt]
+#include \*[Lt]err.h\*[Gt]
+#include \*[Lt]stdlib.h\*[Gt]
+
+int
+main(int argc, char *argv[])
+{
+	struct ifaddrs *ifa, *a;
+
+	if (getifaddrs(\*[Am]ifa) == -1)
+		err(EXIT_FAILURE, getifaddrs);
+
+	for (a = ifa; a; a = a-ifa_next) {
+		char buf[1024];
+		sockaddr_snprintf(buf, sizeof(buf), %f %a,
+		a-ifa_addr);
+		printf(%s %x %s\\n, a-ifa_name, a-ifa_flags, buf);
+	}
+	freeifaddrs(ifa);
+	return EXIT_SUCCESS;
+}
+.Ed
 .Sh ERRORS
 The
 .Fn getifaddrs



CVS commit: src/lib/libc/net

2013-04-07 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Apr  7 23:12:36 UTC 2013

Modified Files:
src/lib/libc/net: getifaddrs.3

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/net/getifaddrs.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getifaddrs.3
diff -u src/lib/libc/net/getifaddrs.3:1.13 src/lib/libc/net/getifaddrs.3:1.14
--- src/lib/libc/net/getifaddrs.3:1.13	Sun Apr  7 22:54:26 2013
+++ src/lib/libc/net/getifaddrs.3	Sun Apr  7 23:12:36 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: getifaddrs.3,v 1.13 2013/04/07 22:54:26 christos Exp $
+.\	$NetBSD: getifaddrs.3,v 1.14 2013/04/07 23:12:36 wiz Exp $
 .\	BSDI	getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp
 .\
 .\ Copyright (c) 1995, 1999
@@ -133,7 +133,7 @@ Upon successful completion, a value of 0
 Otherwise, a value of -1 is returned and
 .Va errno
 is set to indicate the error.
-.Sh EXAMPLES
+.Sh EXAMPLES
 The following example program prints a list of all addresses configured
 on the system.
 .Bd -literal -offset indent



CVS commit: src/lib/libc/net

2012-12-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Dec 27 07:08:59 UTC 2012

Modified Files:
src/lib/libc/net: Makefile.inc

Log Message:
Avoid gcc 4.5.3 compiler bug on ia64 by compiling hesiod.c with -O1 only.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/lib/libc/net/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/Makefile.inc
diff -u src/lib/libc/net/Makefile.inc:1.81 src/lib/libc/net/Makefile.inc:1.82
--- src/lib/libc/net/Makefile.inc:1.81	Fri Jan 20 14:08:05 2012
+++ src/lib/libc/net/Makefile.inc	Thu Dec 27 07:08:59 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.81 2012/01/20 14:08:05 joerg Exp $
+#	$NetBSD: Makefile.inc,v 1.82 2012/12/27 07:08:59 martin Exp $
 #	@(#)Makefile.inc	8.2 (Berkeley) 9/5/93
 
 # net sources
@@ -17,6 +17,9 @@ SRCS+=	base64.c ethers.c gethnamaddr.c g
 
 .if (${MKHESIOD} != no)
 SRCS+=	hesiod.c
+.if ${HAVE_GCC:U} == 45  ${MACHINE_CPU} == ia64
+COPTS.hesiod.c+=	${${ACTIVE_CC} == gcc :? -O1 :}
+.endif
 .endif
 
 SRCS+=	getaddrinfo.c getnameinfo.c



CVS commit: src/lib/libc/net

2012-11-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov  7 15:48:13 UTC 2012

Modified Files:
src/lib/libc/net: resolver.3

Log Message:
fix outdated includes list.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/net/resolver.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/resolver.3
diff -u src/lib/libc/net/resolver.3:1.23 src/lib/libc/net/resolver.3:1.24
--- src/lib/libc/net/resolver.3:1.23	Fri Oct  2 02:49:23 2009
+++ src/lib/libc/net/resolver.3	Wed Nov  7 10:48:13 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: resolver.3,v 1.23 2009/10/02 06:49:23 cegger Exp $
+.\	$NetBSD: resolver.3,v 1.24 2012/11/07 15:48:13 christos Exp $
 .\ Copyright (c) 2004 by Internet Systems Consortium, Inc. (ISC)
 .\
 .\ Permission to use, copy, modify, and distribute this software for any
@@ -33,7 +33,7 @@
 .\	@(#)resolver.3	6.5 (Berkeley) 6/23/90
 .\	Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
 .\
-.Dd July 4, 2000
+.Dd November 7, 2012
 .Dt RESOLVER 3 
 .Os
 .Sh NAME
@@ -75,9 +75,6 @@
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
-.In sys/types.h
-.In netinet/in.h
-.In arpa/nameser.h
 .In resolv.h
 .In res_update.h
 .Vt typedef struct __res_state *res_state ;



CVS commit: src/lib/libc/net

2012-09-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 26 23:13:00 UTC 2012

Modified Files:
src/lib/libc/net: getnameinfo.3 getnameinfo.c

Log Message:
add and document AF_LOCAL (and the rest that were not)


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/lib/libc/net/getnameinfo.3
cvs rdiff -u -r1.52 -r1.53 src/lib/libc/net/getnameinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnameinfo.3
diff -u src/lib/libc/net/getnameinfo.3:1.38 src/lib/libc/net/getnameinfo.3:1.39
--- src/lib/libc/net/getnameinfo.3:1.38	Sat Mar  3 22:23:35 2012
+++ src/lib/libc/net/getnameinfo.3	Wed Sep 26 19:13:00 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: getnameinfo.3,v 1.38 2012/03/04 03:23:35 christos Exp $
+.\	$NetBSD: getnameinfo.3,v 1.39 2012/09/26 23:13:00 christos Exp $
 .\	$KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $
 .\	$OpenBSD: getnameinfo.3,v 1.36 2004/12/21 09:48:20 jmc Exp $
 .\
@@ -17,7 +17,7 @@
 .\ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 .\ PERFORMANCE OF THIS SOFTWARE.
 .\
-.Dd March 3, 2012
+.Dd September 26, 2012
 .Dt GETNAMEINFO 3
 .Os
 .Sh NAME
@@ -47,11 +47,19 @@ The
 .Li sockaddr
 structure
 .Fa sa
-should point to either a
+should point to a
 .Li sockaddr_in
-or
+(for IPv4),
 .Li sockaddr_in6
-structure (for IPv4 or IPv6 respectively) that is
+(for IPv6),
+.Li sockaddr_atalk
+(for AppleTalk),
+.Li sockaddr_link
+(for link layer),
+or
+.Li sockaddr_local
+(for local/unix)
+structures that are
 .Fa salen
 bytes long.
 .Pp

Index: src/lib/libc/net/getnameinfo.c
diff -u src/lib/libc/net/getnameinfo.c:1.52 src/lib/libc/net/getnameinfo.c:1.53
--- src/lib/libc/net/getnameinfo.c:1.52	Tue Mar 20 13:44:18 2012
+++ src/lib/libc/net/getnameinfo.c	Wed Sep 26 19:13:00 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnameinfo.c,v 1.52 2012/03/20 17:44:18 matt Exp $	*/
+/*	$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $	*/
 /*	$KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $	*/
 
 /*
@@ -47,12 +47,13 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: getnameinfo.c,v 1.52 2012/03/20 17:44:18 matt Exp $);
+__RCSID($NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
 #include sys/types.h
 #include sys/socket.h
+#include sys/un.h
 #include net/if.h
 #include net/if_dl.h
 #include net/if_ieee1394.h
@@ -104,6 +105,8 @@ static int ip6_sa2str(const struct socka
 #endif
 static int getnameinfo_atalk(const struct sockaddr *, socklen_t, char *,
 socklen_t, char *, socklen_t, int);
+static int getnameinfo_local(const struct sockaddr *, socklen_t, char *,
+socklen_t, char *, socklen_t, int);
 
 static int getnameinfo_link(const struct sockaddr *, socklen_t, char *,
 socklen_t, char *, socklen_t, int);
@@ -131,6 +134,9 @@ getnameinfo(const struct sockaddr *sa, s
 	case AF_LINK:
 		return getnameinfo_link(sa, salen, host, hostlen,
 		serv, servlen, flags);
+	case AF_LOCAL:
+		return getnameinfo_local(sa, salen, host, hostlen,
+		serv, servlen, flags);
 	default:
 		return EAI_FAMILY;
 	}
@@ -197,6 +203,29 @@ errout:
 }
 
 /*
+ * getnameinfo_local():
+ * Format an local address into a printable format.
+ */
+/* ARGSUSED */
+static int
+getnameinfo_local(const struct sockaddr *sa, socklen_t salen,
+char *host, socklen_t hostlen, char *serv, socklen_t servlen,
+int flags)
+{
+	const struct sockaddr_un *sun =
+	(const struct sockaddr_un *)(const void *)sa;
+
+	if (serv != NULL  servlen  0)
+		serv[0] = '\0';
+
+	if (host  hostlen  0)
+		strlcpy(host, sun-sun_path,
+		MIN(sizeof(sun-sun_path) + 1, hostlen));
+
+	return 0;
+}
+
+/*
  * getnameinfo_inet():
  * Format an IPv4 or IPv6 sockaddr into a printable string.
  */



CVS commit: src/lib/libc/net

2012-09-09 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Sep  9 16:42:23 UTC 2012

Modified Files:
src/lib/libc/net: gethnamaddr.c

Log Message:
implement no-check-names


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.78 src/lib/libc/net/gethnamaddr.c:1.79
--- src/lib/libc/net/gethnamaddr.c:1.78	Tue Mar 13 17:13:40 2012
+++ src/lib/libc/net/gethnamaddr.c	Sun Sep  9 12:42:23 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.78 2012/03/13 21:13:40 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.79 2012/09/09 16:42:23 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = @(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93;
 static char rcsid[] = Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ;
 #else
-__RCSID($NetBSD: gethnamaddr.c,v 1.78 2012/03/13 21:13:40 christos Exp $);
+__RCSID($NetBSD: gethnamaddr.c,v 1.79 2012/09/09 16:42:23 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -101,6 +101,12 @@ __weak_alias(gethostbyname,_gethostbynam
 __weak_alias(gethostent,_gethostent)
 #endif
 
+#define maybe_ok(res, nm, ok) (((res)-options  RES_NOCHECKNAME) != 0U || \
+   (ok)(nm) != 0)
+#define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
+#define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
+
+
 #define	MAXALIASES	35
 #define	MAXADDRS	35
 
@@ -258,7 +264,7 @@ getanswer(const querybuf *answer, int an
 		return NULL;
 	}
 	n = dn_expand(answer-buf, eom, cp, bp, (int)(ep - bp));
-	if ((n  0) || !(*name_ok)(bp)) {
+	if ((n  0) || !maybe_ok(res, bp, name_ok)) {
 		h_errno = NO_RECOVERY;
 		return NULL;
 	}
@@ -288,7 +294,7 @@ getanswer(const querybuf *answer, int an
 	had_error = 0;
 	while (ancount--  0  cp  eom  !had_error) {
 		n = dn_expand(answer-buf, eom, cp, bp, (int)(ep - bp));
-		if ((n  0) || !(*name_ok)(bp)) {
+		if ((n  0) || !maybe_ok(res, bp, name_ok)) {
 			had_error++;
 			continue;
 		}
@@ -311,7 +317,7 @@ getanswer(const querybuf *answer, int an
 			if (ap = host_aliases[MAXALIASES-1])
 continue;
 			n = dn_expand(answer-buf, eom, cp, tbuf, (int)sizeof tbuf);
-			if ((n  0) || !(*name_ok)(tbuf)) {
+			if ((n  0) || !maybe_ok(res, tbuf, name_ok)) {
 had_error++;
 continue;
 			}
@@ -341,7 +347,7 @@ getanswer(const querybuf *answer, int an
 		}
 		if (qtype == T_PTR  type == T_CNAME) {
 			n = dn_expand(answer-buf, eom, cp, tbuf, (int)sizeof tbuf);
-			if (n  0 || !res_dnok(tbuf)) {
+			if (n  0 || !maybe_dnok(res, tbuf)) {
 had_error++;
 continue;
 			}
@@ -379,7 +385,7 @@ getanswer(const querybuf *answer, int an
 continue;	/* XXX - had_error++ ? */
 			}
 			n = dn_expand(answer-buf, eom, cp, bp, (int)(ep - bp));
-			if ((n  0) || !res_hnok(bp)) {
+			if ((n  0) || !maybe_hnok(res, bp)) {
 had_error++;
 break;
 			}



CVS commit: src/lib/libc/net

2012-06-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jun  8 07:54:14 UTC 2012

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
Henning Petersen in PR lib/46561: cosmetic change: avoid self assignement.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.100 src/lib/libc/net/getaddrinfo.c:1.101
--- src/lib/libc/net/getaddrinfo.c:1.100	Tue Mar 20 12:04:01 2012
+++ src/lib/libc/net/getaddrinfo.c	Fri Jun  8 07:54:14 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.100 2012/03/20 12:04:01 kardel Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.101 2012/06/08 07:54:14 martin 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.100 2012/03/20 12:04:01 kardel Exp $);
+__RCSID($NetBSD: getaddrinfo.c,v 1.101 2012/06/08 07:54:14 martin Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -436,7 +436,7 @@ getaddrinfo(const char *hostname, const 
 		}
 		error = get_portmatch(pai, servname, svd);
 		if (error)
-			ERR(error);
+			goto bad;
 
 		*pai = ai0;
 	}



CVS commit: src/lib/libc/net

2012-03-20 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Tue Mar 20 10:34:33 UTC 2012

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
PR 46206: fix programmed SIGSEGV
more work is needed as tests seem to indicate that name resolution now
does no seem to work (firefox reports Server not found)
thanks to Ryo ONODERA for testing.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.98 src/lib/libc/net/getaddrinfo.c:1.99
--- src/lib/libc/net/getaddrinfo.c:1.98	Sat Mar 17 21:56:40 2012
+++ src/lib/libc/net/getaddrinfo.c	Tue Mar 20 10:34:33 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.98 2012/03/17 21:56:40 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.99 2012/03/20 10:34:33 kardel 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.98 2012/03/17 21:56:40 christos Exp $);
+__RCSID($NetBSD: getaddrinfo.c,v 1.99 2012/03/20 10:34:33 kardel Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -1032,7 +1032,7 @@ addrconfig(uint64_t *mask)
 	if (getifaddrs(ifaddrs) == -1)
 		return -1;
 
-	mask = 0;
+	*mask = 0;
 	for (ifa = ifaddrs; ifa != NULL; ifa = ifa-ifa_next)
 		if (ifa-ifa_addr  (ifa-ifa_flags  IFF_UP)) {
 			_DIAGASSERT(ifa-ifa_addr-sa_family  64);



CVS commit: src/lib/libc/net

2012-03-20 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Tue Mar 20 12:04:01 UTC 2012

Modified Files:
src/lib/libc/net: getaddrinfo.c

Log Message:
PR pkg/46206
re-establish fqdn lookup when AI_ADDRCONFIG is used in hints
AI_ADDRCONFIG led to fqdn lookup being skipped as the systems didn't
configure any PF_UNSPEC addresses - check was too strict here.
Thnaks to Ryo ONODERA for testing.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.99 src/lib/libc/net/getaddrinfo.c:1.100
--- src/lib/libc/net/getaddrinfo.c:1.99	Tue Mar 20 10:34:33 2012
+++ src/lib/libc/net/getaddrinfo.c	Tue Mar 20 12:04:01 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.99 2012/03/20 10:34:33 kardel Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.100 2012/03/20 12:04:01 kardel 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.99 2012/03/20 10:34:33 kardel Exp $);
+__RCSID($NetBSD: getaddrinfo.c,v 1.100 2012/03/20 12:04:01 kardel Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -503,8 +503,11 @@ getaddrinfo(const char *hostname, const 
 	for (ex = explore; ex-e_af = 0; ex++) {
 		*pai = ai0;
 
+
 		/* ADDRCONFIG check */
-		if uint64_t)1  ex-e_af)  mask) == 0)
+		/* PF_UNSPEC entries are prepared for DNS queries only */
+		if (ex-e_af != PF_UNSPEC 
+		(((uint64_t)1  ex-e_af)  mask) == 0)
 			continue;
 
 		/* require exact match for family field */



CVS commit: src/lib/libc/net

2012-03-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  4 03:23:37 UTC 2012

Modified Files:
src/lib/libc/net: getnameinfo.3

Log Message:
fix signature according to TOG.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libc/net/getnameinfo.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getnameinfo.3
diff -u src/lib/libc/net/getnameinfo.3:1.37 src/lib/libc/net/getnameinfo.3:1.38
--- src/lib/libc/net/getnameinfo.3:1.37	Mon Mar 22 15:30:54 2010
+++ src/lib/libc/net/getnameinfo.3	Sat Mar  3 22:23:35 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: getnameinfo.3,v 1.37 2010/03/22 19:30:54 joerg Exp $
+.\	$NetBSD: getnameinfo.3,v 1.38 2012/03/04 03:23:35 christos Exp $
 .\	$KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $
 .\	$OpenBSD: getnameinfo.3,v 1.36 2004/12/21 09:48:20 jmc Exp $
 .\
@@ -17,7 +17,7 @@
 .\ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 .\ PERFORMANCE OF THIS SOFTWARE.
 .\
-.Dd March 21, 2005
+.Dd March 3, 2012
 .Dt GETNAMEINFO 3
 .Os
 .Sh NAME
@@ -27,8 +27,8 @@
 .In netdb.h
 .Ft int
 .Fn getnameinfo const struct sockaddr * restrict sa socklen_t salen \
-char * restrict host size_t hostlen char * restrict serv \
-size_t servlen int flags
+char * restrict host socklen_t hostlen char * restrict serv \
+socklen_t servlen int flags
 .Sh DESCRIPTION
 The
 .Fn getnameinfo



CVS commit: src/lib/libc/net

2011-12-25 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Sun Dec 25 12:32:36 UTC 2011

Modified Files:
src/lib/libc/net: Makefile.inc

Log Message:
Apply fix for previous changes per request from joerg@:
http://mail-index.NetBSD.org/source-changes-d/2011/12/25/msg004454.html

XXX1: More Makefiles should be fixed otherwise they will be
  copy-and-pasted blindly again and again.
XXX2: Probably we need more explicit and simple macro to check active CC.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/lib/libc/net/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/Makefile.inc
diff -u src/lib/libc/net/Makefile.inc:1.79 src/lib/libc/net/Makefile.inc:1.80
--- src/lib/libc/net/Makefile.inc:1.79	Sat Dec 24 04:59:00 2011
+++ src/lib/libc/net/Makefile.inc	Sun Dec 25 12:32:36 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.79 2011/12/24 04:59:00 tsutsui Exp $
+#	$NetBSD: Makefile.inc,v 1.80 2011/12/25 12:32:36 tsutsui Exp $
 #	@(#)Makefile.inc	8.2 (Berkeley) 9/5/93
 
 # net sources
@@ -41,9 +41,9 @@ nslexer.c: nslexer.l nsparser.h
 
 .include ${ARCHDIR}/net/Makefile.inc
 
-.if defined(HAVE_GCC)  ${HAVE_GCC} == 45  ${MACHINE_CPU} == arm   
-COPTS.getaddrinfo.c+=	-fno-tree-ter
-COPTS.gethnamaddr.c+=	-fno-tree-ter
+.if ${HAVE_GCC:U} == 45  ${MACHINE_CPU} == arm
+COPTS.getaddrinfo.c+=	${${ACTIVE_CC} == gcc :? -fno-tree-ter :}
+COPTS.gethnamaddr.c+=	${${ACTIVE_CC} == gcc :? -fno-tree-ter :}
 .endif
 
 MAN+=	byteorder.3 ethers.3 gethostbyname.3 getifaddrs.3 \



CVS commit: src/lib/libc/net

2011-10-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 15 22:57:57 UTC 2011

Modified Files:
src/lib/libc/net: hesiod.c

Log Message:
use fparseln


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/net/hesiod.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/hesiod.c
diff -u src/lib/libc/net/hesiod.c:1.25 src/lib/libc/net/hesiod.c:1.26
--- src/lib/libc/net/hesiod.c:1.25	Tue Jan  4 19:09:43 2011
+++ src/lib/libc/net/hesiod.c	Sat Oct 15 18:57:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hesiod.c,v 1.25 2011/01/05 00:09:43 wiz Exp $	*/
+/*	$NetBSD: hesiod.c,v 1.26 2011/10/15 22:57:57 christos Exp $	*/
 
 /* Copyright (c) 1996 by Internet Software Consortium.
  *
@@ -51,7 +51,7 @@ __IDSTRING(rcsid_hesiod_p_h,
 #Id: hesiod_p.h,v 1.1 1996/12/08 21:39:37 ghudson Exp #);
 __IDSTRING(rcsid_hescompat_c,
 #Id: hescompat.c,v 1.1.2.1 1996/12/16 08:37:45 ghudson Exp #);
-__RCSID($NetBSD: hesiod.c,v 1.25 2011/01/05 00:09:43 wiz Exp $);
+__RCSID($NetBSD: hesiod.c,v 1.26 2011/10/15 22:57:57 christos Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include namespace.h
@@ -317,8 +317,7 @@ read_config_file(ctx, filename)
 	struct hesiod_p	*ctx;
 	const char	*filename;
 {
-	char	*key, *data, *p, **which;
-	char	 buf[MAXDNAME + 7];
+	char	*buf, *key, *data, *p, **which;
 	int	 n;
 	FILE	*fp;
 
@@ -344,10 +343,9 @@ read_config_file(ctx, filename)
 	}
 	ctx-lhs = NULL;
 	ctx-rhs = NULL;
-	while (fgets(buf, sizeof(buf), fp) != NULL) {
+	for (; (buf = fparseln(fp, NULL, NULL, NULL, FPARSELN_UNESCALL))
+	!= NULL; free(buf)) {
 		p = buf;
-		if (*p == '#' || *p == '\n' || *p == '\r')
-			continue;
 		while (*p == ' ' || *p == '\t')
 			p++;
 		key = p;
@@ -378,6 +376,7 @@ read_config_file(ctx, filename)
 			*which = strdup(data);
 			if (!*which) {
 errno = ENOMEM;
+free(buf);
 (void)fclose(fp);
 return -1;
 			}



CVS commit: src/lib/libc/net

2011-07-14 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Thu Jul 14 21:25:43 UTC 2011

Modified Files:
src/lib/libc/net: getprotoent.3

Log Message:
Complete prototypes, markup NULL, complete return values, more markup.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/net/getprotoent.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getprotoent.3
diff -u src/lib/libc/net/getprotoent.3:1.11 src/lib/libc/net/getprotoent.3:1.12
--- src/lib/libc/net/getprotoent.3:1.11	Thu Aug  7 16:43:09 2003
+++ src/lib/libc/net/getprotoent.3	Thu Jul 14 21:25:42 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: getprotoent.3,v 1.11 2003/08/07 16:43:09 agc Exp $
+.\	$NetBSD: getprotoent.3,v 1.12 2011/07/14 21:25:42 jruoho Exp $
 .\
 .\ Copyright (c) 1983, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\
 .\ @(#)getprotoent.3	8.1 (Berkeley) 6/4/93
 .\
-.Dd June 4, 1993
+.Dd July 15, 2011
 .Dt GETPROTOENT 3
 .Os
 .Sh NAME
@@ -49,8 +49,10 @@
 .Fn getprotobyname const char *name
 .Ft struct protoent *
 .Fn getprotobynumber int proto
+.Ft void
 .Fn setprotoent int stayopen
-.Fn endprotoent
+.Ft void
+.Fn endprotoent void
 .Sh DESCRIPTION
 The
 .Fn getprotoent ,
@@ -73,7 +75,7 @@
 .Ed
 .Pp
 The members of this structure are:
-.Bl -tag -width p_aliases
+.Bl -tag -width p_aliases -offset indent
 .It Fa p_name
 The official name of the protocol.
 .It Fa p_aliases
@@ -116,8 +118,17 @@
 .Dv EOF
 is encountered.
 .Sh RETURN VALUES
-Null pointer
-(0) returned on
+Upon success,
+.Fn getprotoent ,
+.Fn getprotobyname ,
+and
+.Fn getprotobynumber
+return a pointer to the
+.Vt protoent
+structure as described above.
+A
+.Dv NULL
+pointer is returned on
 .Dv EOF
 or error.
 .Sh FILES



CVS commit: src/lib/libc/net

2011-07-14 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Jul 14 22:12:30 UTC 2011

Modified Files:
src/lib/libc/net: getprotoent.3

Log Message:
New sentence, new line.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/net/getprotoent.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getprotoent.3
diff -u src/lib/libc/net/getprotoent.3:1.12 src/lib/libc/net/getprotoent.3:1.13
--- src/lib/libc/net/getprotoent.3:1.12	Thu Jul 14 21:25:42 2011
+++ src/lib/libc/net/getprotoent.3	Thu Jul 14 22:12:30 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: getprotoent.3,v 1.12 2011/07/14 21:25:42 jruoho Exp $
+.\	$NetBSD: getprotoent.3,v 1.13 2011/07/14 22:12:30 wiz Exp $
 .\
 .\ Copyright (c) 1983, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -92,7 +92,8 @@
 The
 .Fn setprotoent
 function
-opens and rewinds the file.  If the
+opens and rewinds the file.
+If the
 .Fa stayopen
 flag is non-zero,
 the net data base will not be closed after each call to



  1   2   >