这是Windows的C代码还是Unix的C代码? [英] Is This C Code for Windows or C for Unix?

查看:71
本文介绍了这是Windows的C代码还是Unix的C代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre lang="cs">

#include "pcap.h"
main()
{
    pcap_if_t *alldevs;
    pcap_if_t *d;
    int i=0;
    char errbuf[PCAP_ERRBUF_SIZE];
    /* Retrieve the device list from the local machine */
    if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
        exit(1);
    }
    /* Print the list */
    for(d= alldevs; d != NULL; d= d->next)
    {
        printf("%d. %s", ++i, d->name);
        if (d->description)
            printf(" (%s)\n", d->description);
        else
            printf(" (No description available)\n");
    }
    if (i == 0)
    {
        printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
        return;
    }
    /* We don''t need any more the device list. Free it */
    pcap_freealldevs(alldevs);
}







推荐答案

从外观上看,它使用的是PCAP. PCAP在Windows和* NIX上运行.
By the looks of it, it is using PCAP. PCAP runs on Windows and *NIX.


您可能不包括.lib文件吗?

首先,请确保已在pcap.h中定义了这些函数(它们可能是在其中定义的),并确保您拥有pcap.h在Windows中可能需要编译的#define语句(我确定您是否在您将找到pcap.h,或者可以将其写在标题的顶部,或者可以在库随附的文档中指定),然后确保您链接了适当的.lib文件.

[edit]
所有这些都是标准C,因此无论平台如何,它都可以正常工作.
[/edit]
you''re probably not including the .lib file are you?

first, make sure that those functions are defined in pcap.h (which they probably are), make sure you have the #define statements that pcap.h probably needs to compile in windows (I''m sure if you look up info on pcap.h you''ll find out, or it may be written at the top of the header, or it may be specified in a document that came with the library), then make sure you''re linking the appropriate .lib file.

[edit]
all this is standard C, so it should work regardless of platform.
[/edit]


来自WinPcap(全能的Google带我去了那里):

创建使用wpcap.dll的应用程序:

若要创建将wpcap.dll与Microsoft Visual C ++一起使用的应用程序,请按照下列步骤操作:
-在每个使用库导出的功能的源文件的开头都包含文件pcap.h.
-如果您的程序使用WinPcap的Win32特定功能,请记住在预处理程序定义中包括WPCAP.
-如果您的程序使用WinPcap的远程捕获功能,请在预处理器定义中添加HAVE_REMOTE.不要在源文件中直接包含remote-ext.h.
-设置链接器的选项以包括wpcap.lib库文件.可以在WinPcap开发人员包中找到wpcap.lib.
-设置链接器的选项以包括winsock库文件ws2_32.lib.该文件与C编译器一起分发,并且包含Windows的套接字函数.本教程中的示例所使用的某些功能需要使用它.

请记住:

-要添加预处理器定义,必须从项目"菜单中选择设置",然后从选项卡控件中选择C/C ++,并且在常规"类别下,必须在预处理器定义"文本框中添加该定义.
-要使用Microsoft Visual C ++ 6.0将新库添加到项目中,必须从项目"菜单中选择设置",然后从选项卡控件中选择链接",然后在对象/库模块"编辑框中添加新库的名称.
-要在Microsoft Visual C ++ 6.0查找库的位置添加新路径,必须从工具"菜单中选择选项",然后从选项卡控件中选择目录",从显示目录的组合"框中选择库文件",然后在目录框.
-若要在Microsoft Visual C ++ 6.0中查找要包含文件的新路径,必须从工具"菜单中选择选项",然后从选项卡控件中选择目录",从显示目录的组合"框中选择包含文件",然后在目录框.

...从查看它们提供给开发人员的软件包开始,您将不得不弄清楚如何为编译器设置默认包含目录(我不确定如何为您的编译器设置默认包含目录) '正在使用),因为这些文件都是根据默认设置(彼此#include<>彼此)链接在一起的.
From WinPcap (almighty google took me there):

Creating an application that uses wpcap.dll:

To create an application that uses wpcap.dll with Microsoft Visual C++, follow these steps:
-Include the file pcap.h at the beginning of every source file that uses the functions exported by library.
-If your program uses Win32 specific functions of WinPcap, remember to include WPCAP among the preprocessor definitions.
-If your program uses the remote capture capabilities of WinPcap, add HAVE_REMOTE among the preprocessor definitions. Do not include remote-ext.h directly in your source files.
-Set the options of the linker to include the wpcap.lib library file. wpcap.lib can be found in the WinPcap developer''s pack.
-Set the options of the linker to include the winsock library file ws2_32.lib. This file is distributed with the C compiler and contains the socket functions for Windows. It is needed by some functions used by the samples in the tutorial.

Remember that:

-To add a preprocessor definition, you must select Settings from the Project menu, then select C/C++ from the tab control, and under the category General, you must add the definition under the Preprocessor Definitions text box.
-To add a new library to the project with Microsoft Visual C++ 6.0, you must select Settings from the Project menu, then select Link from the tab control, and then add the name of the new library in the Object/library modules edit box.
-To add a new path where Microsoft Visual C++ 6.0 will look for the libraries, you must select Options from the Tools menu, then Directories from the tab control, Library files from the Show directories for combo box, and the add the path in the Directories box.
-To add a new path where Microsoft Visual C++ 6.0 will look for include files, you must select Options from the Tools menu, then Directories from the tab control, Include files from the Show directories for combo box, and the add the path in the Directories box.

...and from looking at the package that they give for development, you''re going to have to figure out how to set default include directories for your compiler (I''m not sure how to do it for the compiler you''re using) because the files are all linked to one another based on default settings (they #include<> one another).


这篇关于这是Windows的C代码还是Unix的C代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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