Skip to content

Commit

Permalink
TwinSock 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Troy Rollo authored and jschwartzenberg committed Jul 10, 2024
1 parent 181e468 commit 3f52e86
Show file tree
Hide file tree
Showing 19 changed files with 1,406 additions and 288 deletions.
695 changes: 672 additions & 23 deletions LICENSE

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions about.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
* Copyright (C) 1994 Troy Rollo <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* it under the terms of the license in the file LICENSE.TXT included
* with the TwinSock distribution.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <windows.h>

Expand Down
15 changes: 12 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,18 @@ else
fi
fi

if [ -f /usr/include/termios.h ]
then
echo "Using POSIX terminals"
TERM_OBJECT=pterm.o
else
echo "Using BSD terminals"
TERM_OBJECT=term.o
fi

rm -f a.out test.c

OBJECTS="tshost.o packet.o commands.o term.o $NEED_MEM"
OBJECTS="tshost.o packet.o commands.o ${TERM_OBJECT} $NEED_MEM"

echo "Building makefile"
echo ".c.o:" > Makefile
Expand All @@ -140,7 +149,7 @@ echo "tshost: ${OBJECTS}" >> Makefile
echo " ${CC} -o tshost ${OBJECTS} ${L_NSL} ${L_RESOLV} ${L_SOCKET}" >> Makefile

echo
echo 'Running "make"'
echo 'Running "make -f Makefile"'
echo
exec make
exec make -f Makefile

225 changes: 205 additions & 20 deletions commands.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
/*
* TwinSock - "Troy's Windows Sockets"
*
* Copyright (C) 1994 Troy Rollo <[email protected]>
* Copyright (C) 1994-1995 Troy Rollo <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* it under the terms of the license in the file LICENSE.TXT included
* with the TwinSock distribution.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

#include <stdio.h>
Expand All @@ -35,6 +29,192 @@ extern int h_errno;
#define h_errno errno
#endif

#ifndef AF_UNSPEC
#define AF_UNSPEC 0
#endif
#ifndef AF_UNIX
#define AF_UNIX -1
#endif
#ifndef AF_INET
#define AF_INET -1
#endif
#ifndef AF_IMPLINK
#define AF_IMPLINK -1
#endif
#ifndef AF_PUP
#define AF_PUP -1
#endif
#ifndef AF_CHAOS
#define AF_CHAOS -1
#endif
#ifndef AF_NS
#define AF_NS -1
#endif
#ifndef AF_ISO
#define AF_ISO -1
#endif
#ifndef AF_ECMA
#define AF_ECMA -1
#endif
#ifndef AF_DATAKIT
#define AF_DATAKIT -1
#endif
#ifndef AF_CCITT
#define AF_CCITT -1
#endif
#ifndef AF_SNA
#define AF_SNA -1
#endif
#ifndef AF_DECnet
#define AF_DECnet -1
#endif
#ifndef AF_DLI
#define AF_DLI -1
#endif
#ifndef AF_LAT
#define AF_LAT -1
#endif
#ifndef AF_HYLINK
#define AF_HYLINK -1
#endif
#ifndef AF_APPLETALK
#define AF_APPLETALK -1
#endif
#ifndef AF_NETBIOS
#define AF_NETBIOS -1
#endif

#define rangeof(x) (sizeof(x) / sizeof(x[0]))

static int HostSocketFamily[] =
{
AF_UNSPEC, /* unspecified */
AF_UNIX, /* local to host (pipes, portals) */
AF_INET, /* internetwork: UDP, TCP, etc. */
AF_IMPLINK, /* arpanet imp addresses */
AF_PUP, /* pup protocols: e.g. BSP */
AF_CHAOS, /* mit CHAOS protocols */
AF_NS, /* NS, IPX and SPX */
AF_ISO, /* ISO protocols */
AF_ECMA, /* european computer manufacturers */
AF_DATAKIT, /* datakit protocols */
AF_CCITT, /* CCITT protocols, X.25 etc */
AF_SNA, /* IBM SNA */
AF_DECnet, /* DECnet */
AF_DLI, /* Direct data link interface */
AF_LAT, /* LAT */
AF_HYLINK, /* NSC Hyperchannel */
AF_APPLETALK, /* AppleTalk */
AF_NETBIOS /* NetBios-style addresses */
};

static int HostSocketType[] =
{
0,
SOCK_STREAM,
SOCK_DGRAM,
SOCK_RAW,
SOCK_RDM,
SOCK_SEQPACKET
};

#ifndef IPPROTO_IP
#define IPPROTO_IP 0
#endif
#ifndef IPPROTO_ICMP
#define IPPROTO_ICMP 1
#endif
#ifndef IPPROTO_GGP
#define IPPROTO_GGP 2
#endif
#ifndef IPPROTO_TCP
#define IPPROTO_TCP 6
#endif
#ifndef IPPROTO_PUP
#define IPPROTO_PUP 12
#endif
#ifndef IPPROTO_UDP
#define IPPROTO_UDP 18
#endif
#ifndef IPPROTO_ND
#define IPPROTO_ND 77
#endif

static int HostSocketProtocol[] =
{
IPPROTO_IP, IPPROTO_ICMP, IPPROTO_GGP, 3, 4,
5, IPPROTO_TCP, 7, 8, 9,
10, 11, IPPROTO_PUP, 13, 14, 15, 16, IPPROTO_UDP, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, IPPROTO_ND, 78, 79
};

static struct
{
int iWindows;
int iHost;
} HostSocketOption[] =
{
{ 0x0001, SO_DEBUG },
{ 0x0002, SO_ACCEPTCONN },
{ 0x0004, SO_REUSEADDR },
{ 0x0008, SO_KEEPALIVE },
{ 0x0010, SO_DONTROUTE },
{ 0x0020, SO_BROADCAST },
{ 0x0040, SO_USELOOPBACK },
{ 0x0080, SO_LINGER },
{ 0x0100, SO_OOBINLINE }
};

static int
GetFamily(int x)
{
return (x < rangeof(HostSocketFamily)) ? HostSocketFamily[x] : x;
}

static int
RevFamily(int x)
{
int i;

for (i = 0; i < rangeof(HostSocketFamily); i++)
{
if (HostSocketFamily[i] == x)
return i;
}
return x;
}

static int
GetType(int x)
{
return (x < rangeof(HostSocketType)) ? HostSocketType[x] : x;
}

static int
GetProtocol(int x)
{
return (x < rangeof(HostSocketProtocol)) ? HostSocketProtocol[x] : x;
}

static int
GetOption(int x)
{
int iOption = 0;
int i;

for (i = 0; i < rangeof(HostSocketOption); i++)
{
if (x & HostSocketOption[i].iWindows)
iOption |= HostSocketOption[i].iHost;
}
return iOption;
}

extern void PacketTransmitData (void *pvData, int iDataLen, int iStream);

struct
Expand Down Expand Up @@ -160,7 +340,7 @@ struct sockaddr *
ConvertSA(struct func_arg *pfa, struct sockaddr_in *sin)
{
memcpy(sin, pfa->pvData, sizeof(*sin));
sin->sin_family = ntohs(sin->sin_family);
sin->sin_family = GetFamily(ntohs(sin->sin_family));
return (struct sockaddr *) sin;
}

Expand Down Expand Up @@ -354,6 +534,7 @@ ResponseReceived(struct tx_request *ptxr_)
int iLen;
int iValue;
int iSocket;
int nOptName;
int nOptVal;
short nError;
struct tx_request *ptxr;
Expand Down Expand Up @@ -471,9 +652,9 @@ ResponseReceived(struct tx_request *ptxr_)
break;

case FN_Socket:
iSocket = socket(GetIntVal(&pfaArgs[0]),
GetIntVal(&pfaArgs[1]),
GetIntVal(&pfaArgs[2]));
iSocket = socket(GetFamily(GetIntVal(&pfaArgs[0])),
GetType(GetIntVal(&pfaArgs[1])),
GetProtocol(GetIntVal(&pfaArgs[2])));
SetIntVal(&faResult,iSocket);
if (iSocket != -1)
{
Expand All @@ -500,6 +681,7 @@ ResponseReceived(struct tx_request *ptxr_)
SetIntVal(&pfaArgs[2], iValue);
iValue = ((struct sockaddr *) pfaArgs[1].pvData)->
sa_family;
iValue = RevFamily(iValue);
iValue = htons((short) iValue);
((struct sockaddr *) pfaArgs[1].pvData)->sa_family =
(short) iValue;
Expand All @@ -517,6 +699,7 @@ ResponseReceived(struct tx_request *ptxr_)
SetIntVal(&pfaArgs[2], iValue);
iValue = ((struct sockaddr *) pfaArgs[1].pvData)->
sa_family;
iValue = RevFamily(iValue);
iValue = htons((short) iValue);
((struct sockaddr *) pfaArgs[1].pvData)->sa_family =
(short) iValue;
Expand All @@ -525,31 +708,33 @@ ResponseReceived(struct tx_request *ptxr_)

case FN_GetSockOpt:
iLen = GetIntVal(&pfaArgs[4]);
nOptName = GetOption(GetIntVal(&pfaArgs[2]));
iValue = getsockopt( GetIntVal(&pfaArgs[0]),
GetIntVal(&pfaArgs[1]),
GetIntVal(&pfaArgs[2]),
nOptName,
(char *) pfaArgs[3].pvData,
&iLen);
if (iValue != -1)
{
SwapSockOptOut(&pfaArgs[3],
GetIntVal(&pfaArgs[2]));
nOptName);
SetIntVal(&pfaArgs[4], iLen);
}
SetIntVal(&faResult, iValue);
break;

case FN_SetSockOpt:
iLen = GetIntVal(&pfaArgs[4]);
nOptName = GetOption(GetIntVal(&pfaArgs[2]));
SwapSockOptIn(&pfaArgs[3],
GetIntVal(&pfaArgs[2]));
nOptName);
iValue = setsockopt( GetIntVal(&pfaArgs[0]),
SOL_SOCKET,
GetIntVal(&pfaArgs[2]),
nOptName,
(char *) pfaArgs[3].pvData,
iLen);
SwapSockOptOut(&pfaArgs[3],
GetIntVal(&pfaArgs[2]));
nOptName);
SetIntVal(&faResult, iValue);
break;

Expand Down Expand Up @@ -667,7 +852,7 @@ SendSocketData(int iSocket,

iDataLen = sizeof(struct sockaddr_in) + iLen;
sa = *psa;
sa.sin_family = htons(sa.sin_family);
sa.sin_family = htons(RevFamily(sa.sin_family));
ptxr = (struct tx_request *) malloc(sizeof(short) * 5 + iDataLen);
ptxr->nLen = htons(iDataLen + sizeof(short) * 5);
ptxr->id = htons(iSocket);
Expand Down
14 changes: 4 additions & 10 deletions comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
* Copyright (C) 1994 Troy Rollo <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* it under the terms of the license in the file LICENSE.TXT included
* with the TwinSock distribution.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <windows.h>
#include <stdio.h>
Expand Down Expand Up @@ -276,7 +270,7 @@ DialDlgProc( HWND hDlg,
iMethod = SendMessage(GetDlgItem(hDlg, DL_TONE), BM_GETCHECK, 0, 0);
WritePrivateProfileString("Config", "DialingMethod", iMethod ? "1" : "0", "TWINSOCK.INI");
EndDialog(hDlg, TRUE);
SendData(iMethod ? "\rATDT" : "\rATDP", 5);
SendData(iMethod ? "ATDT" : "ATDP", 4);
SendData(achNumber, strlen(achNumber));
SendData("\r", 1);
break;
Expand Down
Loading

0 comments on commit 3f52e86

Please sign in to comment.