First, WSAStartup function
int WSAStartup
(
WORD wVersionRequested,
LPWSADATA lpWSAData
);
A program using the socket must call the WSAStartup function before using the socket. The first parameter of the function indicates the version of the socket that the program requests to use, where the high byte indicates the secondary version, the low byte indicates the major version, and the operating system uses the second parameter to return the version information of the requested socket. When an application calls the WSAStartup function, the operating system searches for the corresponding socket library based on the requested version of the socket, and then binds the found socket library to the application. The application can then invoke the other socket functions in the requested socket library. The function returns 0 after successful execution. Example: If a program uses the 2.1 version of the socket, then the program code is as follows:
wVersionRequested = MAKEWORD( 2, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
Second, wsacleanup function int wsacleanup (void); After the application completes the use of the requested socket library, it calls the WSACleanup function to unbind the socket library and free the system resources that the socket library occupies.
Three-socket interface retrieves database functions for Internet information such as domain names, communication services, and protocols, such as
gethostbyaddr、gethostbyname、gethostname、getprotolbyname
getprotolbynumber、getserverbyname、getservbyport。
1.gethostname ()
"Function Prototypes"
int PASCAL FAR gethostname (Char FAR * name, int namelen);
"Instructions for use"
The function can get the host name of the local host, where:
name:< output > A pointer to a buffer that points to the acquired host name.
namelen:< the size of the input > buffer, in bytes.
Return value: If no error, return 0, otherwise, return the wrong generation.
2.gethostbyname ()
"Function Prototypes"
struct hostent FAR * PASCAL FAR gethostbyname (const char FAR * name);
"Instructions for use"
The function can get the corresponding "host" from the host name database.
The unique parameter name of the function is the hostname of the previous Call function GetHostName (). If there is no error, just return a batch pin pointing to the hostent structure, which identifies a "host" list.