1 /*
2 	Relay -- a tool to record and play Quake2 demos
3 	Copyright (C) 2000 Conor Davis
4 
5 	This program is free software; you can redistribute it and/or
6 	modify it under the terms of the GNU General Public License
7 	as published by the Free Software Foundation; either version 2
8 	of the License, or (at your option) any later version.
9 
10 	This program is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program; if not, write to the Free Software
17 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 	Conor Davis
20 	cedavis@planetquake.com
21 */
22 
23 #ifndef __NET_H
24 #define __NET_H
25 
26 #ifdef WIN32
27 
28 #include <windows.h>
29 
30 #else /* WIN32 */
31 #include <sys/types.h>
32 #include <netinet/in.h>
33 #include <sys/ioctl.h>
34 #include <sys/socket.h>
35 #include <sys/time.h>
36 #include <unistd.h>
37 
38 #define closesocket close
39 #define ioctlsocket ioctl
40 #endif
41 
42 #include "q2defines.h"
43 
44 typedef unsigned int SOCKET;
45 
46 // default ports for client, server, and master
47 #define PORT_MASTER 27900
48 #define PORT_CLIENT 27901
49 #define PORT_SERVER 27910
50 
51 #define RELIABLE_FLAG	0x80000000
52 
53 #define KEEPALIVE_TIME	  1000
54 
55 typedef struct
56 {
57 	struct	sockaddr_in addr;
58 	size_t	in_seq;
59 	size_t	in_bit;
60 	size_t	in_reliable_seq;
61 	size_t	out_seq;
62 	size_t	out_bit;
63 	size_t	out_reliable_seq;
64 	size_t	keepalive_time;
65 	unsigned short	qport;
66 	char	pad[2];
67 } net_t;
68 
69 extern int UDP_Begin();
70 extern int UDP_End();
71 extern int UDP_OpenSocket(unsigned short *port);
72 extern int UDP_CloseSocket(SOCKET sd);
73 extern int UDP_Read(SOCKET sd, void *buf, size_t len, struct sockaddr_in *addr);
74 extern int UDP_Write(SOCKET sd, void *buf, size_t len, struct sockaddr_in *addr);
75 extern int UDP_Poll(SOCKET sd, qboolean *readable, qboolean *writeable, qboolean *errors, long msecs);
76 extern char *UDP_AddrToString(struct sockaddr_in *addr);
77 extern int UDP_AddrCompare(struct sockaddr_in *addr1, struct sockaddr_in *addr2);
78 
79 extern int UDP_SendConnectionless(SOCKET sd, void *buf, size_t len, struct sockaddr_in *addr);
80 extern int UDP_SendUnreliable(SOCKET sd, void *buf, size_t len, net_t *net);
81 extern int UDP_SendReliable(SOCKET sd, void *buf, size_t len, net_t *net);
82 extern int UDP_ResendReliable(SOCKET sd, void *buf, size_t len, net_t *net);
83 
84 #endif	// __NET_H
85 
86