分类: LINUX
2007-11-25 14:20:45
|
2. inet_addr
the windows sockets inet_addr function converts a string containing an (ipv4) internet protocol dotted address into a proper address for the in_addr structure. unsigned long inet_addr ( const char far * cp ); parameters cp [in] a null-terminated character string representing a number expressed in the internet standard ". (dotted) notation. remarks the inet_addr function interprets the character string specified by the cp parameter. this string represents a numeric internet address expressed in the internet standard ". notation. the value returned is a number suitable for use as an internet address. all internet addresses are returned in ips network order (bytes ordered from left to right). internet addresses values specified using the ". notation take one of the following forms: a.b.c.d a.b.c a.b a when four parts are specified, each is interpreted as a byte of data and assigned, from left to right, to the four bytes of an internet address. when an internet address is viewed as a 32-bit integer quantity on the intel architecture, the bytes referred to above appear as "d.c.b.a. that is, the bytes on an intel processor are ordered from right to left. the parts that make up an address in "." notation can be decimal, octal or hexidecimal as specified in the c language. numbers that start with "0x" or "0x" imply hexidecimal. numbers that start with "0" imply octal. all other numbers are interpreted at decimal. "4.3.2.16" decimal "004.003.002.020" octal "0x4.0x3.0x2.0x10" hexidecimal "4.003.002.0x10" mix note the following notations are only used by berkeley, and nowhere else on the internet. in the interests of compatibility with their software, they are supported as specified. when a three part address is specified, the last part is interpreted as a 16-bit quantity and placed in the right most two bytes of the network address. this makes the three part address format convenient for specifying class b network addresses as "128.net.host. when a two part address is specified, the last part is interpreted as a 24-bit quantity and placed in the right most three bytes of the network address. this makes the two part address format convenient for specifying class a network addresses as "net.host. when only one part is given, the value is stored directly in the network address without any byte rearrangement. return values if no error occurs, inet_addr returns an unsigned long value containing a suitable binary representation of the internet address given. if the string in the cp parameter does not contain a legitimate internet address, for example if a portion of an "a.b.c.d" address exceeds 255, inet_addr returns the value inaddr_none. quickinfo windows nt: yes windows: yes windows ce: use version 1.0 and later. header: declared in winsock2.h. import library: link with ws2_32.lib. |
3. inet_ntoa
the windows sockets inet_ntoa function converts an (ipv4) internet network address into a string in internet standard dotted format. char far * inet_ntoa ( struct in_addr in ); parameters in [in] a structure that represents an internet host address. remarks the inet_ntoa function takes an internet address structure specified by the in parameter and returns an ascii string representing the address in ". (dot) notation as in "a.b.c.d. the string returned by inet_ntoa resides in memory that is allocated by windows sockets. the application should not make any assumptions about the way in which the memory is allocated. the data is guaranteed to be valid until the next windows sockets function call within the same thread, but no longer. therefore, the data should be copied before another windows sockets call is made. return values if no error occurs, inet_ntoa returns a char pointer to a static buffer containing the text address in standard ". notation. otherwise, it returns null. quickinfo windows nt: yes windows: yes windows ce: use version 1.0 and later. header: declared in winsock2.h. import library: link with ws2_32.lib. |
4. gethostbyaddr
the windows sockets gethostbyaddr function retrieves the host information corresponding to a network address. struct hostent far * gethostbyaddr ( const char far * addr, int len, int type ); parameters addr [in] a pointer to an address in network byte order. len [in] the length of the address. type [in] the type of the address. remarks the gethostbyaddr function returns a pointer to the hostent structure that contains the name and address corresponding to the given network address. all strings are null-terminated. return values if no error occurs, gethostbyaddr returns a pointer to the hostent structure. otherwise, it returns a null pointer, and a specific error code can be retrieved by calling wsagetlasterror. error codes wsanotinitialised a successful wsastartup must occur before using this function. wsaenetdown the network subsystem has failed. wsahost_not_found authoritative fabiao host not found. wsatry_again non-authoritative host not found, or server failed. wsano_recovery nonrecoverable error occurred. wsano_data valid name, no data record of requested type. wsaeinprogress a blocking windows sockets 1.1 call is in progress, or the service provider is still processing a callback function. wsaeafnosupport the type specified is not supported by the windows sockets implementation. wsaefault the addr parameter is not a valid part of the user address space, or the len parameter is too small. wsaeintr a blocking windows socket 1.1 call was canceled through wsacancelblockingcall. quickinfo windows nt: yes windows: yes windows ce: use version 1.0 and later. header: declared in winsock2.h. import library: link with ws2_32.lib. |