




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、程序实践报告(网络程序设计)姓名学号班级指导教师程序实践名称网络程序设计程序实践内容网络程序设计开设学期2009-2010 第二学期开设时间第 1 6周第 1 8周报 告 日 期2010年7月 日评定成绩评定人签字评定日期东北大学软件学院1一、程序实践概述1、题目名称:Linux 程序设计基础2、时间进度:2010 年 6 月 14 日星期一到 2010 年 6 月 20 日星期日3、开发环境:linux二、问题分析1、功能说明:编程实现快速排序算法; 实现文本文件拷贝函数 copy(f_source, f_target) ;即实现如下功能:$ ./copy f1 f2以上程序执行后当前目录会
2、形成一个新的文件 f2 ,且其内容与 f1 完全一致。 编写一个程序,要求:输入 N个学生的学号和成绩,并保存在 stu.txt 文本文件中,对 学生成绩进行排序并把排序后的结果输出到 score.txt 文件中 ,同时在屏幕上输出高于平 均成绩的学生的学号和成绩。 矚慫润厲钐瘗睞枥庑赖。 编写一个程序找出串 str1 和串 str2 的所有最长公共子串。2、解决方案:(1) 将原问题分解为若干个规模更小但结构与原问题相似的子问题。递归地解这些子问题,然 后将这些子问题的解组合为原问题的解。 聞創沟燴鐺險爱氇谴净。(2)定义文件指针 FILE *fp ; 表示 fp 是指向 FILE 结构的指
3、针变量, 通过 fp 即可找存放某个 文件信息的结构变量,然后按结构变量提供的信息找到该文件,实施对文件的操作。 残骛楼諍锩瀨濟溆塹籟。(3) 创建一个结构体储存学生的学号和成绩,利用文件操作写入文档。对成绩进行排序,将大 于平均成绩的输出到屏幕。 酽锕极額閉镇桧猪訣锥。(4) 创建两个数组,搜索字符串,寻找最大的匹配子串。1、模块结构:模块功能图和模块描述(1)在 Rlow.high中任选一个记录作为基准 (Pivot) ,以此基准将当前无序区划分为左、右两个较小的子区间 Rlow.pivotpos-1)和 Rpivotpos+1.high,并使左边子区间中所有记录的关键字均小于等于基准记录
4、 (不妨记为 pivot) 的关键字 pivot.key ,右边的子区间中 所有记录的关键字均大于等于 pivot.key ,而基准记录 pivot 则位于正确的位置 (pivotpos) 上,它无须参加后续的排序。 彈贸摄尔霁毙攬砖卤庑。划分的关键是要求出基准记录所在的位置 pivotpos 。划分的结果可以简单地表示为:Rlow.pivotpos-1.keys Rpivotpos.key Rpivotpos+1.high.keys 謀养抟 箧飆鐸怼类蒋薔。其中 low w pivotpos w high 。(2) fopen 函数 用来打开一个文件,其调用的一般形式为: 文件指针名 =fo
5、pen( 文件名,使用文件方式 ) 。 其中,“文件指针名”必须是被说明为 FILE 类型的指针变量, “文件名”是被打开文件的 文件名。 “使用文件方式”是指文件的类型和操作要求。 “文件名”是字符串常量或字符 串数组。 厦礴恳蹒骈時盡继價骚。fclose 函数 调用的一般形式是: fclose( 文件指针 ) ;正常完成关闭文件操作时,fclose 函数返回值为 0。如返回非零值则表示有错误发生。文件的读写对文件的读和写是最常用的文件操作。茕桢广鳓鯡选块网羈泪。(3) 创建一个结构体储存学生的学号和成绩,每个学生的信息都储存在一个数组里。 利用文件操作写入文档。对成绩进行排序,更新数组信息
6、,将大于平均成绩的输出到屏幕。(4) 将两个字符串储存在数组里,从首地址开始查找相同字符。如果遇到相同字符则开始记录 位置,从该位置开始计数,到不匹配位置。重新搜索,如果最大长度超过记录则更新。 鹅 娅尽損鹌惨歷茏鴛賴。2、数据结构:(1)链表,递归 ( 2)文件操作 ( 3)文件操作,数组 (4)数组3、总体流程: 给出流程图(1)第一步:(初始化)设置两个指针i和j,它们的初值分别为区间的下界和上界, 即i=low , i=high ;选取无序区的第一个记录 Ri( 即 Rlow) 作为基准记录, 并将它保存在变量 pivot 中; 籟丛妈羥为贍偾蛏练淨。第二步:令 j 自 high 起向
7、左扫描, 直到找到第 1 个关键字小于 pivot.key 的记录 Rj , 将 Rj) 移至 i 所指的位置上,这相当于 Rj 和基准 Ri( 即 pivot) 进行了交换,使关键 字小于基准关键字 pivot.key 的记录移到了基准的左边,交换后 Rj 中相当于是 pivot ; 然后,令 i 指针自 i+1 位置开始向右扫描,直至找到第 1 个关键字大于 pivot.key 的记录 Ri ,将 Ri 移到 i 所指的位置上,这相当于交换了 Ri 和基准 Rj ,使关键字大于基 准关键字的记录移到了基准的右边,交换后 Ri 中又相当于存放了 pivot ;接着令指针 j 自位置 j-1
8、开始向左扫描, 如此交替改变扫描方向, 从两端各自往中间靠拢, 直至 i=j 时, i 便是基准 pivot 最终的位置,将 pivot 放在此位置上就完成了一次划分。 預頌圣鉉儐歲龈讶 骅籴。(2)(4)找到第一个相等的字符, 记录下位置。查找最大的相同字符, 如果有大于前一次搜索 的,则更新长度。4、关键算法:给出关键算法描述(1)int Partition(SeqList R ,int i,int j)/ 调用 Partition(R , low , high) 时,对 Rlow.high 做划分, /并返回基准记录的位置ReceType pivot=Ri ; /用区间的第 1 个记录作
9、为基准 while(i while(i=pivot.key) /pivot 相当于在位置 i 上 j-; /从右向左扫描,查找第1 个关键字小于 pivot.key 的记录 Rjif(i Ri+=Rj ; /相当于交换 Ri 和 Rj ,交换后 i 指针加 1 渗釤呛 俨匀谔鱉调硯錦。while(i i+ ; /从左向右扫描,查找第1 个关键字大于 pivot.key 的记录 Ri 铙誅卧泻噦圣骋贶頂廡。if(ipivot.keyR卜=Ri; /相当于交换 Ri和Rj,交换后j指针减1 /endwhileRi=pivot ; /基准记录已被最后定位 return i ;(2) p1=fopen
10、(f1,r);/打开文件p2=fopen(f2,w);for(i=0;i+)/ 写入文件 if(k=getc(p1)=EOF) break; putc(k,p2);(3) for(i=0;iN-1;i+)/对学生成绩进行排序noswap=1; for(j=0;jN-i-1;j+)if(studentj+1.sumbi nd-liste n-accpet-Read,write而对于客户端则是 socket-c onn ect-read,write 1、模块结构:模块功能图和模块描述服务器端:1、创建套接字;使用 socket()#in clude#in cludeint socket(int d
11、omain , int type ,int protocol)建立服务器端的socket套接字2、绑定套接字到一个IP地址和一个端口上;使用bind()#include#includeint bind(int sockfd,struct sockaddr * myaddr,int addrlen); 贓熱俣阃歲匱阊邺镓騷。3、将套接字设置为监听模式,以等待连接请求; 使用 listen()#includeint listen(int sockfd, int backlog)4、请求到来后,接受连接请求,并返回一个与此次连接对应的套接字; 使用 accept()#includeint accep
12、t(int sockfd,struct sockaddr * addr, int * addrlen) 坛摶乡囂忏蒌鍥铃氈淚。此时新建连接,并创建新的 Socket 套接字,此时 addr 为客户端的 addr 信息。5、用返回的套接字和客户端进行通信;使用 recv() 和 send()int read(int fd,char * buf , int len)int write(int fd, char * buf , int len)6、关闭当前的连接,进入等待状态,继续等待客户端的连接; 使用 close()#includeint close(int sockfd);7、关闭服务器端的套
13、接字描述符; 使用 close()#includeint close(int sockfd);客户端:1、创建客户端套接字;使用 socket() #include #include int socket(int domain, int type , int protocol)2、向服务器发出连接请求;使用 connect() #include #include int connect (int sockfd , struct sockaddr * servaddr,int addrlen )蜡變黲癟報伥铉锚鈰赘。其中参数 servaddr 指定远程服务器的套接字地址,包括服务器的 IP 地址
14、和端口号3、和服务器端进行网络通信;使用 recv() 和 send()int read(int fd,char * buf , int len)int write(int fd, char * buf , int len)4、关闭套接字;使用 close() #include int close(int sockfd);2、数据结构: 文件操作, socket3、总体流程: 给出流程图4server4、关键算法: 给出关键算法描述1.Clie nt:尝试接收数据綾镝鯛駕櫬鹕踪韦辚糴。recv_msg=recv(sockfd,buf,20,0);bufrecv_msg=0:printf(rec
15、eived: %sn,buf);server:while(1)/尝试获得数据sin _size=sizeof(struct sockaddr_ in);if(client_fd=accept(sockfd,(structsockaddr *)&remote_addr,&sin_size)=-1)驅踬髏彦浃绥譎饴憂锦。perror(accept error);con ti nue;t=time(NULL);2.clie nt:fp=fope n(file name,r);打开文件if(fp = -1)prin tf(ope n file errorn);fread(buf,sizeof(buf)
16、,1,fp);/ 读取文件fp=fope n( re,a);server:bufrecv_msg=O;prin tf(%s,buf);fwrite(buf,strle n(buf),1,fp);/ 写入文件fclose(fp);5、界面设计:Linux终端命令行界面四、调试记录给出测试用例编号用例描述测试结果修改情况分析五、创新说明猫虿驢绘燈锹籁饗迳琐筆襖鸥娅薔。構氽頑黉輒峄陽檉簖疖網儂號泶。一、程序实践概述1、题目名称:Libpcap 开发包使用2、时间进度:2010 年 6 月 14 日星期一到 2010 年 6 月 20 日星期日3、开发环境:linux二、问题分析1、功能说明:(1)获
17、取网络接口名字和掩码等信息( 2)捕获数据包(单个数据包和多个数据包两种情况)( 3)以太网数据报捕获(4) ARP数据包捕获2、解决方案:1、 打开、读取设备,设置过滤器部分 。1.1 pcap_read()1.2 pcap_t * pcap_open_live ( char * device, int snaplen, int promisc, 鮒诛髅貺庑。int to_ms, char * errbuf ); 该函数用于获取一个抽象的包捕捉句柄,1.3 int pcap_setfilter ( pcap_t * p, struct bpf_program * fp ); 该函数用于设置
18、pcap_compile() 解析完毕的过滤规则 2、编译、优化、调试过滤规则表达式部分2.1 int pcap_compile ( pcap_t * p, struct bpf_program * fp, char * str, 碩饨荠龈话骛。int optimize, bpf_u_int32 netmask ); 该函数用于解析过滤规则串,填写 bpf_program 结构。3、脱机方式监听部分。3.1 pcap_open_offline()3.2 pcap_offline_read ()4、本地网络设置检测部分。4.1 char * pcap_lookupdev ( char * err
19、buf ); 该函数返回一个网络设备接口名,4.2 int pcap_lookupnet ( char * device, bpf_u_int32 * netp,bpf_u_int32 * maskp, char * errbuf );该函数用于获取指定网络接口的 IP 地址、子网掩码。5. 主控程序及版本部分6. 关闭程序void pcap_close(pcap_t *p) 关闭句柄,释放资源1、模块结构:模块功能图和模块描述(1)char error_contentPCAP_ERRBUF_SIZE;/* 错误信息 */struct pcap_pkthdr protocol_header;/
20、* 数据包头 */pcap_t *pcap_handle;/* Libpcap 句柄 */struct bpf_program bpf_filter;/* bpf 过滤规则 */char bpf_filter_string = ;/* 过滤规则 */const u_char *packet_content;/* 数据包内容 */bpf_u_int32 net_mask;/* 网络掩码 */bpf_u_int32 net_ip;/* 网络地址 */char *net_interface;/* 网络接口 */net_interface = pcap_lookupdev(error_content)
21、;/* 获取网络接口 */pcap_lookupnet(net_interface, &net_ip, &net_mask, error_content);/* 获取网络地址和掩码地址 */pcap_handle = pcap_open_live(net_interface,/* 网络接口 */BUFSIZ, /* 数据包大小 */1,/* 混杂模式 */0,/* 等待时间 */error_content); /* 错误信息 */* 打开网络接口 */ pcap_compile(pcap_handle, /* Libpcap 句柄 */ &bpf_filter, /* BPF 过滤规则 */b
22、pf_filter_string, /* BPF 过滤规则字符串 */0, /* 优化参数 */net_ip); /* 网络地址 */* 编译过滤规则 */过*/pcap_setfilter(pcap_handle,/* Libpcap 句柄 */ &bpf_filter); /* BPF滤规则 */* 设置过滤规则 */packet_content = pcap_next(pcap_handle, /* Libpcap 句 柄 &protocol_header); /*数据包信息 */* 捕获一个数据包,返回此数据包的内容 */printf(Capture a packet from : %
23、sn, net_interface);/* 输出网络接口名字 */printf(The packet length is :%dn, protocol_header.len);/* 输出捕获的数据包的长度 */ pcap_close(pcap_handle);/* 关闭 Libpcap 操作 */return 0; 尧侧閆繭絳闕绚勵蜆贅。(2)int main()char error_contentPCAP_ERRBUF_SIZE;struct pcap_pkthdr protocol_header;pcap_t *pcap_handle;struct bpf_program bpf_filt
24、er;char bpf_filter_string=;const u_char *packet_content; bpf_u_int32 net_mask;bpf_u_int32 net_ip;char *net_interface; net_interface=pcap_lookupdev(error_content); pcap_lookupnet(net_interface,&net_ip,&net_mask,error_content); 识饒鎂錕缢灩筧嚌 俨淒。pcap_handle=pcap_open_live(net_interface,BUFSIZ,1,0,error_cont
25、ent);pcap_compile(pcap_handle,&bpf_filter,bpf_filter_string,0,net_ip);pap_setfilter(pcap_handle,&bpf_filter);packet_content=pcap_next(pcap_handle,&protocol_header);凍鈹鋨劳臘锴痫婦胫籴。恥諤銪灭萦欢煬鞏鹜錦printf(Capture a packet from : %sn,net_interface); printf(The packet length is : %dn,protocol_header.len); pcap_clo
26、se(pcap_handle);void main()pcap_t* pcap_handle;char error_contentPCAP_ERRBUF_SIZE;char *net_interface;struct bpf_program bpf_filter;char bpf_filter_string=ip;bpf_u_int32 net_mask;bpf_u_int32 net_ip; net_interface=pcap_lookupdev(error_content); pcap_lookupnet(net_interface,&net_ip,&net_mask, error_co
27、ntent);pcap_handle=pcap_open_live(net_interface, BUFSIZ,1,0,error_content); pcap_compile(pcap_handle,&bpf_filter, bpf_filter_string,0, net_ip);pcap_setfilter(pcap_handle,&bpf_filter);pcap_loop(pcap_handle,10,callback,NULL);pcap_close(pcap_handle);(3)struct ether_headeru_int8_t ether_dhost6;u_int8_t
28、ether_shost6;u_int16_t ether_type;void main()char error_contentPCAP_ERRBUF_SIZE; pcap_t* pcap_handle;const u_char *packet_content;u_char *mac_string;u_short ethernet_type;bpf_u_int32 net_mask;bpf_u_int32 net_ip;char *net_interface;struct pcap_pkthdr protocol_header;struct bpf_program bpf_filter;stru
29、ct ether_header *ethernet_protocol;char bpf_filter_string= ip; net_interface=pcap_lookupdev(error_content); pcap_lookupnet(net_interface,&net_ip,&net_mask,error_content);pcap_handle=pcap_open_live(net_interface,BUFSIZ,1,0,error_content); 鉀沩懼統庫。pcap_compile(pcap_handle,&bpf_filter,bpf_filter_string,0
30、,net_ip); 攜驤蔹。pcap_setfilter(pcap_handle,&bpf_filter); if(pcap_datalink(pcap_handle)!=DLT_EN10MB) return;阌擻輳嬪諫迁择楨秘騖。packet_content=pcap_next(pcap_handle,&protocol_header); printf(Capture a Packet from net_interface :n); printf(%sn,net_interface); printf(Capture Time is: n);printf(%s,ctime(const time
31、_t *)&protocol_header.ts.tv_sec); 澩。printf(Packet Length is :n); printf(%dn,protocol_header.len); ethernet_protocol=(struct ether_header *)packet_content; printf(Ethernet type is : n); ethernet_type=ntohs(ethernet_protocol-ether_type);printf(%04xn,ethernet_type); 怂阐譜鯪迳導嘯畫長凉。 switch(ethernet_type)cas
32、e 0x0800: printf(the network layer is IP protocoln);break; 禪泻類。case 0x0806: printf(the network layer is ARP protocoln);break; 偽純铪锩。case 0x8035: printf(the network layer is RARP protocoln);break; 觶鷹緇機库。鯊腎鑰诎褳硕癘鄴颃诌攆檸氬嚕躑竄贸恳彈瀘颔釷鹆資贏車贖孙滅獅赘。谚辞調担鈧谄动嘰觐詿缧铴嗫熒绐譏钲鏌default: break;printf(Mac Source Address is : n);
33、 mac_string=ethernet_protocol-ether_shost;printf(%02x:%02x:%02x:%02x:%02x:%02xn,*mac_string,*(mac_string+1),*(mac_string+2),*(mac_string+3),*(mac_string+4),*(mac_string+5); 鶼渍螻偉阅劍鲰腎邏蘞。printf(Mac Desination Address is : n); mac_string=ethernet_protocol-ether_dhost;printf(%02x:%02x:%02x:%02x:%02x:%02x
34、n,*mac_string,*(mac_string+1),*(mac_str ing+2),*(mac_string+3),*(mac_string+4),*(mac_string+5); 纣忧蔣氳頑莶驅藥悯骛。 pcap_close(pcap_handle);(4)struct ether_headeru_int8_t ether_dhost6;u_int8_t ether_shost6;u_int16_t ether_type;typedef u_int32_t int_addr_t;struct in_addrint_addr_t s_addr;struct arp_headeru_i
35、nt16_t arp_hardware_type;u_int16_t arp_protocol_type;u_int8_t arp_hardware_length;u_int8_t arp_protocol_length;u_int16_t arp_operation_code;u_int8_t arp_source_ethernet_address6;u_int8_t arp_source_ip_address4;u_int8_t arp_destination_ethernet_address6; u_int8_t arp_destination_ip_address4;*argument
36、,const struct pcap_pkthdr* 颖刍莖蛺饽亿顿裊赔泷。void arp_protocol_packet_callback(u_char packet_header,const u_char* packet_content) struct arp_header *arp_protocol;u_short protocol_type;u_short hardware_type;u_short operation_code;u_char *mac_string;struct in_addr source_ip_address;struct in_addr destination
37、_ip_address; u_char hardware_length;u_char protocol_length;printf(ARP Protocol(Network Layer)n);arp_protocol=(struct arp_header *)(packet_content+14); hardware_type=ntohs(arp_protocol-arp_hardware_type); protocol_type=ntohs(arp_protocol-arp_protocol_type); operation_code=ntohs(arp_protocol-arp_opera
38、tion_code); hardware_length=arp_protocol-arp_hardware_length; protocol_length=arp_protocol-arp_protocol_length; printf(ARP Hardware Type :%dn,hardware_type); printf(ARP Protocol Type :%dn,protocol_type); printf(ARP Hardware Length: %dn,hardware_length); printf(ARP Protocol Length :%Dn ,protocol_leng
39、th); printf(ARP Operation: %dn,operation_code);濫驂膽閉驟羥闈詔寢賻。銚銻縵哜鳗鸿锓謎諏涼。挤貼綬电麥结鈺贖哓类。赔荊紳谘侖驟辽輩袜錈。塤礙籟馐决穩賽釙冊庫。裊樣祕廬廂颤谚鍘羋蔺。switch(operation_code)case 1:printf(ARP Request Protocoln);break; case 2:printf(ARP Reply Protocoln);break;case 3:printf(RARP Request Protocoln);break;case 4:printf(RARP Reply Protocoln);
40、break; default: break;printf(Ethernet Source Address is :n); mac_string=arp_protocol-arp_source_ethernet_address;仓嫗盤紲嘱珑詁鍬齊驁。printf(%02x:%02x:%02x:%02x:%02x:%02xn,*mac_string,*(mac_string+1),*(mac_string+2),*(mac_string+3),*(mac_string+4),*(mac_string+5);绽萬璉轆娛閬蛏鬮绾瀧。memcpy(void *) &source_ip_address,(
41、void *)&arp_protocol-arp_source_ip_address,sizeof(struct in_addr); printf(Source IP Address:%sn,inet_ntoa(source_ip_address);凉。骁顾燁鶚巯瀆蕪領鲡赙。瑣钋濺暧惲锟缟馭篩TO、oprintf(Ethernet Destination Address is:n); mac_string=arp_protocol-arp_destination_ethernet_address; 類。鎦诗涇艳损楼紲鯗餳printf(%02x:%02x:%02x:%02x:%02x:%02xn
42、,*mac_string,*(mac_string+1),*(mac_string+2),*(mac_string+3),*(mac_string+4),*(mac_string+5); 栉缏歐锄棗鈕种鵑瑶 锬。memcpy(void *)&destination_ip_address,(void *) &arp_protocol-arp_destination_ip_address,sizeof(struct in_addr); 辔烨棟剛殓攬瑤丽 阄应。printf(Destination IP Address:%sn,inet_ntoa(destination_ip_address); 峴
43、扬斕 滾澗辐滠兴渙藺。void ethernet_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr *packet_header,const u_char* packet_content)詩叁撻訥烬忧毀厉鋨骜。u_short ethernet_type;struct ether_header *ethernet_protocol;u_char *mac_string;static int packet_number=1;则鯤愜韋瘓賈晖园栋泷。胀鏝彈奥秘孫戶孪钇賻。鳃躋峽祷紉诵帮废掃減。printf(the %d
44、 ARP packet is captured.n,packet_number); printf(Ethernet Protocol(LINK Layer);ethernet_protocol=(struct ether_header *)packet_content;printf(Ethernet type is :n);ethernet_type=ntohs(ethernet_protocol-ether_type);printf(%04xn,ethernet_type);switch(ethernet_type)case 0x0800: printf(layer is ipn);brea
45、k;case 0x0806: printf(layer is ARPn);break;case 0x8035: printf(layer is RARPn);break;default: break;printf(Mac Source Address is :n); mac_string=ethernet_protocol-ether_shost;printf(%02x:%02x:%02x:%02x:%02x:%02xn,*mac_string,*(mac_string+1),* (mac_string+2),*(mac_string+3),*(mac_string+4),*(mac_stri
46、ng+5); 稟虛嬪赈维哜妝扩踴 粜。printf(Mac destination Address is:n); mac_string=ethernet_protocol-ether_dhost;printf(%02x:%02x:%02x:%02x:%02x:%02xn,*mac_string,*(mac_string+1),* (mac_string+2),*(mac_string+3),*(mac_string+4),*(mac_string+5); 陽簍埡鲑罷規呜旧岿 錟。switch(ethernet_type)case 0x0806: arp_protocol_packet_call
47、back(argument,packet_header,packet_content);break; 沩 氣 嘮戇苌鑿鑿槠谔應。default: break;packet_number+;int main()pcap_t* pcap_handle;char error_contentPCAP_ERRBUF_SIZE;char *net_interface;struct bpf_program bpf_filter;char bpf_filter_string=arp;bpf_u_int32 net_mask;bpf_u_i nt32 n et_ip;net_in terface=pcap_lo
48、okupdev(error_c onten t);pcap_lookup net(net_in terface,&n et_ip,&n et_mask,error_c onten t);團蔺。pcap_ha ndle=pcap_ope n_live( net_i nterface,BUFSIZ,1,0,error_c on te nt); 乐鹇烬觶騮。pcap_compile(pcap_ha ndle,& bpf_filter,bpf_filter_stri ng,0,n et_ip);鮐癞别濾。pcap_setfilter(pcap_ha ndle,& bpf_filter);if(pcap
49、_datali nk(pcap_ha ndle)!=DLT_EN10MB)return;pcap_loop(pcap_ha ndle,-1,ether net_protocol_packet_callback,NULL); 荡赚。钡嵐縣緱虜荣产涛懨俠劑鈍触謾饱兗争詣繚呙铉們欤谦鸪饺竞pcap_close(pcap_ha ndle); return 0;2、数据结构:libpcap4、总体流程:给出流程图84、关键算法:给出关键算法描述(1) char error_contentPCAP_ERRBUF_SIZE;struct in_addr net_ip_address; 获得 ip 地址 st
50、ruct in_addr net_mask_address; 获得子网掩码 char *net_interface;char *net_ip_string;char *net_mask_string;(2)捕获一个数据包:packet_content=pcap_next(pcap_handle, &protocol_header); 莹谐龌蕲賞组靄绉嚴减。 捕获多个数据包:pcap_loop(pcap_handle,10, callback, NULL);(3) ethernet_type=ntohs(ethernet_protocol-ether_type); 麸肃鹏镟轿騍镣缚縟糶。prin
51、tf(%04xn,ethernet_type);switch(ethernet_type)case 0x0800: printf(the network layer is IP protocoln);break;納畴鳗吶鄖禎銣腻鰲锬。case 0x0806: printf(the network layer is ARP protocoln);break;風撵鲔貓铁频钙蓟纠庙。case 0x8035: printf(the network layer is RARP protocoln);break;灭嗳骇諗鋅猎輛觏馊藹。default: break;printf(Mac Source Address is : n); mac_string=etherne
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 乐器清洁保养考核试卷
- 2024年行政管理师考试中的解题策略试题及答案
- 行政管理师考前心理预备试题及答案
- 2025年【湖南省汽车修理工(中级)】考试题及答案
- 索道制动系统设计与优化考核试卷
- 材料科学与工程基础考核试卷
- 矿产勘查经济学考核试卷
- 糖果与巧克力产品创新设计考核试卷
- 路基工程挖土施工方案
- 花艺师个人创意题目及答案
- 黑龙江省佳木斯市2023-2024学年八年级下学期期中联考数学试题(无答案)
- 危险化学品无仓储经营单位生产安全事故应急救援预案(新导则版)
- 养蚕观察记录
- 弹力袜的使用课件
- 餐饮设备安全培训
- 粪群移植的护理
- 手术室质控培训课件
- 企业文化与员工认同培训课件
- 古寺庙重建可行性报告
- 老年护理的专科发展课件
- 13《猫》 第二课时 课件
评论
0/150
提交评论