I'm trying to include the following code in my program but the error ('inet_pton': identifier not found) will appeared.
// IPv4:
struct sockaddr_in ip4addr;
int s;
ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons(3490);
inet_pton(AF_INET, "10.0.0.1", &ip4addr.sin_addr);
s = socket(PF_INET, SOCK_STREAM, 0);
bind(s, (struct sockaddr*)&ip4addr, sizeof ip4addr);
Output
error C3861: 'inet_pton': identifier not found
the including header
#include <stdio.h>
#include <stdlib.h>
#include "udpDefine.h"
#include <windows.h>
any helping may be missed some headers or lib.
the function
is declared in header file:
if this is Windows (Vista or later) there is Winsock analog to this ANSI version:
try
#include <Ws2tcpip.h>
add Ws2_32.libIn windows XP (and later) you can use these functions:
Link with ws2_32 library.
To fix this problem just add the following to your code after all #includes
Windows users can also find the answer here:
https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-inetptonw
You need to use the
ws2tcpip.h
header and addWs2_32.lib
to your linker.In my case the function couldn't be found, because there was a "#define WINVER 0x0502" somewere in a header file.
On Windows systems the version 0x600 (= Vista) is as least required for this function.