]> Git Repo - qemu.git/blob - slirp/slirp.h
acpi: add build_append_named_dword, returning an offset in buffer
[qemu.git] / slirp / slirp.h
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
3
4 #include "slirp_config.h"
5
6 #ifdef _WIN32
7
8 typedef char *caddr_t;
9
10 # include <windows.h>
11 # include <winsock2.h>
12 # include <ws2tcpip.h>
13 # include <sys/timeb.h>
14 # include <iphlpapi.h>
15
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
23
24 #ifdef HAVE_SYS_BITYPES_H
25 # include <sys/bitypes.h>
26 #endif
27
28
29 #ifdef HAVE_UNISTD_H
30 #endif
31
32 #ifdef HAVE_STDLIB_H
33 #endif
34
35
36 #ifndef HAVE_MEMMOVE
37 #define memmove(x, y, z) bcopy(y, x, z)
38 #endif
39
40 #if TIME_WITH_SYS_TIME
41 #else
42 # ifdef HAVE_SYS_TIME_H
43 # else
44 # endif
45 #endif
46
47 #ifdef HAVE_STRING_H
48 #else
49 #endif
50
51 #ifndef _WIN32
52 #include <sys/uio.h>
53 #endif
54
55 #ifndef _WIN32
56 #include <netinet/in.h>
57 #include <arpa/inet.h>
58 #endif
59
60 /* Systems lacking strdup() definition in <string.h>. */
61 #if defined(ultrix)
62 char *strdup(const char *);
63 #endif
64
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
70
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
80
81 #if defined(HAVE_SYS_IOCTL_H)
82 # include <sys/ioctl.h>
83 #endif
84
85 #ifdef HAVE_SYS_SELECT_H
86 # include <sys/select.h>
87 #endif
88
89 #ifdef HAVE_SYS_WAIT_H
90 # include <sys/wait.h>
91 #endif
92
93 #ifdef HAVE_SYS_FILIO_H
94 # include <sys/filio.h>
95 #endif
96
97 #ifdef USE_PPP
98 #include <ppp/slirppp.h>
99 #endif
100
101 #ifdef __STDC__
102 #else
103 #include <varargs.h>
104 #endif
105
106
107 /* Avoid conflicting with the libc insque() and remque(), which
108    have different prototypes. */
109 #define insque slirp_insque
110 #define remque slirp_remque
111
112 #ifdef HAVE_SYS_STROPTS_H
113 #include <sys/stropts.h>
114 #endif
115
116 #include "debug.h"
117
118 #include "qemu/queue.h"
119 #include "qemu/sockets.h"
120 #include "net/eth.h"
121
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
140
141 #include "bootp.h"
142 #include "tftp.h"
143
144 #define ARPOP_REQUEST 1         /* ARP request */
145 #define ARPOP_REPLY   2         /* ARP reply   */
146
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 */
151 };
152
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)       */
159
160     /*
161      *  Ethernet looks like this : This bit is variable sized however...
162      */
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;
168
169 #define ARP_TABLE_SIZE 16
170
171 typedef struct ArpTable {
172     struct arphdr table[ARP_TABLE_SIZE];
173     int next_victim;
174 } ArpTable;
175
176 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
177
178 bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
179                       uint8_t out_ethaddr[ETH_ALEN]);
180
181 struct Slirp {
182     QTAILQ_ENTRY(Slirp) entry;
183     u_int time_fasttimo;
184     u_int last_slowtimo;
185     bool do_slowtimo;
186
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;
193
194     struct in_addr client_ipaddr;
195     char client_hostname[33];
196
197     int restricted;
198     struct ex_list *exec_list;
199
200     /* mbuf states */
201     struct mbuf m_freelist, m_usedlist;
202     int mbuf_alloced;
203
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 */
209
210     /* ip states */
211     struct ipq ipq;         /* ip reass. queue */
212     uint16_t ip_id;         /* ip packet ctr, for ids */
213
214     /* bootp/dhcp states */
215     BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
216     char *bootp_filename;
217     size_t vdnssearch_len;
218     uint8_t *vdnssearch;
219
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 */
225
226     /* udp states */
227     struct socket udb;
228     struct socket *udp_last_so;
229
230     /* icmp states */
231     struct socket icmp;
232     struct socket *icmp_last_so;
233
234     /* tftp states */
235     char *tftp_prefix;
236     struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
237
238     ArpTable arp_table;
239
240     void *opaque;
241 };
242
243 extern Slirp *slirp_instance;
244
245 #ifndef NULL
246 #define NULL (void *)0
247 #endif
248
249 #ifndef FULL_BOLT
250 void if_start(Slirp *);
251 #else
252 void if_start(struct ttys *);
253 #endif
254
255 #ifndef HAVE_STRERROR
256  char *strerror(int error);
257 #endif
258
259 #ifndef HAVE_INDEX
260  char *index(const char *, int);
261 #endif
262
263 #ifndef HAVE_GETHOSTID
264  long gethostid(void);
265 #endif
266
267 #ifndef _WIN32
268 #include <netdb.h>
269 #endif
270
271 #define DEFAULT_BAUD 115200
272
273 #define SO_OPTIONS DO_KEEPALIVE
274 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
275
276 /* dnssearch.c */
277 int translate_dnssearch(Slirp *s, const char ** names);
278
279 /* cksum.c */
280 int cksum(struct mbuf *m, int len);
281
282 /* if.c */
283 void if_init(Slirp *);
284 void if_output(struct socket *, struct mbuf *);
285
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 *);
292
293 /* ip_output.c */
294 int ip_output(struct socket *, struct mbuf *);
295
296 /* tcp_input.c */
297 void tcp_input(register struct mbuf *, int, struct socket *);
298 int tcp_mss(register struct tcpcb *, u_int);
299
300 /* tcp_output.c */
301 int tcp_output(register struct tcpcb *);
302 void tcp_setpersist(register struct tcpcb *);
303
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);
319
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
327
328 #ifndef _WIN32
329 #define min(x,y) ((x) < (y) ? (x) : (y))
330 #define max(x,y) ((x) > (y) ? (x) : (y))
331 #endif
332
333 #ifdef _WIN32
334 #undef errno
335 #define errno (WSAGetLastError())
336 #endif
337
338 #endif
This page took 0.039933 seconds and 4 git commands to generate.