9 /* the next few lines mean we need winXP or better,
10 * better being non-windows, really */
14 #define _WIN32_WINNT 0x0501
18 #include <sys/socket.h>
19 #include <sys/select.h>
21 #include <netinet/in.h>
24 #define NETSTATE_UNUSED 0
25 #define NETSTATE_OPEN 1
26 #define NETSTATE_CLOSED 2
30 #define NETTYPE_TCP_HOST 3
31 #define NETTYPE_UDP_HOST 4
33 #ifndef _HAVE_NETTCP_BUFFER_TYPE
34 #define _HAVE_NETTCP_BUFFER_TYPE
35 typedef struct net_tcp_buffer_s
{
36 unsigned char buff
[1024];
42 #ifndef _HAVE_NETUDP_BUFFER_TYPE
43 #define _HAVE_NETUDP_BUFFER_TYPE
44 typedef struct net_udp_buffer_s
{
50 #ifndef _HAVE_NET_TYPE
51 #define _HAVE_NET_TYPE
52 typedef struct net_connection_s
{
53 struct net_connection_s
*prev
;
54 struct net_connection_s
*next
;
55 struct addrinfo hints
;
56 struct addrinfo
*addr
;
57 struct sockaddr_storage remote_addr
;
58 socklen_t remote_addr_len
;
74 /* defined in net.c */
77 net_connection_t
*net_connection(void);
78 net_connection_t
*net_fetch(int id
);
79 int net_state(net_connection_t
*n
);
80 void net_disconnect(net_connection_t
*n
);
81 void net_close(net_connection_t
*n
);
82 array_t
*net_select(unsigned int msec
, int reconnect
, net_connection_t
*n
);
83 array_t
*net_select_array(unsigned int msec
, int reconnect
, array_t
*a
);
84 int net_write(net_connection_t
*n
, void *buff
, unsigned int size
);
85 int net_write_string(net_connection_t
*n
, char* fmt
, ...);
86 int net_read(net_connection_t
*n
, void *buff
, unsigned int size
);
87 int net_readline(net_connection_t
*n
, void *buff
, unsigned int size
);
88 int net_broadcast(net_connection_t
*n
, void *buff
, unsigned int size
);
89 int net_accept(net_connection_t
*n
);
91 /* defined in net_udp.c */
92 file_t
*udp_next(net_connection_t
*n
);
95 /* defined in net_tcp.c */
96 net_connection_t
*tcp_client_connect(char* host
, char* port
);
97 int tcp_client_reconnect(net_connection_t
*n
);
98 net_connection_t
*tcp_host_connect(char* host
, char* port
);
99 int tcp_host_reconnect(net_connection_t
*n
);
100 int tcp_write(net_connection_t
*n
, void *buff
, unsigned int size
);
101 int tcp_pending(net_connection_t
*n
);
102 int tcp_read(net_connection_t
*n
, void *buff
, unsigned int size
);
103 int tcp_readline(net_connection_t
*n
, void *buf
, unsigned int size
);
104 int tcp_broadcast(net_connection_t
*n
, void *buff
, unsigned int size
);
105 int tcp_accept(net_connection_t
*n
);
107 /* defined in net_udp.c */
108 net_connection_t
*udp_client_connect(char* host
, char* port
);
109 int udp_client_reconnect(net_connection_t
*n
);
110 net_connection_t
*udp_host_connect(char* host
, char* port
);
111 int udp_host_reconnect(net_connection_t
*n
);
112 int udp_write(net_connection_t
*n
, void *buff
, unsigned int size
);
113 int udp_pending(net_connection_t
*n
);
114 int udp_read(net_connection_t
*n
, void *buff
, unsigned int size
);
115 int udp_readline(net_connection_t
*n
, void *buf
, unsigned int size
);
116 int udp_broadcast(net_connection_t
*n
, void *buff
, unsigned int size
);
117 int udp_accept(net_connection_t
*n
);