I'm trying to convert an IP address in network order into a dotted decimal string... I cannot seem to figure out how to do this! I've been looking for AGES. I've tried the following ways but they both do absolutely nothing :/
Code:
#include <iostream>
#include <Winsock2.h>
#include <Ws2tcpip.h>
using namespace std;
int main() {
sockaddr_in serv;
memset(&serv, sizeof(serv), 0);
serv.sin_addr.S_un.S_addr = inet_addr("192.168.1.1");
serv.sin_family = AF_INET;
serv.sin_port = htons(22);
char ip[16] = {0};
WSAAddressToString((sockaddr *)&serv, sizeof(serv), 0, ip, (LPDWORD)sizeof(ip));
printf("IP: %s\n", ip);
getnameinfo((sockaddr *)&serv, sizeof(serv), 0, 0, ip, sizeof(ip), 0);
printf("IP: %s\n", ip);
}
Output:
I'm using Windows XP which is why I'm not using inetNtop or whatever it is... (It's Vista only apparently). Compiler is Visual C++ Express. Thanks.