本文介绍了'inet_pton':未找到标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在我的程序中包括以下代码,但会出现错误('inet_pton':identifier not found)。
// 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);
输出
错误C3861:'inet_pton':未找到标识符
#include< stdio.h>
#include< stdlib.h>
#includeudpDefine.h
#include< windows.h>
任何帮助可能会错过一些标题或lib。
解决方案
函数
int inet_pton(int af,const char * src ,void * dst);
在头文件中声明:
#include< arpa / inet.h>
如果这是Windows(Vista或更高版本),Winsock类似于此ANSI版本:
$ b);
请尝试 #include< Ws2tcpip.h>
add Ws2_32.lib
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
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:
INT WSAAPI InetPton(
_In_ INT Family,
_In_ PCTSTR pszAddrString,
_Out_ PVOID pAddrBuf
);
try #include <Ws2tcpip.h>
add Ws2_32.lib
这篇关于'inet_pton':未找到标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!