2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 //====================================================================
26 // Programmer: MrElusive
27 // Last update: TTimo: cross-platform version, l_net library
30 //====================================================================
32 //++timo FIXME: the l_net code understands that as the max size for the netmessage_s structure
33 // we have defined unsigned char data[MAX_NETMESSAGE] in netmessage_s but actually it cannot be filled completely
34 // we need to introduce a new #define and adapt to data[MAX_NETBUFFER]
35 #define MAX_NETMESSAGE 1024
36 #define MAX_NETADDRESS 32
44 typedef struct address_s
46 char ip[MAX_NETADDRESS];
49 typedef struct sockaddr_s
52 unsigned char sa_data[14];
55 typedef struct netmessage_s
57 unsigned char data[MAX_NETMESSAGE];
63 typedef struct socket_s
65 int socket; //socket number
66 sockaddr_t addr; //socket address
67 netmessage_t msg; //current message being read
68 int remaining; //remaining bytes to read for the current message
69 struct socket_s *prev, *next; //prev and next socket in a list
72 void WinPrint( const char *format, ... );
75 int Net_AddressCompare( address_t *addr1, address_t *addr2 );
76 //gives the address of a socket
77 void Net_SocketToAddress( socket_t *sock, address_t *address );
78 //converts a string to an address
79 void Net_StringToAddress( const char *string, address_t *address );
80 //set the address ip port
81 void Net_SetAddressPort( address_t *address, int port );
82 //send a message to the given socket
83 int Net_Send( socket_t *sock, netmessage_t *msg );
84 //recieve a message from the given socket
85 int Net_Receive( socket_t *sock, netmessage_t *msg );
87 // NOTE: port is the localhost port, usually 0
88 // ex: Net_Connect( "192.168.0.1:39000", 0 )
89 socket_t *Net_Connect( address_t *address, int port );
90 //disconnect from a host
91 void Net_Disconnect( socket_t *sock );
92 //returns the local address
93 void Net_MyAddress( address_t *address );
94 //listen at the given port
95 socket_t *Net_ListenSocket( int port );
96 //accept new connections at the given socket
97 socket_t *Net_Accept( socket_t *sock );
99 int Net_Setup( void );
100 //shutdown networking
101 void Net_Shutdown( void );
103 void NMSG_Clear( netmessage_t *msg );
104 void NMSG_WriteChar( netmessage_t *msg, int c );
105 void NMSG_WriteByte( netmessage_t *msg, int c );
106 void NMSG_WriteShort( netmessage_t *msg, int c );
107 void NMSG_WriteLong( netmessage_t *msg, int c );
108 void NMSG_WriteFloat( netmessage_t *msg, float c );
109 void NMSG_WriteString( netmessage_t *msg, char *string );
110 void NMSG_ReadStart( netmessage_t *msg );
111 int NMSG_ReadChar( netmessage_t *msg );
112 int NMSG_ReadByte( netmessage_t *msg );
113 int NMSG_ReadShort( netmessage_t *msg );
114 int NMSG_ReadLong( netmessage_t *msg );
115 float NMSG_ReadFloat( netmessage_t *msg );
116 char *NMSG_ReadString( netmessage_t *msg );
118 //++timo FIXME: the WINS_ things are not necessary, they can be made portable arther easily
119 const char *WINS_ErrorMessage( int error );