ITL Lab Manual

Programming the Interface


Raw Packets

send.c

The program send.c illustrates how to send a packet to a particular interface where the contents of the packet are completely controlled by the program (i.e. even the fields normally devoted to ethernet destination address and ethernet source address are under the control of the program.) The program does not check whether the interface is ready for another packet. It expects to be blocked if the interface is not ready.

There are two buffers involved in sending a raw packet. One is the buffer maintained by the program (in the variable "buffer") to hold the data the program wishes to send. The other is the buffer maintained by the interface to hold the data it wishes to send. In its call to the function "sendto" the program specifies some number of bytes in its buffer to be copied to the interface's buffer. If this number is fewer than the minimum packet size (64 bytes) for ethernet, the remainder of the packet consists of whatever data happened still to be in the interface's buffer. The four byte CRC at the end of the ethernet packet cannot be specified by the program. It is attached by the interface. Thus if the program specifies a buffer size of 64 bytes the packet actually sent will contain 68 bytes. If the program specifies a buffer size of 60 bytes or fewer, the packet actually sent will contain 64 bytes.

Open send.c and its makefile in a separate window.

Using ftp download send.c or its makefile.

blocking examine.c

The program examine.c illustrates how to receive a packet from a particular interface. It also shows how the interface can be placed into promiscuous mode. In this version the program blocks when it attempts to receive data from the network and no data is available. The number of bytes received by the program is either the number in the packet including the CRC, or the number in the packet excluding the CRC, depending on the brand of network interface used for the connection. The interfaces in the computers in the lab will include the CRC in the packet they report, whereas the interfaces in the server will not.

Open blocking examine.c and its makefile in a separate window.

Using ftp download examine.c or its makefile.

non-blocking examine.c

The program examine.c illustrates how to receive a packet from a particular interface without blocking. If there is no data avaiable from the interface when the program requests it the call returns immediately with an error value. The program must continue to attempt to read data until some is available.

Open non-blocking examine.c and its makefile in a separate window.

Using ftp download examine.c or its makefile.

timeout examine.c

The program examine.c illustrates how to receive a packet from a particular interface without blocking by having the operating system suspend the program until one of two situations occurs:

Open timeout blocking examine.c and its makefile in a separate window.

Using ftp download examine.c or its makefile.

Exercises

  1. By specifying the appropriate values for the last argument to send.c you can cause an ethernet address to be placed in the packet in the location appropriate for the ethernet destination address. Use this program to send packets to another computer in the lab whose ethernet address you know. Try it with the receiving computer in promiscuous mode and try it with the receiving computer not in promiscuous mode. Verify that when the receiving computer is not in promiscuous mode only packets addressed to its ethernet address or to the broadcast address are received.

  2. Write two functions - set_allmulti_mode and clear_allmulti_mode - which are similar to set_promiscuous_mode and clear_promiscuous_mode but which set and clear the allmulti mode of an interface. Put them into a program and verify that they work.

  3. Modify send.c so that the argument that specifies the string to be placed in the packet is not available. Instead the program places into the packet the binary representation of the number of the packet (i.e. the first packet sent contains a 0, the second a 1, and so on). Verify that the changes work by examining the packets using ethereal.

    Then modify examine.c so that the number in each packet is checked against the value expected (i.e. the first packet received should contain a 0, the second a 1, and so on). As soon as a packet is received whose sequence number is incorrect the program displays both the expected and received sequence numbers and terminates. Verify that the program works correctly.

    Use these programs to determine whether large numbers of packets can be sent from one computer to another without loss. If there is packet loss, determine after how many packets the loss occurs when the connection is a 10BaseT connection and when the connection is a 100BaseT connection. Run experiments (these may involve modifying send.c to introduce a small delay between packets) to determine whether the packet loss is because of a low quality connection or because buffers in the receiver are overrun. (It has been suggested that when two computers in the lab are connected at the rack using a crossover cable that wiring standard have been violated. The presence of 3 patch cables in the connection is 1 too many.)

  4. Modify send.c and examine.c so that you can measure the throughput of a connection between two computers.

    The new version of send.c should allow you to specify the size of the packet that is sent. It need not allow you to specify the number of packets and the contents of the packet. Instead it should send packets as quickly as possible. The contents of the packet can be anything you choose. The program is terminated by killing it from the terminal. When it terminates the program should display the total number of packets it sent, the total number of bytes it sent, the total time it was running, and the throughput (number of bytes per second).

    The new version of examine.c should be changed so that when it terminates it displays the total number of packets it received, the total number of bytes it received, the total time it was running, and the throughput (number of bytes per second).

    Use these programs to determine how close to the bandwidth of a 10BaseT connection (or to a 100BaseT connection) you can get.

  5. Modify send.c and examine.c so that you can display the current throughput of a connection between two computers.

    The new version of send.c should allow you to specify the size of the packet that is sent. It need not allow you to specify the number of packets and the contents of the packet. Instead it should send packets as quickly as possible. The contents of the packet can be anything you choose. The program is terminated by killing it from the terminal. As it runs it should compute the throughput (number of bytes per second) over intervals that are long enough to provide a stable value, but short enough to show changes in time. The program should constantly display the current value of the throughput.

    The new version of examine.c should be changed so that as it runs it should compute the throughput (number of bytes per second) over intervals that are long enough to provide a stable value, but short enough to show changes in time. The program should constantly display the current value of the throughput.

    Use these programs to determine whether the throughput between the computers is affected by simultaneous use of other programs that communicate with the computers.

  6. Modify send.c and examine.c into programs named transmit.c and receive.c. The program transmit.c will send the contents of a specified file to a computer that is running receive.c. The arguments to transmit.c should be:

    transmit <filename> <interface> <destination ethernet address>
    

    where <filename> is the path to the file to be transmitted, <interface> is eth0, eth1, etc, and <destination ethernet address> is the ethernet address of the computer running receive.c.

    The arguments to receive.c should be:

    receive <filename> <interface>
    

    where <filename> is the path to the file to be transmitted, and <interface> is eth0, eth1, etc.

    The receive program assumes that only one transmit program is active at a time. The programs should use a stop-and-wait protocol to guarantee that the file arrives intact. You should be able to compare the received file with the transmitted file using a unix comparison utility to verify that it arrived intact.

    Neither the transmitting program nor the receiving program should terminate until both are sure that the file transfer is complete. When the transfer is complete both programs will terminate on their own. You should begin by designing the protocol to be used by the programs and documenting it.

  7. Modify send.c so that it sends an ARP reply packet from one computer to the ethernet address of another device. Determine whether it is possible for the computer to get itself installed in the ARP table of the device even if the device never sent an ARP request. Try this with a computer as the device and with a router as the device.


| Sonoma State University | CS Department | Computer and Engineering Science | Internet Teaching Laboratory | Lab Manual Table of Contents |