Ad

Socket With Mingw32 On Windows, Implicit Declaration

- 1 answer

I have a problem coding with windows socket with MinGW-gcc.

I have a code that uses inetPton() function from windows sockets. I included winsock2.h, WS2tcpip.h.

The same code previously work in Visual Studio but is not working here. I have the message :

implicit declaration of function 'inetPton'; did you mean 'inet_ntoa'

I checked the content of the header "WS2tcpip.h" used by visual studio and inetPton() is declared in it. But in the "WS2tcpip.h" of MinGW there is no definition of inetPton().

Do you have any idea which header to include with MinGW-gcc ?

Thanks ;)

Ad

Answer

Ok I found the answer myself.

The sockets with windows is a mess so, instead of using inet_pton() that works with msvc and not with mingw32, I used WSAStringToAddress. It is working with mingw32 but I have not tested it with msvc.

SOCKADDR_IN sin;
char *ip_address="127.0.0.1";
int size_sock_addr_in = sizeof(sin);
WSAStringToAddress((LPSTR)ip_address, AF_INET, NULL, (LPSOCKADDR)&sin, (LPINT)&size_sock_addr_in);
Ad
source: stackoverflow.com
Ad