Beijing Institute of Electronic Technology (BESTI)
Real Inspection report
Course: Information Security system Design Basic class: 1453 classes
Name: Peng No.: 20145317
Score: Instructor: Lou Jia Peng Experimental Date: 2016.11.16
Test level: Preview degree: Experimental time 10:00-12:00
Instrument Group: Compulsory/Elective: compulsory test number: five
Experiment name: Experiment Five: Communication protocol design
Experimental purposes and requirements:
1. Master the process of implementing a simple Web server in the arm Development Board.
2. Learn the socket network programming on the arm Development Board.
3. Learn the use of the signal () function under Linux.
Experimental instrument:
Name |
Model |
Number |
PC Machine |
Lenovo |
1 |
Embedded experimental Platform |
Up-tech S2410 |
1 |
Experiment contents, steps and experience:
First, the contents and steps of the experiment
1. Read and understand the source code
Go to the/ARM2410CL/EXP/BASIC/07_HTTPD directory and read the source code using the VI editor or other editor
1 HTTPD.C Code Analysis 2 3/* httpd.c:a very simple HTTP Server 4 * Copyfight (c) 2003 Zou Jian Guo <[email pr Otected]> 5 * Copyright (C) Lineo, Inc. (www.lineo.com) 6 * Copyright (c) 1997-1999 D. Jeff Dionne <[email protected]> 7 * Copyright (c) 1998 Ke Nneth Albanowski <[email protected]> 8 * Copyright (c) 1999 Nick Brok <[email protected]> 9 * Ten * This program is free software; You can redistribute it and/or modify one * it under the terms of the GNU general public License as published by * t He free software Foundation; Either version 2 of the License, or * (at your option) any later version. * * * * #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include &l t;string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #i Nclude <errno.h> #include <sys/stat.h> #include<dirent.h> #include <signal.h> #include <unistd.h> #include <ctype.h> #include "pt Hread.h "#define DEBUG key_quit=0 int; timeout=30 int; Set the alarm number of seconds; #ifndef o_binary #define O_binary 0 #endif, referrer[128]; content_length int; #define SERVER_PORT Printheader Int (FILE *f, int content_type)//Send HTTP protocol data header (alarm UT); fprintf (F, "http/1.0 OKn"); The server responds to the status line of the HTTP protocol data header, and the sending request succeeds; (Content_Type) (N-T ': fprintf (F, "Content-type:text/plain n "); Send plain text file information; Case ' G ': fprintf (F, "CONTENT-TYPE:IMAGE/GIFN"); Send picture information in GIF format; "J": fprintf (F, "content-type:image/jpegn"); Send gpeg format picture information; The case ' H ': fprintf (F, "content-type:text/htmln"); Send HTML information; fprintf (F, "server:uclinux-httpd 0.2.2n"); Send server version information; fprintf (F, "expires:0n"); HairSend files never expire information; fprintf (F, "n"); Print line break; alarm (0); return (0); dojpeg int (file *f, char *name)//for processing JPEG files; {*buf char; FILE * infile; int count; if (!) ( infile = fopen (name, "R")) {//Open a file by file name, read-only property; alarm (TIMEOUT); fprintf (stderr, "Unable to open JPEG file%s,%dn", name, errno); Bayi fflush (f); Alarm (0); return-1; Printheader (F, ' J ');//Send the HTTP protocol header information of type J; (Infile,f); /* Prints the page */alarm (TIMEOUT); Fclose (infile); Alarm (0); 94 0; The 98 int dogif (file *f, char *name)//is processed in GIF format, and the file is {[] char *buf; 101 file * infile; 102 int Count ; 103 104 if (! ( infile = fopen (name, "R"))) {//Open a file by file name, read-only property; alarm (TIMEOUT); 106 fprintf (stderr, "Unable to open GIF file%s,%dn ", name, errno); 107 fflush (f); 108 Alarm (0); 109 return-1; 111 Printheader (F, ' G '); Send HTTP protocol data header information for type G 113 1Copy (INFILE,F); /* Prints the page */alarm (TIMEOUT); 117 fclose (infile); 118 alarm (0); 119 return 0; 121} 122 123 int dodir (FILE *f, char *name)//directory processing; 124 {char *buf; 126 dir * dir; 127 struct dirent * dir Ent Dirent not only to the directory, but also to the specific files in the directory, dirent the structure of the information about the file is very small, so dirent plays an index of the role of 129 if (dir = opendir (name)) = = 0) {//open a directory; fprintf (stderr, "Unable to open directory%s,%dn", name, errno); 131 fflush (f); return-1; 133} 134 135 Printheader (F, ' H '); Sends HTTP protocol data header information of type H 136 137 alarm (TIMEOUT); 138 fprintf (F, "2. Compiling the application
GCC compile, run make to generate executable file httpd
3. Download and debug
Use the NFS service to download the HTTPD to the Development Board and copy the test page for debugging, in this case the index test page. Download results
4. Native Test
In the desktop browser, enter http://192.168.0.111 (111 for the IP address of the Up-cup S2410 Lab board), observe the results of the connection request in the client's browser, and print information on the server on the Development Board. The experimental results are as follows:
Experiment Five: Communication protocol design