Linux super server inetd and linux Server inetd

Source: Internet
Author: User

Linux super server inetd and linux Server inetd

The inetd service is a daemon process started by the rc program during linux boot initialization. It starts various services through listening ports. The process is tcp/udp services ----> (send a letter to port 5000) ----> inted finds a letter -----> Start the corresponding service program, that is, the inted server acts as a function to create the first half of the socket server, that is, create socket ----> bind (port) ----> listener ----> accept (receiving signal). When a request from this port is sent, it will fork + exec to execute the corresponding service program. here is a small example to illustrate the inetd service process:

① First add the last line in the/etc/inetd. conf file

Ma streamtcpnowaitroot/home/human/bb xiao

Tip: these parameters are separated by the tab key. the inetd. conf file is the configuration file of the inetd server. After the configuration is complete, you need to restart the file to take effect.

First, when the rc starts the inetd service, the service reads the inetd. listen to each line in the conf file. For example, this line reads the first parameter ma and finds it is the ma service.

Then it will find the corresponding port of the ma service in the/etc/service file, so we also need to fill in a line of ma 6234/tcp in the/etc/service file in advance

Then the second and third parameters are read, and socket, bind, listen, accept, the fourth parameter indicates that the parent process does not have to wait to directly accept the next command received by this port after the sub-process is created.

Therefore, after accept, it is fork + exec. The start function in exec is the fifth/home/human/bb process named bb. The sixth parameter xiao is unclear, not tested...

The source code of program bb is very simple as follows:

#include <stdio.h>#include <string.h>int main(int argc, char *argv[]){    FILE *fp;    system("echo hello >> /home/human/ma.txt");    return 0;}
Here is a sentence printed in the network file.

Create an Access Program (tcp)

#include <sys/types.h>#include <sys/socket.h>#include <stdio.h>#include <arpa/inet.h>#include <netdb.h>#include <string.h>#include <stdlib.h>#define BUFLEN 255#define SOCKADDR struct sockaddr#define SERVER_PORT 6234  int main(int argc, char** argv){      struct sockaddr_in servaddr;      int sockfd, n, flag;      int num1, num2;      char buffer[BUFLEN];      char errmsg[] = "Server does not function. /n";      struct hostent *hp;                       if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)       {          printf("socket creating error!/n");          exit(1);      };           memset(&servaddr, 0, sizeof(struct sockaddr_in));      servaddr.sin_family = AF_INET;      servaddr.sin_port = htons(SERVER_PORT);      servaddr.sin_addr.s_addr=htonl(INADDR_ANY);       if(connect(sockfd, (struct sockaddr *)(&servaddr), sizeof(struct sockaddr_in)) <0 )      {           printf("Connection Failure!/n");           exit(3);      }}
 


Conclusion: By the way, I would like to explain why there is an inetd server. If there is no inetd server, if there are 10 request servers in the system, then 10 accept processes will be created to accept the service, in this way, the system has 10 more processes. If no request is sent, the 10 processes are suspended, which seriously wastes system resources, so people want to use a process for listening, so they come up with an inetd server, that is, it reads/etc/inetd. the conf file reads the service items of 10 processes, and then creates a socket. In this way, only a process is suspended in the system. When a request is sent, the corresponding task process can be called, this saves system resources.




How to build an FTP server in linux

VSFTPD is recommended. It is very easy to use. Find a tutorial online. A basic FTP server can be built at around 30 minutes. I can also teach you. If necessary, leave your QQ address and I will contact you.

Linux security issues

Security is highly targeted, depending on the linux version.
For example, suse is configured by default and is highly secure.
Reference: zhidao.baidu.com/question/42329486.html

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.