简体   繁体   中英

Socket with mingw32 on windows, implicit declaration

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;)

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM