InetNtop:找不到它使用哪个头 [英] InetNtop: can't find which header it is using

查看:441
本文介绍了InetNtop:找不到它使用哪个头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道为使用InetNtop函数必须包含什么头文件?

我试过winsock2.h,ws2tcpip.h和我包括Ws2_32 librabry。我使用windows 7

这是我的错误,我得到一个编译时间:InetNtop:函数无法解决



编辑:

char temp [10];

int bytes_recv = Recv(temp,sizeof(temp));

char result [INET_ADDRSTRLEN]; < br>
InetNtop(AF_INET,(void *)(& temp [4]),result,sizeof(result));


解决方案

根据文档 Ws2tcpip.h 是它的实际头文件。



编辑:



根据文档, em>需要代码编译为Windows Vista或更高版本。由于您 包含必要的标头,但该函数不可见,因此我猜测您尚未设置适当的定义或编译器选项,以便为适当的版本编译代码。



您使用的实际Windows版本并不重要 - 您正在编译(即目标版本)是



2:



您应该如下所述添加正确的 #define 指令此处指示要编译的Windows版本。例如

  #include< SdkDdkver.h> 

#define NTDDI_VERSION NTDDI_VISTA
#define WINVER _WIN32_WINNT_VISTA
#define _WIN32_WINNT _WIN32_WINNT_VISTA

其中一些定义重叠,可能不需要,但在我为Windows编写的罕见的时间,我只是用它们来确保: - )



编辑3:



MinGW / GCC的功能有点不同:

  #include< w32api.h> 

#define WINVER WindowsVista
#define _WIN32_WINDOWS WindowsVista
#define _WIN32_WINNT WindowsVista

注意:这些定义应放在 Windows.h 或任何其他标题之前,但 w32api.h



编辑4:



WS2tcpip.h 在Visual Studio 2010中:

  #if(NTDDI_VERSION> = NTDDI_VISTA)



PCSTR
WSAAPI
inet_ntop(
__in INT Family,
__in PVOID pAddr,
__out_ecount(StringBufSize)PSTR pStringBuf,
__in size_t StringBufSize
);

PCWSTR
WSAAPI
InetNtopW(
__in INT Family,
__in PVOID pAddr,
__out_ecount(StringBufSize)PWSTR pStringBuf,
__in size_t StringBufSize
);

#define InetPtonA inet_pton
#define InetNtopA inet_ntop

#ifdef UNICODE
#define InetPton InetPtonW
#define InetNtop InetNtopW
#else
#define InetPton InetPtonA
#define InetNtop InetNtopA
#endif



#endif //(NTDDI_VERSION> = NTDDI_VISTA)



我在MinGW32 / GCC中找不到 InetNtop 定义-4.4.2,所以很有可能是你的版本不支持。


Anyone knows what header I must include for the use of InetNtop function ?
I tried winsock2.h, ws2tcpip.h and i've include the Ws2_32 librabry. I am using windows 7
This is my error that i get an compile time: InetNtop : function could not be resolved

edit:
char temp[10];
int bytes_recv = Recv(temp, sizeof(temp));
char result[INET_ADDRSTRLEN];
InetNtop(AF_INET, (void*)(&temp[4]), result, sizeof(result));

I am trying to print an IP what is in temp.

解决方案

According to its documentation Ws2tcpip.h is its actual header file.

EDIT:

According to the documentation, using this function requires your code to be compiled for Windows Vista or later. Since you are including the necessary header and yet the function is not visible, I surmise the you have not set the proper defines or compiler options to compile your code for a suitable version.

The actual Windows version that you are using is not important - what you are compiling for (i.e. the target version) is.

EDIT 2:

You should add the proper #define directive as described here to indicate which Windows version you are compiling for. E.g.

#include <SdkDdkver.h>

#define NTDDI_VERSION NTDDI_VISTA
#define WINVER _WIN32_WINNT_VISTA
#define _WIN32_WINNT _WIN32_WINNT_VISTA

Some of these defines overlap and may not be needed, but on the rare times that I code for Windows I just use them all to make sure :-)

EDIT 3:

Things are a bit different for MinGW/GCC:

#include <w32api.h>

#define WINVER                  WindowsVista
#define _WIN32_WINDOWS          WindowsVista
#define _WIN32_WINNT            WindowsVista

Note: These defines should be placed before including Windows.h or any other header but w32api.h.

EDIT 4:

From the WS2tcpip.h in Visual Studio 2010:

#if (NTDDI_VERSION >= NTDDI_VISTA)
.
.
.
PCSTR
WSAAPI
inet_ntop(
    __in                                INT             Family,
    __in                                PVOID           pAddr,
    __out_ecount(StringBufSize)         PSTR            pStringBuf,
    __in                                size_t          StringBufSize
    );

PCWSTR
WSAAPI
InetNtopW(
    __in                                INT             Family,
    __in                                PVOID           pAddr,
    __out_ecount(StringBufSize)         PWSTR           pStringBuf,
    __in                                size_t          StringBufSize
    );

#define InetPtonA       inet_pton
#define InetNtopA       inet_ntop

#ifdef UNICODE
#define InetPton        InetPtonW
#define InetNtop        InetNtopW
#else
#define InetPton        InetPtonA
#define InetNtop        InetNtopA
#endif
.
.
.
#endif  //  (NTDDI_VERSION >= NTDDI_VISTA)

Therefore the critical define in this case is NTDDI_VERSION, as expected for a new API addition.

I cannot find the InetNtop definition in MinGW32/GCC-4.4.2, so it's quite possible that it is not supported in your version either.

这篇关于InetNtop:找不到它使用哪个头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆