From e42f274c9bb52d06f3e87e92b1d70797342beec8 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Mon, 14 May 2018 08:36:30 +1000 Subject: [PATCH] add dosbox shim --- src/Makefile.freebsd | 12 ++-- src/Makefile.freebsd.WWW | 12 ++-- src/Makefile.linux | 12 ++-- src/Makefile.linux.WWW | 12 ++-- src/Makefile.netbsd | 12 ++-- src/Makefile.netbsd.WWW | 12 ++-- src/Makefile.openbsd | 13 +++-- src/Makefile.openbsd.WWW | 13 +++-- src/Makefile.osx | 12 ++-- src/Makefile.osx.WWW | 12 ++-- src/Makefile.sunos | 12 ++-- src/Makefile.sunos.WWW | 14 +++-- utils/dosbox_shim/Makefile | 51 ++++++++++++++++ utils/dosbox_shim/main.c | 116 +++++++++++++++++++++++++++++++++++++ 14 files changed, 264 insertions(+), 51 deletions(-) create mode 100644 utils/dosbox_shim/Makefile create mode 100644 utils/dosbox_shim/main.c diff --git a/src/Makefile.freebsd b/src/Makefile.freebsd index c352d24..56c8f15 100644 --- a/src/Makefile.freebsd +++ b/src/Makefile.freebsd @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile freebsd MAKEFLAGS= @@ -51,8 +51,11 @@ magichat: $(JSMN) mgpost: $(JAMLIB) cd ../utils/mgpost && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -74,6 +77,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.freebsd.WWW b/src/Makefile.freebsd.WWW index 348ac29..fad558e 100644 --- a/src/Makefile.freebsd.WWW +++ b/src/Makefile.freebsd.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile freebsd MAKEFLAGS= @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,6 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.linux b/src/Makefile.linux index 1cd1313..ad62edc 100644 --- a/src/Makefile.linux +++ b/src/Makefile.linux @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile linux MAKEFLAGS= @@ -52,8 +52,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -75,6 +78,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.linux.WWW b/src/Makefile.linux.WWW index ca047e0..11cec93 100644 --- a/src/Makefile.linux.WWW +++ b/src/Makefile.linux.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile linux MAKEFLAGS= @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,6 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.netbsd b/src/Makefile.netbsd index 44b5d76..2392299 100644 --- a/src/Makefile.netbsd +++ b/src/Makefile.netbsd @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile bsd MAKEFLAGS= @@ -51,8 +51,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -74,6 +77,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.netbsd.WWW b/src/Makefile.netbsd.WWW index d5affef..543830c 100644 --- a/src/Makefile.netbsd.WWW +++ b/src/Makefile.netbsd.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile bsd MAKEFLAGS= @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,6 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean \ No newline at end of file diff --git a/src/Makefile.openbsd b/src/Makefile.openbsd index 9c0fbb2..f72b5fc 100644 --- a/src/Makefile.openbsd +++ b/src/Makefile.openbsd @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile bsd MAKEFLAGS= @@ -51,8 +51,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -74,7 +77,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean - + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.openbsd.WWW b/src/Makefile.openbsd.WWW index 047118d..43d984a 100644 --- a/src/Makefile.openbsd.WWW +++ b/src/Makefile.openbsd.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile bsd MAKEFLAGS= @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,7 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean - + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.osx b/src/Makefile.osx index 49f0fa0..653589e 100644 --- a/src/Makefile.osx +++ b/src/Makefile.osx @@ -10,7 +10,7 @@ CDK = ../deps/cdk-5-20161210/libcdk.a OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile macosx MAKEFLAGS= @@ -52,8 +52,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -75,6 +78,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean \ No newline at end of file diff --git a/src/Makefile.osx.WWW b/src/Makefile.osx.WWW index 0d58ee0..f6cfbf4 100644 --- a/src/Makefile.osx.WWW +++ b/src/Makefile.osx.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile macosx MAKEFLAGS= @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -79,6 +82,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean \ No newline at end of file diff --git a/src/Makefile.sunos b/src/Makefile.sunos index 928b8c9..7cb0971 100644 --- a/src/Makefile.sunos +++ b/src/Makefile.sunos @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile solaris MAKEFLAGS= @@ -52,8 +52,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -f Makefile.sunos -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -75,6 +78,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.sunos.WWW b/src/Makefile.sunos.WWW index 486ff5e..902751f 100644 --- a/src/Makefile.sunos.WWW +++ b/src/Makefile.sunos.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile solaris MAKEFLAGS= @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -f Makefile.sunos -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,6 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean - cd ../utils/reset_pass && $(MAKE) clean \ No newline at end of file + cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/utils/dosbox_shim/Makefile b/utils/dosbox_shim/Makefile new file mode 100644 index 0000000..cdab50f --- /dev/null +++ b/utils/dosbox_shim/Makefile @@ -0,0 +1,51 @@ +OS := $(shell uname -s) + +ifeq ($(OS), FreeBSD) + CC=cc + CFLAGS=-I/usr/local/include + LDFLAGS=-L/usr/local/lib +endif +ifeq ($(OS), DragonFly) + CC=cc + CFLAGS=-I/usr/local/include -I/usr/local/include/ncurses + LDFLAGS=-L/usr/local/lib +endif +ifeq ($(OS), NetBSD) + CC=cc + CFLAGS=-I/usr/pkg/include + LDFLAGS=-R/usr/pkg/lib -L/usr/pkg/lib +endif +ifeq ($(OS), OpenBSD) + CC=cc + CFLAGS=-I/usr/local/include + LDFLAGS=-L/usr/local/lib +endif +ifeq ($(OS), Linux) + CC=gcc + CFLAGS= + LDFLAGS= +endif +ifeq ($(OS), Darwin) + CC=cc + CFLAGS= + LDFLAGS= +endif +ifeq ($(OS), SunOS) + CC=gcc + CFLAGS= + LDFLAGS= +endif + +DEPS = main.c + +OBJ = main.o +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(CFLAGS) + +shim: $(OBJ) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) + +.PHONY: clean + +clean: + rm -f $(OBJ) shim diff --git a/utils/dosbox_shim/main.c b/utils/dosbox_shim/main.c new file mode 100644 index 0000000..26b7529 --- /dev/null +++ b/utils/dosbox_shim/main.c @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(__OpenBSD__) +# include +#endif + +int main(int argc, char **argv) { + int port; + int node; + char *script; + pid_t pid; + int server_socket; + int on = 1; + struct sockaddr_in server, client; + int client_fd; + int c; + fd_set master, read_fds; + int len; + char inbuf[256]; + int i; + char *arguments[4]; + + if (argc < 4) { + fprintf(stderr, "Usage ./dosbox_shim [port] [node] [script]\n"); + exit(-1); + } + + port = atoi(argv[1]); + node = atoi(argv[2]); + script = strdup(argv[3]); + + + pid = fork(); + + if (pid < 0) { + fprintf(stderr, "Error forking!\n"); + exit(-1); + } else if (pid == 0) { + arguments[0] = strdup(script); + sprintf(inbuf, "%d", port); + arguments[1] = strdup(inbuf); + sprintf(inbuf, "%d", node); + arguments[2] = strdup(inbuf); + arguments[3] = NULL; + + + execvp(script, arguments); + } else { + server_socket = socket(AF_INET, SOCK_STREAM, 0); + if (server_socket == -1) { + fprintf(stderr, "Couldn't create socket.\n"); + exit(-1); + } + if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { + fprintf(stderr, "setsockopt(SO_REUSEADDR) failed"); + exit(1); + } + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(port); + + c = sizeof(struct sockaddr_in); + + if (bind(server_socket, (struct sockaddr *)&server, sizeof(server)) < 0) { + perror("Bind Failed, Error\n"); + exit(-1); + } + + listen(server_socket, 1); + + client_fd = accept(server_socket, (struct sockaddr *)&client, (socklen_t *)&c); + + if (client_fd == -1) { + perror("accept"); + exit(-1); + } + + FD_ZERO(&master); + + FD_SET(STDIN_FILENO, &master); + FD_SET(client_fd, &master); + + while(1) { + read_fds = master; + + if (select(client_fd + 1, &read_fds, NULL, NULL, NULL) == -1) { + perror("select"); + exit(-1); + } + + if (FD_ISSET(STDIN_FILENO, &read_fds)) { + len = read(STDIN_FILENO, inbuf, 256); + for (i=0;i