my goal is to successfully call the function inet_pton
in C.
I am using Windows 7. So far I learned that inet_pton
has 3 arguments. Besides, its job is to translate human IP representation into binary representation for the computer.
Details on my understanding of the arguments of inet_pton(a,b,c)
:
a
: An address_family. For example AF_INET
b
: A pointer to the human readable representation of the IP address (e.g."127.0.0.1").
c
: A pointer to the "thing" where the translated IP address (binary form) is stored.
In a tutorial I read it is said inet_pton
will store the translation inside the array c points to.
This page
https://msdn.microsoft.com/de-de/library/windows/desktop/cc805844(v=vs.85).aspx
tells me, that the third argument has the type PVOID
.
INT WSAAPI inet_pton(__in INT Family,__in PCTSTR pszAddrString,__out PVOID pAddrBuf);
In my opinion the receiving array should be an char array. But PVOID
is not equal to char.
The last idea I have is that a cast is involved, though I am only familiar with a cast in a situation like
buffer = (char*) malloc (i+1);
At the moment my code Looks like this:
#include <stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <windows.h>
#include <Winsock2.h>
#include <Ws2tcpip.h>
int main(int argc, char *argv[])
{
char *ptr2="127.0.0.1";
char buffe[512];
PVOID *ptr3;
PVOID ptr3=&buffe;
inet_pton(AF_INET,ptr2,ptr3);
system("PAUSE");
return 0;
}
How can I initialize the 3rd argument correctly (if it's necessary)? How to deal with the fact that the array storing the binary representation of the IP address should have the type char while the pointer should have the type PVOID
?
My compiler is complaining about conflicting types for ptr3. Thank you so much for your help.