“inet_pton":找不到标识符标识符、找不到、inet_pton、quot

2023-09-07 12:37:20 作者:你的名字再不是我的心事

我试图在我的程序中包含以下代码,但会出现错误('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, "10.0.0.1", &ip4addr.sin_addr);

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

输出

 error C3861: 'inet_pton': identifier not found

包含标题

 #include <stdio.h>
 #include <stdlib.h>
 #include "udpDefine.h"
 #include <windows.h>

任何帮助都可能会遗漏一些标头或库.

any helping may be missed some headers or lib.

推荐答案

函数

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

在头文件中声明:

#include <arpa/inet.h>

如果这是 Windows(Vista 或更高版本),则有与此 ANSI 版本类似的 Winsock:

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

INT WSAAPI InetPton(
  _In_   INT  Family,
  _In_   PCTSTR pszAddrString,
  _Out_  PVOID pAddrBuf
);

试试#include <Ws2tcpip.h>添加 Ws2_32.lib

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

 
精彩推荐
图片推荐