⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inet.3

📁 ecos实时嵌入式操作系统
💻 3
字号:
.\"	$OpenBSD: inet.3,v 1.13 2001/02/17 23:13:26 pjanzen Exp $.\"	$NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $.\".\" Copyright (c) 1983, 1990, 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. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. 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..\".\"     @(#)inet.3	8.1 (Berkeley) 6/4/93.\".Dd June 18, 1997.Dt INET 3.Os.Sh NAME.Nm inet_addr ,.Nm inet_aton ,.Nm inet_lnaof ,.Nm inet_makeaddr ,.Nm inet_netof ,.Nm inet_network ,.Nm inet_ntoa ,.Nm inet_ntop ,.Nm inet_pton.Nd Internet address manipulation routines.Sh SYNOPSIS.Fd #include <sys/socket.h>.Fd #include <netinet/in.h>.Fd #include <arpa/inet.h>.Ft in_addr_t.Fn inet_addr "const char *cp".Ft int.Fn inet_aton "const char *cp" "struct in_addr *addr".Ft in_addr_t.Fn inet_lnaof "struct in_addr in".Ft struct in_addr.Fn inet_makeaddr "unsigned long net" "unsigned long lna".Ft in_addr_t.Fn inet_netof "struct in_addr in".Ft in_addr_t.Fn inet_network "const char *cp".Ft char *.Fn inet_ntoa "struct in_addr in".Ft const char *.Fn inet_ntop "int af" "const void *src" "char *dst" "size_t size".Ft int.Fn inet_pton "int af" "const char *src" "void *dst".Sh DESCRIPTIONThe routines.Fn inet_aton ,.Fn inet_addrand.Fn inet_networkinterpret character strings representingnumbers expressed in the Internet standard.Ql \&.notation.The.Fn inet_ptonfunction converts a presentation format address (that is, printable formas held in a character string) to network format (usually a.Li struct in_addror some other internal binary representation, in network byte order).It returns 1 if the address was valid for the specified address family, or0 if the address wasn't parseable in the specified address family, or \-1if some system error occurred (in which case.Va errnowill have been set).This function is presently valid for.Dv AF_INETand.Dv AF_INET6 .The.Fn inet_atonroutine interprets the specified character string as an Internet address,placing the address into the structure provided.It returns 1 if the string was successfully interpreted,or 0 if the string was invalid.The.Fn inet_addrand.Fn inet_networkfunctions return numbers suitable for useas Internet addresses and Internet networknumbers, respectively..PpThe function.Fn inet_ntopconverts an address from network format (usually a.Li struct in_addror some other binary form, in network byte order) to presentation format(suitable for external display purposes).It returns.Dv NULLif a systemerror occurs (in which case,.Va errnowill have been set), or it returns a pointer to the destination string.The routine.Fn inet_ntoatakes an Internet address and returns an.Tn ASCIIstring representing the address in.Ql \&.notation.The routine.Fn inet_makeaddrtakes an Internet network number and a localnetwork address and constructs an Internet addressfrom it.The routines.Fn inet_netofand.Fn inet_lnaofbreak apart Internet host addresses, returningthe network number and local network address part,respectively..PpAll Internet addresses are returned in networkorder (bytes ordered from left to right).All network numbers and local address parts arereturned as machine format integer values..Sh INTERNET ADDRESSES (IP VERSION 4)Values specified using the.Ql \&.notation take oneof the following forms:.Bd -literal -offset indenta.b.c.da.b.ca.ba.Ed.PpWhen four parts are specified, each is interpretedas a byte of data and assigned, from left to right,to the four bytes of an Internet address.Note that when an Internet address is viewed as a 32-bitinteger quantity on a system that uses little-endianbyte order (such as the.Tn Intel 386, 486and.Tn Pentiumprocessors) the bytes referred to above appear as.Dq Li d.c.b.a .That is, little-endian bytes are ordered from right to left..PpWhen a three part address is specified, the lastpart is interpreted as a 16-bit quantity and placedin the rightmost two bytes of the network address.This makes the three part address format convenientfor specifying Class B network addresses as.Dq Li 128.net.host ..PpWhen a two part address is supplied, the last partis interpreted as a 24-bit quantity and placed inthe rightmost three bytes of the network address.This makes the two part address format convenientfor specifying Class A network addresses as.Dq Li net.host ..PpWhen only one part is given, the value is storeddirectly in the network address without any byterearrangement..PpAll numbers supplied as.Dq partsin a.Ql \&.notationmay be decimal, octal, or hexadecimal, as specifiedin the C language (i.e., a leading 0x or 0X implieshexadecimal; otherwise, a leading 0 implies octal;otherwise, the number is interpreted as decimal)..Sh INTERNET ADDRESSES (IP VERSION 6)In order to support scoped IPv6 addresses,.Xr getaddrinfo 3and.Xr getnameinfo 3are recommended rather than the functions presented here..PpThe presentation format of an IPv6 address is given in [RFC1884 2.2]:.PpThere are three conventional forms for representing IPv6 addresses astext strings:.Bl -enum.ItThe preferred form is x:x:x:x:x:x:x:x, where the 'x's are thehexadecimal values of the eight 16-bit pieces of the address.Examples:.Bd -literal -offset indentFEDC:BA98:7654:3210:FEDC:BA98:7654:32101080:0:0:0:8:800:200C:417A.Ed.PpNote that it is not necessary to write the leading zeros in anindividual field, but there must be at least one numeral inevery field (except for the case described in 2.)..ItDue to the method of allocating certain styles of IPv6addresses, it will be common for addresses to contain longstrings of zero bits.In order to make writing addresses.Ppcontaining zero bits easier a special syntax is available tocompress the zeros.The use of.Dq \&:\&:indicates multiple groupsof 16 bits of zeros.The.Dq \&:\&:can only appear once in anaddress.The.Dq \&:\&:can also be used to compress the leading and/or trailing zeros in an address..PpFor example the following addresses:.Bd -literal -offset indent1080:0:0:0:8:800:200C:417A  a unicast addressFF01:0:0:0:0:0:0:43         a multicast address0:0:0:0:0:0:0:1             the loopback address0:0:0:0:0:0:0:0             the unspecified addresses.Ed.Ppmay be represented as:.Bd -literal -offset indent1080::8:800:200C:417A       a unicast addressFF01::43                    a multicast address::1                         the loopback address::                          the unspecified addresses.Ed.ItAn alternative form that is sometimes more convenient whendealing with a mixed environment of IPv4 and IPv6 nodes isx:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal valuesof the six high-order 16-bit pieces of the address, and the 'd'sare the decimal values of the four low-order 8-bit pieces of theaddress (standard IPv4 representation).Examples:.Bd -literal -offset indent0:0:0:0:0:0:13.1.68.30:0:0:0:0:FFFF:129.144.52.38.Ed.Ppor in compressed form:.Bd -literal -offset indent::13.1.68.3::FFFF:129.144.52.38.Ed.El.Sh DIAGNOSTICSThe constant.Dv INADDR_NONEis returned by.Fn inet_addrand.Fn inet_networkfor malformed requests..Sh SEE ALSO.Xr byteorder 3 ,.Xr gethostbyname 3 ,.Xr getnetent 3 ,.Xr inet_net 3 ,.Xr hosts 5 ,.Xr networks 5.Sh STANDARDSThe.Nm inet_ntopand.Nm inet_ptonfunctions conforms to the IETF IPv6 BSD API and address formattingspecifications.Note that.Nm inet_ptondoes not accept 1-, 2-, or 3-part dotted addresses; all four partsmust be specified.This is a narrower input set than that accepted by.Nm inet_aton ..Sh HISTORYThe.Nm inet_addr ,.Nm inet_network ,.Nm inet_makeaddr ,.Nm inet_lnaofand.Nm inet_netoffunctions appeared in.Bx 4.2 .The.Nm inet_atonand.Nm inet_ntoafunctions appeared in.Bx 4.3 .The.Nm inet_ptonand.Nm inet_ntopfunctions appeared in BIND 4.9.4..Sh BUGSThe value.Dv INADDR_NONE(0xffffffff) is a valid broadcast address, but.Fn inet_addrcannot return that value without indicating failure.Also,.Fn inet_addrshould have been designed to return a.Li struct in_addr .The newer.Fn inet_atonfunction does not share these problems, and almost all existing codeshould be modified to use.Fn inet_atoninstead..PpThe problem of host byte ordering versus network byte ordering isconfusing..PpThe string returned by.Fn inet_ntoaresides in a static memory area.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -