Archive | May 2013

Programming Languages Homework 8

Ed Smart
CSC 340
Homework 8

7.1 For the languages C and Java, give as precise binding times as you can for the following attributes. Explain your answers.

(a) The maximum number of significant digits in a real number

This is depends on the real number itself, so it occurs during execution., making it dynamically bound.

(b) The meaning of char

This occurs during language definition, making it statically bound.

(c) The size of an array variable

It is possible to declare an array variable at either compile time or runtime. Due to this, it can either be statically or dynamically bound.

(d) The size of an array parameter

The size of an array parameter is statically bound, since it is declared during compile time.

(e) The location of a local variable

Local variables are statically bound, as they cannot be changed during runtime.

(f) The value of a constant

The value of a constant is bound during loading time, making the binding static.

(g) The location of a function

The location of a function may either be bound at compile time or runtime, so it can be either statically or dynamically bound.

7.7 As noted in this chapter, C and C++ make a distinction between a declaration and a definition. Which of the following are declarations only and which are definitions?

To declare something means to give the compiler only the minimum of its information, mainly just a name and type. Defining, on the other hand, provides the compiler with all of the information for creating whatever it is that is being defined.

(a) char * name;

This is a definition.

(b) typedef int * IntPtr;

This is a definition.

(c) struct rec;

This is a declaration.

(d) int gcd(int,int);

This is a declaration.

(e) double y;

This is a definition.

(f) extern int z;

This is a declaration.

7.14 The following program prints two integer values; the first value typically is garbage (or possibly 0, if you are executing inside a debugger or other controlled environment), but the second value might be 2. Explain why.

#include <stdio.h>
void p(void){
int y;
printf(“%d\n”, y);
y = 2;
}
main(){
p(); p();
return 0;
}

The first value would be garbage because the variable y is being printed before it has been given a value. The second value might be 2 because y is given a value of 2 in the line following the printf, so it may print 2 during the second call, if y retains its value.

7.16 Explain the difference between aliasing and side effects.

Aliasing can be thought of as the binding of two different names to the same object. For example, the following code results in x and y becoming aliases.

int *x, *y;
x = (int *) malloc(sizeof(int));
*x = 1;
y = x; /* *x and *y now aliases */

A side effect, however, is any change in the value of a variable that persists beyond the execution of the statement. Side effects may become harmful if they cannot be determined from the written code.

Networking Wireshark 4

Ed Smart
CSC 251
Wireshark Lab 4: Exploring TCP

1. What is the IP address and TCP port number used by the client computer (source) that is transferring the file to gaia.cs.umass.edu? To answer this question, it’s probably easiest to select an HTTP message and explore the details of the TCP packet used to carry this HTTP message, using the “details of the selected packet header window.”

The IP address used by the client computer transferring the file is 192.168.1.102, and the TCP port number used is 1161.

Image

2. What is the IP address of gaia.cs.umass.edu? On what port number is it sending and receiving TCP segments for this connection?

The IP address of gaia.cs.umass.edu is 128.119.245.12. It is sending and receiving TCP segments for this connection on port 80.

Image

If you have been able to create your own trace, answer the following question:
3. What is the IP address and TCP port number used by your client computer (source) to transfer the file to gaia.cs.umass.edu?

The IP address used by my client computer to transfer the file is 10.33.152.47, and the TCP port number used is 54233.

Image

4. What is the sequence number of the TCP SYN segment that is used to initiate the TCP connection between the client computer and gaia.cs.umass.edu? What is it in the segment that identifies the segment as a SYN segment?

The sequence number of the TCP SYN segment that is used to initiate the TCP connection is 0. The feature that identifies the segment as a SYN segment is the Flag.

Image

5. What is the sequence number of the SYNACK segment sent by gaia.cs.umass.edu to the client computer in reply to the SYN? What is the value of the Acknowledgement field in the SYNACK segment? How did gaia.cs.umass.edu determine that value? What is it in the segment that identifies the segment as a SYNACK segment?

The sequence number of the SYNACK segment is 0. The value of the Acknowledgement field in the SYNACK segment is 1. Gaia.cs.umass.edu determined that value by considering the relative sequence and ACK numbers. The feature in the segment that identifies the segment as a SYNACK segment are the Flags.

Image

6. What is the sequence number of the TCP segment containing the HTTP POST command? Note that in order to find the POST command, you’ll need to dig into the packet content field at the bottom of the Wireshark window, looking for a segment with a “POST” within its DATA field.

The sequence number of the TCP segment containing the HTTP POST command is 152494.

Image

7. Consider the TCP segment containing the HTTP POST as the first segment in the TCP connection. What are the sequence numbers of the first six segments in the TCP connection (including the segment containing the HTTP POST)? At what time was each segment sent? When was the ACK for each segment received? Given the difference between when each TCP segment was sent, and when its acknowledgement was received, what is the RTT value for each of the six segments?

The sequence numbers of the first six segments in the TCP connection are:
1. 152494
2. 1
3. 152977
4. 0
5. 1
6. 0

The time (in seconds) at which each segment was sent was:
1. 5.184
2. 5.503
3. 5.708
4. 6.122
5. 6.128
6. 6.164

The ACK for each segment was received at time (in seconds):
1. 5.186
2. 5.703
3. 5.723
4. 6.125
5. 6.168
6. 6.1681

The RTT (in seconds) for each segment is:
1. 0.039
2. 0.2
3. 0.233
4. 0.00007
5. 0.0007
6. 0.0009

8. What is the length of each of the first six TCP segments?

The length of each of the first six TCP segments is:
1. 537
2. 739
3. 384
4. 532
5. 701
6. 602

Networking Project 4: Web Proxy Server Program

Socket Programming Assignment 4: HTTP Web Proxy Server

In this lab, you will learn how web proxy servers work and one of their basic functionalities – caching.

Your task is to develop a small web proxy server which is able to cache web pages. It is a very simple proxy server which only understands simple GET-requests, but is able to handle all kinds of objectsnot just HTML pages, but also images.

Generally, when the client makes a request, the request is sent to the web server. The web server then processes the request and sends back a response message to the requesting client. In order to improve the performance we create a proxy server between the client and the web server. Now, both the request message sent by the client and the response message delivered by the web server pass through the proxy server. In other words, the client requests the objects via the proxy server. The proxy server will forward the client’s request to the web server. The web server will then generate a response message and deliver it to the proxy server, which in turn sends it to the client.

Below is the code for the web proxy server.

ImageImage

Image

Networking Project 3: SMTP Mail Client Program

Socket Programming Assignment 3: SMTP
By the end of this lab, you will have acquired a better understanding of SMTP protocol. You will also gain experience in implementing a standard protocol using Python.

Your task is to develop a simple mail client that sends email to any recipient. Your client will need to connect to a mail server, dialogue with the mail server using the SMTP protocol, and send an email message to the mail server.

ImageImage

Networking Project 2: UDP Pinger Program

Socket Programming Assignment 2: UDP
In this lab, you will learn the basics of socket programming for UDP in Python. You will learn how to send and receive datagram packets using UDP sockets and also, how to set a proper socket timeout. Throughout the lab, you will gain familiarity with a Ping application and its usefulness in computing statistics such as packet loss rate.

Client Code
You need to implement the following client program.
The client should send 10 pings to the server. Because UDP is an unreliable protocol, a packet sent from the client to the server may be lost in the network, or vice versa. For this reason, the client cannot wait indefinitely for a reply to a ping message. You should get the client wait up to one second for a reply; if no reply is received within one second, your client program should assume that the packet was lost during transmission across the network. You will need to look up the Python documentation to find out how to set the timeout value on a datagram socket.
Specifically, your client program should
(1) send the ping message using UDP (Note: Unlike TCP, you do not need to establish a connection first, since UDP is a connectionless protocol.)
(2) print the response message from server, if any
(3) calculate and print the round trip time (RTT), in seconds, of each packet, if server responses
(4) otherwise, print “Request timed out”

Below is the code for the UDP pinger server.

Image

This is the code for the UDP pinger client.

Image

Image

Here is the output.

Image

Networking Project 1: Web Server Program

Image

Image

This web server program, written in Python, creates a socket, binds it to a specific address and port, and handles HTTP requests. It handles one request at a time; accepting the request, parsing it, getting the requested file from the server’s file system, creating an HTTP response message containing the requested file preceded by header lines, and sending the response directly to the client. If the server does not have the file specified in the request, the server responds by sending an HTTP message back to the client saying “Error 404: File not found.”