CSE378 Homework #3


Due: electronically, Wed. evening 11:59, Oct 22. See turnin instructions below. Paperwork (if any) in class the next day.

A short one this time, with the midterm coming up. 

1. Complete E3, left over from Homework 2.

2. Master of the Internet. C programming, intended to give practice with bit manipulation operations.
(Backgrround: This information about IP addresses is widely available in print and on the Internet.  I'll summarize it here and have a handout for anyone who would like it.)
Internet Protocol (IP) address are 32-bit quantities which in some sense identify a "host" (endpoint computer) on the Internet.  One could write the IP address out for humans to read in decimal or in hex, but by tradition, another notation, called "dotted decimal" is used.  Each byte of the address is converted separated to decimal, and the resulting 4 numbers are written with periods between them.  (E.g. 0x86180842 is written 134.24.8.66).  Everybody knows that, right?  But only true Masters of the Internet know the following: internally, the IP address is not structured as four bytes.  There are three fields: network class, network ID, and host ID.  The network class field comes first and determines the size of the other two fields.  The fun part is that the class field is variable in length: from 1 bit to 5 bits.  The values in binary are A:0, B:10, C:110, D:1110, E:11110.  Consult the handout the resulting size and position of the network ID and host ID for each case.

Write a C program which, given an IP address (as a hex integer), prints out 1) the address in dotted decimal format 2) the network class as the letter A, B, C, D, or E  3) for classes A, B, and C, the network ID and the host ID (each in decimal).  The address is supplied as the (single) command line parameter. The input is an  8-character string, interpreted as a hex integer (i.e., no leading 0x.  So for the example above, the user would type just 86180842).  Don't use any library functions except for printing.

In your program, there will most likely be expressions which use the C bit-manipulation operations.  On these lines of code, place a comment stating in words what the operation is ("shifting left 3 bits...", "masking out the host ID", etc.) and stating what the corresponding MIPS instruction would be (at least the op-code, and the other MIPS fields roughly).

"C program" implies something with a main.  Please place all your code in one .c file named ipmaster.c.

You may work in groups of no more than three people.  Please make only ONE submission per group, with ALL of the the participants names on it (as highly visible comments at the beginning of the program).

Hints: In the program, start by converting the 8-character string to an int variable (consider: should the int be signed or unsigned?  does it matter?).  Once you have the int, think in terms of bit-manipulation operations.

Electronic Turnin Instructions

To turn in your files electronically, you will need to: