abdo.eng 2006210 abdo.eng 2006210 - 5 months ago 37
Linux Question

'inet_pton': identifier not found

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, "", &ip4addr.sin_addr);

s = socket(PF_INET, SOCK_STREAM, 0);
bind(s, (struct sockaddr*)&ip4addr, sizeof ip4addr);


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

int inet_pton(int af, const char *src, void *dst);

is declared in header file:

#include <arpa/inet.h>

if this is Windows (Vista or later) there is Winsock analog to this ANSI version:

  _In_   INT  Family,
  _In_   PCTSTR pszAddrString,
  _Out_  PVOID pAddrBuf

try #include <Ws2tcpip.h> add Ws2_32.lib