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