Homework 1: 1. List Five Benefits That TCP Adds To IP. (5 Points)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Nathan Yeung

Homework 1
1. List five benefits that TCP adds to IP. (5 points) Five benefits that TCP adds to IP include the following: * TCP also conducts ordered data transfer - Every segment that is sent is numbered and acknowledged. The destination host then rearranges according to the sequence numbering. * TCP uses flow control which helps keep the sender from overrunning the receiver. * TCP also uses congestion control which helps keep the sender from overrunning the network. * TCP kindly performs retransmission of lost packets. Therefore if there are any cumulative stream that has not been acknowledged they would be retransmitted. * TCP conducts the transfer of data error-free.

2. In the OSI Reference Model, what layers are TCP, HTTP, IP, and Ethernet in? (4 points) In the OSI Reference Model, TCP is within the Transport Layer, HTTP is within the Application Layer, IP is within the Network Layer, and the Ethernet is within both the Data Link and Physical Layers.

3. List five HTTP status codes and their meanings. (5 points) 200 OK - The standard response for a successful HTTP request. The actual response is dependent of the request method provided. A GET will contain the entity for the requested resource on the host. A POST will contain entity describing or containing the results of the POST request. 301 Moved Permanently - The current request and requests from here on out will be directed to the specified URI or resource. 404 Not Found - The requested resource on the host could not be located. 403 Forbidden - The request was a good request but the server didn't not respond to it. Authenticating would have made no difference. 500 Internal Server Error - A basic error message, given when nothing else is suitable.

Nathan Yeung 4. Use telnet to ask for the cs.byu.edu index.html and index.php pages using a HTTP request. Include the response headers for both requests as your answer. (3 points) telnet use: telnet {server} {port} {HTTP request goes here.. just hit return twice for the empty line} example: (The HTTP request in this example is bad, so youll need to change that part to get the index.html and index.php pages.) A. For index.html nyeung:~ lookandlive$ telnet cs.byu.edu 80 Trying 128.187.80.80... Connected to cs.byu.edu. Escape character is '^]'. GET /index.html HTTP/1.1 HTTP/1.1 400 Bad Request Date: Thu, 22 Sep 2011 05:30:35 GMT Server: Apache/2.2.14 (Ubuntu) Vary: Accept-Encoding Content-Length: 301 Connection: close Content-Type: text/html; charset=iso-8859-1

Bad Request Your browser sent a request that this server could not understand.

Apache/2.2.14 (Ubuntu) Server at 127.0.1.1 Port 80 Connection closed by foreign host.

B. For index.php nyeung:~ lookandlive$ telnet cs.byu.edu 80 Trying 128.187.80.80... Connected to cs.byu.edu. Escape character is '^]'. GET /index.php HTTP\1.1 HTTP/1.1 404 Not Found Date: Thu, 22 Sep 2011 05:33:41 GMT Server: Apache/2.2.14 (Ubuntu) Vary: Accept-Encoding Content-Length: 282 Connection: close Content-Type: text/html; charset=iso-8859-1

Nathan Yeung

Not Found The requested URL /index.php was not found on this server. Apache/2.2.14 (Ubuntu) Server at 127.0.1.1 Port 80 Connection closed by foreign host.

5.

Use dig to determine the IP address of amazon.com (3 points)

The IP address is 72.21.214.128

6. Describe the allocation of IP addresses and how this impacts address depletion. (3 points) (http://www.bleepingcomputer.com/tutorials/tutorial37.html) The current version of IP being used is IPv4 which is a 32-bit address. This limits the amount of addresses to 4.2 billion possible unique addresses. However 290 million are reserved for special purposes. Because of the growth of the internet soon all the possible addresses will be used up. The new version IPv6 addresses this issue by increasing the size of the address to 128-bit addresses. This will allow for allocations on networks without any real concern of conflicting addresses. Hardware would have to be upgraded in order to receive the benefits of IPv6.

7. Detail the effects of a call to gethostbyname(), focusing on the Domain Name System. (3 points) The gethostbyname() is used to resolve a host names in the domain name system or the local hosts other resolver mechnisms via /etc/hosts. A pointer to a struct object called hostent is returned. hostent describes and IP host. The call queries a DNS server using the host name provided and gives the IP address that corresponds to that host name.

8. Compare and contrast the GET and POST methods in HTML.(3 points) GET is the default method used to retrieve any images, style sheets, JavaScript, and other entities loaded into a webpage. The HTTP specification explains that there may sometimes be a ? in the URL in consideration. Anything that comes after the ? is expected to be a key value pair. A server application can read these key value pairs thereby dynamically generating the page. These key value pairs can be modified by anyone by simply modify the URL by replacing the original text with texts of your choosing. The HTTP GET request method is limited in how much data that can be sent. This limitation is not specified in the HTTP specification and servers and browsers have various implementations. Therefore, we cannot rely on using GET to pass large amounts of data between client and server. The POST request method is similar

Nathan Yeung to the GET method because it can also send data to the server. POST is typically the method of choice for sending large amounts of data and especially for sending binary data. POST encapsulates the parameters or key value pairs that GET makes openly visible in the URL. The data sent using POST is therefore safer because it cannot be easily modified by visitors since there is no data footprint in the URL. Also the GET request has no message body whereas the POST request does have a message body.

9. What are the symptoms you would expect to see when you have made errors in your semaphore code?(3 points) If I have made errors in my semaphore code then when my code runs, the data in my program would be changed or modified by multiple threads even though it should not do so. If I misplace my code, the wrong section of code will be essentially blocked off, the data in the program that I did not want to be accessible would be accessed by a thread in the buffer. When I create a semaphore I can initialize its value to any integer, if I fail to initialize the semaphore, the code will perform haphazardly. Another symptom may manifest itself when I try to decrement the semaphore, the program may not block or notify the scheduler that it cannot proceed, like it should do until another thread increments the semaphore. Lastly, another symptom would show when the thread is suppose to increment the semaphore and if there are other threads waiting in the buffer, one of the waiting threads is suppose to get unblocked, but instead remains blocked and therefore the data is not modified in that situation although it should be modified.

10.

Compare and contrast user-mode threads with kernel-mode threads. (3 points)

For user-mode threads, all the thread management is done by the application. This would include the creating and destroying of threads, thread communication, thread synchronization, and thread scheduling. User mode threads run within a single process and has no kernel involvement. Some advantages of user-mode threads is that it provides efficiency since there is no kernel mode switch to handle a different thread. Another advantage is that it will use application-specific scheduling. But the main advantage is that it will be operating system independent. There are also some disadvantages of using user-mode threads. One disadvantage is that the thread system call blocks the entire process. Another disadvantage is that no multiprocessing can occur because the threads of the same process cannot run on different processors. For kernel-mode threads, the thread management is handled by the kernel this time. The kernel schedules threads instead of processes. The main advantages of kernellevel threads are that they provide multiprocessing support, when a thread is blocked it doesnt block the entire process, and the kernel can be multithreaded if desired. The disadvantage of using kernel-mode threads is that the thread switching operation is more expensive because it requires mode switching.

11. What does fork() return? (3 points) If successful, fork() returns the PID (pid_t) of the child process is returned in the parent process while a 0 is returned in the child process. If unsuccessful, -1 is returned in the parent and no child process is made.

Nathan Yeung

12.

What does this code print out? (-: Try to figure it out without running the code :-)

int globalVariable = 2; int *globptr =&globalVariable; main() { string sIdentifier; int iStackVariable = 20; pid_t pID = fork(); if (pID == 0) // child { // code only executed by the child process (child runs second) sIdentifier = "Zero Process: "; globalVariable+=5; iStackVariable+=6; *globptr = 12; } else if (pID < 0) // failed to fork { globalVariable = 30; iStackVariable = 60; } else // parent { // code only executed by the parent process (parent runs first) sIdentifier = "NonZero Process:"; globalVariable+=8; iStackVariable+=9; } // Code executed by both parent and child. cout << sIdentifier; cout << " Global variable: " << globalVariable; cout << " Stack variable: " << iStackVariable << endl; } Output: NonZero Process: Global variable: 10 Stack variable: 29 Zero Process: Global variable: 12 Stack variable: 26 See comments for explanations.

13.

What is a race condition? (3 points)

Nathan Yeung

A race condition is a situation that occurs when a separate process of thread of execution is dependent on some shared state. Operations that occur on shared states are known as critical sections and need to be mutually exclusive in order to prevent the harmful collision between processes and threads that are involved in the sharing of those states.

14.

Compare and contrast execl, execlp, execle and execv. (4 points)

The these functions are members of the exec() family of functions. Members of this family of functions will initiate a program from within a program. execl() creates a new program in the current operating environment using an executable with a fully qualified path and arguments as parameters to this function. execlp() is similar except that it will use the environment variable path to determine the executable to process and will not need to use a fully qualified path. In execl() arg0 is the command or resource file name that is to be executed. Whereas in execlp() the first argument could be ls. The execle() function specifies the environment for the executed process by following the terminating null pointer of the list of arguments found in the parameter list. In addition, it could be the pointer to the argv array with an additional parameter.This additional parameter consists of an array of pointers for null-terminated strings and must also be terminated by a null-pointer. In contrast, execle() has an argument, envp, which is an array of pointers to the environment settings. Lastly, execv() is the same as execl() execpt that the arguments are passed into it as null terminated array of pointers to char. The first element argv[0] is the command name.

15. When a signal occurs in a process with multiple threads, which thread handles the signal? (2 points) Based on how sigaction() was used to bind a signal handler to its corresponding signal, the signal handler that has been bound to that signal would handle the signal.

16. What system call could you use to determine file size and file type (directory or normal file)? (1 point) The system call I could use to determine the file size and file type (directory or normal file) is accomplished by using stat() because the system call stat() will determine the type (includes types.h) of a file as well as the content-length (includes stat.h).

You might also like