Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
3rd Edition
ISBN: 9780134123837
Author: Randal E. Bryant, David R. O'Hallaron
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 11, Problem 11.6HW

A.

Program Plan Intro

IP addresses:

  • The IP address denotes an unsigned integer that is 32-bit.
  • The IP addresses is been stored by network programs in IP address structure.
  • The addresses present in IP address structure are stored in network byte order.
  • An unsigned 32-bit integer is transformed from host byte order to network byte order by “htonl” function.
  • An unsigned 32-bit integer is transformed from network byte order host byte order by “ntohl” function.
  • The IP address is presented to humans in a form known as “dotted-decimal” notation.
    • Each byte is been represented by its corresponding decimal value and is separated by a period from other bytes.

Passing program arguments to server:

  • The arguments for “GET” requests are passed in the URI.
  • The character “?” separates filename from the arguments.
  • The character “&” separates each argument.
  • The arguments do not allow spaces in it.

Server passes arguments to child:

  • The server calls “fork” to create a child process and calls “execve” to run program in child’s context once it receives a request.
  • The child process sets CGI environment variable values.
  • The “adder” program can reference it at run time using “getenv” function of linux.

Output is sent by child:

  • The dynamic content of a CGI program is to be sent to standard output.
  • A CGI program sends dynamic content to standard output.
  • It uses “dup2” function for redirecting standard output to connected descriptor associated with client.
  • The result written to standard output by CGI program, it goes directly to client.

A.

Expert Solution
Check Mark

Explanation of Solution

Modified C code:

//Define method

void clienterror(int fd, char *cause, char *errnum, char *shortmsg, char *longmsg);

//Define method

void echo(int connfd);

//Define main method

int main(int argc, char **argv)

{

//Declare variables

int listenfd, connfd;

//Call method

Getnameinfo((SA *) &clientaddr, clientlen, hostname, MAXLINE,port, MAXLINE, 0);

//Display message

printf("Accepted connection from (%s, %s)\n", hostname, port);

//Call method

echo(connfd);

//Close

Close(connfd);

}

//Define method

void echo(int connfd)

{

//Declare variable

size_t n;

//Declare array

char buf[MAXLINE];

//Declare variable

rio_t rio;

//Call method

Rio_readinitb(&rio, connfd);

//Loop

while ((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0)

{

//If condition satisfies

if (strcmp(buf, "\r\n") == 0)

//Break

break;

//Call method

Rio_writen(connfd, buf, n);

}

}

Explanation:

  • The method “echo” declares the variables first.
  • It handles one HTTP response/request transaction.
  • The value is been read using method “readinitb” and is stored.
  • The value is been written into buffer using “written” method.
  • The comparison is made until new line occurs.

B.

Program Plan Intro

IP addresses:

  • The IP address denotes an unsigned integer that is 32-bit.
  • The IP addresses is been stored by network programs in IP address structure.
  • The addresses present in IP address structure are stored in network byte order.
  • An unsigned 32-bit integer is converted from host byte order to network byte order by “htonl” function.
  • An unsigned 32-bit integer is converted from network byte order host byte order by “ntohl” function.
  • The IP address is presented to humans in a form known as “dotted-decimal” notation.
    • Each byte is been represented by its corresponding decimal value and is separated by a period from other bytes.

Passing program arguments to server:

  • The arguments for “GET” requests are passed in the URI.
  • The character “?” separates filename from the arguments.
  • The character “&” separates each argument.
  • The arguments do not allow spaces in it.

Server passes arguments to child:

  • The server calls “fork” to create a child process and calls “execve” to run program in child’s context once it receives a request.
  • The child process sets CGI environment variable values.
  • The “adder” program can reference it at run time using “getenv” function of linux.

Output is sent by child:

  • The dynamic content of a CGI program is to be sent to standard output.
  • A CGI program sends dynamic content to standard output.
  • It uses “dup2” function for redirecting standard output to connected descriptor associated with client.
  • The result written to standard output by CGI program, it goes directly to client.

B.

Expert Solution
Check Mark

Explanation of Solution

Request to TINY for static content:

GET / HTTP/1.1

Host: localhost:5000

User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Connection: keep-alive

Explanation:

  • The given code denotes a request to “TINY” for static content.
  • It echoes each and every request line.
  • It echoes each and every request header.
  • It takes a particular “Accept-Language” and “Accept-Encoding” for the content.

C.

Program Plan Intro

IP addresses:

  • The IP address denotes an unsigned integer that is 32-bit.
  • The IP addresses is been stored by network programs in IP address structure.
  • The addresses present in IP address structure are stored in network byte order.
  •  An unsigned 32-bit integer is converted from host byte order to network byte order by “htonl” function.
  • An unsigned 32-bit integer is converted from network byte order host byte order by “ntohl” function.
  • The IP address is presented to humans in a form known as “dotted-decimal” notation.
    • Each byte is been represented by its corresponding decimal value and is separated by a period from other bytes.

Passing program arguments to server:

  • The arguments for “GET” requests are passed in the URI.
  • The character “?” separates filename from the arguments.
  • The character “&” separates each argument.
  • The arguments do not allow spaces in it.

Server passes arguments to child:

  • The server calls “fork” to create a child process and calls “execve” to run program in child’s context once it receives a request.
  • The child process sets CGI environment variable values.
  • The “adder” program can reference it at run time using “getenv” function of linux.

Output is sent by child:

  • The dynamic content of a CGI program is to be sent to standard output.
  • A CGI program sends dynamic content to standard output.
  • It uses “dup2” function for redirecting standard output to connected descriptor associated with client.
  • The result written to standard output by CGI program, it goes directly to client.

C.

Expert Solution
Check Mark

Explanation of Solution

Version of HTTP:

  • The version of HTTP used by browser is HTTP 1.1.
  • The output from “TINY” is been inspected for determining HTTP version of browser.
  • The “TINY” denotes an iterative server that listens for connection requests on ports.
  • The “TINY” executes infinite server loop; it accepts a connection request repeatedly.
  • It performs the transaction and closes its end of connection.
  • Hence, version of HTTP is “HTTP 1.1”.

D.

Program Plan Intro

IP addresses:

  • The IP address denotes an unsigned integer that is 32-bit.
  • The IP addresses is been stored by network programs in IP address structure.
  • The addresses present in IP address structure are stored in network byte order.
  •  An unsigned 32-bit integer is converted from host byte order to network byte order by “htonl” function.
  • An unsigned 32-bit integer is converted from network byte order host byte order by “ntohl” function.
  • The IP address is presented to humans in a form known as “dotted-decimal” notation.
    • Each byte is been represented by its corresponding decimal value and is separated by a period from other bytes.

Passing program arguments to server:

  • The arguments for “GET” requests are passed in the URI.
  • The character “?” separates filename from the arguments.
  • The character “&” separates each argument.
  • The arguments do not allow spaces in it.

Server passes arguments to child:

  • The server calls “fork” to create a child process and calls “execve” to run program in child’s context once it receives a request.
  • The child process sets CGI environment variable values.
  • The “adder” program can reference it at run time using “getenv” function of linux.

Output is sent by child:

  • The dynamic content of a CGI program is to be sent to standard output.
  • A CGI program sends dynamic content to standard output.
  • It uses “dup2” function for redirecting standard output to connected descriptor associated with client.
  • The result written to standard output by CGI program, it goes directly to client.

D.

Expert Solution
Check Mark

Explanation of Solution

Meaning of HTTP headers:

  • The details of each HTTP header is shown below:
    • Accept:14.1:
      • It can be used for specifying certain media types that are acceptable for response.
      • Accept headers are used to indicate that request is limited specifically to a small set of desired types.
      • It has same impact as in case of an in-line image request.
    • Accept-Encoding: 14.3:
      • The request header field is almost similar to “Accept”.
      • It restricts the content-coding that are acceptable in response.
    •  Accept-Language: 14.4:
      • The “Accept-Language” request header is similar to that of “Accept”.
      • It restricts set of natural languages preferred as response to request.
    • Connection: 14.10:
      • The connection header field allows sender to specify options that are desired for particular connection.
      • It must not be communicated by proxies over further connections.
    • Host: 14.23:
      • The host request header field would specify internet host and port number of resource being requested.
      • The host field value denotes origin server’s naming authority or gateway given by original URL.
      • It allows origin server or gateway in differentiating between ambiguous URLs.
      • The root “/” server’s URL is used for multiple host names with single IP address.
    • User-Agent: 14.43:
      • The user-agent request header has information about user agent initiating the request.
      • It is used for tracing protocol violations, automated acknowledgment of user agents for avoiding limitations of user agent.
      • The requests are been added with the field.
      • The field contains multiple product tokens and comments that identifies agent.
      • It includes sub products that forms a significant part of user agent.
      • The product tokens are listed in order of their significance for application identification.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
What are the major threats of using the internet? How do you use it? How do children use it? How canwe secure it? Provide four references with your answer. Two of the refernces can be from an article and the other two from websites.
Assume that a string of name & surname is saved in S. The alphabetical characters in S can be in lowercase and/or uppercase letters. Name and surname are assumed to be separated by a space character and the string ends with a full stop "." character. Write an assembly language program that will copy the name to NAME in lowercase and the surname to SNAME in uppercase letters. Assume that name and/or surname cannot exceed 20 characters. The program should be general and work with every possible string with name & surname. However, you can consider the data segment definition given below in your program. .DATA S DB 'Mahmoud Obaid." NAME DB 20 DUP(?) SNAME DB 20 DUP(?) Hint: Uppercase characters are ordered between 'A' (41H) and 'Z' (5AH) and lowercase characters are ordered between 'a' (61H) and 'z' (7AH) in the in the ASCII Code table. For lowercase letters, bit 5 (d5) of the ASCII code is 1 where for uppercase letters it is 0. For example, Letter 'h' Binary ASCII 01101000 68H 'H'…
What did you find most interesting or surprising about the scientist Lavoiser?
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
A+ Guide To It Technical Support
Computer Science
ISBN:9780357108291
Author:ANDREWS, Jean.
Publisher:Cengage,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
Computer Science
ISBN:9781337569798
Author:ECKERT
Publisher:CENGAGE L
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage