|  | @@ -6,6 +6,11 @@
 | 
	
		
			
				|  |  |  #include <termios.h>
 | 
	
		
			
				|  |  |  #include <unistd.h>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// auto zombie reaping
 | 
	
		
			
				|  |  | +#include <errno.h>
 | 
	
		
			
				|  |  | +#include <signal.h>
 | 
	
		
			
				|  |  | +#include <sys/wait.h>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  void doprocessing(int sock);
 | 
	
		
			
				|  |  |  char *cmds[10];
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -23,7 +28,7 @@ int drain(int fd) {
 | 
	
		
			
				|  |  |    char buffer[21];
 | 
	
		
			
				|  |  |    int total = 0;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -   printf("draining... \n");
 | 
	
		
			
				|  |  | +  printf("draining... \n");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    do {
 | 
	
		
			
				|  |  |      FD_ZERO(&set);
 | 
	
	
		
			
				|  | @@ -47,6 +52,12 @@ int main(int argc, char *argv[]) {
 | 
	
		
			
				|  |  |    struct sockaddr_in serv_addr, cli_addr;
 | 
	
		
			
				|  |  |    int n, pid;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +  // Automatically reap zombies.
 | 
	
		
			
				|  |  | +  if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
 | 
	
		
			
				|  |  | +    perror(0);
 | 
	
		
			
				|  |  | +    exit(1);
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    /* First call to socket() function */
 | 
	
		
			
				|  |  |    sockfd = socket(AF_INET, SOCK_STREAM, 0);
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -62,8 +73,10 @@ int main(int argc, char *argv[]) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    int listen_port = atoi(argv[1]);
 | 
	
		
			
				|  |  |    char *command = strdup(argv[2]);
 | 
	
		
			
				|  |  | +  printf("Port %d Cmd [%s]\n", listen_port, command);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    char *cp;
 | 
	
		
			
				|  |  | -  int cmd_count;
 | 
	
		
			
				|  |  | +  int cmd_count = 0;
 | 
	
		
			
				|  |  |    cp = command;
 | 
	
		
			
				|  |  |    cmds[cmd_count] = cp;
 | 
	
		
			
				|  |  |    cmd_count++;
 | 
	
	
		
			
				|  | @@ -171,7 +184,7 @@ void doprocessing(int sock) {
 | 
	
		
			
				|  |  |    https://stackoverflow.com/questions/10413963/telnet-iac-command-answering
 | 
	
		
			
				|  |  |    http://ryobbs.com/doku.php/terminal_iac
 | 
	
		
			
				|  |  |    https://www.omnisecu.com/tcpip/telnet-commands-and-options.php
 | 
	
		
			
				|  |  | -  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |     */
 | 
	
		
			
				|  |  |    write(sock, "\xff\xfb\x01", 3);
 | 
	
		
			
				|  |  |    // drain(sock);
 | 
	
	
		
			
				|  | @@ -181,7 +194,7 @@ void doprocessing(int sock) {
 | 
	
		
			
				|  |  |    // write(sock, "\xff\xfc\x22", 3);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // syncterm is slow.  It needs time to drain.  :()
 | 
	
		
			
				|  |  | -  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    drain(sock);
 | 
	
		
			
				|  |  |    // drain(sock);
 | 
	
		
			
				|  |  |    /*
 |