convert ip address from string to uint in windows
2019.03.26
呼呼呼山
 热度
℃
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <windows.h> #include <winsock2.h> #include <ws2tcpip.h> #include <iphlpapi.h> #include <stdio.h> #pragma comment(lib,"Ws2_32.lib") using namespace std; int main() { struct sockaddr_in sa; char str[INET_ADDRSTRLEN]; inet_pton(AF_INET, "25.125.211.145", &(sa.sin_addr)); printf("%lu\n", sa.sin_addr); printf("%d\n", sa.sin_addr); inet_ntop(AF_INET, &(sa.sin_addr), str, INET_ADDRSTRLEN); printf("%s\n", str); getchar(); return 0; }
|