CONTENTS

  1. INTRODUCTION

  2. GOALS OF THE PROJECT

  3. INTRODUCTION TO TCP/IP

  4. THE LINUX OPERATING SYSTEM

  5. PING

  6. USAGE OF PING

  7. SAMPLE PING SESSION

  8. BIBLIOGRAPHY

 

1. INTRODUCTION   

A network is composed of a large number of entities that work together in order to provide some services to the end user. Computer networks have revolutionized our use of computers. They pervade our everyday life. We are in an information age and computer networks are becoming an integral part in the dissemination of information.  In our project, by the term ’Network Topology’, we exclusively refer to the logical IP topology, ignoring hubs and bridges. We have tried to develop routines for PING.

In the course of doing research, it has been found that it has taken on several distinct meanings. One is that Ping is actually an acronym for the words 'Packet INternet Groper'. Another is that it is in fact not an acronym at all, but a noun that was adopted from a verb that the US Navy that uses to describe what its submarines do when looking for objects under the sea. Their subs send out sonar waves and then wait for a return wave when it bounces off something, such as another sub, whale, ocean floor etc. This, in turn, was adopted from bats and dolphins, which navigate in roughly the same way. This is what a system administrator does when Ping is used. As such, Ping has also evolved into a verb in the computer industry, and it is used in somewhat the same manner of the Navy.  

The Ping utility is essentially a system administrator's tool that is used to see if a computer is operating and also to see if network connections are intact. Ping uses the Internet Control Message Protocol (ICMP) Echo function, which is detailed in RFC 792. A small packet is sent through the network to a particular IP address. This packet contains 64 bytes - 56 data bytes and 8 bytes of protocol reader information. The computer that sent the packet then waits (or 'listens') for a return packet. If the connections are good and the target computer is up, a good return packet will be received. PING can also tell the user the number of hops that lie between two computers and the amount of time it takes for a packet to make the complete trip. Additionally, an administrator can use Ping to test out name resolution. If the packet bounces back when sent to the IP address but not when sent to the name, then the system is having a problem matching the name to the IP address. As mentioned previously, Ping has also evolved from a noun/acronym into a verb, for example: "Ping server X to see if it is up" The time it takes for the packet to get to the target computer and back again is known as the round trip time. If this takes an extended period of time, it is indicative that something may be wrong.  

 

2. GOALS OF THE PROJECT  

The goal of this project is to find out whether the destination host, we are trying to PING, is alive or not. i.e. whether the destination host is connected to the network or not.

What Ping can tell you

What Ping can not tell you 

 

3. INTRODUCTION TO TCP/IP    

TCP/IP is a set of protocols developed to allow co-operating computers to share resources across a network. A community of researchers centred on the ARPANET developed these set of protocols.

TCP/IP is a family of protocols. A few provide ‘low-level’ functions needed for many applications. These include IP (Internet Protocol), TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). Other protocols are for specific tasks like transferring files between computers (FTP), sending mail (SMTP, POP3), or finding out who is logged in on another computer.  

Since TCP and IP are two of the important protocols of the ‘Internet Protocol’ suite, it is sometimes referred to as ‘TCP/IP Protocol Suite’.  

The working of our program is implemented in layer 3 of the ISO’s OSI Model. This layer is the Network Layer.  

The layering in the Internet protocol suite consisting of the network layer along with its inner parameters is as shown in the Fig. [1]. 

4. THE LINUX OPERATING SYSTEM   

4.1  Linux:   

Linux is a 32-bit operating system that uses the minimal resources, without sacrificing functionality. The Linux software is developed under ‘Open and Free Distribution’ conditions. This means that anyone can become involved if they are able to and allows anyone to find out how the system works and to trace and remove any bugs. With their built-in support, Linux computers can be linked into existing networks without any problem.  

The main characteristics are: 

4.2  Inter Process Communication (IPC):  

A fundamental entity in a computer network is a process. A process is a program that is being executed by the computer’s operating system. If two computers are communication with each other, it means two processes, one running on each computer, are in communication with each other. For two processes to communicate with each other, they must both agree to it.    

Unix/Linux provides various forms of IPC like pipes, FIFOs, message queues, semaphores and shared memory. Network programming involves the interaction of two or more processes on different systems. Sockets (BSD) and Transport Layer Interface or TLI (System V) are forms of IPC provided for both, communication between processes on a single system and between processes on different system.  

4.3  The Client-Server Model:   

The standard model for network applications is the client-server model. A server is a process that is waiting to be contacted by a client process, so that the server can do something that the client has requested for.  

4.4  Signals:   

A signal is a notification to a process that an event has occurred. Signals usually occur asynchronously, that is, the process doesn’t know ahead of time exactly when a signal will occur. Signals can be sent,  

Signals are generated, 

Whenever a specific type of signal occurs, a process can provide a function called ‘signal handler’, which is invoked to do whatever the process wants to do to handle the condition. This is called catching the signal. A process can choose to ignore a signal or allow the default action to happen. Normally, a process is terminated on receipt of a signal.   

4.5  Sockets:   

Socket is one of the methods of inter-process communication that allows developing true distributed client/server applications to run across networks. A socket allows client/server systems to be developed either locally, on a single server, or across networks. Socket mechanism can implement multiple clients attached to a single server.   

A socket is one end point of two-way communication link between two programs running on the network. Socket provides an endpoint for communication for the Linux/Unix file access mechanism.   

4.5.1  Socket Connections:  

Sockets can be connection oriented or connectionless, depending on whether connection is opened with the other process prior to the communication or not. Application programs request the operating system to create a socket when one is needed, since socket provides an end point for communication.    

The system call for socket requires three parameters to be mentioned, viz. the protocol family (specifies if the socket is used in Unix or Internet domain), the socket type (specifies the type of communication desired which include reliable stream service (SOCK_STREAM) and a connectionless datagram service (SOCK_DGRAM) and a ‘raw’ type (SOCK_RAW) that allows privileged programs to access low-level protocols or network interfaces), and lastly, the protocol to be used for communication through the socket (used to select a specific protocol namely ICMP, TCP, UDP or ‘raw’ type).  

The ping client, that is being implemented, uses connectionless socket.

4.5.2   Socket Addresses:   

Many of the BSD networking system calls require a pointer to a socket address structure as an argument. The definition of this structure is in <sys/socket.h>  

struct sockaddr        {  
    u_short sa_family;   /*address family; AF-XXX    value*/  
    char sa_data[14];    /*upto 14 bytes of protocol-specific address*/  
};  

For the Internet family, the following structures are defined in <netinet/in.h>:  

struct in_addr {  
    u_long  s_addr;       /*32-bit netid/hostid n/w byte ordered*/ 
};  
 
struct sockaddr_in   {  
   short sin_family;               /*AF_INET*/  
   u_short sin_port;              /*16-bit port no. n/w byte ord*/
    struct in_addr sin_addr;       /*32-bit netid/hosted      */       
    char   sin_zero (8);           /*unused*/  
};  
 

4.6.3   Byte ordering Routines: 

Functions that convert between the local machine byte order and the network standard byte order are ntohs(), ntohl(), htons() and htonl()  

4.6.4     Address Conversion Routines:   

Translation between 32-bit IP address and the corresponding dotted decimal notation are achieved by inet_addr(), which converts address in dotted form to 32-bit address and inet_ntoa(), which does the reverse.   

4.7  Socket Options  

The options can be set so as to affect a socket using the system call setsockopt(). The other functions are fcntl() and ioctl().  

int setsockopt(int sockfd, int level, int optname, char *optval, int *optlen);  
int getsockopt(int sockfd, int level, int optname, char *optval, int *optlen);  

sockfd argument must refer to an open socket descriptor, level specifies who in the system is to interpret the option, the optval is a pointer to a user variable from which an option is set, optlen is a value-result parameter that is set to the size of optval before the call, and is then set by the system on return to specify the amount of data stored into the optval variable.   

4.8  Network Library Calls   

Unix/Linux offers a set of library routines that performs useful functions related to networking. Library routines are similar to procedures that a programmer binds into a program. Library routines allow a process to obtain information from an entry given any piece.  

The functions defined below are available for only Internet services. All these functions return a pointer to the hostent structure defined as below:  

struct hostent { 
    char h_name;                    /*official name of host*/ 
    char **h_aliases;               /*alias list*/ 
    int h_addrtype;                  /*host addr type, only AF_INET*/ 
    int h_length;                      /*length of addresses*/ 
    char **h_addr_list    ;         /*list of addr. from name server*/  
};  
#define h_addr  h_addr_list[0]  

The ‘gethostbyname’ and ‘gethostbyaddr’ are the library functions that allow a process to retrieve information about a host given either its domain name or its IP address respectively.   

The structure pointed to by the timeout argument is defined in <sys/time.h> as:  

struct timeval { 
    long  tv_sec;           /*seconds*/ 
    long  tv_usec;         /*microseconds*/ 
};  

The request to select could be to check if readfds is ready for reading, or if writefds is ready for writing or exceptfds has an exceptional condition like arrival of out-of-band data for a socket pending. The kernel can be instructed using this call to either return immediately after checking the descriptors (timer value specified by the structure must be zero) OR return when one of the file descriptors is ready for I/O, within the fixed time, which is pointed to by the timeval structure OR return only when the specified descriptors is ready for I/O i.e. wait indefinitely. The timeout argument must be NULL. The descriptor values for each of the three arguments, readfds, writefds and exceptfds are specified through the fd_set structure and FD_xxx macros.   

These days, socket interface has become more popular and is being widely supported.  

 

5. PING  

The word PING stands for ‘Packet Inter Net Groper’ and is used to describe the transmission of a sound wave to detect an underground object. Here, the Internet ping program is used to test the reach ability of another host on the Internet. We ping the other host by sending it ‘echo requests’ that it must respond to, if it is operational.

This program sends an ICMP (Internet Control Message Protocol) echo request message to a specified host and waits for a reply. A feature of using ICMP for sending an echo request is that the operation of ICMP does not depend of higher-level protocols, the TCP and UDP. Most of the TCP/IP implementations have the facility of Ping program. This has proved to be a useful tool in discovering network. This ping is also known as ‘Testing destination reachability and status’. 

Our program mainly deals with creating an ICMP packet. It is important to keep in mind that even though ICMP messages are encapsulated and sent using IP, ICMP is not considered a higher-level protocol, it is a required part of IP. The very important reason for using IP to deliver ICMP message is that they need to travel across several physical networks to reach their final destination. Thus, ICMP cannot be delivered by physical transport alone.   

The ICMP message is encapsulated in an IP datagram, which is further encapsulated in a frame of transmission.  

5.1.1  Format of ICMP message:  

Every ICMP message has its own format, but they all begin with:  

In addition to this, ICMP messages that report errors always include the header and the first 64 bits of the datagram, which has caused the problem. The reason for returning more than the datagram header alone is to allow the receiver to determine more precisely which protocols and which application programs were responsible for this. Higher-level protocols in the TCP/IP suite are designed so that the critical information is encoded in the first 64 bits.   

Some of the ICMP ‘type’ field messages, which we use in our program, are defined as below: 

TYPE

ICMP MESSAGE TYPE

0

Echo reply

3

Destination Unreachable

8

Echo request

11

Time exceeded for datagram

 

5.1.2  Echo request (type 8) and reply (type 0) message:

Here a host or router sends an ICMP echo request message to a specified destination. Any machine that receives an echo request formulates an echo reply and returns it to the original sender. The request, which can contain optional data in the data area, which is a variable length field, is returned as it is, in the data section of the reply. The fields Identifier and Sequence number are used by the sender to match replies to requests.  

The echo request and the associated reply can be used to test whether a destination is reachable and responding. As both the request and reply travel in IP datagrams, successful receipt of a reply/ack. verifies that major pieces of the transport system are working fine.  

5.1.3  ICMP Destination Unreachable Message:   

When a router cannot forward or deliver the IP datagram, it sends a destination unreachable message back to the original source, using the format shown below.   

The Code field contains an integer that further describes the problem. Network (0), host (1), protocol (2) and port (3) unreachable are few of the important ones. Network unreachable errors usually imply routing failures; host unreachable errors imply delivery failures. Destinations may be unreachable because hardware is temporarily out of service or because the sender specified a nonexistent destination address. Protocol and port unreachable messages are generated when an invalid protocol or an invalid port number (a port is an abstract destination point used by higher level protocols like TCP and UDP to run services), where no host is running any process, is mentioned by the user in the outgoing datagram. 

5.2  The various structures used in the program   

5.2.1   The IP structure:   
struct ip        {  
unsigned int ip_hl:4;                              /* header length */  
unsigned int ip_v:4;                     /* version */  
u_int8_t ip_tos;                            /* type of service */  
u_short ip_len;                            /* total length */  
u_short ip_id;                              /* identification */  
u_short ip_off;                             /* fragment offset field */  
u_int8_t ip_ttl;                             /* time to live */  
u_int8_t ip_p;                              /* protocol */  
u_short ip_sum;                          /* checksum */  
struct in_addr ip_src, ip_dst;        /* source& dest. address*/  
}; 

5.2.2  The UDP structure:  

struct udphdr {  
u_int16_t       source;                   /* source port */  
u_int16_t       dest;                       /* destination port */  
u_int16_t       len;                         /* udp length */  
u_int16_t       check                     /* udp checksum */  
};   

5.2.3  The ICMP structure: (for echo request & reply only)   

struct icmp    { 
                    u_char icmp_type; 
                    u_char icmp_code;             
                    u_short icmp_cksum; 
                    u_char icmp_id; 
                    u_short icmp_seq; 
           };                                               /*for only echo request and echo reply*/  

 

 

6. USAGE OF PING   

SYNOPSIS   

ping [ -drv ] host [ datasize ] [ npackets ]  

DESCRIPTION   

PING uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams (“pings”) have an IP and ICMP header, followed by a struct timeval and then an arbitrary number of  “pad” bytes used to fill out the packet.  

OPTIONS   

-d       Set the SO_DEBUG option on the socket being used. Essentially, this socket option is not used by Linux kernel.  

-r        Bypass the normal routing tables and send directly to a host on an attached interface. If the host is not on a directly-attached network, an error is returned.  

-v       Verbose output.  

datasize        Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.  

npackets       Stop after sending count ECHO_REQUEST packets. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires.   

When using ping for fault isolation, it should first be run on the local host, to verify that the local network interface is up and running. Then, hosts and gateways further and further away should be ``pinged''. Round-trip times and packet loss statistics are computed. If duplicate packets are received, they are not included in the packet loss calculation, although the round trip time of these packets is used in calculating the minimum/average/maximum round-trip time numbers. When the specified number of packets has been sent (and received) or if the program is terminated with a SIGINT, a brief summary is displayed. Shorter current statistics can be obtained without termination of process with signal SIGQUIT.  

This program is intended for use in network testing, measurement and management. Because of the load it can impose on the network, it is unwise to use ping during normal operations or from automated scripts.

SAMPLE PING SESSION   

This ping session shows a ten packet exchange over the loopback interface. One line is printed for every reply received. Note that for each sequence number, a single reply is received, and they are all in order. The IP TTL values are reported, as are the round-trip times. Both are very consistent. At the end of the session, statistics are reported. Pinging the loopback interface is a good way to test a machine's basic network configuration, since no packets are physically transmitted. Any problems in such a test are a cause for alarm.  

$ PING 127.0.0.1
PING 127.0.0.1 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=8 ttl=255 time=2 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=255 time=2 ms
--- 127.0.0.1 ping statistics ---
10 packets transmitted, 10 packets received, 0% packet loss
round-trip min/avg/max = 2/2/2 ms 

 

BIBLIOGRAPHY 

  1. Stevens, W. Richard, “UNIX Network Programming”, 2001, 1st Edition, Prentice Hall-India.  

  2. Tanenbaum, Andrew S., “Computer Networks”, 2001, 3rd Edition, Prentice Hall-India.  

  3. RFC 792 - Internet Control Message Protocol, DARPA Internet Program Protocol Specification  

  4. Connected: An Internet Encyclopedia (http://www.freesoft.org/CIE/index.htm)

  5. The Ping Page (http://www.ping127001.com/index.htm)

  6. Mike Muuss – The Story of PING (http://ftp.arl.mil/~mike/ping.html)

  7. Manpages for PING (http://www.fifi.org/)