sockaddr_in serverAddress{};
serverAddress.sin_addr.S_un.S_un_b.s_b1=127;
serverAddress.sin_addr.S_un.S_un_b.s_b2=0;
serverAddress.sin_addr.S_un.S_un_b.s_b3=0;
serverAddress.sin_addr.S_un.S_un_b.s_b4=1;
手动将ip硬编码。结构体格式参考
https://learn.microsoft.com/zh-cn/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_pton
https://learn.microsoft.com/zh-cn/windows/win32/api/winsock2/ns-winsock2-in_addr
INT WSAAPI inet_pton(
[in] INT Family,
[in] PCSTR pszAddrString,
[out] PVOID pAddrBuf
);
第三个参数即为该结构体:
struct in_addr {
union {
struct {
u_char s_b1;
u_char s_b2;
u_char s_b3;
u_char s_b4;
} S_un_b;
struct {
u_short s_w1;
u_short s_w2;
} S_un_w;
u_long S_addr;
} S_un;
};