Dialysis ICMP protocol (2): Windows Socket Introduction =============================== This article is from Bugfree / 9CBS platform: VC6 Windows XP
Introduction: ------- Windows's socket function has a lot, I have not made a detailed introduction, the functions here are briefly explained, for details, please refer to MSDN. The main purpose is to serve the next three applications .
Function Description: ---------
WSAStartup function initializes Winsock [declared] int WSASTARUP (Word WVersionRequested, LPWSADATA LPWSADATA); [Parameters] WVersionRequested - Requires the minimum version number of Winsock LPWSADATA - WINSOCK Details [Return Value] When the function is successfully called, return 0 failure when returning 0 failure 0 value ---
Socket function is used to generate Socket (Soket Descriptor) [Declared] Socket Socket (Int Af, INT TYPE, INT Protocol); [Parameter] AF - Address Family (Usually Use: AF_INET) Type - SOCKET Type SOCK_STREAM: Used for TCP Protocol SOCK_DGRAM: Used for UDP Protocol Protocol - The protocol used [Return Value] Returns to INVALID_SOCKET when the function returns a new socket (socket descriptor) fails when the function is successfully called. ---
INET_ADDR function address translation, convert "ABCD" IP address to 32-bit long integer [declared] unsigned long inet_addr (const char far * cp); [parameter] CP - pointing to the pointer of the IP address string [Return Value] When a function Returns IP address when the IP address represented by 32-bit integer is successfully invoked. ---
The gethostByname function acquires host information from the host name. [Declaration] Struct Hostent Far * GethostByName (Const Char Far * Name); [Parameter] Name - Pointer to the Host Name String [Return Value] When the function is successfully called, return host information failure Return null (null)
---
The RECV function accepts data using Socket. [Declaration] Int Recv (Socket S, CHAR FAR * BUF, INT LEN, INT FLAGS); [Parameter] S - Socket Descriptor BUF-receiving data with Socket Function (Socket ") Buffer ( Array) Pointer LEN - Buffer size FLAG - Call mode (MSG_PEEK or MSG_OOB) [Return Value] Returns to receive the number of bytes when successfully. If the connection is interrupted, return 0 failure, return SOCKET_ERROR
---
Sendto function sends data. [Declaration] Int Sendto (Socket S, Const Char Far * Buf, Int Len, Int Flags, Int token); [Parameters] S - Socket Descriptor generated by Socket Function BUF - Buffer (array) of the buffer (array) of the data, the size of the size of the buffer FLAG - call mode (MSG_DONTROUTE, MSG_OOB) TO - Pointer to the sender socket address TOKEN - the size of the sender Socket address [Return value] Returns the number of bytes already sent. Return to Socket_ERROR when fails
Link: ------- My other article, << dialysis ICMP protocol >>, and other articles see: http://www.9cbs.net/develop/author/netauthor/bugfree/ Contact: - ----- zhangliangsd@hotmail.com
Related Resources: Simple Ping Programs ICMP Protocol Using RawSocket