Network function

zhaozj2021-02-16  196

S: Identify a description of a connected interface.

NAME: The name structure of the receiving end address.

Namelen: a pointer pointing to the name structure.

Note:

The getPeerName () function is used to get the port name bundled with it from port s and store it in SockAddr.

Type Name structure. It applies to datagrams or stream sockets.

return value:

If there is no error, getPeerName () returns 0. Otherwise, return to Socket_ERROR, the application

The order can obtain the corresponding error code by wsagetlasterror ().

error code:

WSANotInitialiad: WSAStartup () should be successfully called before using this API.

WSAENETDOWN: Windows Set Interface Implementation Detecting Network Subsystem Failure.

WSAEFAULT: Namelen parameters are not big enough.

WSAEINPROGRESS: A blocking Windows socket call is running.

The WSAENOTCONN socket is not connected.

WSAENOTSOCK: Description word is not a set of interfaces.

See:

Bind (), socket (), getSockName ().

5.1.6 getSockName ()

Brief description:

Get the local name of a set of interfaces.

#include

Int Pascal Far GetsockName (Socket S, Struct Sockaddr Far * Name,

INT FAR * NAMELEN;

S: Identify a description word for a bundled interface.

Name: Receive address (name) of the socket.

Namelen: Name buffer length.

Note:

The getSockName () function is used to get the name of a set of interfaces. It is used for a bundled or connected tape

The port s, the local address will be returned. This call is particularly applicable to the following cases: no bind () is called

CONNECT (), only getSockName () calls can know the local address of the system. When returning,

The Namelen parameter contains the number of actual bytes of the name.

If a socket is bundled with INADDR_any, that is, the socket can be used with any host

Site, at this time, getSockName () will not return host IP unless Connect () or accept () is invoked.

Any information on the address. Unless the interface is connected, the Windows socket application should not assume IP addresses

Will get from INADDR_Any into other addresses. This is because for multiple host environments, unless the socket is

Connect, otherwise the IP address used by the socket is unknown.

return value:

If there is no error, getSockName () returns 0. Otherwise, return to the socket_error error,

The application can get the corresponding error code via WSageTlasterror ().

error code:

WSANotInitialiad: WSAStartup () should be successfully called before using this API.

WSAENETDOWN: Windows Set Interface Implementation Detecting Network Subsystem Failure.

WSAEFAULT: Namelen parameters are not big enough.

WSAEINPROGRESS: A blocking Windows socket call is running.

WSAENOTSOCK: Description word is not a set of interfaces.

WSAEINVAL: The socket is not bundled with bind ().

See:

Bind (), socket (), getPeername ().

5.1.7 getsockopt ()

Brief description:

Get a socket option.

#include int Pascal Far getSockopt (Socket S, Int Level, Int Optname,

Char Far * Optval, int far * optlen;

S: A description word that identifies the socket.

Level: Options defined hierarchy. The supported level has only SOL_Socket and IPPROTO_TCP.

Optname: The socket options you need to get.

OptVal: The pointer points to the buffer where the selected option value is stored.

Optlen: Pointer, pointing to the length value of the OptVal buffer.

Note:

The getSockopt () function is used to get any type, any status set of options, and save the results

Into OptVal. There is an option on different protocol layers, but it is often at the highest "socket" hierarchy.

Options affect the operation of the socket, such as the occlusion or not, the package is selected, and the delivery of external data, etc.

The value of the selected option is placed in the OptVal buffer. The shape of the shape pointed to by Optlen contains a buffer at the initial time.

The length is set to the length of the actual value when the call is returned. For the SO_LINGER option, it is equivalent to Linger

The size of the structure, is a size of an integer number of other options.

If a setSockOpt () call is not performed, getSockOpt () returns the system default.

GetSockOpt () supports the following options. The "Type" field indicates the value pointed to by OptVal. Only

The TCP_NodeLay option uses the ipproto_tcp layer; the rest of the options use SOL_SOCKET

Floor.

Option type meaning

The SO_ACCEPTCONN BOOL socket is in listening with Listen ().

The SO_BROADCAST BOOL socket is set to transmit broadcast information.

SO_DEBUG BOOL allows debugging.

If the SO_DONTLINER BOOL is true, the SO_LINGER option is disabled.

SO_DONTROUTE BOOL prohibits the selection.

SO_ERROR INT Gets the error status and clears.

SO_KEEPAlive Bool Sends "Keep Activity".

SO_LINGER STRUCT LINGER FAR * Returns the current linger option.

SO_OOBINLINE BOOL receives out-of-band data in a normal data stream.

SO_RCVBUF INT Receives buffer sizes.

The SO_REUSEADDR BOOL socket can be bundled with an address already used in use.

SO_SNDBUF INT Sends buffer size.

SO_TYPE INT socket type (such as Sock_Stream).

TCP_Nodelay Bool prohibits sending a merged Nagle algorithm.

The BSD options that getsockopt () are:

Option name type meaning

SO_RCVLOWAT INT Receives low-level watermarks.

SO_RCVTIMEO INT receives timeout.

SO_SNDLOWAT INT Sends a low-level watermark.

SO_SNDTIMEO INT Send timeout.

IP_OPTIONS Gets the options in the IP header.

TCP_MAXSEG INT Gets the length of the TCP maximum segment.

Use a unsupported option to call getSockopt () will return a WSAENoProtoopt error

Misused code (available for wsagetlasterror ()).

return value:

If there is no error, getSockOpt () returns 0. Otherwise, return to the socket_error error, the application can get the corresponding error code via WSageTlasterror ().

error code:

WSANotInitialiad: WSAStartup () should be successfully called before using this API.

WSAENETDOWN: Windows Set Interface Implementation Detecting Network Subsystem Failure.

WSAEFAULT: OPTLEN parameters illegally.

WSAEINPROGRESS: A blocking Windows socket call is running.

WSAENOPROTOOPT: Unknown or does not support the option. Among them, the socket_stream type of the socket

The mouth does not support the SO_Broadcast option, the socket interface of the SOCK_DGRAM type does not support

SO_ACCEPTCONN, SO_DONTLINGER, SO_KEEPALIVE, SO_LINGER and

SO_OOBINLINE options.

WSAENOTSOCK: Description word is not a set of interfaces.

See:

Setsockopt (), wsaasyncselect (), socket ().

5.1.8 htonl ()

Brief description:

Convert the number of unsigned long shapes of the host into network byte order.

#include

u_long pascal far htonl; u_long hostlong;

Hostlong: 32 digits expressed in host byte sequence.

Note:

This function converts a 32-bit number into a network byte order from host byte.

return value:

Htonl () returns a value of a network byte order.

See:

Htons (), NTOHL (), NTOHS ().

5.1.9 htons ()

Brief description:

Convert the host's non-symbolic short-integrated number into network byte order.

#include

U_SHORT PASCAL FAR HTONS (U_SHORT HOSTSHORT);

Hostshort: The 16-digit of the host byte sequence is expressed.

Note:

This function converts a 16-bit number from host byte to network byte order.

return value:

Htons () returns a value of a network byte order.

See:

HTONL (), NTOHL (), NTOHS ().

5.1.10 inet_addr ()

Brief description: Convert a point interval address into an in_addr.

#include

Unsigned long pascal far inet_addr (const struct far * cp);

CP: A string of internet standard ".".

Note:

This function explains the string in the CP parameter, which uses the Internet "." Interval format indicates one

Digital Internet Address. The return value can be used as an Internet address. All Internet addresses in network byte order

Return (byte from left to right).

The address of the Internet address "." Can have the following ways:

A.b.c.d, a.b.c, a.b, a

When four parts have a value, each interprets into one byte data, consisting of INTERNET from left to right.

The section address. Note that when an Internet address is indicated on the Intel machine, it is a 32-bit integer number.

The above bytes are "d.c.b.a". This is because the INTEL processor's byte is arranged from right to left.

Please note: Only Berkeley supports the following expressions, the rest of the Internet is not supported. Consider with soft

The compatibility should be used as required.

For a three part address, the last part explains 16-bit data and as the top right of the network address. In this way, the three part addresses easily represent B group network addresses, such as "128.Net.host".

For a two part address, the last part explains 24-bit data and as the hardest word of the network address.

In this way, the two part addresses easily represent the C group network address, such as "net.host".

For only one part of the address, it is stored directly into the network address without any bytes.

return value:

If there is no error, inet_addr () returns an unsigned long-intensive number, where appropriate byte order

Internet address. If the incoming string is not a legitimate Internet address, such as "a.b.c.d" address

Any item exceeds 255, then inet_addr () returns INADDR_NONE.

See:

inet_ntoa ().

5.1.11 inet_ntoa ()

Brief description:

Convert network addresses to ".". String string format.

#include

Char Far * Pascal Far inet_ntoa (struct in_addr in);

IN: A structure representing the Internet host address.

Note:

This function converts an Internet address structure represented by the IN parameter to "." Intervals.

"A.b.c.d" string form. Please note that the string returned by inet_ntoa () is stored in the Windows Set

The mouth implementation is allocated. The application should not assume how the memory is assigned. In the same thread

Before the next Windows socket call, the data will guarantee that it is valid.

return value:

If there is no error, INET_NTOA () returns a character pointer. Otherwise, return NVLL. Number of

It should be copied before the next Windows socket call is called.

See:

inet_addr ().

5.1.12 ioctlsocket ()

Brief description:

Control the mode of the socket interface.

#include

Int Pascal Far ioctlsocket (Socket S, Long CMD, U_LONG FAR * ARGP);

S: A description word that identifies the socket.

CMD: The operation command of the set of interface s.

Argp: Pointer to the parameters of the CMD command.

Note:

This function can be used for any set of interfaces in either state. It is used to obtain operational parameters related to the socket, and

Not related to specific agreements or communication subsystems. Support the following commands:

Fionbio: Allow or disable the non-blocking mode of the socket S. Argp points to an unsigned long integer. Such as

Allows non-blocking mode, non-zero, if the non-blocking mode is prohibited, it is zero. When you create a set of interfaces, it is

The blocking mode (that is, the non-blocking mode is prohibited). This is consistent with the BSD socket.

The wsaasynselect () function automatically sets the socket to non-blocking mode. If a socket has been made

WSAAsYNSELECT (), any use of ioctlsocket () to reset the interface to block mode

The figure will fail with WSAEINVAL. In order to reset the socket to block mode, the application must first

Use wsaasynselect () call (IEvent parameter set to 0) to ban wsaasynselect ().

FionRead: Determines the amount of data automatically read in the socket. Argp points to an unsigned long integer,

There is an ioctlsocket () return value. If S is a socket_stream type, FionRead returns

Back in all the amounts of data received in a RECV (). This is usually the same as the total amount of data queued in the socket.

If S is SOCK_DGRAM type, FionRead returns the first data report size queued on the interface.

Siocatmark: Individual data has been read. This order is only available

Sock_stream type socket, and the interface has been set to receive external data online

(SO_OOBINLINE). If there is no external data waiting to be read, then the operation returns true. if not

Returns false fake, the next RECV () or RECVFROM () operation will retrieve some of the "tag" or all data.

The application can use the SiocatMark operation to determine if there is data left. If in "emergency" (outside)

There is regular data before the data, then receive these data in order (please note that the RECV () and Recvfrom () will not

Confused regular data and out-of-band data in one call). Argp points to a BOOL type, IOCTLSocket () is

The return value is deposited.

compatibility:

This function is a subset of the Berkeley socket function IOCTL (). Among them, there is no fioasync equivalent.

Command, Siocatmark is the only command supported by the interface level support.

return value:

After success, IOCTLSOCKET () returns 0. Otherwise, return to Socket_ERROR Error, Application

The corresponding error code can be obtained via WsageTlasterror ().

error code:

WSANotInitialiad: WSAStartup () should be successfully called before using this API.

WSAENETDOWN: Windows Set Interface Implementation Detecting Network Subsystem Failure.

WSAEINVAL: CMD is an illegal command, or the parameters referred to as Argp do not apply to the cmd command, or

This command

Not applicable to this type of socket.

WSAEINPROGRESS: A blocking Windows socket call is running.

WSAENOTSOCK: Description word is not a set of interfaces.

See:

Socket (), setsockopt (), getsockopt (), wsaasyncselect ().

5.1.13 listen ()

Brief description:

Create a set of interfaces and listen to the connection.

#include

Int Pascal Far Listen (Socket S, INT Backlog);

S: Used to identify a descriptor that has been bundled unconnected interface.

Backlog: Wait for the maximum length of the connection queue.

Note:

In order to accept the connection, first create a set of interfaces with Socket (), then use listen () to apply for access

转载请注明原文地址:https://www.9cbs.com/read-8545.html

New Post(0)