QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2341|回复: 2

使用libpcap编程问题

[复制链接]
发表于 2007-5-13 16:54:04 | 显示全部楼层 |阅读模式
#include <pcap.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>



/* Libpcap的头文件,必须包含 */

//typedef u_int32_t in_addr_t;

//struct in_addr /* 地址类型 */

//{

//  in_addr_t s_addr; /* IP地址类型 */

//};
int main(void)

{

    char error_content[PCAP_ERRBUF_SIZE];

    /* 出错信息 */

    struct in_addr net_ip_address;

    /* 网络地址 */

    struct in_addr net_mask_address;

    /* 掩码地址 */

    char *net_interface;

    /* 接口名字 */

    char *net_ip_string;

    /* 网络地址字符串形式 */

    char *net_mask_string;

    /* 掩码地址字符串形式 */

    u_int32_t net_ip;

    /* 网络地址 */

    u_int32_t net_mask;

    /* 掩码地址 */
       

   net_interface = pcap_lookupdev(error_content);
       
        printf("%s \n",error_content);

    /* 获取网络接口 */

    pcap_lookupnet(net_interface,  /* 网络接口 */ &net_ip,  /* 网络地址 */

     &net_mask,  /* 网络掩码 */error_content); /* 错误信息

     * */

    /* 获取网络地址和掩码地址 */

    printf("Network Interface is :%s\n", net_interface);
        sleep(3);

    /* 输出接口名字 */

    net_ip_address.s_addr = net_ip;
        printf("%u",net_ip);

    net_ip_string = inet_ntoa(net_ip_address);

    /* 把二进制网络地址格式转换为字符串形式 */

    printf("Network IP Address is :%s\n", net_ip_string);

    /* 输出网络地址 */

    net_mask_address.s_addr = net_mask;

    net_mask_string = inet_ntoa(net_mask_address);

    /* 把二进制掩码地址格式转换为字符串形式 */

    printf("Network Mask Address is:%s\n", net_mask_string);

    /* 输出掩码地址 */

        return 0;
}

用libpcap0.8.3编译时找到的网络接口是petho
而用libpcap0.9.5编译执行是找不到网络接口
这是为什么呢???
 楼主| 发表于 2007-5-14 15:31:39 | 显示全部楼层
呵呵,这么多人看了,怎么就没有一个人回复呢,版主???
回复

使用道具 举报

发表于 2007-5-22 13:42:05 | 显示全部楼层
没用过
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-19 22:44 , Processed in 0.112531 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表