1.XINETD provides passive super service, that is, the service program is started by the use of the end, usually need not exist. For example, FTP, telnetd, Pop3,imap, Auth, and so on, these services are not used when people do not need to start. In addition, XINETD converts the socket to stdin/stdout, which simplifies the design of the Web service program, allowing you to complete the processing of very complex network protocols using only printf and fgets.
2. A simple service program goodie
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Char *cmds[]={
"Help",
"Say",
"Hello",
"Bye",
"Exit",
Null
};
int Getcmd (char *cmd)
{
int n=0;
while (Cmds[n]!=null) {
if (strncasecmp (Cmd,cmds[n],strlen (cmds[n)) ==0) return n;
n++;
}
return-1;
}
void Main (void)
{
Char buf[1024];
int OK;
printf ("Welcome to Goodie service!");
Fflush (stdout);
ok=0;
do {
while (Fgets (Buf,1023,stdin) ==null);
Switch (Getcmd (BUF)) {
Case-1: printf ("Unknown command!"); Break
Case 0:
printf ("How may I help, sir?");
int j=0;
while (cmds[j++]!=null) printf ("%s\t\t", cmds[j-1]);
Break
Case 1:printf ("I'll say%s", &buf[3]); Break
Case 2:printf ("How ' re you doing today?"); Break
Case 3:printf ("Si ya, mate!"); ok=1; Break
Case 4:printf ("Go ahead!"); ok=1; Break
}
Fflush (stdout);
while (!ok);
}