summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/getaddrinfo.347
-rw-r--r--lib/libc/net/getnameinfo.316
2 files changed, 29 insertions, 34 deletions
diff --git a/lib/libc/net/getaddrinfo.3 b/lib/libc/net/getaddrinfo.3
index cc5eaa4182c..4fba44bb737 100644
--- a/lib/libc/net/getaddrinfo.3
+++ b/lib/libc/net/getaddrinfo.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: getaddrinfo.3,v 1.34 2004/12/21 01:01:47 itojun Exp $
+.\" $OpenBSD: getaddrinfo.3,v 1.35 2004/12/21 03:40:31 jaredy Exp $
.\"
.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
.\" Copyright (C) 2000, 2001 Internet Software Consortium.
@@ -27,7 +27,8 @@
.Fd #include <sys/socket.h>
.Fd #include <netdb.h>
.Ft int
-.Fn getaddrinfo "const char *hostname" "const char *servname" "const struct addrinfo *hints" "struct addrinfo **res"
+.Fn getaddrinfo "const char *hostname" "const char *servname" \
+ "const struct addrinfo *hints" "struct addrinfo **res"
.Ft void
.Fn freeaddrinfo "struct addrinfo *ai"
.Sh DESCRIPTION
@@ -98,7 +99,7 @@ operating system.
.It Fa ai_socktype
Denotes the type of socket that is wanted:
.Dv SOCK_STREAM ,
-.Dv SOCK_DGRAM
+.Dv SOCK_DGRAM ,
or
.Dv SOCK_RAW .
When
@@ -140,11 +141,11 @@ and no name resolution should be attempted.
If the
.Dv AI_PASSIVE
bit is set it indicates that the returned socket address structure
-is intended for used in a call to
+is intended for use in a call to
.Xr bind 2 .
In this case, if the
.Fa hostname
-argument is a the null pointer, then the IP address portion of the
+argument is the null pointer, then the IP address portion of the
socket address structure will be set to
.Dv INADDR_ANY
for an IPv4 address or
@@ -158,7 +159,7 @@ for use in a call to
.Xr connect 2
for a connection-oriented protocol or
.Xr connect 2 ,
-.Xr sendto 2
+.Xr sendto 2 ,
or
.Xr sendmsg 2
if a connectionless protocol was chosen.
@@ -167,7 +168,7 @@ The
address portion of the socket address structure will be set to the
loopback address if
.Fa hostname
-is the null pointer and the
+is the null pointer and
.Dv AI_PASSIVE
is not set.
.El
@@ -203,7 +204,7 @@ The list can be traversed by following the
pointer in each
.Li addrinfo
structure until a null pointer is encountered.
-The three members,
+The three members
.Fa ai_family,
.Fa ai_socktype,
and
@@ -221,16 +222,17 @@ member points to a filled-in socket address structure of length
.Pp
This implementation of
.Fn getaddrinfo
-allows experimental numeric IPv6 address notation with scope identifier.
+allows experimental numeric IPv6 address notation with scope identifiers.
By appending the percent character and scope identifier to addresses,
-you can fill the
+one can fill the
.Li sin6_scope_id
field for addresses.
-This would make management of scoped address easier,
-and allows cut-and-paste input of scoped address.
+This would make management of scoped addresses easier
+and allows cut-and-paste input of scoped addresses.
.Pp
At this moment the code supports only link-local addresses with the format.
-Scope identifier is hardcoded to the name of the hardware interface associated
+The scope identifier is hardcoded to the name of the hardware interface
+associated
with the link
.Po
such as
@@ -276,31 +278,22 @@ structure created by a call to
returns zero on success or one of the error codes listed in
.Xr gai_strerror 3
if an error occurs.
-If both
-.Fa hostname
-and
-.Fa servname
-are
-.Dv NULL ,
-.Fn getaddrinfo
-returns
-.Dv EAI_NONAME .
.Sh EXAMPLES
The following code tries to connect to
.Dq Li www.kame.net
service
-.Dq Li http .
-via stream socket.
+.Dq Li http
+via a stream socket.
It loops through all the addresses available, regardless of address family.
-If the destination resolves to an IPv4 address, it will use
+If the destination resolves to an IPv4 address, it will use an
.Dv AF_INET
socket.
-Similarly, if it resolves to IPv6,
+Similarly, if it resolves to IPv6, an
.Dv AF_INET6
socket is used.
Observe that there is no hardcoded reference to a particular address family.
The code works even if
-.Nm getaddrinfo
+.Fn getaddrinfo
returns addresses that are not IPv4/v6.
.Bd -literal -offset indent
struct addrinfo hints, *res, *res0;
diff --git a/lib/libc/net/getnameinfo.3 b/lib/libc/net/getnameinfo.3
index ccb46faecea..b83b9d5079f 100644
--- a/lib/libc/net/getnameinfo.3
+++ b/lib/libc/net/getnameinfo.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: getnameinfo.3,v 1.34 2004/12/21 01:01:47 itojun Exp $
+.\" $OpenBSD: getnameinfo.3,v 1.35 2004/12/21 03:40:31 jaredy Exp $
.\"
.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
.\" Copyright (C) 2000, 2001 Internet Software Consortium.
@@ -26,7 +26,8 @@
.Fd #include <sys/socket.h>
.Fd #include <netdb.h>
.Ft int
-.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" "size_t hostlen" "char *serv" "size_t servlen" "int flags"
+.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" \
+ "size_t hostlen" "char *serv" "size_t servlen" "int flags"
.Sh DESCRIPTION
The
.Fn getnameinfo
@@ -68,7 +69,7 @@ The maximum value for
is
.Dv NI_MAXHOST
and
-the maximum value for
+the maximum value for
.Fa servlen
is
.Dv NI_MAXSERV ,
@@ -95,7 +96,7 @@ instead of a host name.
A name is required.
If the host name cannot be found in DNS and this flag is set,
a non-zero error code is returned.
-If the host name is not found and the flag is not set, the
+If the host name is not found and the flag is not set, the
address is returned in numeric form.
.It NI_NUMERICSERV
The service name is returned as a digit string representing the port number.
@@ -107,7 +108,7 @@ to be called with a second argument of
.Dq udp
instead of its default of
.Dq tcp .
-This is required for the few ports (512-514) that have different services
+This is required for the few ports (512\-514) that have different services
for
.Tn UDP
and
@@ -222,8 +223,9 @@ when it is actually
.Pp
To prevent such attacks, the use of
.Dv NI_NAMEREQD
-is recommended when you use the result of
+is recommended when the result of
.Fn getnameinfo
+is used
for access control purposes:
.Bd -literal -offset indent
struct sockaddr *sa;
@@ -241,7 +243,7 @@ if (error == 0) {
if (getaddrinfo(addr, "0", &hints, &res) == 0) {
/* malicious PTR record */
freeaddrinfo(res);
- printf("bogus PTR record\\n");
+ printf("bogus PTR record\en");
return -1;
}
/* addr is FQDN as a result of PTR lookup */