diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/getaddrinfo.3 | 47 | ||||
| -rw-r--r-- | src/lib/libc/net/getnameinfo.3 | 16 |
2 files changed, 29 insertions, 34 deletions
diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 index cc5eaa4182..4fba44bb73 100644 --- a/src/lib/libc/net/getaddrinfo.3 +++ b/src/lib/libc/net/getaddrinfo.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: getaddrinfo.3,v 1.34 2004/12/21 01:01:47 itojun Exp $ | 1 | .\" $OpenBSD: getaddrinfo.3,v 1.35 2004/12/21 03:40:31 jaredy Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") | 3 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") |
| 4 | .\" Copyright (C) 2000, 2001 Internet Software Consortium. | 4 | .\" Copyright (C) 2000, 2001 Internet Software Consortium. |
| @@ -27,7 +27,8 @@ | |||
| 27 | .Fd #include <sys/socket.h> | 27 | .Fd #include <sys/socket.h> |
| 28 | .Fd #include <netdb.h> | 28 | .Fd #include <netdb.h> |
| 29 | .Ft int | 29 | .Ft int |
| 30 | .Fn getaddrinfo "const char *hostname" "const char *servname" "const struct addrinfo *hints" "struct addrinfo **res" | 30 | .Fn getaddrinfo "const char *hostname" "const char *servname" \ |
| 31 | "const struct addrinfo *hints" "struct addrinfo **res" | ||
| 31 | .Ft void | 32 | .Ft void |
| 32 | .Fn freeaddrinfo "struct addrinfo *ai" | 33 | .Fn freeaddrinfo "struct addrinfo *ai" |
| 33 | .Sh DESCRIPTION | 34 | .Sh DESCRIPTION |
| @@ -98,7 +99,7 @@ operating system. | |||
| 98 | .It Fa ai_socktype | 99 | .It Fa ai_socktype |
| 99 | Denotes the type of socket that is wanted: | 100 | Denotes the type of socket that is wanted: |
| 100 | .Dv SOCK_STREAM , | 101 | .Dv SOCK_STREAM , |
| 101 | .Dv SOCK_DGRAM | 102 | .Dv SOCK_DGRAM , |
| 102 | or | 103 | or |
| 103 | .Dv SOCK_RAW . | 104 | .Dv SOCK_RAW . |
| 104 | When | 105 | When |
| @@ -140,11 +141,11 @@ and no name resolution should be attempted. | |||
| 140 | If the | 141 | If the |
| 141 | .Dv AI_PASSIVE | 142 | .Dv AI_PASSIVE |
| 142 | bit is set it indicates that the returned socket address structure | 143 | bit is set it indicates that the returned socket address structure |
| 143 | is intended for used in a call to | 144 | is intended for use in a call to |
| 144 | .Xr bind 2 . | 145 | .Xr bind 2 . |
| 145 | In this case, if the | 146 | In this case, if the |
| 146 | .Fa hostname | 147 | .Fa hostname |
| 147 | argument is a the null pointer, then the IP address portion of the | 148 | argument is the null pointer, then the IP address portion of the |
| 148 | socket address structure will be set to | 149 | socket address structure will be set to |
| 149 | .Dv INADDR_ANY | 150 | .Dv INADDR_ANY |
| 150 | for an IPv4 address or | 151 | for an IPv4 address or |
| @@ -158,7 +159,7 @@ for use in a call to | |||
| 158 | .Xr connect 2 | 159 | .Xr connect 2 |
| 159 | for a connection-oriented protocol or | 160 | for a connection-oriented protocol or |
| 160 | .Xr connect 2 , | 161 | .Xr connect 2 , |
| 161 | .Xr sendto 2 | 162 | .Xr sendto 2 , |
| 162 | or | 163 | or |
| 163 | .Xr sendmsg 2 | 164 | .Xr sendmsg 2 |
| 164 | if a connectionless protocol was chosen. | 165 | if a connectionless protocol was chosen. |
| @@ -167,7 +168,7 @@ The | |||
| 167 | address portion of the socket address structure will be set to the | 168 | address portion of the socket address structure will be set to the |
| 168 | loopback address if | 169 | loopback address if |
| 169 | .Fa hostname | 170 | .Fa hostname |
| 170 | is the null pointer and the | 171 | is the null pointer and |
| 171 | .Dv AI_PASSIVE | 172 | .Dv AI_PASSIVE |
| 172 | is not set. | 173 | is not set. |
| 173 | .El | 174 | .El |
| @@ -203,7 +204,7 @@ The list can be traversed by following the | |||
| 203 | pointer in each | 204 | pointer in each |
| 204 | .Li addrinfo | 205 | .Li addrinfo |
| 205 | structure until a null pointer is encountered. | 206 | structure until a null pointer is encountered. |
| 206 | The three members, | 207 | The three members |
| 207 | .Fa ai_family, | 208 | .Fa ai_family, |
| 208 | .Fa ai_socktype, | 209 | .Fa ai_socktype, |
| 209 | and | 210 | and |
| @@ -221,16 +222,17 @@ member points to a filled-in socket address structure of length | |||
| 221 | .Pp | 222 | .Pp |
| 222 | This implementation of | 223 | This implementation of |
| 223 | .Fn getaddrinfo | 224 | .Fn getaddrinfo |
| 224 | allows experimental numeric IPv6 address notation with scope identifier. | 225 | allows experimental numeric IPv6 address notation with scope identifiers. |
| 225 | By appending the percent character and scope identifier to addresses, | 226 | By appending the percent character and scope identifier to addresses, |
| 226 | you can fill the | 227 | one can fill the |
| 227 | .Li sin6_scope_id | 228 | .Li sin6_scope_id |
| 228 | field for addresses. | 229 | field for addresses. |
| 229 | This would make management of scoped address easier, | 230 | This would make management of scoped addresses easier |
| 230 | and allows cut-and-paste input of scoped address. | 231 | and allows cut-and-paste input of scoped addresses. |
| 231 | .Pp | 232 | .Pp |
| 232 | At this moment the code supports only link-local addresses with the format. | 233 | At this moment the code supports only link-local addresses with the format. |
| 233 | Scope identifier is hardcoded to the name of the hardware interface associated | 234 | The scope identifier is hardcoded to the name of the hardware interface |
| 235 | associated | ||
| 234 | with the link | 236 | with the link |
| 235 | .Po | 237 | .Po |
| 236 | such as | 238 | such as |
| @@ -276,31 +278,22 @@ structure created by a call to | |||
| 276 | returns zero on success or one of the error codes listed in | 278 | returns zero on success or one of the error codes listed in |
| 277 | .Xr gai_strerror 3 | 279 | .Xr gai_strerror 3 |
| 278 | if an error occurs. | 280 | if an error occurs. |
| 279 | If both | ||
| 280 | .Fa hostname | ||
| 281 | and | ||
| 282 | .Fa servname | ||
| 283 | are | ||
| 284 | .Dv NULL , | ||
| 285 | .Fn getaddrinfo | ||
| 286 | returns | ||
| 287 | .Dv EAI_NONAME . | ||
| 288 | .Sh EXAMPLES | 281 | .Sh EXAMPLES |
| 289 | The following code tries to connect to | 282 | The following code tries to connect to |
| 290 | .Dq Li www.kame.net | 283 | .Dq Li www.kame.net |
| 291 | service | 284 | service |
| 292 | .Dq Li http . | 285 | .Dq Li http |
| 293 | via stream socket. | 286 | via a stream socket. |
| 294 | It loops through all the addresses available, regardless of address family. | 287 | It loops through all the addresses available, regardless of address family. |
| 295 | If the destination resolves to an IPv4 address, it will use | 288 | If the destination resolves to an IPv4 address, it will use an |
| 296 | .Dv AF_INET | 289 | .Dv AF_INET |
| 297 | socket. | 290 | socket. |
| 298 | Similarly, if it resolves to IPv6, | 291 | Similarly, if it resolves to IPv6, an |
| 299 | .Dv AF_INET6 | 292 | .Dv AF_INET6 |
| 300 | socket is used. | 293 | socket is used. |
| 301 | Observe that there is no hardcoded reference to a particular address family. | 294 | Observe that there is no hardcoded reference to a particular address family. |
| 302 | The code works even if | 295 | The code works even if |
| 303 | .Nm getaddrinfo | 296 | .Fn getaddrinfo |
| 304 | returns addresses that are not IPv4/v6. | 297 | returns addresses that are not IPv4/v6. |
| 305 | .Bd -literal -offset indent | 298 | .Bd -literal -offset indent |
| 306 | struct addrinfo hints, *res, *res0; | 299 | struct addrinfo hints, *res, *res0; |
diff --git a/src/lib/libc/net/getnameinfo.3 b/src/lib/libc/net/getnameinfo.3 index ccb46faece..b83b9d5079 100644 --- a/src/lib/libc/net/getnameinfo.3 +++ b/src/lib/libc/net/getnameinfo.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: getnameinfo.3,v 1.34 2004/12/21 01:01:47 itojun Exp $ | 1 | .\" $OpenBSD: getnameinfo.3,v 1.35 2004/12/21 03:40:31 jaredy Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") | 3 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") |
| 4 | .\" Copyright (C) 2000, 2001 Internet Software Consortium. | 4 | .\" Copyright (C) 2000, 2001 Internet Software Consortium. |
| @@ -26,7 +26,8 @@ | |||
| 26 | .Fd #include <sys/socket.h> | 26 | .Fd #include <sys/socket.h> |
| 27 | .Fd #include <netdb.h> | 27 | .Fd #include <netdb.h> |
| 28 | .Ft int | 28 | .Ft int |
| 29 | .Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" "size_t hostlen" "char *serv" "size_t servlen" "int flags" | 29 | .Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" \ |
| 30 | "size_t hostlen" "char *serv" "size_t servlen" "int flags" | ||
| 30 | .Sh DESCRIPTION | 31 | .Sh DESCRIPTION |
| 31 | The | 32 | The |
| 32 | .Fn getnameinfo | 33 | .Fn getnameinfo |
| @@ -68,7 +69,7 @@ The maximum value for | |||
| 68 | is | 69 | is |
| 69 | .Dv NI_MAXHOST | 70 | .Dv NI_MAXHOST |
| 70 | and | 71 | and |
| 71 | the maximum value for | 72 | the maximum value for |
| 72 | .Fa servlen | 73 | .Fa servlen |
| 73 | is | 74 | is |
| 74 | .Dv NI_MAXSERV , | 75 | .Dv NI_MAXSERV , |
| @@ -95,7 +96,7 @@ instead of a host name. | |||
| 95 | A name is required. | 96 | A name is required. |
| 96 | If the host name cannot be found in DNS and this flag is set, | 97 | If the host name cannot be found in DNS and this flag is set, |
| 97 | a non-zero error code is returned. | 98 | a non-zero error code is returned. |
| 98 | If the host name is not found and the flag is not set, the | 99 | If the host name is not found and the flag is not set, the |
| 99 | address is returned in numeric form. | 100 | address is returned in numeric form. |
| 100 | .It NI_NUMERICSERV | 101 | .It NI_NUMERICSERV |
| 101 | The service name is returned as a digit string representing the port number. | 102 | 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 | |||
| 107 | .Dq udp | 108 | .Dq udp |
| 108 | instead of its default of | 109 | instead of its default of |
| 109 | .Dq tcp . | 110 | .Dq tcp . |
| 110 | This is required for the few ports (512-514) that have different services | 111 | This is required for the few ports (512\-514) that have different services |
| 111 | for | 112 | for |
| 112 | .Tn UDP | 113 | .Tn UDP |
| 113 | and | 114 | and |
| @@ -222,8 +223,9 @@ when it is actually | |||
| 222 | .Pp | 223 | .Pp |
| 223 | To prevent such attacks, the use of | 224 | To prevent such attacks, the use of |
| 224 | .Dv NI_NAMEREQD | 225 | .Dv NI_NAMEREQD |
| 225 | is recommended when you use the result of | 226 | is recommended when the result of |
| 226 | .Fn getnameinfo | 227 | .Fn getnameinfo |
| 228 | is used | ||
| 227 | for access control purposes: | 229 | for access control purposes: |
| 228 | .Bd -literal -offset indent | 230 | .Bd -literal -offset indent |
| 229 | struct sockaddr *sa; | 231 | struct sockaddr *sa; |
| @@ -241,7 +243,7 @@ if (error == 0) { | |||
| 241 | if (getaddrinfo(addr, "0", &hints, &res) == 0) { | 243 | if (getaddrinfo(addr, "0", &hints, &res) == 0) { |
| 242 | /* malicious PTR record */ | 244 | /* malicious PTR record */ |
| 243 | freeaddrinfo(res); | 245 | freeaddrinfo(res); |
| 244 | printf("bogus PTR record\\n"); | 246 | printf("bogus PTR record\en"); |
| 245 | return -1; | 247 | return -1; |
| 246 | } | 248 | } |
| 247 | /* addr is FQDN as a result of PTR lookup */ | 249 | /* addr is FQDN as a result of PTR lookup */ |
