Concept explainers
A.
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
- 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.
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.
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.
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.
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.
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.
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.
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.
- Accept:14.1:
Want to see more full solutions like this?
Chapter 11 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- Using the domain name www.practice.com, construct the URL for a file called overview.html in a folder called video, which is in a folder called Resources, which is in the web root directory. Do NOT include a protocol (e.g. http:// or https://). Please note that case does matter for many servers, but the Canvas quiz tool cannot check for case. For example, history.html and History.html are NOT the same, but Canvas cannot discern the difference, so be careful to match the case exactly for file and folder names.arrow_forwardConsider the following string of ASCII characters that were captured by Wireshark when the browser sent an HTTP GET message (i.e., this is the actual content of an HTTP GET message). The characters <cr><lf> are carriage return and line-feed characters (that is, the italized character string <cr> in the text below represents the single carriage-return character that was contained at that point in the HTTP header). Answer the following questions, indicating where in the HTTP GET message below you will find the answer.arrow_forwardWrite a program to create a new key pair, and then use the new key pair to launch an EC2 instance, which has 20GB EBS attached, and allows public http request.arrow_forward
- Write the head and tail commands that swaps two chunks of 51 lines from file myfile and re-saves it as myfile2. 4.) Specifically, swap the first 1-51 lines (first chunk) of myfile with lines 52-102 (second chunk). Assume myfile has 1000+ lines (the exact quantity is not given), and file myfile2 will end up having the same number of lines as myfile.arrow_forwardIn this part, we add the CPU temperature ID of the Raspberry Pi to the MQTT stream. Open a new terminal and create a new script by the name of py and add the following content to it. import paho.mqtt.client as mqtt import time from subprocess import check_output from re import findall def get_temp(): temp = check_output(["vcgencmd","measure_temp"]).decode("UTF-8") return(findall("\d+\.\d+",temp)[0]) def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) client.subscribe("etec224_mqtt_test/") global Connected Connected = True Connected = False client = mqtt.Client() client.on_connect = on_connect client.connect("broker.emqx.io", 1883, 60) client.loop_start() while Connected!= True: #Wait Here time.sleep(0.1) try: while True: value = get_temp() client.publish('etec224_mqtt_test/', value) time.sleep(1) except KeyboardInterrupt: client.disconnect()…arrow_forwardSuppose you are writing JavaScript code to send an asynchronous GET request to the action.pl file on the server. You have written code that defines your request. Which statement should you use next to send it to the server? a. httpReq.send("id=41088"); b. httpReq.XMLHttpRequest("get", "action.pl&id=41088"); c. httpReq.send(null); d. httpReq.open("get", "action.pl&id=41088");arrow_forward
- Given the following specifications of an email: 1. An email address is defined as 'name@domain.org' or 'name@domain.net'. 2. The name is an alphanumeric string that is at least one character and less than or equal to 6 characters long. The only additional characters allowed are periods (.) but the email cannot start or end with a period. 3. The domain also consists of alphanumeric characters with no additional characters allowed. which of the following regular expressions will recognize an email correctly? Select one option only. O [A-Za-z0-9](?:(A-Za-z0-9.J{0,4}[A-Za-z0-9])?@[A-Za-z0-9]*(?:\.net|\.org) O A-Za-z0-9(?:(A-Za-20-9.J{0,5}{A-Za-z0-9])?@[A-Za-z0-9]+(?:\.net|\.org) O [A-Za-z0-9)(?:(A-Za-z0-9.J{0,4}[A-Za-z0-9]}?@[A-Za-z0-9]+.(?:netlorg) O (A-Za-z0-9)[A-Za-z0-9.J{0,4}[A-Za-z0-9]@lA-Za-z0-9]+(?:\.net|\.org) O A-Za-z0-9){1.6}@[A-Za-z0-9]+(?:\.net|\.org) O (A-Za-z0-9)(?:(A-Za-z0-9.}{0,4}{A-Za-z0-9))?@[A-Za-z0-9)+(?:\.net|\.org) O none of the options are correctarrow_forwardGiven the following specifications of an email: 1. An email address is defined as 'name@domain.org' or 'name@domain.net'. 2. The name is an alphanumeric string that is at least one character and less than or equal to 6 characters long. The only additional characters allowed are periods (.) but the email cannot start or end with a period. 3. The domain also consists of alphanumeric characters with no additional characters allowed. which of the following regular expressions will recognize an email correctly? Select one option only. O [A-Za-z0-91(?:[A-Za-z0-9.][0,4}[A-Za-z0-9])?@[A-Za-z0-9](?:\net \org) O [A-Za-z0-9](?:[A-Za-z0-9.1{0,5}[A-Za-z0-9])?@IA-Za-z0-91+(?:\.net\.org) O IA-Za-z0-9](?:[A-Za-z0-9.1{0,4][A-Za-z0-9])?@IA-Za-z0-91+ (?:netorg) O IA-Za-z0-9]|A-Za-z0-9.1[0.4}[A-Za-z0-9]@IA-Za-z0-9]=(?:\.net \.org) O (A-Za-z0-9|(1.6}@IA-Za-z0-9]+(?:\.net|\.org) O IA-Za-z0-9](?:(A-Za-z0-9.1[0.4)|A-Za-z0-9])?@lA Za-z0-9]+(?:\.net|\.org)- O none of the options are correctarrow_forwardPHP, MYSGL The company "Visitors" wants a website for a guestbook. They want the guestbook to work so that you can create and delete posts in it.The guestbook must contain the entries who made the post (name or alias),The post (the text written) anddate and time when the post took place.The created posts must be stored in a text file in serialized form.NOTE! You do not need to be able to update these posts, it is enough that you can create new ones and delete any post. Your solution should be object-oriented with PHP and be able to store / read all information against a serialized file on your server.The features to be implemented in your solution on the guestbook website should be: possibility to create and delete posts in the guestbookInformation that should be in each record should be:username / signature, post, date + time of created postExamples of entries in the file:The silver surfer, In the sea are the biggest fish, 2018-01-17 22:41:55Falo, 100 small mice built a nest in a…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education