-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,546 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CC = gcc | ||
CFLAGS = -O2 -Wall -I . | ||
|
||
# This flag includes the Pthreads library on a Linux box. | ||
# Others systems will probably require something different. | ||
LIB = -lpthread | ||
|
||
all: tiny cgi | ||
|
||
tiny: tiny.c csapp.o | ||
$(CC) $(CFLAGS) -o tiny tiny.c csapp.o $(LIB) | ||
|
||
csapp.o: csapp.c | ||
$(CC) $(CFLAGS) -c csapp.c | ||
|
||
cgi: | ||
(cd cgi-bin; make) | ||
|
||
clean: | ||
rm -f *.o tiny *~ | ||
(cd cgi-bin; make clean) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CC = gcc | ||
CFLAGS = -O2 -Wall -I .. | ||
|
||
all: adder | ||
|
||
adder: adder.c | ||
$(CC) $(CFLAGS) -o adder adder.c | ||
|
||
clean: | ||
rm -f adder *~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* adder.c - a minimal CGI program that adds two numbers together | ||
*/ | ||
/* $begin adder */ | ||
#include "csapp.h" | ||
|
||
int main(void) { | ||
char *buf, *p; | ||
char arg1[MAXLINE], arg2[MAXLINE], content[MAXLINE]; | ||
int n1=0, n2=0; | ||
|
||
/* Extract the two arguments */ | ||
if ((buf = getenv("QUERY_STRING")) != NULL) { | ||
p = strchr(buf, '&'); | ||
*p = '\0'; | ||
strcpy(arg1, buf); | ||
strcpy(arg2, p+1); | ||
n1 = atoi(arg1); | ||
n2 = atoi(arg2); | ||
} | ||
|
||
/* Make the response body */ | ||
sprintf(content, "Welcome to add.com: "); | ||
sprintf(content, "%sTHE Internet addition portal.\r\n<p>", content); | ||
sprintf(content, "%sThe answer is: %d + %d = %d\r\n<p>", | ||
content, n1, n2, n1 + n2); | ||
sprintf(content, "%sThanks for visiting!\r\n", content); | ||
|
||
/* Generate the HTTP response */ | ||
printf("Connection: close\r\n"); | ||
printf("Content-length: %d\r\n", (int)strlen(content)); | ||
printf("Content-type: text/html\r\n\r\n"); | ||
printf("%s", content); | ||
fflush(stdout); | ||
|
||
exit(0); | ||
} | ||
/* $end adder */ |
Oops, something went wrong.