Windows API Reference: Internet Protocols
Overview
This section provides documentation for Windows APIs related to Internet protocols. Developers can find information on implementing and managing network communications using various internet standards and protocols.
Key Protocols and APIs
-
TCP/IP Protocols
APIs for Transmission Control Protocol/Internet Protocol, the fundamental suite of communication protocols used for the Internet and similar computer networks.
-
HTTP and HTTPS
Documentation for Hypertext Transfer Protocol and its secure version, used for fetching resources like HTML documents.
-
DNS Resolution
APIs for the Domain Name System, which translates domain names into IP addresses.
-
Socket Programming
Information on Winsock (Windows Sockets API) for network communication across various protocols.
-
IPv6 Support
APIs and guidance for implementing and managing IPv6, the latest version of the Internet Protocol.
-
SSL/TLS Security
APIs for Secure Sockets Layer and Transport Layer Security for secure internet communications.
Common Tasks
Example Snippet
A basic example of creating a TCP socket using Winsock:
#include <winsock2.h>
#include <ws2tcpip.h>
// Link with Ws2_32.lib
#pragma comment(lib, "Ws2_32.lib")
int main() {
WSADATA wsaData;
SOCKET ConnectSocket = INVALID_SOCKET;
struct sockaddr_in clientService;
int iResult;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
// Create a SOCKET for connecting to server
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (ConnectSocket == INVALID_SOCKET) {
printf("Error at socket(): %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
// Setup the client structure
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr("127.0.0.1"); // Example IP
clientService.sin_port = htons(27015); // Example port
// Connect to server
iResult = connect(ConnectSocket, (SOCKADDR *) &clientService, sizeof(clientService));
if (iResult == SOCKET_ERROR) {
printf("connect failed with error: %ld\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
printf("Connected successfully!\n");
// Clean up
closesocket(ConnectSocket);
WSACleanup();
return 0;
}