// Louis 2004-8-21
#include
#include
#define port 1234
Int main () {int Sockfd, ClientFD, ChildPid; Struct Sockaddr_in Addr, Cliaddr; Int Len = SizeOf (Struct SockAddr_in); Char BUF [256];
MEMSET (BUF, 0, 256); // Bzero (BUF, 256);
IF ((SOCKFD = Socket (AF_INET, SOCK_STREAM, 0) <0) {// perror ("");
// Fill in struct sockaddr_in bzero (& addr, len); addr.sin_family = AF_INET; addr.sin_port = htons (port); addr.sin_addr.s_addr = HTONL (INADDR_Any);
IF (Bind (Sockfd, (Struct SockAddr *) & addr, len) <0) {syslog (log_local4 | log_info, "[test] bind error"); exit (1);
IF (Listen (SockFD, 5) <0) {syslog (log_local4 | log_info, "[test] listen error"); exit (1);
While (1) {ClientFD = Accept (Sockfd, (Struct SockAddr *) & cliaddr, & len); IF ((ChildPid = fork ()) == 0) {// Child Process Close (SockFD); // Handle The Clientfd; While (1) {IF (Recv (Clientfd, BUF, 256, 0)! = -1) {char * p = strstr (buf, "/ r / n"); * p = '/ 0'; syslog (log_local4 | Log_info, "[TEST] BUF IS% S, LEN IS% D", BUF, STRLEN (BUF)); IF (strcmp (buf, "start") == 0) System ("/ usr / sbin / named - u Named -c /etc/named.conf "); if (strcmp (buf," stop ") == 0) System (" killall -9 named "); if (strcmp (buf," restart ") == 0 "" KILLALL-HUP NAMED ";