Statistics
| Branch: | Revision:

root / slirp / slirp.h @ 1a0ca1e1

History | View | Annotate | Download (7.7 kB)

1 f0cbd3ec bellard
#ifndef __COMMON_H__
2 f0cbd3ec bellard
#define __COMMON_H__
3 f0cbd3ec bellard
4 5fa0ab8f bellard
#include "config-host.h"
5 f0cbd3ec bellard
#include "slirp_config.h"
6 f0cbd3ec bellard
7 379ff53d bellard
#ifdef _WIN32
8 379ff53d bellard
# include <inttypes.h>
9 379ff53d bellard
10 379ff53d bellard
typedef char *caddr_t;
11 379ff53d bellard
12 34444131 bellard
# include <windows.h>
13 379ff53d bellard
# include <winsock2.h>
14 116842ee balrog
# include <ws2tcpip.h>
15 379ff53d bellard
# include <sys/timeb.h>
16 379ff53d bellard
# include <iphlpapi.h>
17 379ff53d bellard
18 379ff53d bellard
# define EWOULDBLOCK WSAEWOULDBLOCK
19 379ff53d bellard
# define EINPROGRESS WSAEINPROGRESS
20 379ff53d bellard
# define ENOTCONN WSAENOTCONN
21 379ff53d bellard
# define EHOSTUNREACH WSAEHOSTUNREACH
22 379ff53d bellard
# define ENETUNREACH WSAENETUNREACH
23 379ff53d bellard
# define ECONNREFUSED WSAECONNREFUSED
24 379ff53d bellard
#else
25 379ff53d bellard
# define ioctlsocket ioctl
26 379ff53d bellard
# define closesocket(s) close(s)
27 4a2b39d3 Andreas Färber
# if !defined(__HAIKU__)
28 4a2b39d3 Andreas Färber
#  define O_BINARY 0
29 4a2b39d3 Andreas Färber
# endif
30 379ff53d bellard
#endif
31 379ff53d bellard
32 f0cbd3ec bellard
#include <sys/types.h>
33 f0cbd3ec bellard
#ifdef HAVE_SYS_BITYPES_H
34 f0cbd3ec bellard
# include <sys/bitypes.h>
35 f0cbd3ec bellard
#endif
36 f0cbd3ec bellard
37 170c6f87 bellard
#include <sys/time.h>
38 170c6f87 bellard
39 f0cbd3ec bellard
#ifdef HAVE_UNISTD_H
40 f0cbd3ec bellard
# include <unistd.h>
41 f0cbd3ec bellard
#endif
42 f0cbd3ec bellard
43 f0cbd3ec bellard
#ifdef HAVE_STDLIB_H
44 f0cbd3ec bellard
# include <stdlib.h>
45 f0cbd3ec bellard
#endif
46 f0cbd3ec bellard
47 f0cbd3ec bellard
#include <stdio.h>
48 f0cbd3ec bellard
#include <errno.h>
49 f0cbd3ec bellard
50 f0cbd3ec bellard
#ifndef HAVE_MEMMOVE
51 f0cbd3ec bellard
#define memmove(x, y, z) bcopy(y, x, z)
52 f0cbd3ec bellard
#endif
53 f0cbd3ec bellard
54 f0cbd3ec bellard
#if TIME_WITH_SYS_TIME
55 f0cbd3ec bellard
# include <sys/time.h>
56 f0cbd3ec bellard
# include <time.h>
57 f0cbd3ec bellard
#else
58 eb38c52c blueswir1
# ifdef HAVE_SYS_TIME_H
59 f0cbd3ec bellard
#  include <sys/time.h>
60 f0cbd3ec bellard
# else
61 f0cbd3ec bellard
#  include <time.h>
62 f0cbd3ec bellard
# endif
63 f0cbd3ec bellard
#endif
64 f0cbd3ec bellard
65 f0cbd3ec bellard
#ifdef HAVE_STRING_H
66 f0cbd3ec bellard
# include <string.h>
67 f0cbd3ec bellard
#else
68 f0cbd3ec bellard
# include <strings.h>
69 f0cbd3ec bellard
#endif
70 f0cbd3ec bellard
71 379ff53d bellard
#ifndef _WIN32
72 f0cbd3ec bellard
#include <sys/uio.h>
73 379ff53d bellard
#endif
74 f0cbd3ec bellard
75 379ff53d bellard
#ifndef _WIN32
76 f0cbd3ec bellard
#include <netinet/in.h>
77 f0cbd3ec bellard
#include <arpa/inet.h>
78 379ff53d bellard
#endif
79 f0cbd3ec bellard
80 f0cbd3ec bellard
/* Systems lacking strdup() definition in <string.h>. */
81 f0cbd3ec bellard
#if defined(ultrix)
82 6cb9c6d3 Blue Swirl
char *strdup(const char *);
83 f0cbd3ec bellard
#endif
84 f0cbd3ec bellard
85 f0cbd3ec bellard
/* Systems lacking malloc() definition in <stdlib.h>. */
86 f0cbd3ec bellard
#if defined(ultrix) || defined(hcx)
87 6cb9c6d3 Blue Swirl
void *malloc(size_t arg);
88 6cb9c6d3 Blue Swirl
void free(void *ptr);
89 f0cbd3ec bellard
#endif
90 f0cbd3ec bellard
91 f0cbd3ec bellard
#ifndef HAVE_INET_ATON
92 6cb9c6d3 Blue Swirl
int inet_aton(const char *cp, struct in_addr *ia);
93 f0cbd3ec bellard
#endif
94 f0cbd3ec bellard
95 f0cbd3ec bellard
#include <fcntl.h>
96 f0cbd3ec bellard
#ifndef NO_UNIX_SOCKETS
97 f0cbd3ec bellard
#include <sys/un.h>
98 f0cbd3ec bellard
#endif
99 f0cbd3ec bellard
#include <signal.h>
100 f0cbd3ec bellard
#ifdef HAVE_SYS_SIGNAL_H
101 f0cbd3ec bellard
# include <sys/signal.h>
102 f0cbd3ec bellard
#endif
103 379ff53d bellard
#ifndef _WIN32
104 f0cbd3ec bellard
#include <sys/socket.h>
105 379ff53d bellard
#endif
106 f0cbd3ec bellard
107 ee2654ac bellard
#if defined(HAVE_SYS_IOCTL_H)
108 f0cbd3ec bellard
# include <sys/ioctl.h>
109 f0cbd3ec bellard
#endif
110 f0cbd3ec bellard
111 f0cbd3ec bellard
#ifdef HAVE_SYS_SELECT_H
112 f0cbd3ec bellard
# include <sys/select.h>
113 f0cbd3ec bellard
#endif
114 f0cbd3ec bellard
115 f0cbd3ec bellard
#ifdef HAVE_SYS_WAIT_H
116 f0cbd3ec bellard
# include <sys/wait.h>
117 f0cbd3ec bellard
#endif
118 f0cbd3ec bellard
119 f0cbd3ec bellard
#ifdef HAVE_SYS_FILIO_H
120 f0cbd3ec bellard
# include <sys/filio.h>
121 f0cbd3ec bellard
#endif
122 f0cbd3ec bellard
123 f0cbd3ec bellard
#ifdef USE_PPP
124 f0cbd3ec bellard
#include <ppp/slirppp.h>
125 f0cbd3ec bellard
#endif
126 f0cbd3ec bellard
127 f0cbd3ec bellard
#ifdef __STDC__
128 f0cbd3ec bellard
#include <stdarg.h>
129 f0cbd3ec bellard
#else
130 f0cbd3ec bellard
#include <varargs.h>
131 f0cbd3ec bellard
#endif
132 f0cbd3ec bellard
133 f0cbd3ec bellard
#include <sys/stat.h>
134 f0cbd3ec bellard
135 f0cbd3ec bellard
/* Avoid conflicting with the libc insque() and remque(), which
136 f0cbd3ec bellard
   have different prototypes. */
137 f0cbd3ec bellard
#define insque slirp_insque
138 f0cbd3ec bellard
#define remque slirp_remque
139 f0cbd3ec bellard
140 f0cbd3ec bellard
#ifdef HAVE_SYS_STROPTS_H
141 f0cbd3ec bellard
#include <sys/stropts.h>
142 f0cbd3ec bellard
#endif
143 f0cbd3ec bellard
144 f0cbd3ec bellard
#include "debug.h"
145 f0cbd3ec bellard
146 72cf2d4f Blue Swirl
#include "qemu-queue.h"
147 b1c99fcd Jan Kiszka
148 460fec67 Jan Kiszka
#include "libslirp.h"
149 f0cbd3ec bellard
#include "ip.h"
150 f0cbd3ec bellard
#include "tcp.h"
151 f0cbd3ec bellard
#include "tcp_timer.h"
152 f0cbd3ec bellard
#include "tcp_var.h"
153 f0cbd3ec bellard
#include "tcpip.h"
154 f0cbd3ec bellard
#include "udp.h"
155 e6d43cfb Jan Kiszka
#include "ip_icmp.h"
156 f0cbd3ec bellard
#include "mbuf.h"
157 f0cbd3ec bellard
#include "sbuf.h"
158 f0cbd3ec bellard
#include "socket.h"
159 f0cbd3ec bellard
#include "if.h"
160 f0cbd3ec bellard
#include "main.h"
161 f0cbd3ec bellard
#include "misc.h"
162 f0cbd3ec bellard
#ifdef USE_PPP
163 f0cbd3ec bellard
#include "ppp/pppd.h"
164 f0cbd3ec bellard
#include "ppp/ppp.h"
165 f0cbd3ec bellard
#endif
166 f0cbd3ec bellard
167 f0cbd3ec bellard
#include "bootp.h"
168 c7f74643 bellard
#include "tftp.h"
169 460fec67 Jan Kiszka
170 40ff6d7e Kevin Wolf
/* osdep.c */
171 40ff6d7e Kevin Wolf
int qemu_socket(int domain, int type, int protocol);
172 40ff6d7e Kevin Wolf
173 1a0ca1e1 Fabien Chouteau
#define ETH_ALEN 6
174 1a0ca1e1 Fabien Chouteau
#define ETH_HLEN 14
175 1a0ca1e1 Fabien Chouteau
176 1a0ca1e1 Fabien Chouteau
#define ETH_P_IP  0x0800        /* Internet Protocol packet  */
177 1a0ca1e1 Fabien Chouteau
#define ETH_P_ARP 0x0806        /* Address Resolution packet */
178 1a0ca1e1 Fabien Chouteau
179 1a0ca1e1 Fabien Chouteau
#define ARPOP_REQUEST 1         /* ARP request */
180 1a0ca1e1 Fabien Chouteau
#define ARPOP_REPLY   2         /* ARP reply   */
181 1a0ca1e1 Fabien Chouteau
182 1a0ca1e1 Fabien Chouteau
struct ethhdr {
183 1a0ca1e1 Fabien Chouteau
    unsigned char  h_dest[ETH_ALEN];   /* destination eth addr */
184 1a0ca1e1 Fabien Chouteau
    unsigned char  h_source[ETH_ALEN]; /* source ether addr    */
185 1a0ca1e1 Fabien Chouteau
    unsigned short h_proto;            /* packet type ID field */
186 1a0ca1e1 Fabien Chouteau
};
187 1a0ca1e1 Fabien Chouteau
188 1a0ca1e1 Fabien Chouteau
struct arphdr {
189 1a0ca1e1 Fabien Chouteau
    unsigned short ar_hrd;      /* format of hardware address */
190 1a0ca1e1 Fabien Chouteau
    unsigned short ar_pro;      /* format of protocol address */
191 1a0ca1e1 Fabien Chouteau
    unsigned char  ar_hln;      /* length of hardware address */
192 1a0ca1e1 Fabien Chouteau
    unsigned char  ar_pln;      /* length of protocol address */
193 1a0ca1e1 Fabien Chouteau
    unsigned short ar_op;       /* ARP opcode (command)       */
194 1a0ca1e1 Fabien Chouteau
195 1a0ca1e1 Fabien Chouteau
    /*
196 1a0ca1e1 Fabien Chouteau
     *  Ethernet looks like this : This bit is variable sized however...
197 1a0ca1e1 Fabien Chouteau
     */
198 1a0ca1e1 Fabien Chouteau
    unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
199 1a0ca1e1 Fabien Chouteau
    uint32_t      ar_sip;           /* sender IP address       */
200 1a0ca1e1 Fabien Chouteau
    unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
201 1a0ca1e1 Fabien Chouteau
    uint32_t      ar_tip;           /* target IP address       */
202 1a0ca1e1 Fabien Chouteau
} __attribute__((packed));
203 1a0ca1e1 Fabien Chouteau
204 1a0ca1e1 Fabien Chouteau
#define ARP_TABLE_SIZE 16
205 1a0ca1e1 Fabien Chouteau
206 1a0ca1e1 Fabien Chouteau
typedef struct ArpTable {
207 1a0ca1e1 Fabien Chouteau
    struct arphdr table[ARP_TABLE_SIZE];
208 1a0ca1e1 Fabien Chouteau
    int next_victim;
209 1a0ca1e1 Fabien Chouteau
} ArpTable;
210 1a0ca1e1 Fabien Chouteau
211 1a0ca1e1 Fabien Chouteau
void arp_table_add(Slirp *slirp, int ip_addr, uint8_t ethaddr[ETH_ALEN]);
212 1a0ca1e1 Fabien Chouteau
213 1a0ca1e1 Fabien Chouteau
bool arp_table_search(Slirp *slirp, int in_ip_addr,
214 1a0ca1e1 Fabien Chouteau
                      uint8_t out_ethaddr[ETH_ALEN]);
215 40ff6d7e Kevin Wolf
216 460fec67 Jan Kiszka
struct Slirp {
217 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(Slirp) entry;
218 b1c99fcd Jan Kiszka
219 460fec67 Jan Kiszka
    /* virtual network configuration */
220 460fec67 Jan Kiszka
    struct in_addr vnetwork_addr;
221 460fec67 Jan Kiszka
    struct in_addr vnetwork_mask;
222 460fec67 Jan Kiszka
    struct in_addr vhost_addr;
223 460fec67 Jan Kiszka
    struct in_addr vdhcp_startaddr;
224 460fec67 Jan Kiszka
    struct in_addr vnameserver_addr;
225 460fec67 Jan Kiszka
226 460fec67 Jan Kiszka
    struct in_addr client_ipaddr;
227 460fec67 Jan Kiszka
    char client_hostname[33];
228 460fec67 Jan Kiszka
229 460fec67 Jan Kiszka
    int restricted;
230 460fec67 Jan Kiszka
    struct timeval tt;
231 460fec67 Jan Kiszka
    struct ex_list *exec_list;
232 460fec67 Jan Kiszka
233 460fec67 Jan Kiszka
    /* mbuf states */
234 460fec67 Jan Kiszka
    struct mbuf m_freelist, m_usedlist;
235 460fec67 Jan Kiszka
    int mbuf_alloced;
236 460fec67 Jan Kiszka
237 460fec67 Jan Kiszka
    /* if states */
238 460fec67 Jan Kiszka
    int if_queued;          /* number of packets queued so far */
239 460fec67 Jan Kiszka
    struct mbuf if_fastq;   /* fast queue (for interactive data) */
240 460fec67 Jan Kiszka
    struct mbuf if_batchq;  /* queue for non-interactive data */
241 460fec67 Jan Kiszka
    struct mbuf *next_m;    /* pointer to next mbuf to output */
242 460fec67 Jan Kiszka
243 460fec67 Jan Kiszka
    /* ip states */
244 460fec67 Jan Kiszka
    struct ipq ipq;         /* ip reass. queue */
245 b6dce92e Stefan Weil
    uint16_t ip_id;         /* ip packet ctr, for ids */
246 460fec67 Jan Kiszka
247 460fec67 Jan Kiszka
    /* bootp/dhcp states */
248 460fec67 Jan Kiszka
    BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
249 460fec67 Jan Kiszka
    char *bootp_filename;
250 460fec67 Jan Kiszka
251 460fec67 Jan Kiszka
    /* tcp states */
252 460fec67 Jan Kiszka
    struct socket tcb;
253 460fec67 Jan Kiszka
    struct socket *tcp_last_so;
254 460fec67 Jan Kiszka
    tcp_seq tcp_iss;        /* tcp initial send seq # */
255 b6dce92e Stefan Weil
    uint32_t tcp_now;       /* for RFC 1323 timestamps */
256 460fec67 Jan Kiszka
257 460fec67 Jan Kiszka
    /* udp states */
258 460fec67 Jan Kiszka
    struct socket udb;
259 460fec67 Jan Kiszka
    struct socket *udp_last_so;
260 460fec67 Jan Kiszka
261 e6d43cfb Jan Kiszka
    /* icmp states */
262 e6d43cfb Jan Kiszka
    struct socket icmp;
263 e6d43cfb Jan Kiszka
    struct socket *icmp_last_so;
264 e6d43cfb Jan Kiszka
265 460fec67 Jan Kiszka
    /* tftp states */
266 460fec67 Jan Kiszka
    char *tftp_prefix;
267 460fec67 Jan Kiszka
    struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
268 460fec67 Jan Kiszka
269 1a0ca1e1 Fabien Chouteau
    ArpTable arp_table;
270 1a0ca1e1 Fabien Chouteau
271 9f8bd042 Jan Kiszka
    void *opaque;
272 460fec67 Jan Kiszka
};
273 460fec67 Jan Kiszka
274 ad0d8c4c Jan Kiszka
extern Slirp *slirp_instance;
275 f0cbd3ec bellard
276 f0cbd3ec bellard
#ifndef NULL
277 f0cbd3ec bellard
#define NULL (void *)0
278 f0cbd3ec bellard
#endif
279 f0cbd3ec bellard
280 f0cbd3ec bellard
#ifndef FULL_BOLT
281 6cb9c6d3 Blue Swirl
void if_start(Slirp *);
282 f0cbd3ec bellard
#else
283 6cb9c6d3 Blue Swirl
void if_start(struct ttys *);
284 f0cbd3ec bellard
#endif
285 f0cbd3ec bellard
286 f0cbd3ec bellard
#ifndef HAVE_STRERROR
287 64b85a8f Blue Swirl
 char *strerror(int error);
288 f0cbd3ec bellard
#endif
289 f0cbd3ec bellard
290 f0cbd3ec bellard
#ifndef HAVE_INDEX
291 6cb9c6d3 Blue Swirl
 char *index(const char *, int);
292 f0cbd3ec bellard
#endif
293 f0cbd3ec bellard
294 f0cbd3ec bellard
#ifndef HAVE_GETHOSTID
295 6cb9c6d3 Blue Swirl
 long gethostid(void);
296 f0cbd3ec bellard
#endif
297 f0cbd3ec bellard
298 8b7968f7 Stefan Weil
void lprint(const char *, ...) GCC_FMT_ATTR(1, 2);
299 f0cbd3ec bellard
300 379ff53d bellard
#ifndef _WIN32
301 f0cbd3ec bellard
#include <netdb.h>
302 379ff53d bellard
#endif
303 f0cbd3ec bellard
304 f0cbd3ec bellard
#define DEFAULT_BAUD 115200
305 f0cbd3ec bellard
306 9634d903 blueswir1
#define SO_OPTIONS DO_KEEPALIVE
307 9634d903 blueswir1
#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
308 9634d903 blueswir1
309 f0cbd3ec bellard
/* cksum.c */
310 f0cbd3ec bellard
int cksum(struct mbuf *m, int len);
311 f0cbd3ec bellard
312 f0cbd3ec bellard
/* if.c */
313 6cb9c6d3 Blue Swirl
void if_init(Slirp *);
314 6cb9c6d3 Blue Swirl
void if_output(struct socket *, struct mbuf *);
315 f0cbd3ec bellard
316 f0cbd3ec bellard
/* ip_input.c */
317 6cb9c6d3 Blue Swirl
void ip_init(Slirp *);
318 6cb9c6d3 Blue Swirl
void ip_input(struct mbuf *);
319 6cb9c6d3 Blue Swirl
void ip_slowtimo(Slirp *);
320 6cb9c6d3 Blue Swirl
void ip_stripoptions(register struct mbuf *, struct mbuf *);
321 f0cbd3ec bellard
322 f0cbd3ec bellard
/* ip_output.c */
323 6cb9c6d3 Blue Swirl
int ip_output(struct socket *, struct mbuf *);
324 f0cbd3ec bellard
325 f0cbd3ec bellard
/* tcp_input.c */
326 6cb9c6d3 Blue Swirl
void tcp_input(register struct mbuf *, int, struct socket *);
327 6cb9c6d3 Blue Swirl
int tcp_mss(register struct tcpcb *, u_int);
328 f0cbd3ec bellard
329 f0cbd3ec bellard
/* tcp_output.c */
330 6cb9c6d3 Blue Swirl
int tcp_output(register struct tcpcb *);
331 6cb9c6d3 Blue Swirl
void tcp_setpersist(register struct tcpcb *);
332 f0cbd3ec bellard
333 f0cbd3ec bellard
/* tcp_subr.c */
334 6cb9c6d3 Blue Swirl
void tcp_init(Slirp *);
335 6cb9c6d3 Blue Swirl
void tcp_template(struct tcpcb *);
336 6cb9c6d3 Blue Swirl
void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
337 6cb9c6d3 Blue Swirl
struct tcpcb * tcp_newtcpcb(struct socket *);
338 6cb9c6d3 Blue Swirl
struct tcpcb * tcp_close(register struct tcpcb *);
339 6cb9c6d3 Blue Swirl
void tcp_sockclosed(struct tcpcb *);
340 6cb9c6d3 Blue Swirl
int tcp_fconnect(struct socket *);
341 6cb9c6d3 Blue Swirl
void tcp_connect(struct socket *);
342 6cb9c6d3 Blue Swirl
int tcp_attach(struct socket *);
343 b6dce92e Stefan Weil
uint8_t tcp_tos(struct socket *);
344 6cb9c6d3 Blue Swirl
int tcp_emu(struct socket *, struct mbuf *);
345 6cb9c6d3 Blue Swirl
int tcp_ctl(struct socket *);
346 9fafc9ea bellard
struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
347 f0cbd3ec bellard
348 f0cbd3ec bellard
#ifdef USE_PPP
349 f0cbd3ec bellard
#define MIN_MRU MINMRU
350 f0cbd3ec bellard
#define MAX_MRU MAXMRU
351 f0cbd3ec bellard
#else
352 f0cbd3ec bellard
#define MIN_MRU 128
353 f0cbd3ec bellard
#define MAX_MRU 16384
354 f0cbd3ec bellard
#endif
355 f0cbd3ec bellard
356 379ff53d bellard
#ifndef _WIN32
357 379ff53d bellard
#define min(x,y) ((x) < (y) ? (x) : (y))
358 379ff53d bellard
#define max(x,y) ((x) > (y) ? (x) : (y))
359 379ff53d bellard
#endif
360 379ff53d bellard
361 02d2c54c bellard
#ifdef _WIN32
362 ef6ff6b7 bellard
#undef errno
363 02d2c54c bellard
#define errno (WSAGetLastError())
364 02d2c54c bellard
#endif
365 02d2c54c bellard
366 f0cbd3ec bellard
#endif