Sign-up....

关于数据包嗅探器的!!!急用 !!

以下是一个数据包嗅探器的源代码,它主要完成的任务是截获网络数据包并解析数据包文头中的各字段的意义。(注:是 唐正军 编著的《网络入侵检测系统的设计与实现》一书中的)

*******小弟无论如何也调试不出来,请各位高手帮忙了!!急用啊 ********

只要能成功实现功能就行

先谢过了

谢能解答的和未能解答问题的高手!!!!!!!!

**********************TCP.C*****************

#include <stdio.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include "headers.h"

int main()

{

int sock,bytes_received,fromlen;

char buffer[65535];

struct sockaddr_in from;

struct ip *ip;

struct tcp *tcp;

sock=socket(AF_INET,SOCK_RAW,IPPROTO_TCP);

while(1)

{

fromlen=sizeof(from);

bytes_received=recvfrom(sock,buffer,sizeof(buffer),0,(struct sockaddr*)&from,&fromlen);

printf("\nBytes received:::%5d\n",bytes_received);

printf("Source address:::%s\n",inet_ntoa(from.sin_addr));

ip=(struct ip *)buffer;

printf("IP header length:::%d\n",ip->ip_length);

printf("Protocol:::%d\n",ip->ip_protocol);

tcp=(struct tcp *)(buffer+4*ip->ip_length);

printf("Source port:::%d\n",ntohs(tcp->tcp_source_port));

printf("Dest port:::%d\n",ntohs(tcp->tcp_dest_port));

}

}

*************************headers.h************************

struct ip{

unsigned int ip_versin:4;

unsigned int ip_length:4;

unsigned char ip_tos;

unsigned short ip_tatal_length;

unsigned short ip_id;

unsigned short ip_flags;

unsigned char ip_ttl;

unsigned char ip_protocol;

unsigned short ip_cksum;

unsigned int ip_source;

unsigned int ip_dest;

};

struct tcp{

unsigned short tcp_source_port;

unsigned short tcp_dest_port;

unsigned int tcp_sepno;

unsigned int tcp_ackno;

unsigned int tcp_res1:4,

tcp_hlen:4,

tcp_fin:1,

tcp_syn:1,

tcp_rst:1,

tcp_ack:1,

tcp_urg:1,

cp_res2:2;

unsigned short tcp_winsize;

unsigned short tcp_cksum;

unsigned short tcp_urgent;

};

[1658 byte] By [msdn] at [2007-9-26 8:19:58]
# 1 Re: 关于数据包嗅探器的!!!急用 !!

他的哪个代码主要是在linux下调试的代码,自己转换成windows看看

ksyou at 2005-3-28 11:16:13 >
# 2 Re: 关于数据包嗅探器的!!!急用 !!

怎么转化成windows哦 谢谢

bilingya at 2005-4-9 18:08:40 >
# 3 Re: 关于数据包嗅探器的!!!急用 !!

几个头文件

wangbangjie at 2005-4-13 23:25:55 >
# 4 Re: 关于数据包嗅探器的!!!急用 !!

这是unix等系统下的代码,转换成windows下,需要用windows对应的头文件和api

oyljerry at 2005-4-14 18:57:52 >
# 5 Re: 关于数据包嗅探器的!!!急用 !!

就是,我也觉得很多网络编程的书全是Unix下的,艾~

sodangerous at 2005-4-15 15:30:39 >
# 6 Re: 关于数据包嗅探器的!!!急用 !!

你是怎么编译的??

fotti at 2005-5-3 20:19:25 >
# 7 Re: 关于数据包嗅探器的!!!急用 !!

或者贴出错误提示来

这个程序我也试过,编译运行都没问题

fotti at 2005-5-3 20:22:59 >
# 8 Re: 关于数据包嗅探器的!!!急用 !!

我在学习

LinYF1980 at 2005-5-10 12:19:59 >

专题开发

All Classified