The basic experiment of information security system Design Five: Communication protocol design 20135211 Lihangyi 20135216 Liu Weihan

Source: Internet
Author: User

Beijing Institute of Electronic Technology (BESTI)Lab Report Cover

Course : Fundamentals of Information Security system design

class : 1352

name : (rank by contribution size) Lihangyi's Liu Weihan

Study number : (by contribution size) 20135211 20135216

score :

Instructor: Lou Jia Peng

date of experiment : 2015.12.1

Experimental Classification :

Preview Level :

experimental time : 15:30-17:30

Instrument Group : 11

compulsory/elective : Compulsory

Experiment Number : 5

Experiment name : Communication protocol Design

experimental purposes and requirements : 1. Learn how to use the socket for communication programming, understand the overall design of an actual network communication application, read the relevant content of the HTTP protocol, and learn how to use several important network functions. 2. Read the HTTPD.C source code. Add some additional features on this basis. Test the functionality of an embedded Web server using a browser on a PC computer. 3. (required) Correct use of the cable and other experimental equipment, and pay attention to the protection of the Experimental chamber. The lab is sent back after the experiment is over.

Experimental Instrument :

    • (name) (model number) (Qty)

    • Embedded development Platform UP-NETARM2410-CL 1

    • PC Machine 1

Body (individual understanding part by "" Mark) one, the experiment content:

(same experiment) This experiment is based on mastering the method and configuration method of the embedded development platform, requiring the use of Windows Xp,linux (Red Hat), arm three systems (i.e. NFS), and the installation of ARM systems in a Linux system.

Second, the principle of experiment
    • General Description: Establish a TCP type socket on port 80 to listen for connection requests. A connection request is received and the request is routed to the connection processing module for processing. and continue to monitor.
    • Schematic diagram

(figure)

    • Module design
      • Client Connection Processing module: Used to initially process the customer's connection request and pass the request information to the customer request resolution function processing.
      • Client Request resolution Processing module: used to parse the client's request and invoke the corresponding function for request processing according to the request information
      • Send HTTP protocol data Header module: Different HTTP protocol header information is sent according to the different parameters.
    • Main functions

Copy.c

#include <stdio.h>static char copybuf[16384];extern int TIMEOUT;int copy(FILE *read_f, FILE *write_f)//完成从一个文件到另一个文件的字符复制{    int n;    int wrote;    alarm(TIMEOUT);    while (n = fread(copybuf,1,sizeof(copybuf),read_f)) {    alarm(TIMEOUT);    wrote = fwrite(copybuf,n,1,write_f);    alarm(TIMEOUT);    if (wrote < 1)        return -1;    }    alarm(0);//清空之前的闹钟    return 0;}

Explain

After looking up the meaning of the alarm function on the net, we get the following explanation ———— the alarm function is also called the alarm function, alarm () is used to set the signal aigalrm the number of seconds specified by the seconds (parameter) to the current process. There are two places to note: A process can only be caused by an alarm time, if the alarm time has been set before calling alarm, then any previous alarm will be replaced by the new alarm, if the parameter seconds is set to 0, then the previous alarm will be canceled.

h TTPD.C (the code that only extracts the main function)

int main (int argc, char *argv[]) {int FD, S;  int Len;  volatile int true = 1;  struct SOCKADDR_IN EC;  struct sockaddr_in server_sockaddr;  pthread_t Th_key;  void * RETVAL;  /* First step, process (interrupt) signal processing */signal (SIGCHLD, sig_ign);//See 1 signal (Sigpipe, sig_ign);  Signal (SIGALRM, SIGALRM);  /* Switch working directory */chroot (httpd_document_root);//See 2 printf ("Starting httpd...\n");  printf ("Press Q to Quit.\n");//ChDir ("/"); /* Second step, enter the command and process */if (argc > 1 &&!strcmp (argv[1], "-i")) {/* i ' m running from inetd, handle the request on St Din */fclose (stderr);  Handleconnect (0);//Call the previously defined function, see 3exit (0); }/* Third step, set up the socket interface */if ((s = socket (af_inet, sock_stream, ipproto_tcp) = =-1) {perror ("Unable to obtain network"); Exit (  1); } if ((SetSockOpt (S, Sol_socket, SO_REUSEADDR, (void *) &true, sizeof (true))) = =-1) {perror ("setsockopt faile  D "); exit (1);  }/* Defines the contents of the server_sockaddr struct */server_sockaddr.sin_family = af_inet;  Server_sockaddr.sin_port = htons (Server_port); Server_sockaddr.sin_addr.s_ADDR = htonl (Inaddr_any); /* Fourth, bind the port and address */if (bind (s, struct sockaddr *) &server_sockaddr, sizeof (server_sockaddr)) = = 1) {perror ("Un  Able to bind socket "); exit (1);  }/* Fifth, listen port */if (listen (s, 8*3) = = 1) {/* arbitrary, 8 files/page, 3 clients */perror ("Unable to listen"); exit (4);  }/* Sixth step, multi-threaded creation, waiting for connection */Pthread_create (&th_key, NULL, key, 0); /* Wait until producer and consumer finish.   */printf ("Wait for connection.\n");  while (1) {len = sizeof (EC);/* Seventh, receive client connection request */if (FD = Accept (S, (void *) &ec, &len)) = =-1) {exit (5); Close (s);}  Handleconnect (FD); }/* Eighth, wait for the thread connection to end before ending the main function */Pthread_join (Th_key, &retval);}

"1.signal (xx,xx) function"

Signal (parameter 1, parameter 2), parameter 1: The signal we want to process. Actually these signals are the system-defined macros. Parameter 2: How we handle it (whether the system is default or ignored or captured). For the parameters in the three calls in this code, the following are explained:

    • sigign--This symbol means that the signal is ignored, and after the corresponding signal () call is executed, the process ignores the signal type sig
    • When the sigchld--process is terminate or stop, SIGCHLD sends it to its parent process.
    • sigpipe--is sent when writing pipe after reader abort.
    • sigalrm--Timer Timeout or Setitimer function set with alarm function interval Timer timeout
    • sigalrm--Unlike the above parameters, it is a function that handles SIGALRM. In code 291 lines there is a definition

"2.chroot () function"

Chroot () is used to change the directory specified by the root directory for the parameter path. Only the superuser is allowed to change the root directory, and the child process inherits the new root directory. It also switches the working directory to the new directory.

"3.handleconnect (xx,xx) function"

The code of this function is generally easy to understand, the core is 304 lines of f = Fdopen (FD, "A +"); By lookup, the Fdopen function takes an existing file descriptor and combines a standard I/O stream with the descriptor. The parameter "A +" indicates that a read-write file is opened in an additional way. If the file does not exist, the file will be created, and if the file exists, the data written will be added to the end of the file, that is, the original content of the file will be retained. In this way, the function is obvious, which is to read the contents of the standard input (because the parameter passed in is 0).

Third, the experimental process

1. Configure the Lab box

    • As in experiment one, configure the experimental environment
      • Connect the arm Development Board;
      • Establish HyperTerminal;
      • Start the experimental platform;
      • Modify the IP of the Windows XP system so that it is in the same network segment as the IP of the arm machine;
      • Install the arm compiler in red Hat;
      • Configure environment variables.

2. go to the 07_hpptd folder and try to make the automatic compilation directly. The error appears as shown.

(Fig. 3)

3. as shown in, in order to resolve the problem that httpd failed to compile automatically, the Hpptd.c file is manually multithreaded compiled.

4. Use the NFS service mode to download the httpd to the Development Board and copy the test page for debugging.

[/mnt/yaffs] mount -t nfs -o nolock 192.168.0.56:/arm2410cl /host[/mnt/yaffs]cd /host/exp/basic/07_httpd/[/host/exp/basic/07_httpd]./httpd(结果)starting httpd...    press q to quit.    wait for connection.

5. in the Desktop browser, enter http://192.168.0.121 (121 for the IP address of the Up-cup S2410 Lab board) and observe the results of the connection request (for example) in the client's browser.

(Fig. 4)

Iv. Summary

The experiment was built on the basis of experimental four-building experimental platform. Moreover, this experiment has been carried out successfully with the experience of the problem processing of automatic compiling using make.

The basic experiment of information security system Design Five: Communication protocol design 20135211 Lihangyi 20135216 Liu Weihan

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.