c - What is the third argument for inet_pton()? -
My goal is to call the function inet_pton in C. I'm using Windows 7. By now I have come to know that inet_pton has 3 arguments. In addition, its job is to translate human IP representation into binary representation for computers.
Description on my understanding of the arguments of inet_pton (a, b, c) :
one : an address_family example For AF_INET
b : An indicator for human readable representation of IP addresses (such as "127.0.0.1")
c : An indicator for "talk" where the translated IP address (binary form) gets accumulated.
In a tutorial I have read it called inet_pton indicates the translation inside the array C.
This page
tells me that the third argument is PVOID type
INT WSAAPI inet_pton (In the INT family, in PCTSTR pszAddrString, __ out PVOID pAddrBuf); The array received in my opinion should be a four array. But my final idea is that an artist is included, although I am only familiar with an artist in a situation such as
buffer = ( Four *) malloc (i + 1); At the moment my code looks like this:
#include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; #to & lt include, stdio.h & gt; #include & lt; Windows.h & gt; # Include & lt; Winsock2.h & gt; # Include & lt; Ws2tcpip.h & gt; Int main (int argc, char * argv []) {char * ptr2 = "127.0.0.1"; Four buff [512]; PVOID * ptr3; PVOID ptr3 = & amp; Buffe; Inet_pton (AF_INET, ptr2, ptr3); System ("pause"); Return 0; } How can I start the third argument correctly (if it is necessary)? To deal with the fact that the array that aligns the binary representation of IP address should be of type char , while the type of indicator should be PVOID ?
My compiler is complaining about contradictory types for ptr3. Thank you very much for your help.
PVOD for an Typedef > Zero * which means that the third argument is expected of a general indicator PCTSTR eventually typedef either to const char * (If UNICODE is not defined) or const Wchar_t * (if Unicode is defined) See for more information about those specific types.
malloc () (hint:
sizeof (IN_ADDR)), So you can use the data type directly, which is expected: According to the first logic, when the family is AF_INET , the third argument is pAddrBuf Should be enough to hold IN_ADDR code>. Try doing something like this:
#include & lt; WinDef.h & gt; # Include & lt; Winsock2.h & gt; # Include & lt; Ws2tcpip.h & gt; Int main (int argc, char * argv []) {char ip_string [] = "127.0.0.1"; IN_ADDR ip_value; Inet_pton (AF_INET, ip_string, and ip_value); System ("pause"); Return 0; }
Comments
Post a Comment