2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
mplpc.c
|
|
|
|
|
|
|
|
@description@
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <go32.h>
|
|
|
|
#include "mpdosock.h"
|
|
|
|
|
|
|
|
//#include "types.h"
|
|
|
|
typedef unsigned char BYTE;
|
|
|
|
typedef unsigned short WORD;
|
|
|
|
typedef unsigned long DWORD;
|
|
|
|
|
|
|
|
//#include "lpc.h"
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
short version; // version of LPC requested
|
|
|
|
short sizeOfArgs; // size of arguments
|
|
|
|
short service; // service # requested
|
|
|
|
char Data[1]; // data
|
2001-02-19 21:15:25 +00:00
|
|
|
} LPCData;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
short version; // LPC version
|
|
|
|
short sizeOfReturn; // return data size
|
|
|
|
short error; // any error codes
|
|
|
|
short noRet; // number of returns
|
|
|
|
char Data[1]; // data
|
2001-02-19 21:15:25 +00:00
|
|
|
} LPCReturn;
|
|
|
|
|
|
|
|
//#include "services.h"
|
|
|
|
#define MAXSOCKETS 20
|
|
|
|
|
|
|
|
// services
|
|
|
|
#define LPC_SOCKBIND 4
|
|
|
|
#define LPC_SOCKGETHOSTBYNAME 5
|
|
|
|
#define LPC_SOCKGETHOSTNAME 6
|
|
|
|
#define LPC_SOCKGETHOSTBYADDR 7
|
|
|
|
#define LPC_SOCKCLOSE 8
|
|
|
|
#define LPC_SOCKSOCKET 9
|
|
|
|
#define LPC_SOCKRECVFROM 10
|
|
|
|
#define LPC_SOCKSENDTO 11
|
|
|
|
#define LPC_SOCKIOCTL 12
|
|
|
|
#define LPC_SOCKGETSOCKNAME 13
|
|
|
|
#define LPC_SOCKFLUSH 14
|
|
|
|
#define LPC_SOCKSETOPT 15
|
|
|
|
#define LPC_SOCKGETLASTERROR 16
|
|
|
|
#define LPC_SOCKINETADDR 17
|
|
|
|
|
|
|
|
// htons, ntohs, htonl, ntohl implemented locally
|
|
|
|
|
|
|
|
// errors
|
|
|
|
#define LPC_UNRECOGNIZED_SERVICE -1
|
|
|
|
#define LPC_NOERROR 0
|
|
|
|
|
|
|
|
// structures for support
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
SOCKET s;
|
|
|
|
int namelen;
|
|
|
|
char name[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} BindArgs;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
SOCKET s;
|
|
|
|
long cmd;
|
|
|
|
char data[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} IoctlArgs;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int retVal;
|
|
|
|
int namelen;
|
|
|
|
char name[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} GetSockNameRet;
|
|
|
|
|
|
|
|
typedef GetSockNameRet GetHostNameRet;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int retVal;
|
|
|
|
int h_addr_0; // that's the only important value
|
2001-02-19 21:15:25 +00:00
|
|
|
} GetHostByNameRet;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int len;
|
|
|
|
int type;
|
|
|
|
char addr[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} GetHostByAddrArgs;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int retVal;
|
|
|
|
char h_name[1]; // h_name is the only important value
|
2001-02-19 21:15:25 +00:00
|
|
|
} GetHostByAddrRet;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
SOCKET s;
|
|
|
|
int flags;
|
2001-02-19 21:15:25 +00:00
|
|
|
} RecvFromArgs;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int retVal;
|
|
|
|
int errCode;
|
|
|
|
int len; // message len
|
|
|
|
struct sockaddr sockaddr;
|
|
|
|
int sockaddrlen;
|
|
|
|
char Data[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} RecvFromRet;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
SOCKET s;
|
|
|
|
int flags;
|
|
|
|
int len;
|
|
|
|
struct sockaddr sockaddr;
|
|
|
|
int sockaddrlen;
|
|
|
|
char Data[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} SendToArgs;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int retVal;
|
|
|
|
int errCode;
|
2001-02-19 21:15:25 +00:00
|
|
|
} SendToRet;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int bufflen;
|
|
|
|
SOCKET s;
|
|
|
|
int len;
|
|
|
|
int sockaddrlen;
|
|
|
|
struct sockaddr address;
|
|
|
|
char data[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} SocketChannelData;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int af;
|
|
|
|
int type;
|
|
|
|
int protocol;
|
2001-02-19 21:15:25 +00:00
|
|
|
} SocketArgs;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
SOCKET s;
|
|
|
|
int len;
|
|
|
|
int flags;
|
|
|
|
int addrlen;
|
|
|
|
struct sockaddr addr;
|
|
|
|
char data[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} WinSockData;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
SOCKET s;
|
|
|
|
int level;
|
|
|
|
int optname;
|
|
|
|
int optlen;
|
|
|
|
char optval[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
} SetSockOptArgs;
|
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
SOCKET sock[MAXSOCKETS];
|
2001-02-19 21:15:25 +00:00
|
|
|
} SocketMap;
|
|
|
|
|
|
|
|
//#include "rtq.h"
|
|
|
|
#define RTQ_NODE struct rtq_node
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE {
|
|
|
|
RTQ_NODE *self; // Ring zero address of this node
|
|
|
|
RTQ_NODE *left; // Ring zero address of preceding
|
|
|
|
|
|
|
|
// node
|
|
|
|
RTQ_NODE *right; // Ring zero address of succeding
|
|
|
|
|
|
|
|
// node
|
|
|
|
BYTE *rtqDatum; // Ring 3 Datum of Buffer (start of
|
|
|
|
|
|
|
|
// preface)
|
|
|
|
BYTE *rtqInsert; // Ring 3 insertion position
|
|
|
|
WORD rtqLen; // Length of buffer, excluding
|
|
|
|
|
|
|
|
// preface
|
|
|
|
WORD rtqUpCtr; // Up Counter of bytes used so far
|
|
|
|
WORD rtqQCtr; // number of nodes attached
|
|
|
|
WORD padding; // DWORD alignment
|
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define RTQ_PARAM_MOVENODE struct rtq_param_movenode
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_PARAM_MOVENODE {
|
|
|
|
WORD rtqFromDQ;
|
|
|
|
WORD rtqToDQ;
|
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *rtq_fetch (RTQ_NODE *, RTQ_NODE *); // To, From
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
//#include "mplib.h"
|
|
|
|
// give up time slice
|
2001-02-26 06:48:02 +00:00
|
|
|
void Yield (void);
|
|
|
|
void MGenWakeupDll (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// post a message to win32 side
|
2001-02-26 06:48:02 +00:00
|
|
|
void PostWindowsMessage (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// get # of items on qNo
|
2001-02-26 06:48:02 +00:00
|
|
|
int MGenGetQueueCtr (int qNo);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// move first node from qFrom to qTo
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *MGenMoveTo (int qFrom, int qTo);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// get first node from q
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *MGenGetNode (int q);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// get master node, returning size of RTQ_NODE for size verification
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *MGenGetMasterNode (unsigned *size);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// move all nodes from qFrom to qTo
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *MGenFlushNodes (int qFrom, int qTo);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// count number of nodes in queues designated by bitmask
|
|
|
|
// lowerOrderBits == 0..31, upperOrderBits == 32-63
|
2001-02-26 06:48:02 +00:00
|
|
|
int MGenMCount (unsigned lowerOrderBits, unsigned upperOrderBits);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// perform consistency check on chunnel address space
|
2001-02-26 06:48:02 +00:00
|
|
|
int MGenSanityCheck (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/farptr.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define SOCKET_MAP_QUEUE 41
|
|
|
|
|
|
|
|
#define IDLE_QUEUE 44
|
|
|
|
#define REC_QUEUE 45
|
|
|
|
#define SEND_QUEUE 46
|
|
|
|
|
|
|
|
// queue sizes
|
|
|
|
#define FREEQBASE 58
|
|
|
|
#define FREEQ64 58
|
|
|
|
#define FREEQ128 59
|
|
|
|
#define FREEQ256 60
|
|
|
|
#define FREEQ512 61
|
|
|
|
#define FREEQ1024 62
|
|
|
|
#define FREEQ2048 63
|
|
|
|
|
|
|
|
#define NFREEQ 6
|
|
|
|
|
|
|
|
#define QLIMIT 10
|
|
|
|
|
|
|
|
#define PRIVATEQ 50
|
|
|
|
|
|
|
|
#define FARPKL(x) (_farnspeekl((unsigned long) x))
|
|
|
|
#define FARPKB(x) (_farnspeekb((unsigned long) x))
|
|
|
|
#define FARPKS(x) (_farnspeekw((unsigned long) x))
|
|
|
|
|
|
|
|
#define FARPOKL(x, y) (_farnspokel((unsigned long) x, (unsigned long) y))
|
|
|
|
#define FARPOKB(x, y) (_farnspokeb((unsigned long) x, (unsigned char) y))
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int Qsizes[] = { 64, 128, 256, 512, 1024, 2048 };
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int SocketError = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SocketMap *SockMap;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define HOSTENT_ALIAS_LIMIT 5
|
|
|
|
#define HOSTENT_STRLEN_LIMIT 50
|
|
|
|
#define HOSTENT_ADDR_LIST_LIMIT 5
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
struct hostent HostEnt;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
char HostEnt_hname[HOSTENT_STRLEN_LIMIT];
|
|
|
|
char *HostEnt_h_aliases[HOSTENT_ALIAS_LIMIT];
|
|
|
|
char HostEnt_names[HOSTENT_ALIAS_LIMIT][HOSTENT_STRLEN_LIMIT];
|
|
|
|
struct in_addr *HostEnt_addr_list[HOSTENT_ADDR_LIST_LIMIT];
|
2001-02-19 21:15:25 +00:00
|
|
|
struct in_addr HostEnt_addrs[HOSTENT_ADDR_LIST_LIMIT];
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
fmemcpyto (void *to, const void *from, int length)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
movedata (_my_ds (), (unsigned) from, flat_selector, (unsigned) to, length);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
fmemcpyfrom (void *to, const void *from, int length)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
movedata (flat_selector, (unsigned) from, _my_ds (), (unsigned) to, length);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
fstrcpyto (char *to, const char *from)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
while (*from) {
|
|
|
|
FARPOKB (to, *from);
|
|
|
|
to++;
|
|
|
|
from++;
|
|
|
|
}
|
|
|
|
FARPOKB (to, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
fstrncpyto (char *to, const char *from, int len)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
while (*from && len) {
|
|
|
|
FARPOKB (to, *from);
|
|
|
|
to++;
|
|
|
|
from++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
FARPOKB (to, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
fstrcpyfrom (char *to, const char *from)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
while (FARPKB (from)) {
|
|
|
|
*to = FARPKB (from);
|
|
|
|
from++;
|
|
|
|
to++;
|
|
|
|
}
|
|
|
|
*to = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
fstrncpyfrom (char *to, const char *from, int len)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
while (FARPKB (from) && len) {
|
|
|
|
*to = FARPKB (from);
|
|
|
|
from++;
|
|
|
|
to++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
*to = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
GetSocketMap (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (SOCKET_MAP_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SockMap = (SocketMap *) FARPKL (&n->rtqDatum);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void *
|
|
|
|
GetFreeBufferToQueue (int q, int bufSize)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NFREEQ; i++) {
|
|
|
|
if (Qsizes[i] >= bufSize && MGenGetQueueCtr (i + FREEQBASE)) {
|
|
|
|
RTQ_NODE *n = MGenMoveTo (i + FREEQBASE, q);
|
|
|
|
|
|
|
|
if (!n)
|
|
|
|
continue;
|
|
|
|
FARPOKL (&n->rtqUpCtr, bufSize);
|
|
|
|
return (void *) FARPKL (&n->rtqDatum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
FreeBufferFromQueue (int q)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
RTQ_NODE *n = MGenGetNode (q);
|
|
|
|
|
|
|
|
for (i = 0; i < NFREEQ; i++) {
|
|
|
|
if (Qsizes[i] == FARPKS (&n->rtqLen)) {
|
|
|
|
MGenMoveTo (q, i + FREEQBASE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
SetLPCData (LPCData * lpc)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
FARPOKL (&(lpc->version), 1);
|
|
|
|
FARPOKL (&(lpc->sizeOfArgs), 0);
|
|
|
|
FARPOKL (&(lpc->service), 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
bind (SOCKET s, const struct sockaddr *name, int namelen)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
BindArgs *bargs;
|
|
|
|
int retVal;
|
|
|
|
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
SocketError = 0;
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKBIND);
|
|
|
|
bargs = (BindArgs *) p->Data;
|
|
|
|
FARPOKL (&bargs->s, s);
|
|
|
|
FARPOKL (&bargs->namelen, namelen);
|
|
|
|
fmemcpyto (bargs->name, name, namelen);
|
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
|
|
|
|
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
|
|
|
|
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
|
|
|
|
|
|
|
if (FARPKS (&r->error) != LPC_NOERROR) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
retVal = FARPKL (r->Data);
|
|
|
|
|
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
|
|
|
|
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
closesocket (SOCKET s)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
int retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
_farsetsel (flat_selector);
|
|
|
|
SocketError = 0;
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKCLOSE);
|
|
|
|
FARPOKL (p->Data, s);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (FARPKS (&r->error) != LPC_NOERROR) {
|
|
|
|
return -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
retVal = FARPKL (r->Data);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
ZapHostEnt ()
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
// do nothing
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
ReconstructHostEnt (struct hostent *s, void *flattened)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
struct hostent *old = (struct hostent *) flattened;
|
|
|
|
int i;
|
|
|
|
char **ptr;
|
|
|
|
|
|
|
|
|
|
|
|
s->h_name = HostEnt_hname;
|
|
|
|
fstrncpyfrom (s->h_name, (char *) FARPKL (&old->h_name),
|
|
|
|
HOSTENT_STRLEN_LIMIT - 1);
|
|
|
|
s->h_name[HOSTENT_STRLEN_LIMIT - 1] = 0;
|
|
|
|
|
|
|
|
s->h_aliases = HostEnt_h_aliases;
|
|
|
|
ptr = (char **) FARPKL (&old->h_aliases);
|
|
|
|
for (i = 0; i < (HOSTENT_ALIAS_LIMIT - 1) && FARPKL (ptr); i++, ptr++) {
|
|
|
|
s->h_aliases[i] = HostEnt_names[i];
|
|
|
|
// fstrncpyfrom(s->h_aliases[i], (void *) FARPKL(ptr),
|
|
|
|
// HOSTENT_STRLEN_LIMIT-1);
|
|
|
|
s->h_aliases[i][HOSTENT_STRLEN_LIMIT - 1] = 0;
|
|
|
|
}
|
|
|
|
s->h_aliases[i] = 0;
|
|
|
|
|
|
|
|
s->h_addrtype = FARPKS (&old->h_addrtype);
|
|
|
|
s->h_length = FARPKS (&old->h_length);
|
|
|
|
|
|
|
|
if (FARPKS (&old->h_length) != sizeof (struct in_addr)) {
|
2001-10-18 16:49:40 +00:00
|
|
|
Con_Printf ("Error!\n");
|
2001-02-26 06:48:02 +00:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->h_addr_list = (char **) HostEnt_addr_list;
|
|
|
|
ptr = (char **) FARPKL (&old->h_addr_list);
|
|
|
|
for (i = 0; i < (HOSTENT_ADDR_LIST_LIMIT - 1) && FARPKL (ptr); i++, ptr++) {
|
|
|
|
s->h_addr_list[i] = (char *) &(HostEnt_addrs[i]);
|
|
|
|
fmemcpyfrom (s->h_addr_list[i], (void *) FARPKL (ptr), s->h_length);
|
|
|
|
}
|
|
|
|
s->h_addr_list[i] = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
getsockname (SOCKET s, struct sockaddr *name, int *namelen)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
GetSockNameRet *ret;
|
|
|
|
int retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SocketError = 0;
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKGETSOCKNAME);
|
|
|
|
FARPOKL (p->Data, s);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (FARPKS (&r->error) != LPC_NOERROR) {
|
|
|
|
return -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ret = (GetSockNameRet *) r->Data;
|
|
|
|
retVal = FARPKL (&ret->retVal);
|
|
|
|
fmemcpyfrom (name, ret->name, FARPKL (&ret->namelen));
|
|
|
|
*namelen = FARPKL (&ret->namelen);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
gethostname (char *name, int namelen)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n;
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
GetHostNameRet *ret;
|
|
|
|
int retVal;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
SocketError = 0;
|
|
|
|
n = (RTQ_NODE *) MGenGetNode (IDLE_QUEUE);
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKGETHOSTNAME);
|
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
|
|
|
|
|
|
|
while ((n = (RTQ_NODE *) (MGenGetNode (REC_QUEUE))) == 0)
|
|
|
|
Yield ();
|
|
|
|
|
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
|
|
|
|
|
|
|
if (FARPKS (&r->error) != LPC_NOERROR) {
|
|
|
|
return -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ret = (GetHostNameRet *) r->Data;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
retVal = FARPKL (&ret->retVal);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
s = ret->name;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
fstrncpyfrom (name, s, namelen);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#if 0
|
2001-02-26 06:48:02 +00:00
|
|
|
len = strlen (ret->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (len > namelen)
|
|
|
|
memcpy (name, ret->name, ret->namelen);
|
|
|
|
else
|
|
|
|
strcpy (name, ret->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hostent *
|
2001-02-26 06:48:02 +00:00
|
|
|
gethostbyname (const char *name)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
struct hostent *retVal;
|
|
|
|
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
SocketError = 0;
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKGETHOSTBYNAME);
|
|
|
|
fstrcpyto (p->Data, name);
|
|
|
|
|
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
|
|
|
|
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
|
|
|
|
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
|
|
|
retVal = (struct hostent *) r->Data;
|
|
|
|
|
|
|
|
if (FARPKL (&retVal->h_name) == 0) {
|
|
|
|
retVal = 0;
|
|
|
|
} else {
|
|
|
|
ZapHostEnt ();
|
|
|
|
ReconstructHostEnt (&HostEnt, (void *) retVal);
|
|
|
|
retVal = &HostEnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
|
|
|
|
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hostent *
|
2001-02-26 06:48:02 +00:00
|
|
|
gethostbyaddr (const char *addr, int len, int type)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
GetHostByAddrArgs *args;
|
|
|
|
struct hostent *retVal;
|
|
|
|
|
|
|
|
SocketError = 0;
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKGETHOSTBYADDR);
|
|
|
|
args = (GetHostByAddrArgs *) p->Data;
|
|
|
|
FARPOKL (&args->len, len);
|
|
|
|
FARPOKL (&args->type, type);
|
|
|
|
fmemcpyto (args->addr, addr, len);
|
|
|
|
|
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
|
|
|
|
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
|
|
|
retVal = (struct hostent *) r->Data;
|
|
|
|
|
|
|
|
if (FARPKL (&retVal->h_name) == 0) {
|
|
|
|
retVal = 0;
|
|
|
|
} else {
|
|
|
|
ZapHostEnt ();
|
|
|
|
|
|
|
|
ReconstructHostEnt (&HostEnt, (void *) retVal);
|
|
|
|
retVal = &HostEnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
|
|
|
|
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SOCKET socket (int af, int type, int protocol)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
SocketArgs *args;
|
|
|
|
int retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
_farsetsel (flat_selector);
|
|
|
|
SocketError = 0;
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKSOCKET);
|
|
|
|
args = (SocketArgs *) p->Data;
|
|
|
|
FARPOKL (&args->af, af);
|
|
|
|
FARPOKL (&args->type, type);
|
|
|
|
FARPOKL (&args->protocol, protocol);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (FARPKS (&r->error) != LPC_NOERROR) {
|
|
|
|
return -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
retVal = FARPKL (r->Data);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
sockets_flush (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SocketError = 0;
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKFLUSH);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
recvfrom (SOCKET s, char *buf, int len, int flags, struct sockaddr *from,
|
|
|
|
int *fromlen)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
RTQ_NODE *n;
|
|
|
|
WinSockData *data;
|
|
|
|
int bytesRead;
|
|
|
|
|
|
|
|
SocketError = 0;
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
if (!SockMap)
|
|
|
|
GetSocketMap ();
|
|
|
|
|
|
|
|
for (i = 0; i < MAXSOCKETS; i++) {
|
|
|
|
if (FARPKL (&(SockMap->sock[i])) == s)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == MAXSOCKETS)
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
|
|
|
|
// pick up node
|
|
|
|
n = MGenGetNode (i);
|
|
|
|
if (n == 0) {
|
|
|
|
SocketError = WSAEWOULDBLOCK;
|
|
|
|
return -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
data = (WinSockData *) FARPKL (&n->rtqDatum);
|
|
|
|
bytesRead = FARPKL (&data->len);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (from) {
|
|
|
|
fmemcpyfrom (from, &data->addr, sizeof (struct sockaddr));
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (fromlen) {
|
|
|
|
*fromlen = FARPKL (&data->addrlen);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
fmemcpyfrom (buf, data->data, len > bytesRead ? bytesRead : len);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((flags & MSG_PEEK) == 0) {
|
|
|
|
FreeBufferFromQueue (i);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return bytesRead;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
sendto (SOCKET s, const char *buf, int len, int flags,
|
|
|
|
const struct sockaddr *to, int tolen)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
int outQ;
|
|
|
|
WinSockData *data;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SocketError = 0;
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
if (!SockMap)
|
|
|
|
GetSocketMap ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < MAXSOCKETS; i++) {
|
|
|
|
if (FARPKL (&SockMap->sock[i]) == s) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (i == MAXSOCKETS) {
|
|
|
|
SocketError = WSAENOTSOCK;
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
outQ = i + MAXSOCKETS;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (MGenGetQueueCtr (outQ) >= QLIMIT) {
|
|
|
|
SocketError = WSAEWOULDBLOCK;
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
data = GetFreeBufferToQueue (PRIVATEQ, len + sizeof (WinSockData));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!data) {
|
|
|
|
SocketError = WSAEWOULDBLOCK;
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
FARPOKL (&data->s, s);
|
|
|
|
FARPOKL (&data->len, len);
|
|
|
|
if (to) {
|
|
|
|
fmemcpyto (&data->addr, to, tolen);
|
|
|
|
FARPOKL (&data->addrlen, tolen);
|
|
|
|
} else {
|
|
|
|
FARPOKL (&data->addrlen, 0);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
FARPOKL (&data->flags, flags);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
fmemcpyto (data->data, buf, len);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (PRIVATEQ, outQ);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return len;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
ioctlsocket (SOCKET s, long cmd, unsigned long *argp)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
IoctlArgs *args;
|
|
|
|
int retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SocketError = 0;
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKIOCTL);
|
|
|
|
args = (IoctlArgs *) p->Data;
|
|
|
|
FARPOKL (&args->s, s);
|
|
|
|
FARPOKL (&args->cmd, cmd);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case FIONBIO:
|
|
|
|
FARPOKL (args->data, *argp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
retVal = FARPKL (r->Data);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
setsockopt (SOCKET s, int level, int optname, const char *optval, int optlen)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
SetSockOptArgs *args;
|
|
|
|
int retVal;
|
|
|
|
|
|
|
|
SocketError = 0;
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKSETOPT);
|
|
|
|
args = (SetSockOptArgs *) p->Data;
|
|
|
|
FARPOKL (&args->s, s);
|
|
|
|
FARPOKL (&args->level, level);
|
|
|
|
FARPOKL (&args->optname, optname);
|
|
|
|
FARPOKL (&args->optlen, optlen);
|
|
|
|
fmemcpyto (args->optval, optval, optlen);
|
|
|
|
|
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
|
|
|
|
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
|
|
|
|
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
|
|
|
|
|
|
|
retVal = FARPKL (r->Data);
|
|
|
|
|
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
|
|
|
|
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-02-26 06:48:02 +00:00
|
|
|
WSAGetLastError (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
int retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
_farsetsel (flat_selector);
|
|
|
|
if (SocketError) {
|
|
|
|
int err = SocketError;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SocketError = 0;
|
|
|
|
return err;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKGETLASTERROR);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
retVal = FARPKL (r->Data);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
unsigned long
|
|
|
|
inet_addr (const char *cp)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int ret;
|
2001-02-19 21:15:25 +00:00
|
|
|
unsigned int ha1, ha2, ha3, ha4;
|
|
|
|
unsigned long ipaddr;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ret = sscanf (cp, "%d.%d.%d.%d", &ha1, &ha2, &ha3, &ha4);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (ret != 4)
|
|
|
|
return -1;
|
|
|
|
ipaddr = (ha1 << 24) | (ha2 << 16) | (ha3 << 8) | ha4;
|
|
|
|
return ipaddr;
|
|
|
|
#if 0
|
2001-02-26 06:48:02 +00:00
|
|
|
RTQ_NODE *n = MGenGetNode (IDLE_QUEUE);
|
|
|
|
LPCData *p;
|
|
|
|
LPCReturn *r;
|
|
|
|
int retVal;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SocketError = 0;
|
|
|
|
_farsetsel (flat_selector);
|
|
|
|
p = (LPCData *) FARPKL (&n->rtqDatum);
|
|
|
|
SetLPCData (p);
|
|
|
|
FARPOKL (&p->service, LPC_SOCKINETADDR);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
fstrcpyto (p->Data, cp);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGenMoveTo (IDLE_QUEUE, SEND_QUEUE);
|
|
|
|
PostWindowsMessage ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((n = MGenGetNode (REC_QUEUE)) == 0)
|
|
|
|
Yield ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r = (LPCReturn *) FARPKL (&n->rtqDatum);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (FARPKS (&r->error) != LPC_NOERROR) {
|
|
|
|
return -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
retVal = FARPKL (r->Data);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// get ready for next call
|
|
|
|
MGenMoveTo (REC_QUEUE, IDLE_QUEUE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return retVal;
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
char *
|
|
|
|
inet_ntoa (struct in_addr in)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
static char buf[32];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (buf, sizeof (buf), "%u.%u.%u.%u", in.S_un.S_un_b.s_b1,
|
|
|
|
in.S_un.S_un_b.s_b2, in.S_un.S_un_b.s_b3, in.S_un.S_un_b.s_b4);
|
2001-02-19 21:15:25 +00:00
|
|
|
return buf;
|
|
|
|
}
|