90 likes | 214 Views
Homework Assignment #2. ICMP Message Processing. Homework Assignment #2: ICMP Message Processing. In this work, you are asked to use timestamp request/reply message to simulate the ping function and calculate the RTT value
E N D
Homework Assignment #2 ICMP Message Processing
Homework Assignment #2: ICMP Message Processing • In this work, you are asked to use timestamp request/reply message to simulate the ping function and calculate the RTT value • Write a program that send a ICMP timestamp request packet to a host, and receive ICMP timestamp reply packet • Furthermore, also calculate the round-trip time (RTT)
Flowchart Start Header: #include <sys/types.h> #include <sys/socket.h> Define: int socket(int domain,int type,int protocol) The third parameter, Protocol, is ICMP Establish socket Header: #include <netinet/ip_icmp.h> struct icmp *icmp_hdr=(struct icmp *)buffer; //#define ICMP_TIMESTAMP icmp_hdr->icmp_type=13; icmp_hdr->icmp_code=0; Establish ICMP packet
Flowchart (cont.) Use sendto() function Ex. sendto(sockfd,buffer,packsize,0,(struct sockaddr*)&addr,addr_len) Send ICMP request Use recvfrom() function Ex. recvfrom(sockfd,rbuf,sizeof(rbuf),0,NULL,NULL) Receive ICMP reply struct icmp *icmp_hdr_R=(struct iphdr*)(rbuf+20); 28~31 byte : original time(T1) 32~35 byte : receive time(T2) 36~40 byte : transmit time(T3) You need calculating back time by yourself (use time.h)(T4) RTT= (T4-T3) + (T2-T1) Calculate RTT
Executable Command • Format: myping [addr] • Ex. • #myping 140.120.15.125 icmp_type= 13,icmp_code=0 Original time=11096271 Receive time=875902519 Transmit time=943274555 Back time=60140638416 RTT=-67372035 ------------------------------------------------ icmp_type=14,icmp_code=0 Original time=11096271 Receive time=11096271 Transmit time=11096271 Back time=11096276 RTT=6
Turn In • Source code • Executing result (snapshot)
Turn In (cont.) • Deadline • 23:59, Dec 22, 2005 • Ftp • IP:140.120.15.123 2222 • Username/Password: comm94/comm94 • Filename • HW2_ID.doc eg.HW2_79356001.doc • If you want to update • HW2_ID_new1.doc, HW2_ID_new2.doc …etc
Turn In (cont.) • No late work is acceptable • You get zero if you miss the due day • No cheat work is acceptable • You get zero if you copy other people’s version
Reference • Linux C/C++ 網路程式設計,金禾 • Linux C 函式庫參考手冊,旗標 • Linux Socket Programming,碁峰