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 enum { qfalse, qtrue } qboolean;
45 typedef unsigned char byte;
48 typedef struct address_s
50 char ip[MAX_NETADDRESS];
53 typedef struct sockaddr_s
56 unsigned char sa_data[14];
59 typedef struct netmessage_s
61 unsigned char data[MAX_NETMESSAGE];
67 typedef struct socket_s
69 int socket; //socket number
70 sockaddr_t addr; //socket address
71 netmessage_t msg; //current message being read
72 int remaining; //remaining bytes to read for the current message
73 struct socket_s *prev, *next; //prev and next socket in a list
77 int Net_AddressCompare(address_t *addr1, address_t *addr2);
78 //gives the address of a socket
79 void Net_SocketToAddress(socket_t *sock, address_t *address);
80 //converts a string to an address
81 void Net_StringToAddress(char *string, address_t *address);
82 //set the address ip port
83 void Net_SetAddressPort(address_t *address, int port);
84 //send a message to the given socket
85 int Net_Send(socket_t *sock, netmessage_t *msg);
86 //recieve a message from the given socket
87 int Net_Receive(socket_t *sock, netmessage_t *msg);
89 // NOTE: port is the localhost port, usually 0
90 // ex: Net_Connect( "192.168.0.1:39000", 0 )
91 socket_t *Net_Connect(address_t *address, int port);
92 //disconnect from a host
93 void Net_Disconnect(socket_t *sock);
94 //returns the local address
95 void Net_MyAddress(address_t *address);
96 //listen at the given port
97 socket_t *Net_ListenSocket(int port);
98 //accept new connections at the given socket
99 socket_t *Net_Accept(socket_t *sock);
102 //shutdown networking
103 void Net_Shutdown(void);
105 void NMSG_Clear(netmessage_t *msg);
106 void NMSG_WriteChar(netmessage_t *msg, int c);
107 void NMSG_WriteByte(netmessage_t *msg, int c);
108 void NMSG_WriteShort(netmessage_t *msg, int c);
109 void NMSG_WriteLong(netmessage_t *msg, int c);
110 void NMSG_WriteFloat(netmessage_t *msg, float c);
111 void NMSG_WriteString(netmessage_t *msg, char *string);
112 void NMSG_ReadStart(netmessage_t *msg);
113 int NMSG_ReadChar(netmessage_t *msg);
114 int NMSG_ReadByte(netmessage_t *msg);
115 int NMSG_ReadShort(netmessage_t *msg);
116 int NMSG_ReadLong(netmessage_t *msg);
117 float NMSG_ReadFloat(netmessage_t *msg);
118 char *NMSG_ReadString(netmessage_t *msg);
120 //++timo FIXME: the WINS_ things are not necessary, they can be made portable arther easily
121 char *WINS_ErrorMessage(int error);