Experiment 12.1 Sample Output and Raw Packets

Sample output from pingpackets

Destination: 8:0:20:88:b6:10 Source: 8:0:20:e7:89:8d Type: 2048
Destination: 8:0:20:e7:89:8d Source: 8:0:20:a8:ef:3e Type: 2048
Destination: 8:0:20:e7:89:8d Source: 8:0:20:a8:ef:3e Type: 2048

Packets from pingpackets

For those of you who have never spent hours pouring over IBM core dumps, here is a somewhat color-coded example of what the output of snoop looks like in hexidecimal. The file is essentially the output of the command od -A x -x modified to add color. The first several packets are identified using the following scheme:

736e 6f6f 7000 0000 0000 0002 0000 0004 
0000 0036 0000 0036 0000 0050 0000 0000
3c5a b51b 0002 98cc 0800 2088 b610 0800
20e7 898d 0800 4500 0028 2587 4000 4006
fde8 0a02 025b 0a02 0102 0346 0801 9ce6
88c0 f6f8 2827 5010 60f4 e771 0000 7f30
0000 05ea 0000 05ea 0000 0608 0000 0000
3c5a b51b 0009 1879 0800 20e7 898d 0800
20a8 ef3e 0800 4500 05dc 35e0 6000 ff01
078f 0a02 0253 0a02 025b 0800 921a 431a
0000 3c5a b5a7 0000 ebc9 0809 0a0b 0c0d
0e0f 1011 1213 1415 1617 1819 1a1b 1c1d
1e1f 2021 2223 2425 2627 2829 2a2b 2c2d
2e2f 3031 3233 3435 3637 3839 3a3b 3c3d
3e3f 4041 4243 4445 4647 4849 4a4b 4c4d
4e4f 5051 5253 5455 5657 5859 5a5b 5c5d
5e5f 6061 6263 6465 6667 6869 6a6b 6c6d
6e6f 7071 7273 7475 7677 7879 7a7b 7c7d
7e7f 8081 8283 8485 8687 8889 8a8b 8c8d
8e8f 9091 9293 9495 9697 9899 9a9b 9c9d
9e9f a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad
aeaf b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd
bebf c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd
cecf d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd
dedf e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced
eeef f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd
feff 0001 0203 0405 0607 0809 0a0b 0c0d
0e0f 1011 1213 1415 1617 1819 1a1b 1c1d
1e1f 2021 2223 2425 2627 2829 2a2b 2c2d
2e2f 3031 3233 3435 3637 3839 3a3b 3c3d
3e3f 4041 4243 4445 4647 4849 4a4b 4c4d
4e4f 5051 5253 5455 5657 5859 5a5b 5c5d
5e5f 6061 6263 6465 6667 6869 6a6b 6c6d
6e6f 7071 7273 7475 7677 7879 7a7b 7c7d
7e7f 8081 8283 8485 8687 8889 8a8b 8c8d
8e8f 9091 9293 9495 9697 9899 9a9b 9c9d
9e9f a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad
aeaf b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd
bebf c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd
cecf d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd
dedf e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced
eeef f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd
feff 0001 0203 0405 0607 0809 0a0b 0c0d
0e0f 1011 1213 1415 1617 1819 1a1b 1c1d
1e1f 2021 2223 2425 2627 2829 2a2b 2c2d
2e2f 3031 3233 3435 3637 3839 3a3b 3c3d
3e3f 4041 4243 4445 4647 4849 4a4b 4c4d
4e4f 5051 5253 5455 5657 5859 5a5b 5c5d
5e5f 6061 6263 6465 6667 6869 6a6b 6c6d
6e6f 7071 7273 7475 7677 7879 7a7b 7c7d
7e7f 8081 8283 8485 8687 8889 8a8b 8c8d
8e8f 9091 9293 9495 9697 9899 9a9b 9c9d
9e9f a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad
aeaf b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd
bebf c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd
cecf d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd
dedf e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced
eeef f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd
feff 0001 0203 0405 0607 0809 0a0b 0c0d
0e0f 1011 1213 1415 1617 1819 1a1b 1c1d
1e1f 2021 2223 2425 2627 2829 2a2b 2c2d
2e2f 3031 3233 3435 3637 3839 3a3b 3c3d
3e3f 4041 4243 4445 4647 4849 4a4b 4c4d
4e4f 5051 5253 5455 5657 5859 5a5b 5c5d
5e5f 6061 6263 6465 6667 6869 6a6b 6c6d
6e6f 7071 7273 7475 7677 7879 7a7b 7c7d
7e7f 8081 8283 8485 8687 8889 8a8b 8c8d
8e8f 9091 9293 9495 9697 9899 9a9b 9c9d
9e9f a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad
aeaf b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd
bebf c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd
cecf d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd
dedf e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced
eeef f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd
feff 0001 0203 0405 0607 0809 0a0b 0c0d
0e0f 1011 1213 1415 1617 1819 1a1b 1c1d
1e1f 2021 2223 2425 2627 2829 2a2b 2c2d
2e2f 3031 3233 3435 3637 3839 3a3b 3c3d
3e3f 4041 4243 4445 4647 4849 4a4b 4c4d
4e4f 5051 5253 5455 5657 5859 5a5b 5c5d
5e5f 6061 6263 6465 6667 6869 6a6b 6c6d
6e6f 7071 7273 7475 7677 7879 7a7b 7c7d
7e7f 8081 8283 8485 8687 8889 8a8b 8c8d
8e8f 9091 9293 9495 9697 9899 9a9b 9c9d
9e9f a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad
aeaf b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd
bebf c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd
cecf d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd
dedf e0e1 e2e3 e4e5 e6e7 e8e9 eaeb eced
eeef f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd
feff 0001 0203 0405 0607 0809 0a0b 0c0d
0e0f 1011 1213 1415 1617 1819 1a1b 1c1d
1e1f 2021 2223 2425 2627 2829 2a2b 2c2d
2e2f 3031 3233 3435 3637 3839 3a3b 3c3d
3e3f 4041 4243 4445 4647 4849 4a4b 4c4d
4e4f 5051 5253 5455 5657 5859 5a5b 5c5d
5e5f 6061 6263 6465 6667 6869 6a6b 6c6d
6e6f 7071 7273 7475 7677 7879 7a7b 7c7d
7e7f 8081 8283 8485 8687 8889 8a8b 8c8d
8e8f 9091 9293 9495 9697 9899 9a9b 9c9d
9e9f a0a1 a2a3 a4a5 a6a7 a8a9 aaab acad
aeaf b0b1 b2b3 b4b5 b6b7 b8b9 babb bcbd
bebf 05ea f950 05ea 0000 05ea 0000 05ea
0000 0608 0000 0000 3c5a b51b 0009 18b8
0800 20e7 898d 0800 20a8 ef3e 0800 4500
05dc 35e0 60b9 ff01 06d6 0a02 0253 0a02
025b c0c1 c2c3 c4c5 c6c7 c8c9 cacb cccd
cecf d0d1 d2d3 d4d5 d6d7 d8d9 dadb dcdd

Experiment 5.2

Assuming that you have already done Experiment 5.1 you have already obtained and compiled the chat server and client.

After testing the programs you move on to the first modification, adding a name for each. (Tip: when testing do not use Harry and Sally, use Client and Server. It makes things a lot easier, especially if you have short-term memory problems.) I used a printf followed by a gets. If you just add those two lines along with a variable for the name, you will get a compiler warning. You should do that if you are somewhat new to C even though I am about to tell you how to avoid it. Hint: in the absence of any indication as to the type returned by a function, what does the C compiler assume? Now the fix: just add string.h to the files you are including. Why did that fix the problem?

In order to prepend the name to the message you need to use strcat. This is harder to do in C than in C++, say, because you need to use a strcpy followed by two strcat functions.

This small step has an important implication for testing. Depending on where you pit this code you may encounter the following oddity: you fire up your server and while it is still waiting for the name, you fire up your client which immediately terminates. Why?

The first Optional Extension is very interesting! It requires slightly different behavior when sending and receiving depending on whether it is the first time through. Straightforward, but my first effort met a fascinating problem. The client sent data and then, somehow, received data before the server had a chance to respond. Then the two got out of sync, each being in input mode. For my own sanity in debugging I cleared buffers right after each use. Voila! The problem was gone. Apparently, the function readln did not provide the NULL termination. When I later used strlen to determine how many bytes to send, I was way over and somehow overwrote my connection variable.

The second Optional Extension seems at first blush to be easy, almost trivial. It is not! You would probably first try to use getchar in a loop. This will not do what you want. What makes this extension difficult is that you need to change the mode of your keyboard so that it will not buffer the input until a line-feed. I found it quite difficult to do in the given context, that is, working with the code provided, so I cheated. I took a simpler, self-contained chat program and modified that code. There are two ways to do this, and each involves its own intricacies. The simpler way is use a system call. On a Linux box you code

system("stty cbreak")

before your chat session code and

system("stty -cbreak")

after it. On Solaris 8 you use raw in place of cbreak.

What this does is change the settings of your keyboard so that input is not buffered, ie, the program does not wait for a \n but really accepts a single character. The problem is that your keyboard behavior is changed in other ways as well. You will certainly have a loop in which you read a character from stdin and send one character to the other host. This loop will terminate when the user hits the Enter key. Normally, the test would be a comparison with \n. I found (Solaris 8) that it was a \r! The session should terminate when one or the other user hits Control-D . That would normally mean a test for EOF, -1, but with the keyboard mode alterred, I found that I needed to test for EOT, 4. How do you figure this out? You use gdb, and you examine the value of your variable at the appropriate point. In other words you experiment!

An alternate approach, preferred by Professor Comer, is to write code to modify the keyboard settings. This involves the functions tcgetattr and tcsetattr. I wrote a fuction with one parameter and called it twice. Everything worked fine except that I had to test for EOT instead of EOF as described above.

Please do not be turned off by these comments. This is a very interesting and rewarding exercise. I personally found a great deal of satisfaction in it, and think how much better you are prepared for its challenges than I was!


This site is maintained by by W. David Laverell of the Computer Science Department at Calvin College.
For assistance or corrections, please contact him at lave@calvin.edu.