#include <iostream>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#pragma comment (lib, "Ws2_32.lib")
int socket_client_demo(char* addr, int port) {
char recvbuf[1024] = { 0 };
int retVal = -1;
#if defined(_WIN32) || defined(_WIN64)
short family;
#else
sa_family_t family = AF_INET;
#endif
WSADATA ws;
SOCKET sock;
struct sockaddr_in address;
#if defined(AF_INET6)
struct sockaddr_in6 address6;
#endif
struct addrinfo* result = NULL;
struct addrinfo hints = { 0, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0, NULL, NULL, NULL };
if (WSAStartup(MAKEWORD(2, 2), &ws) != 0)
{
goto exit;
}
retVal = getaddrinfo(addr, NULL, &hints, &result);
if (retVal == 0)
{
struct addrinfo* res = result;
while (res)
{ /* prefer ip4 addresses */
if (res->ai_family
标签:include,struct,family,示例,windows,res,addrinfo,NULL,socket
From: https://blog.csdn.net/qq_45662588/article/details/137106527