mirror of
https://github.com/id-Software/Quake.git
synced 2026-03-19 16:39:38 +01:00
The Quake sources as originally release under the GPL license on December 21, 1999
This commit is contained in:
452
QW/qwfwd/misc.c
Normal file
452
QW/qwfwd/misc.c
Normal file
@@ -0,0 +1,452 @@
|
||||
#include "master.h"
|
||||
|
||||
int com_argc;
|
||||
char **com_argv;
|
||||
|
||||
/*
|
||||
================
|
||||
COM_CheckParm
|
||||
|
||||
Returns the position (1 to argc-1) in the program's argument list
|
||||
where the given parameter apears, or 0 if not present
|
||||
================
|
||||
*/
|
||||
int COM_CheckParm (char *parm)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=1 ; i<com_argc ; i++)
|
||||
{
|
||||
if (!com_argv[i])
|
||||
continue; // NEXTSTEP sometimes clears appkit vars.
|
||||
if (!strcmp (parm,com_argv[i]))
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *AdrToString (netadr_t a)
|
||||
{
|
||||
static char s[64];
|
||||
|
||||
sprintf (s, "%i.%i.%i.%i:%i",
|
||||
a.sin_addr.S_un.S_un_b.s_b1,
|
||||
a.sin_addr.S_un.S_un_b.s_b2,
|
||||
a.sin_addr.S_un.S_un_b.s_b3,
|
||||
a.sin_addr.S_un.S_un_b.s_b4,
|
||||
ntohs(a.sin_port));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
netadr_t StringToAdr (char *s)
|
||||
{
|
||||
netadr_t a;
|
||||
int b1, b2, b3, b4, p;
|
||||
|
||||
b1 = b2 = b3 = b4 = p = 0;
|
||||
sscanf (s, "%i.%i.%i.%i:%i", &b1, &b2, &b3, &b4, &p);
|
||||
|
||||
a.sin_addr.S_un.S_un_b.s_b1 = b1;
|
||||
a.sin_addr.S_un.S_un_b.s_b2 = b2;
|
||||
a.sin_addr.S_un.S_un_b.s_b3 = b3;
|
||||
a.sin_addr.S_un.S_un_b.s_b4 = b4;
|
||||
a.sin_port = ntohs(p);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
qboolean CompareAdr (netadr_t a, netadr_t b)
|
||||
{
|
||||
if (a.sin_addr.s_addr == b.sin_addr.s_addr
|
||||
&& a.sin_port == b.sin_port)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void mprintf (char *msg, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start (argptr, msg);
|
||||
vprintf (msg, argptr);
|
||||
vfprintf (logfile, msg, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
}
|
||||
|
||||
int msg_readcount;
|
||||
char *MSG_ReadString (void)
|
||||
{
|
||||
char *start;
|
||||
|
||||
start = packet_data + msg_readcount;
|
||||
|
||||
for ( ; msg_readcount < packet_length ; msg_readcount++)
|
||||
if (packet_data[msg_readcount] == '\n'
|
||||
|| packet_data[msg_readcount] == 0)
|
||||
break;
|
||||
|
||||
packet_data[msg_readcount] = 0;
|
||||
msg_readcount++;
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
/*
|
||||
=====================================================================
|
||||
|
||||
COMMAND LINES
|
||||
|
||||
=====================================================================
|
||||
*/
|
||||
|
||||
#define MAX_ARGS 32
|
||||
#define MAX_ARG_LENGTH 1024
|
||||
int cmd_argc;
|
||||
char cmd_argv[MAX_ARGS][MAX_ARG_LENGTH];
|
||||
|
||||
char com_token[1024];
|
||||
/*
|
||||
==============
|
||||
COM_Parse
|
||||
|
||||
Parse a token out of a string
|
||||
==============
|
||||
*/
|
||||
char *COM_Parse (char *data)
|
||||
{
|
||||
int c;
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
com_token[0] = 0;
|
||||
|
||||
if (!data)
|
||||
return NULL;
|
||||
|
||||
// skip whitespace
|
||||
skipwhite:
|
||||
while ( (c = *data) <= ' ')
|
||||
{
|
||||
if (c == 0)
|
||||
return NULL; // end of file;
|
||||
data++;
|
||||
}
|
||||
|
||||
// skip // comments
|
||||
if (c=='/' && data[1] == '/')
|
||||
{
|
||||
while (*data && *data != '\n')
|
||||
data++;
|
||||
goto skipwhite;
|
||||
}
|
||||
|
||||
|
||||
// handle quoted strings specially
|
||||
if (c == '\"')
|
||||
{
|
||||
data++;
|
||||
while (1)
|
||||
{
|
||||
c = *data++;
|
||||
if (c=='\"' || !c)
|
||||
{
|
||||
com_token[len] = 0;
|
||||
return data;
|
||||
}
|
||||
com_token[len] = c;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
|
||||
// parse a regular word
|
||||
do
|
||||
{
|
||||
com_token[len] = c;
|
||||
data++;
|
||||
len++;
|
||||
c = *data;
|
||||
} while (c>32);
|
||||
|
||||
com_token[len] = 0;
|
||||
return data;
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
Cmd_Argc
|
||||
============
|
||||
*/
|
||||
int Cmd_Argc (void)
|
||||
{
|
||||
return cmd_argc;
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
Cmd_Argv
|
||||
============
|
||||
*/
|
||||
char *Cmd_Argv (int arg)
|
||||
{
|
||||
if ( (unsigned)arg >= cmd_argc )
|
||||
return "";
|
||||
return cmd_argv[arg];
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
Cmd_TokenizeString
|
||||
|
||||
Parses the given string into command line tokens.
|
||||
============
|
||||
*/
|
||||
void Cmd_TokenizeString (char *text)
|
||||
{
|
||||
cmd_argc = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
// skip whitespace up to a /n
|
||||
while (*text && *text <= ' ')
|
||||
{
|
||||
text++;
|
||||
}
|
||||
|
||||
if (!*text)
|
||||
return;
|
||||
|
||||
text = COM_Parse (text);
|
||||
if (!text)
|
||||
return;
|
||||
|
||||
if (cmd_argc < MAX_ARGS)
|
||||
{
|
||||
strcpy (cmd_argv[cmd_argc], com_token);
|
||||
cmd_argc++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=====================================================================
|
||||
|
||||
INFO STRINGS
|
||||
|
||||
=====================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
===============
|
||||
Info_ValueForKey
|
||||
|
||||
Searches the string (userinfo or masterinfo) for the given
|
||||
key and returns the associated value, or an empty string.
|
||||
===============
|
||||
*/
|
||||
char *Info_ValueForKey (char *s, char *key)
|
||||
{
|
||||
char pkey[512];
|
||||
static char value[512];
|
||||
char *o;
|
||||
|
||||
if (*s == '\\')
|
||||
s++;
|
||||
while (1)
|
||||
{
|
||||
o = pkey;
|
||||
while (*s != '\\')
|
||||
{
|
||||
if (!*s)
|
||||
return "";
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
s++;
|
||||
|
||||
o = value;
|
||||
while (*s != '\\' && *s)
|
||||
{
|
||||
if (!*s)
|
||||
return "";
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
|
||||
if (!strcmp (key, pkey) )
|
||||
return value;
|
||||
|
||||
if (!*s)
|
||||
return "";
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
void Info_RemoveKey (char *s, char *key)
|
||||
{
|
||||
char *start;
|
||||
char pkey[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
|
||||
if (strstr (key, "\\"))
|
||||
{
|
||||
printf ("Can't use a key with a \\\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
start = s;
|
||||
if (*s == '\\')
|
||||
s++;
|
||||
o = pkey;
|
||||
while (*s != '\\')
|
||||
{
|
||||
if (!*s)
|
||||
return;
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
s++;
|
||||
|
||||
o = value;
|
||||
while (*s != '\\' && *s)
|
||||
{
|
||||
if (!*s)
|
||||
return;
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
|
||||
if (!strcmp (key, pkey) )
|
||||
{
|
||||
strcpy (start, s); // remove this part
|
||||
return;
|
||||
}
|
||||
|
||||
if (!*s)
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Info_RemovePrefixedKeys (char *start, char prefix)
|
||||
{
|
||||
char *s;
|
||||
char pkey[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
|
||||
s = start;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (*s == '\\')
|
||||
s++;
|
||||
o = pkey;
|
||||
while (*s != '\\')
|
||||
{
|
||||
if (!*s)
|
||||
return;
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
s++;
|
||||
|
||||
o = value;
|
||||
while (*s != '\\' && *s)
|
||||
{
|
||||
if (!*s)
|
||||
return;
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
|
||||
if (pkey[0] == prefix)
|
||||
{
|
||||
Info_RemoveKey (start, pkey);
|
||||
s = start;
|
||||
}
|
||||
|
||||
if (!*s)
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Info_SetValueForKey (char *s, char *key, char *value)
|
||||
{
|
||||
char new[512];
|
||||
|
||||
if (strstr (key, "\\") || strstr (value, "\\") )
|
||||
{
|
||||
printf ("Can't use keys or values with a \\\n");
|
||||
return;
|
||||
}
|
||||
if (strstr (key, "\"") || strstr (value, "\"") )
|
||||
{
|
||||
printf ("Can't use keys or values with a \\\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Info_RemoveKey (s, key);
|
||||
if (!value || !strlen(value))
|
||||
return;
|
||||
|
||||
sprintf (new, "\\%s\\%s", key, value);
|
||||
|
||||
if (strlen(new) + strlen(s) > MAX_INFO_STRING)
|
||||
{
|
||||
printf ("Info string length exceeded\n");
|
||||
return;
|
||||
}
|
||||
strcat (s, new);
|
||||
}
|
||||
|
||||
void Info_Print (char *s)
|
||||
{
|
||||
char key[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
int l;
|
||||
|
||||
if (*s == '\\')
|
||||
s++;
|
||||
while (*s)
|
||||
{
|
||||
o = key;
|
||||
while (*s && *s != '\\')
|
||||
*o++ = *s++;
|
||||
|
||||
l = o - key;
|
||||
if (l < 20)
|
||||
{
|
||||
memset (o, ' ', 20-l);
|
||||
key[20] = 0;
|
||||
}
|
||||
else
|
||||
*o = 0;
|
||||
printf ("%s", key);
|
||||
|
||||
if (!*s)
|
||||
{
|
||||
printf ("MISSING VALUE\n");
|
||||
return;
|
||||
}
|
||||
|
||||
o = value;
|
||||
s++;
|
||||
while (*s && *s != '\\')
|
||||
*o++ = *s++;
|
||||
*o = 0;
|
||||
|
||||
if (*s)
|
||||
s++;
|
||||
printf ("%s\n", value);
|
||||
}
|
||||
89
QW/qwfwd/qwfwd.001
Normal file
89
QW/qwfwd/qwfwd.001
Normal file
@@ -0,0 +1,89 @@
|
||||
# Microsoft Developer Studio Project File - Name="QWFwd" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=QWFwd - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "QWFwd.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "QWFwd.mak" CFG="QWFwd - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "QWFwd - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "QWFwd - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "QWFwd - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "QWFwd - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "QWFwd - Win32 Release"
|
||||
# Name "QWFwd - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qwfwd.c
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
269
QW/qwfwd/qwfwd.c
Normal file
269
QW/qwfwd/qwfwd.c
Normal file
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
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 the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* udpred - a inetd launched udp port redirector
|
||||
*
|
||||
* Version: @(#)udpred.c 0.01 01/15/97
|
||||
*
|
||||
* Author: Chris Faherty <chrisf@america.com>
|
||||
*
|
||||
* syntax:
|
||||
*
|
||||
* udpred toip toport
|
||||
*
|
||||
* sample inetd.conf entry:
|
||||
*
|
||||
* 7000 dgram udp wait root /usr/sbin/tcpd /usr/sbin/udpred 192.168.100.16 7000
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#endif
|
||||
|
||||
int host_port; // port we are listening on
|
||||
|
||||
typedef struct peer {
|
||||
time_t last;
|
||||
struct sockaddr_in sin;
|
||||
struct sockaddr_in dest;
|
||||
int s; // connected socket to remote
|
||||
struct peer *next;
|
||||
} peer_t;
|
||||
|
||||
peer_t *peers;
|
||||
|
||||
/*
|
||||
====================
|
||||
NET_Init
|
||||
====================
|
||||
*/
|
||||
void NET_Init (void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
static WSADATA winsockdata;
|
||||
// WORD wVersionRequested;
|
||||
int r;
|
||||
|
||||
// wVersionRequested = MAKEWORD(1, 1);
|
||||
|
||||
r = WSAStartup (MAKEWORD(2, 1), &winsockdata);
|
||||
|
||||
if (r) {
|
||||
fprintf(stderr, "Winsock initialization failed.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("Winsock Initialized\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
int connectsock(char *host, char *service, char *protocol)
|
||||
{
|
||||
struct hostent *phe;
|
||||
struct servent *pse;
|
||||
struct protoent *ppe;
|
||||
struct sockaddr_in sin;
|
||||
int s, type;
|
||||
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
|
||||
/* Map service name to port number */
|
||||
if(pse = getservbyname(service, protocol))
|
||||
sin.sin_port = pse->s_port;
|
||||
else if((sin.sin_port = htons((u_short)atoi(service))) == 0)
|
||||
{
|
||||
fprintf(stderr, "udpred: can't get \"%s\" service entry\n", service);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* Map host name to IP address, allowing for dotted decimal */
|
||||
if(phe = gethostbyname(host))
|
||||
memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
|
||||
else if((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE)
|
||||
{
|
||||
fprintf(stderr, "udpred: can't get \"%s\" host entry\n", host);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* Map protocol name to protocol number */
|
||||
if((ppe = getprotobyname(protocol)) == 0)
|
||||
{
|
||||
fprintf(stderr, "udpred: can't get \"%s\" protocol entry\n", protocol);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* Use protocol to choose a socket type */
|
||||
if(strcmp(protocol, "udp") == 0)
|
||||
type = SOCK_DGRAM;
|
||||
else
|
||||
type = SOCK_STREAM;
|
||||
|
||||
/* Allocate a socket */
|
||||
s = socket(PF_INET, type, ppe->p_proto);
|
||||
if(s < 0)
|
||||
{
|
||||
fprintf(stderr, "udpred: can't create socket: %s\n", sys_errlist[errno]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* Connect the socket */
|
||||
if(connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
|
||||
{
|
||||
fprintf(stderr, "udpred: can't connect to %s.%s: %s\n", host, service, sys_errlist[errno]);
|
||||
exit(2);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
int retval;
|
||||
int i1;
|
||||
char buffer[4095];
|
||||
struct sockaddr_in fsin;
|
||||
int alen;
|
||||
peer_t *p;
|
||||
int s;
|
||||
struct sockaddr_in address;
|
||||
|
||||
if (argc < 3) {
|
||||
printf("Usage: %s <port> <remote server> <remote server port>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NET_Init();
|
||||
|
||||
if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
|
||||
perror("socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = INADDR_ANY;
|
||||
address.sin_port = htons((unsigned short)atoi(argv[1]));
|
||||
if (bind (s, (void *)&address, sizeof(address)) == -1)
|
||||
perror("bind");
|
||||
|
||||
while(1)
|
||||
{
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(s, &rfds);
|
||||
i1 = s;
|
||||
for (p = peers; p; p = p->next) {
|
||||
FD_SET(p->s, &rfds);
|
||||
if (p->s >= i1)
|
||||
i1 = p->s + 1;
|
||||
}
|
||||
/* Wait up to two minutes. */
|
||||
tv.tv_sec = 2;
|
||||
tv.tv_usec = 0;
|
||||
retval = select(i1, &rfds, (fd_set *)0, (fd_set *)0, &tv);
|
||||
if(retval > 0)
|
||||
{
|
||||
if(FD_ISSET(s, &rfds))
|
||||
{
|
||||
alen = sizeof(fsin);
|
||||
i1 = recvfrom(s, buffer, 4096, 0, (struct sockaddr *) &fsin, &alen);
|
||||
if(i1 > 0) {
|
||||
for (p = peers; p; p = p->next)
|
||||
if (memcmp(&p->sin.sin_addr, &fsin.sin_addr, sizeof(p->sin.sin_addr)) == 0 &&
|
||||
memcmp(&p->sin.sin_port, &fsin.sin_port, sizeof(p->sin.sin_port)) == 0)
|
||||
{
|
||||
send(p->s, buffer, i1, 0);
|
||||
time(&p->last);
|
||||
break;
|
||||
}
|
||||
if (p == NULL) { // new peer
|
||||
printf("peer %s:%d added", inet_ntoa(fsin.sin_addr), (int)ntohs(fsin.sin_port));
|
||||
p = malloc(sizeof *p);
|
||||
p->sin = fsin;
|
||||
p->s = connectsock(argv[2], argv[3], "udp");
|
||||
p->next = peers;
|
||||
peers = p;
|
||||
send(p->s, buffer, i1, 0);
|
||||
time(&p->last);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (p = peers; p; p = p->next)
|
||||
if(FD_ISSET(p->s, &rfds))
|
||||
{
|
||||
i1 = recv(p->s, buffer, 4096, 0);
|
||||
if(i1 > 0) {
|
||||
time(&p->last);
|
||||
sendto(s, buffer, i1, 0, (struct sockaddr *) &p->sin,
|
||||
sizeof(p->sin));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
peer_t *pp;
|
||||
|
||||
pp = NULL;
|
||||
p = peers;
|
||||
while (p) {
|
||||
if (time(NULL) - p->last > 300) {
|
||||
if (!pp && !p->next) {
|
||||
printf("peer %s:%d removed (timeout)", inet_ntoa(p->sin.sin_addr), (int)ntohs(p->sin.sin_port));
|
||||
free(p);
|
||||
p = pp = NULL;
|
||||
continue;
|
||||
}
|
||||
pp->next = p->next;
|
||||
printf ("peer %s:%d removed (timeout)", inet_ntoa(p->sin.sin_addr), (int)ntohs(p->sin.sin_port));
|
||||
free(p);
|
||||
p = pp->next;
|
||||
} else {
|
||||
pp = p;
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
90
QW/qwfwd/qwfwd.dsp
Normal file
90
QW/qwfwd/qwfwd.dsp
Normal file
@@ -0,0 +1,90 @@
|
||||
# Microsoft Developer Studio Project File - Name="QWFwd" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=QWFwd - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "qwfwd.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "qwfwd.mak" CFG="QWFwd - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "QWFwd - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "QWFwd - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "QWFwd - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "QWFwd - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "QWFwd - Win32 Release"
|
||||
# Name "QWFwd - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qwfwd.c
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
QW/qwfwd/qwfwd.dsw
Normal file
29
QW/qwfwd/qwfwd.dsw
Normal file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 5.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "QWFwd"=.\QWFwd.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
32
QW/qwfwd/qwfwd.plg
Normal file
32
QW/qwfwd/qwfwd.plg
Normal file
@@ -0,0 +1,32 @@
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: QWFwd - Win32 Release--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\TEMP\RSP775.tmp" with contents
|
||||
[
|
||||
/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Release/qwfwd.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c
|
||||
"D:\Work\quake source\QW\qwfwd\qwfwd.c"
|
||||
]
|
||||
Creating command line "cl.exe @C:\TEMP\RSP775.tmp"
|
||||
Creating temporary file "C:\TEMP\RSP776.tmp" with contents
|
||||
[
|
||||
wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:"Release/qwfwd.pdb" /machine:I386 /out:"Release/qwfwd.exe"
|
||||
".\Release\qwfwd.obj"
|
||||
]
|
||||
Creating command line "link.exe @C:\TEMP\RSP776.tmp"
|
||||
<h3>Output Window</h3>
|
||||
Compiling...
|
||||
qwfwd.c
|
||||
Linking...
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
qwfwd.exe - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user