--- src/hardware/softmodem.cpp.orig	Tue Nov 22 02:05:27 2005
+++ src/hardware/softmodem.cpp	Tue Nov 22 02:34:00 2005
@@ -20,6 +20,9 @@
 
 #if C_MODEM
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
 #include <stdarg.h>
 #include <string.h>
 #include <ctype.h>
@@ -98,6 +101,30 @@
 	Bit8u command;
 };
 
+/* Taken from SDL_net SDLnetTCP.c */
+#ifndef MACOS_OPENTRANSPORT
+
+/* System-dependent definitions */
+
+#if defined(__WIN32__) || defined(WIN32)
+typedef int	socklen_t;
+#else
+#define closesocket	close
+#define SOCKET	int
+#define INVALID_SOCKET	-1
+#define SOCKET_ERROR	-1
+#endif /* Open Transport */
+
+struct _TCPsocket {
+	int ready;
+	SOCKET channel;
+	IPaddress remoteAddress;
+	IPaddress localAddress;
+	int sflag;
+};
+
+struct _TCPsocket sockhack;
+#endif
 
 #if 1
 
@@ -118,48 +145,124 @@
 	CSerialModem(Bit16u baseAddr, Bit8u initIrq, Bit32u initBps, const char *remotestr = NULL, Bit16u lport = 27)
 		: CSerial(baseAddr, initIrq, initBps)
 	{
-		
-		
-		mhd.cmdpos = 0;
-		mhd.commandmode = true;
-		mhd.plusinc = 0;
-		mhd.incomingsocket = 0;
-		mhd.answermode = false;
-		memset(&mhd.reg,0,sizeof(mhd.reg));
-		mhd.cmdpause = 0;
-		mhd.echo = true;
-		mhd.response = true;
-		mhd.numericresponse = false;
-
-		/* Default to direct null modem connection.  Telnet mode interprets IAC codes */
-		mhd.telnetmode = false;
-
-		/* Bind the modem to the correct serial port */
-		//strcpy(mhd.remotestr, remotestr);
-
-		/* Initialize the sockets and setup the listening port */
-		mhd.socketset = SDLNet_AllocSocketSet(1);
-		if (!mhd.socketset) {
-			LOG_MSG("MODEM:Can't open socketset:%s",SDLNet_GetError());
-	//TODO Should probably just exit
-			return;
-		}
-		mhd.socket=0;
-		mhd.listenport=lport;
-		if (mhd.listenport) {
-			IPaddress listen_ip;
-			SDLNet_ResolveHost(&listen_ip, NULL, mhd.listenport);
-			mhd.listensocket=SDLNet_TCP_Open(&listen_ip);
-			if (!mhd.listensocket) LOG_MSG("MODEM:Can't open listen port:%s",SDLNet_GetError());
-		} else mhd.listensocket=0;
-
-		// TODO: Fix dialtones if requested
-		//mhd.chan=MIXER_AddChannel((MIXER_MixHandler)this->MODEM_CallBack,8000,"MODEM");
-		//MIXER_Enable(mhd.chan,false);
-		//MIXER_SetMode(mhd.chan,MIXER_16MONO);
+#ifndef MACOS_OPENTRANSPORT
+		int livesock=0;
 
+		if (control->cmdline->FindInt("-socket",livesock,false)) {
+			if (control->cmdline->FindExist("-telnet",false)) {
+				mhd.telnetmode = true;
+				telClient.binary[TEL_SERVER] = true;
+				telClient.echo[TEL_SERVER] = true;
+				telClient.supressGA[TEL_SERVER] = true;
+				telClient.timingMark[TEL_SERVER] = false;
+				telClient.binary[TEL_CLIENT] = true;
+				telClient.echo[TEL_CLIENT] = true;
+				telClient.supressGA[TEL_CLIENT] = true;
+				telClient.timingMark[TEL_CLIENT] = false;
+				telClient.inIAC = false;
+				telClient.recCommand = false;
+			}
+			else
+				mhd.telnetmode = false;
+
+			sockaddr_in		sa;
+			socklen_t		sz;
+
+			sockhack.ready=0;
+			sockhack.channel=livesock;
+			sz=sizeof(sa);
+			if(getpeername(livesock, (sockaddr *)(&sa), &sz)) {
+				LOG_MSG("getpeername failed.");
+				sockhack.remoteAddress.host=ntohl(sa.sin_addr.s_addr);
+				sockhack.remoteAddress.port=ntohs(sa.sin_port);
+			}
+			else {
+				sockhack.remoteAddress.host=INADDR_NONE;
+				sockhack.remoteAddress.port=0;
+			}
+			sz=sizeof(sa);
+			if(getsockname(livesock, (sockaddr *)(&sa), &sz)) {
+				LOG_MSG("getsockname failed.");
+				sockhack.localAddress.host=ntohl(sa.sin_addr.s_addr);
+				sockhack.localAddress.port=ntohs(sa.sin_port);
+			}
+			else {
+				sockhack.localAddress.host=INADDR_NONE;
+				sockhack.localAddress.port=0;
+			}
+			sockhack.sflag=0;
+			LOG_MSG("Opening %s socket %d as serial port",mhd.telnetmode?"telnet":"raw",livesock);
+			mhd.cmdpos = 0;
+			mhd.commandmode = false;
+			mhd.plusinc = 0;
+			mhd.incomingsocket = 0;
+			mhd.answermode = false;
+			memset(&mhd.reg,0,sizeof(mhd.reg));
+			mhd.cmdpause = 0;
+			mhd.echo = true;
+			mhd.response = true;
+			mhd.numericresponse = false;
+
+			mhd.socket = (TCPsocket)(&sockhack);
+
+			mhd.socketset = SDLNet_AllocSocketSet(1);
+			if (!mhd.socketset) {
+				LOG_MSG("MODEM:Can't open socketset:%s",SDLNet_GetError());
+		//TODO Should probably just exit
+				return;
+			}
+			SDLNet_TCP_AddSocket(mhd.socketset,mhd.socket);
+			mhd.listenport=lport;
+			if (mhd.listenport) {
+				IPaddress listen_ip;
+				SDLNet_ResolveHost(&listen_ip, NULL, mhd.listenport);
+				mhd.listensocket=SDLNet_TCP_Open(&listen_ip);
+				if (!mhd.listensocket) LOG_MSG("MODEM:Can't open listen port:%s",SDLNet_GetError());
+			} else mhd.listensocket=0;
+		}
+		else {
+#endif
+			mhd.cmdpos = 0;
+			mhd.commandmode = true;
+			mhd.plusinc = 0;
+			mhd.incomingsocket = 0;
+			mhd.answermode = false;
+			memset(&mhd.reg,0,sizeof(mhd.reg));
+			mhd.cmdpause = 0;
+			mhd.echo = true;
+			mhd.response = true;
+			mhd.numericresponse = false;
+
+			/* Default to direct null modem connection.  Telnet mode interprets IAC codes */
+			mhd.telnetmode = false;
+
+			/* Bind the modem to the correct serial port */
+			//strcpy(mhd.remotestr, remotestr);
+
+			/* Initialize the sockets and setup the listening port */
+			mhd.socketset = SDLNet_AllocSocketSet(1);
+			if (!mhd.socketset) {
+				LOG_MSG("MODEM:Can't open socketset:%s",SDLNet_GetError());
+		//TODO Should probably just exit
+				return;
+			}
+			mhd.socket=0;
+			mhd.listenport=lport;
+			if (mhd.listenport) {
+				IPaddress listen_ip;
+				SDLNet_ResolveHost(&listen_ip, NULL, mhd.listenport);
+				mhd.listensocket=SDLNet_TCP_Open(&listen_ip);
+				if (!mhd.listensocket) LOG_MSG("MODEM:Can't open listen port:%s",SDLNet_GetError());
+			} else mhd.listensocket=0;
+
+			// TODO: Fix dialtones if requested
+			//mhd.chan=MIXER_AddChannel((MIXER_MixHandler)this->MODEM_CallBack,8000,"MODEM");
+			//MIXER_Enable(mhd.chan,false);
+			//MIXER_SetMode(mhd.chan,MIXER_16MONO);
+#ifndef MACOS_OPENTRANSPORT
+		}
+#endif
 	}
-
 
 
 	void SendLine(const char *line) {
