已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ipdump 源码#includestdio.h#include#include#include#include#include#include#include#include#include#include#define _FAVOR_BSD#include#include#include#include#ifdef _linux#include#include#else#include/i nclude#include#include#endif#define MAXSIZE 65535#define EXIT_FAILURE 0void print_ethernet(struct ether_header *eth);void print_arp(struct ether_arp *arp);void print_ip(struct ip *ip);void print_tcp(struct tcphdr *tcp);void print_icmp(struct icmp *icmp);void print_udp(struct udphdr *udp);char *mac_ntoa(u_char *d);char *ip_ttoa(int flag);char *ip_ftoa(int flag);char *tcp_ftoa(int flag);int main(int argc, char *argv) struct ether_header *eth;struct ether_arp *arp;struct ip *ip;struct icmp *icmp;struct tcphdr *tcp;struct udphdr *udp;int sock;int len;char buffMAXSIZE;char *p;printf(begin!n);if ( (sock = socket(AF_INET, SOCK_PACKET, htons(ETH_P_ALL) 0) perror( socket); return(EXIT_FAILURE); /*struct socket local;memset(&local, 0, sizeof(local);local.sa_family = AF_INET;local.sin_port = 0;local.sin_addr.s_addr = INADDR_ANY;*/while (1) printf(+begin+n); if (len = read(sock, buff, MAXSIZE) ether_type) = ETHERTYPE_ARP) print_arp(arp); arp = (struct ether_arp *)p; else if (ntohs(eth-ether_type) = ETHERTYPE_IP) ip = (struct ip *)p; p += (int)(ip-ip_hl)ip_p = IPPROTO_TCP) print_ip(ip); switch (ip-ip_p) case IPPROTO_TCP: tcp = (struct tcphdr *)p; p += (int)(tcp-th_off)ether_type);if (type ether_dhost);printf(Source MAC Adress: %17sn, mac_ntoa(eth-ether_shost);if (type ea_hdr.ar_op);if (op = 0 | 5 ea_hdr.ar_hrd), (ntohs(arp-ea_hdr.ar_hrd) = ARPHRD_ETHER) ? (Ethernet) : (Notther), ntohs(arp-ea_hdr.ar_pro), (ntohs(arp-ea_hdr.ar_pro) = ETHERTYPE_IP) ? (IP) : (Not IP); printf( Hardlen: %3u | Addr Len: %2u | op: %4d %16sn, arp-ea_hdr.ar_hln, arp-ea_hdr.ar_pln, ntohs(arp-ea_hdr.ar_op), arp_operationop); printf( Source MAC Address: %17sn, mac_ntoa(arp-arp_sha); printf( Source IP Address: %7sn, inet_ntoa(* (struct in_addr *) &arp-arp_spa); printf( Destination MAC Address: %17sn, mac_ntoa(arp-arp_tha); printf( Destination IP Adress: %7sn, inet_ntoa(* (struct in_addr *) &arp-arp_tpa); return; void print_ip(struct ip *ip) printf( Protocal: IPn);printf( IV: %1u | HL:%2u | T:%8s | Total Length: %10un, ip-ip_v, ip-ip_hl, ip_ttoa(ip-ip_tos), ntohs(ip-ip_len);printf( Tdentifier: %5u | FF: %3s | FO: %5un, ntohs(ip-ip_id), ip_ftoa(ntohs(ip-ip_off), ntohs(ip-ip_off)&IP_OFFMASK);printf( TTL: %3u | Pro: %3u | Head Checksum: %5un, ip-ip_ttl, ip-ip_p, ntohs(ip-ip_sum);printf( Source IP Address: %15sn, inet_ntoa(*(struct in_addr *) &(ip-ip_src);printf( Destination IP Address: %15sn, inet_ntoa(*(struct in_addr *) &(ip-ip_dst);return; void print_tcp(struct tcphdr *tcp) printf( Protocal: TCPn);printf( Source Port: %5u | Destination Port: %5un, ntohs(tcp-th_sport), ntohs(tcp-th_dport);printf( Sequence Number: %10un, (u_long)(tcp-th_seq);printf( Acknowledgement Number: %10un, (u_long)(tcp-th_ack);printf( Do: %2u | Reserved | F: %6s | Windows Size: %5un, tcp-th_off, tcp_ftoa(tcp-th_flags), ntohs(tcp-th_win);printf( Checksum: %5u | Urgent Pointer: %5un, ntohs(tcp-th_sum), ntohs(tcp-th_urp);return; void print_udp(struct udphdr *udp) printf( Protocal: UDPn);printf( Source Port: %5u | Dest Port: %5un, ntohs(udp-uh_sport), ntohs(udp-uh_dport);printf( Length: %5u | Checksum: %5un, ntohs(udp-uh_ulen), udp-uh_sum);return; void print_icmp(struct icmp *icmp) printf( Protocal: ICMPn);printf( Type: %3u | Code: %3u | Checksum: %5un, icmp-icmp_type, icmp-icmp_code, ntohs(icmp-icmp_cksum);if (icmp-icmp_type = 0 | icmp-icmp_type = 8) printf( Identification: %5u | Sequence Num: %5un, ntohs(icmp-icmp_id), ntohs(icmp-icmp_seq);else if (icmp-icmp_type = 3) if (icmp-icmp_code = 4) printf( void: %5u | Next MTU: %5un, ntohs(icmp-icmp_pmvoid), ntohs(icmp-icmp_nextmtu); else printf( Unused: %10un, (u_long)ntohs(icmp-icmp_void); else if (icmp-icmp_type = 5) printf( Router IP Address: %15un, inet_ntoa(*(struct in_addr *) &(icmp-icmp_gwaddr); else if (icmp-icmp_type = 11) printf( Unused: %10lun, (u_long)ntohl(icmp-icmp_void); return; char *mac_ntoa(u_char *d) static char str50;sprintf(str, %02x:%02x:%02x:%02x:%02x:%02x, d0,d1,d2,d3,d4,d5);return(str); char *ip_ttoa(int flag) static int f = 1,1,1,D,T,R,C,X ;static char str17;u_int mask = 0x80;int i;for (i = 0; i 8; i +) if (flagi) & mask) != 0) stri = fi; else stri = 0; stri = 0;return(str); char *ip_ftoa(int flag) static int f = R,D,M ;static char str17;u_int mask = 0x8000;int i;for (i = 0;i 3;i +) if (flagi) & mask) != 0)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 柠檬酸制造工岗中基础常识考核试卷含答案
- 室内木装修工安全生产能力考核试卷含答案
- 微波铁氧体元器件制造工岗中技能安全考核试卷含答案
- 电线电缆交联工安全知识竞赛考核试卷含答案
- 废片白银回收工岗前知识理论考核试卷含答案
- 2026年人力资源管理师二级《员工培训与发展》考试试卷
- 小诊所社会实践活动报告
- 生物医药研发合作协议书范本
- 银行全面转让协议
- 家具意向车辆租赁协议
- DZ/T 0001-1991区域地质调查总则(1∶50 000)
- T/CEMIA 015-2018光纤预制棒用四氯化硅容器清洗技术规范
- 冰冻切片技术课件教学
- 外墙保温装饰一体板施工方案
- 医疗美容外科诊所制度完整版及目录
- 城市更新项目资金申请报告-超长期特别国债投资专项
- 某研发中心工程施工组织设计
- 变压器淋涂工艺
- 女装项目融资计划书
- 中华文明的起源和发展
- 商品混凝土技术规格书
评论
0/150
提交评论