The basic experiment of information security system Design: Communication protocol Design

Source: Internet
Author: User

Beijing Institute of Electronic Technology (BESTI)

Lab Report

Course: Information Security system Design Basic class: 52.53

Name: Wang Sixian Zhao Yanglin

Study No.: 20135205 20135334

Results:

Instructor: Lou Jia Peng Experimental Date: 2015.11.24

Experiment level: Preview degree: Experiment time: 15:30-18:00

Instrument Group: Compulsory/elective: Compulsory test serial number:

Experiment Name: 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:
ARM Machine 1 Units
PC Machine 1 Units
REDHAT 1 Units

First, the contents of the experiment

1. Read and understand the source code
Enter the directory where 07_HTTPD is located and use the VI Editor to understand the source code.

2. Compiling the application
With the GCC compiler, the copy.c and HTTPD.C under the folder are compiled, and the copy and httpd executables appear.

3. Download and debug
Download the HPPTD to the Development Board using the NFS service and copy the test page for debugging

4. Native Test
Enter http://192.168.0.121 in the desktop browser to observe the results of the link request in the client's browser and the print information on the board server.

Second, the experimental Code understanding

HTTPD.C Code Analysis

 /* httpd.c:a very simple HTTP server * Copyfight (c) 2003 Zou Jian Guo <[email protected]> * Copyright (  C) Lineo, Inc. (www.lineo.com) * Copyright (c) 1997-1999 D. Jeff Dionne <[email protected]> * Copyright (c) 1998 Kenneth Al  Banowski <[email protected]> * Copyright (c) 1999 Nick Brok <[email protected]> * * This program is free software; You can redistribute it and/or modify * it under the terms of the GNU general public License as published by * The 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 <string.h> #include < sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> #include <sys/ stat.h> #include <dirent.h> #include <signal.h> #include <unistd.h> #include <ctype.h> # Include "Pthread.h" #define DEBUG int key_quit=0; int timeout=30; Set the alarm number seconds; #ifndef o_binary #define O_binary 0 #endif Char referrer[128];  int content_length;   #define SERVER_PORT int Printheader (FILE *f, int content_type)//Send HTTP protocol data header {alarm (TIMEOUT); fprintf (F, "http/1.0 OKn"); The server responds to the status line of the HTTP protocol data header; the send request succeeds; switch (content_type) {case ' t ': fprintf (F, "Content-type:text/plainn");//Send plain text file information    ; break; Case ' G ': fprintf (F, "CONTENT-TYPE:IMAGE/GIFN");    Send picture information in GIF format; Case ' J ': fprintf (F, "content-type:image/jpegn");    Send gpeg format picture information; Case ' H ': fprintf (F, "content-type:text/htmln");   Send HTML information; break; } fprintf (F, "server:uclinux-httpd 0.2.2n"); Send server version information; fprintf (F, "expires:0n"); Send file never expires information; fprintf (F, "n");   Print line breaks; alarm (0); return (0);   } int dojpeg (file *f, char *name)//For processing files in JPEG format; {char *buf;   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 JPEGFile%s,%dn ", name, errno); Fflush (f); Alarm (0);   return-1; } printheader (F, ' J ');//Send HTTP protocol header information of type J; copy (INFILE,F);   /* Prints the page */alarm (TIMEOUT);   Fclose (infile);     Alarm (0); return 0;   } int dogif (file *f, char *name)//For processing files in GIF format; {char *buf;   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 GIF file%s,%dn", name, errno); Fflush (f); Alarm (0);   return-1; } printheader (F, ' G '); Sends the HTTP protocol header information of type G to copy (INFILE,F);   /* Prints the page */alarm (TIMEOUT);   Fclose (infile);      Alarm (0); return 0;   } int Dodir (FILE *f, char *name)//to the directory for processing; {char *buf;   dir * DIR; struct dirent * dirent; Dirent not only refers 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 function if (dir = opendir (name)) = = 0) {//open a directory; fprintf (stderr, "Unable to open directory%s,%dn", name, errno); Fflush (f);   return-1; } printheader (F, ' H '); Send HTTP protocol data header information of type H alaRM (TIMEOUT);   fprintf (F, "
Third, encounter problems and solve

1. Although all copies of the 07_httpd file have been copied into BC, the folder has a makefile file, but it is still not possible to get the copy and httpd executable files in that folder through make.
Resolution: The first time is that the path in the makefile file is not correct, change it to/home/bc/07_httpd after the exit to find or unable to execute, the second time we directly use GCC to compile its single step:
Armv4l-unknow-linux-gcc–e Copy.c–o copy.i
Armv4l-unknow-linux-gcc–s Copy.i–o COPY.S
Armv4l-unknow-linux-gcc–c Copy.s–o COPY.O
The httpd is compiled in the same way as above.
make--project Manager, in order to reduce duplication of effort, the "automatic compilation manager", "automatic" is that it can automatically discover the updated files based on the file timestamp and reduce the compilation effort, and it performs a lot of compilation work by reading the contents of the makefile file. Users only need to write a simple compile statement, that is, just typing make can compile all the files, it greatly improves the actual project efficiency, almost all of the programming of the Linux project needs to use it.

Iv. Summary of the experiment

With the foundation of the previous experiments, this experiment for ARM Development Board and the establishment of the Super terminal has a certain familiarity, the operation is relatively skilled, for the Linux environment has a certain understanding, the preliminary preparation work compared to the previous several smooth.
This experiment is a simple embedded Web server experiment, through experiments, and prior to our team copy and httpd Code preview, let us for the arm Development Board on the development of a simple web process, And a certain understanding of the use of socket network programming and Linux signal () functions on the arm Development Board.
Overall, these five experiments through the actual operation, from the experiment more in-depth understanding of some of the characteristics of the Linux system, and other systems have something else, we have benefited, I believe that the information Security System Design Foundation This course also has a great help, we will continue to work hard

The basic experiment of information security system Design: Communication protocol Design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.