A.
Explanation of Solution
C code:
//Include Header file
#include <stdio.h>
#include "csapp.h"
//Define the maximum entry for blocked list
#define MAXIMUMSIZE 100
//Function declaration
int divideURI(char *URIName, char *hostName, char *portNumber, char *pName);
void parseBlockList(char *fName, char list[MAXIMUMSIZE][MAXLINE], int limit);
int blockedURIList(char *URIName, char list[MAXIMUMSIZE][MAXLINE]);
//Main function
int main(int argc, char **argv)
{
//Declare required variable
int i, listenfd, connfd;
int clientfd;
//Create socket
socklen_t clientlen;
//Create structure for client address
struct sockaddr_storage clientaddr;
//Create rio function
rio_t cRio, sRio;
char cbuffer[MAXLINE], sbuffer[MAXLINE];
ssize_t ssn, ccn;
char methodName[MAXLINE], URIName[MAXLINE], versionNo[MAXLINE];
char hostName[MAXLINE], portNumber[MAXLINE], pName[MAXLINE];
char block_list[MAXIMUMSIZE][MAXLINE];
int logFileDes;
char logFileBuffer[MAXLINE];
//Check command line arguments
if (argc != 2)
{
//Display message
fprintf(stderr, "usage: %s <port>\n", argv[0]);
fprintf(stderr, "use default portNumber 5000\n");
listenfd = Open_listenfd("5000");
}
else
{
listenfd = Open_listenfd(argv[1]);
}
//Open log files
logFileDes = Open("log.list", O_WRONLY | O_APPEND, 0);
//Set memory for block list
memset(block_list, '\0', MAXLINE * MAXIMUMSIZE);
//Call function for parse file
parseBlockList("block.list", block_list, MAXIMUMSIZE);
//Check condition
while (1)
{
/* wait for connection as a server */
clientlen = sizeof(struct sockaddr_storage);
//Call accept method
connfd = Accept(listenfd, (SA *) &clientaddr, &clientlen);
Rio_readinitb(&sRio, connfd);
/* Check URI Name full path */
if (!Rio_readlineb(&sRio, sbuffer, MAXLINE))
{
Close(connfd);
continue;
}
//Display the uri path
sscanf(sbuffer, "%s %s %s", methodName, URIName, versionNo);
/* Check blocked uri */
if (blockedURIList(URIName, block_list))
{
printf("%s is blocked\n", URIName);
Close(connfd);
continue;
}
//Display the visit uri
sprintf(logFileBuffer, "visit url: %s\n", URIName);
Write(logFileDes, logFileBuffer, strlen(logFileBuffer));
memset(hostName, '\0', MAXLINE);
memset(portNumber, '\0', MAXLINE);
memset(pName, '\0', MAXLINE);
//Declare variable
int res;
/* Check if the given uri is separate */
if ((res = divideURI(URIName, hostName, portNumber, pName)) == -1)
{
fprintf(stderr, "is not http protocol\n");
Close(connfd);
continue;
}
else if (res == 0)
{
fprintf(stderr, "is not a abslute request path\n");
Close(connfd);
continue;
}
//Connect server as a client
clientfd = Open_clientfd(hostName, portNumber);
Rio_readinitb(&cRio, clientfd);
//Send the first request
sprintf(sbuffer, "%s %s %s\n", methodName, pName, versionNo);
Rio_writen(clientfd, sbuffer, strlen(sbuffer));
printf("%s", sbuffer);
do
{
/* Call next http requests */
ssn = Rio_readlineb(&sRio, sbuffer, MAXLINE);
printf("%s", sbuffer);
Rio_writen(clientfd, sbuffer, ssn);
}
while(strcmp(sbuffer, "\r\n"));
//For server send reply back
while ((ccn = Rio_readlineb(&cRio, cbuffer, MAXLINE)) != 0)
Rio_writen(connfd, cbu...
B.
Explanation of Solution
C code:
#include <stdio.h>
#include "csapp.h"
//Define the maximum entry for blocked list
#define MAXIMUMSIZE 100
//Function declaration
int divideURI(char *URIName, char *hostName, char *portName, char *pathName);
void parseBlockList(char *fName, char list[MAXIMUMSIZE][MAXLINE], int limit);
int blockedURIList(char *URIName, char list[MAXIMUMSIZE][MAXLINE]);
void *proxyThreadFunction(void *vargp);
//Declare variable for blocked url list
static char bList[MAXIMUMSIZE][MAXLINE];
//Declare variable for log file fd
static int logFileDesc;
//Main function
int main(int argc, char **argv)
{
//Declare required variable
int listenfd;
//Create socket
socklen_t clientlen;
//Create structure for client address
struct sockaddr_storage clientaddr;
int *connfdp;
pthread_t tid;
//Check command line arguments
if (argc != 2)
{
//Display message
fprintf(stderr, "usage: %s <port>\n", argv[0]);
fprintf(stderr, "use default port 5000\n");
listenfd = Open_listenfd("5000");
}
else
{
listenfd = Open_listenfd(argv[1]);
}
//Open log files
logFileDesc = Open("log.list", O_WRONLY | O_APPEND, 0);
//Set memory for block list
memset(bList, '\0', MAXLINE * MAXIMUMSIZE);
//Call function for parse file
parseBlockList("block.list", bList, MAXIMUMSIZE);
//Check condition
while (1)
{
/* wait for connection as a server */
clientlen = sizeof(struct sockaddr_storage);
connfdp = Malloc(sizeof(int));
//Call accept method
*connfdp = Accept(listenfd, (SA *) &clientaddr, &clientlen);
//Generate new thread
Pthread_create(&tid, NULL, proxyThreadFunction, connfdp);
}
//Close log file descriptor
Close(logFileDesc);
}
//Function definition for proxy thread
void *proxyThreadFunction(void *vargp)
{
//Create thread id
pthread_t tid = Pthread_self();
Pthread_detach(tid);
int connfd = *(int*)vargp;
Free(vargp);
//Create rio function
rio_t cRio, sRio;
/* Declare required variable for client and server buffer */
char cBuffer[MAXLINE], sBuffer[MAXLINE];
ssize_t ssn, ccn;
/* Declare variable for method name, uri, version number, host name, port number and path name*/
char methodName[MAXLINE], URIName[MAXLINE], versionNumber[MAXLINE];
char hostName[MAXLINE], portName[MAXLINE], pathName[MAXLINE];
char logFileBuffer[MAXLINE];
int clientfd;
Rio_readinitb(&sRio, connfd);
/* Check URI Name full path */
if (!Rio_readlineb(&sRio, sBuffer, MAXLINE))
{
Close(connfd);
return NULL;
}
//Display the uri path
sscanf(sBuffer, "%s %s %s", methodName, URIName, versionNumber);
/* Check blocked uri */
if (blockedURIList(URIName, bList))
{
printf("Thread %ld: %s is blocked\n", tid, URIName);
Close(connfd);
return NULL;
}
//Print the log visit
sprintf(logFileBuffer, "Thread %ld: visit url: %s\n", tid, URIName);
Write(logFileDesc, logFileBuffer, strlen(logFileBuffer));
memset(hostName, '\0', MAXLINE);
memset(portName, '\0', MAXLINE);
memset(pathName, '\0', MAXLINE);
int res;
/* Check if the given uri is separate */
if ((res = divideURI(URIName, hostName, portName, pathName)) == -1)
{
fprintf(stderr, "tid %ld: not http protocol\n", tid);
Close(connfd);
return NULL;
}
else if (res == 0)
{
fprintf(stderr, "tid %ld: not a abslute request path\n", tid);
Close(connfd);
return NULL;
}
//Connect server as a client
clientfd = Open_clientfd(hostName, portName);
Rio_readinitb(&cRio, clientfd);
//Send the first request
sprintf(sBuffer, "%s %s %s\n", methodName, pathName, versionNumber);
Rio_writen(clientfd, sBuffer, strlen(sBuffer));
printf("tid %ld: %s", tid, sBuffer);
do
{
/* Call next http requests */
ssn = Rio_readlineb(&sRio, sBuffer, MAXLINE);
printf("Tid %ld: %s", tid, sBuffer);
Rio_writen(clientfd, sBuffer, ssn);
} while(strcmp(sBuffer, "\r\n"));
//For server send reply back
while ((ccn = Rio_readlineb(&cRio, cBuffer, MAXLINE)) != 0)
Rio_writen(connfd, cBuffer, ccn);
�...

Trending nowThis is a popular solution!

Chapter 12 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
- Is developed App in play store much easier than in app store because i look app like human anonymus and like walter labs prioritize iphone app store first is it difficult to developed app on play store ? And btw i want to move to iphone anroid suckarrow_forwardQ12- A three phase transformer 3300/400 V,has D/Y connected and working on 50Hz. The line current on the primary side is 12A and secondary has a balanced load at 0.8 lagging p.f. Determine the i) Secondary phase voltage ii) Line current iii) Output power Ans. (230.95 V, 99.11 A, 54.94 kW)arrow_forwardmake corrections of this program based on the errors shown. this is CIS 227 .arrow_forward
- Create 6 users: Don, Liz, Shamir, Jose, Kate, and Sal. Create 2 groups: marketing and research. Add Shamir, Jose, and Kate to the marketing group. Add Don, Liz, and Sal to the research group. Create a shared directory for each group. Create two files to put into each directory: spreadsheetJanuary.txt meetingNotes.txt Assign access permissions to the directories: Groups should have Read+Write access Leave owner permissions as they are “Everyone else” should not have any access Submit for grade: Screenshot of /etc/passwd contents showing your new users Screenshot of /etc/group contents showing new groups with their members Screenshot of shared directories you created with files and permissionsarrow_forward⚫ your circuit diagrams for your basic bricks, such as AND, OR, XOR gates and 1 bit multiplexers, ⚫ your circuit diagrams for your extended full adder, designed in Section 1 and ⚫ your circuit diagrams for your 8-bit arithmetical-logical unit, designed in Section 2. 1 An Extended Full Adder In this Section, we are going to design an extended full adder circuit (EFA). That EFA takes 6 one bit inputs: aj, bj, Cin, Tin, t₁ and to. Depending on the four possible combinations of values on t₁ and to, the EFA produces 3 one bit outputs: sj, Cout and rout. The EFA can be specified in principle by a truth table with 26 = 64 entries and 3 outputs. However, as the EFA ignores certain inputs in certain cases, it is easier to work with the following overview specification, depending only on t₁ and to in the first place: t₁ to Description 00 Output Relationship Ignored Inputs Addition Mode 2 Coutsjaj + bj + Cin, Tout= 0 Tin 0 1 Shift Left Mode Sj = Cin, Cout=bj, rout = 0 rin, aj 10 1 1 Shift Right…arrow_forwardShow the correct stereochemistry when needed!! mechanism: mechanism: Show the correct stereochemistry when needed!! Br NaOPh diethyl ether substitutionarrow_forward
- In javaarrow_forwardKeanPerson #keanld:int #keanEmail:String #firstName:String #lastName: String KeanAlumni -yearOfGraduation: int - employmentStatus: String + KeanPerson() + KeanPerson(keanld: int, keanEmail: String, firstName: String, lastName: String) + getKeanld(): int + getKeanEmail(): String +getFirstName(): String + getLastName(): String + setFirstName(firstName: String): void + setLastName(lastName: String): void +toString(): String +getParkingRate(): double + KeanAlumni() + KeanAlumni(keanld: int, keanEmail: String, firstName: String, lastName: String, yearOfGraduation: int, employmentStatus: String) +getYearOfGraduation(): int + setYearOfGraduation(yearOfGraduation: int): void +toString(): String +getParkingRate(): double In this question, write Java code to Create and Test the superclass: Abstract KeanPerson and a subclass of the KeanPerson: KeanAlumni. Task 1: Implement Abstract Class KeanPerson using UML (10 points) • Four data fields • Two constructors (1 default and 1 constructor with all…arrow_forwardPlz correct answer by best experts...??arrow_forward
- Q3) using the following image matrix a- b- 12345 6 7 8 9 10 11 12 13 14 15 1617181920 21 22 23 24 25 Using direct chaotic one dimension method to convert the plain text to stego text (hello ahmed)? Using direct chaotic two-dimension method to convert the plain text to stego text?arrow_forward: The Multithreaded Cook In this lab, we'll practice multithreading. Using Semaphores for synchronization, implement a multithreaded cook that performs the following recipe, with each task being contained in a single Thread: 1. Task 1: Cut onions. a. Waits for none. b. Signals Task 4 2. Task 2: Mince meat. a. Waits for none b. Signals Task 4 3. Task 3: Slice aubergines. a. Waits for none b. Signals Task 6 4. Task 4: Make sauce. a. Waits for Task 1, and 2 b. Signals Task 6 5. Task 5: Finished Bechamel. a. Waits for none b. Signals Task 7 6. Task 6: Layout the layers. a. Waits for Task 3, and 4 b. Signals Task 7 7. Task 7: Put Bechamel and Cheese. a. Waits for Task 5, and 6 b. Signals Task 9 8. Task 8: Turn on oven. a. Waits for none b. Signals Task 9 9. Task 9: Cook. a. Waits for Task 7, and 8 b. Signals none At the start of each task (once all Semaphores have been acquired), print out a string of the task you are starting, sleep for 2-11 seconds, then print out a string saying that you…arrow_forwardProgramming Problems 9.28 Assume that a system has a 32-bit virtual address with a 4-KB page size. Write a C program that is passed a virtual address (in decimal) on the command line and have it output the page number and offset for the given address. As an example, your program would run as follows: ./addresses 19986 Your program would output: The address 19986 contains: page number = 4 offset = 3602 Writing this program will require using the appropriate data type to store 32 bits. We encourage you to use unsigned data types as well. Programming Projects Contiguous Memory Allocation In Section 9.2, we presented different algorithms for contiguous memory allo- cation. This project will involve managing a contiguous region of memory of size MAX where addresses may range from 0 ... MAX - 1. Your program must respond to four different requests: 1. Request for a contiguous block of memory 2. Release of a contiguous block of memory 3. Compact unused holes of memory into one single block 4.…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning




