io: introduce qio_channel_create_socket_watch
[qemu/rayw.git] / slirp / slirp.h
blob07c13b4725e20d424c91f7fbfee165d30c4f46cb
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
4 #include "slirp_config.h"
6 #ifdef _WIN32
8 typedef char *caddr_t;
10 # include <windows.h>
11 # include <winsock2.h>
12 # include <ws2tcpip.h>
13 # include <sys/timeb.h>
14 # include <iphlpapi.h>
16 #else
17 # define ioctlsocket ioctl
18 # define closesocket(s) close(s)
19 # if !defined(__HAIKU__)
20 # define O_BINARY 0
21 # endif
22 #endif
24 #ifdef HAVE_SYS_BITYPES_H
25 # include <sys/bitypes.h>
26 #endif
29 #ifdef HAVE_UNISTD_H
30 #endif
32 #ifdef HAVE_STDLIB_H
33 #endif
36 #ifndef HAVE_MEMMOVE
37 #define memmove(x, y, z) bcopy(y, x, z)
38 #endif
40 #if TIME_WITH_SYS_TIME
41 #else
42 # ifdef HAVE_SYS_TIME_H
43 # else
44 # endif
45 #endif
47 #ifdef HAVE_STRING_H
48 #else
49 #endif
51 #ifndef _WIN32
52 #include <sys/uio.h>
53 #endif
55 #ifndef _WIN32
56 #include <netinet/in.h>
57 #include <arpa/inet.h>
58 #endif
60 /* Systems lacking strdup() definition in <string.h>. */
61 #if defined(ultrix)
62 char *strdup(const char *);
63 #endif
65 /* Systems lacking malloc() definition in <stdlib.h>. */
66 #if defined(ultrix) || defined(hcx)
67 void *malloc(size_t arg);
68 void free(void *ptr);
69 #endif
71 #ifndef NO_UNIX_SOCKETS
72 #include <sys/un.h>
73 #endif
74 #ifdef HAVE_SYS_SIGNAL_H
75 # include <sys/signal.h>
76 #endif
77 #ifndef _WIN32
78 #include <sys/socket.h>
79 #endif
81 #if defined(HAVE_SYS_IOCTL_H)
82 # include <sys/ioctl.h>
83 #endif
85 #ifdef HAVE_SYS_SELECT_H
86 # include <sys/select.h>
87 #endif
89 #ifdef HAVE_SYS_WAIT_H
90 # include <sys/wait.h>
91 #endif
93 #ifdef HAVE_SYS_FILIO_H
94 # include <sys/filio.h>
95 #endif
97 #ifdef USE_PPP
98 #include <ppp/slirppp.h>
99 #endif
101 #ifdef __STDC__
102 #else
103 #include <varargs.h>
104 #endif
107 /* Avoid conflicting with the libc insque() and remque(), which
108 have different prototypes. */
109 #define insque slirp_insque
110 #define remque slirp_remque
112 #ifdef HAVE_SYS_STROPTS_H
113 #include <sys/stropts.h>
114 #endif
116 #include "debug.h"
118 #include "qemu/queue.h"
119 #include "qemu/sockets.h"
120 #include "net/eth.h"
122 #include "libslirp.h"
123 #include "ip.h"
124 #include "tcp.h"
125 #include "tcp_timer.h"
126 #include "tcp_var.h"
127 #include "tcpip.h"
128 #include "udp.h"
129 #include "ip_icmp.h"
130 #include "mbuf.h"
131 #include "sbuf.h"
132 #include "socket.h"
133 #include "if.h"
134 #include "main.h"
135 #include "misc.h"
136 #ifdef USE_PPP
137 #include "ppp/pppd.h"
138 #include "ppp/ppp.h"
139 #endif
141 #include "bootp.h"
142 #include "tftp.h"
144 #define ARPOP_REQUEST 1 /* ARP request */
145 #define ARPOP_REPLY 2 /* ARP reply */
147 struct ethhdr {
148 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
149 unsigned char h_source[ETH_ALEN]; /* source ether addr */
150 unsigned short h_proto; /* packet type ID field */
153 struct arphdr {
154 unsigned short ar_hrd; /* format of hardware address */
155 unsigned short ar_pro; /* format of protocol address */
156 unsigned char ar_hln; /* length of hardware address */
157 unsigned char ar_pln; /* length of protocol address */
158 unsigned short ar_op; /* ARP opcode (command) */
161 * Ethernet looks like this : This bit is variable sized however...
163 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
164 uint32_t ar_sip; /* sender IP address */
165 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
166 uint32_t ar_tip; /* target IP address */
167 } QEMU_PACKED;
169 #define ARP_TABLE_SIZE 16
171 typedef struct ArpTable {
172 struct arphdr table[ARP_TABLE_SIZE];
173 int next_victim;
174 } ArpTable;
176 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
178 bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
179 uint8_t out_ethaddr[ETH_ALEN]);
181 struct Slirp {
182 QTAILQ_ENTRY(Slirp) entry;
183 u_int time_fasttimo;
184 u_int last_slowtimo;
185 bool do_slowtimo;
187 /* virtual network configuration */
188 struct in_addr vnetwork_addr;
189 struct in_addr vnetwork_mask;
190 struct in_addr vhost_addr;
191 struct in_addr vdhcp_startaddr;
192 struct in_addr vnameserver_addr;
194 struct in_addr client_ipaddr;
195 char client_hostname[33];
197 int restricted;
198 struct ex_list *exec_list;
200 /* mbuf states */
201 struct mbuf m_freelist, m_usedlist;
202 int mbuf_alloced;
204 /* if states */
205 struct mbuf if_fastq; /* fast queue (for interactive data) */
206 struct mbuf if_batchq; /* queue for non-interactive data */
207 struct mbuf *next_m; /* pointer to next mbuf to output */
208 bool if_start_busy; /* avoid if_start recursion */
210 /* ip states */
211 struct ipq ipq; /* ip reass. queue */
212 uint16_t ip_id; /* ip packet ctr, for ids */
214 /* bootp/dhcp states */
215 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
216 char *bootp_filename;
217 size_t vdnssearch_len;
218 uint8_t *vdnssearch;
220 /* tcp states */
221 struct socket tcb;
222 struct socket *tcp_last_so;
223 tcp_seq tcp_iss; /* tcp initial send seq # */
224 uint32_t tcp_now; /* for RFC 1323 timestamps */
226 /* udp states */
227 struct socket udb;
228 struct socket *udp_last_so;
230 /* icmp states */
231 struct socket icmp;
232 struct socket *icmp_last_so;
234 /* tftp states */
235 char *tftp_prefix;
236 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
238 ArpTable arp_table;
240 void *opaque;
243 extern Slirp *slirp_instance;
245 #ifndef NULL
246 #define NULL (void *)0
247 #endif
249 #ifndef FULL_BOLT
250 void if_start(Slirp *);
251 #else
252 void if_start(struct ttys *);
253 #endif
255 #ifndef HAVE_STRERROR
256 char *strerror(int error);
257 #endif
259 #ifndef HAVE_INDEX
260 char *index(const char *, int);
261 #endif
263 #ifndef HAVE_GETHOSTID
264 long gethostid(void);
265 #endif
267 #ifndef _WIN32
268 #include <netdb.h>
269 #endif
271 #define DEFAULT_BAUD 115200
273 #define SO_OPTIONS DO_KEEPALIVE
274 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
276 /* dnssearch.c */
277 int translate_dnssearch(Slirp *s, const char ** names);
279 /* cksum.c */
280 int cksum(struct mbuf *m, int len);
282 /* if.c */
283 void if_init(Slirp *);
284 void if_output(struct socket *, struct mbuf *);
286 /* ip_input.c */
287 void ip_init(Slirp *);
288 void ip_cleanup(Slirp *);
289 void ip_input(struct mbuf *);
290 void ip_slowtimo(Slirp *);
291 void ip_stripoptions(register struct mbuf *, struct mbuf *);
293 /* ip_output.c */
294 int ip_output(struct socket *, struct mbuf *);
296 /* tcp_input.c */
297 void tcp_input(register struct mbuf *, int, struct socket *);
298 int tcp_mss(register struct tcpcb *, u_int);
300 /* tcp_output.c */
301 int tcp_output(register struct tcpcb *);
302 void tcp_setpersist(register struct tcpcb *);
304 /* tcp_subr.c */
305 void tcp_init(Slirp *);
306 void tcp_cleanup(Slirp *);
307 void tcp_template(struct tcpcb *);
308 void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
309 struct tcpcb * tcp_newtcpcb(struct socket *);
310 struct tcpcb * tcp_close(register struct tcpcb *);
311 void tcp_sockclosed(struct tcpcb *);
312 int tcp_fconnect(struct socket *, unsigned short af);
313 void tcp_connect(struct socket *);
314 int tcp_attach(struct socket *);
315 uint8_t tcp_tos(struct socket *);
316 int tcp_emu(struct socket *, struct mbuf *);
317 int tcp_ctl(struct socket *);
318 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
320 #ifdef USE_PPP
321 #define MIN_MRU MINMRU
322 #define MAX_MRU MAXMRU
323 #else
324 #define MIN_MRU 128
325 #define MAX_MRU 16384
326 #endif
328 #ifndef _WIN32
329 #define min(x,y) ((x) < (y) ? (x) : (y))
330 #define max(x,y) ((x) > (y) ? (x) : (y))
331 #endif
333 #ifdef _WIN32
334 #undef errno
335 #define errno (WSAGetLastError())
336 #endif
338 #endif