1 | /* $Id: libslirp.h 28449 2010-04-19 09:52:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NAT - slirp interface.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef _LIBSLIRP_H
|
---|
23 | #define _LIBSLIRP_H
|
---|
24 |
|
---|
25 | #ifdef RT_OS_WINDOWS
|
---|
26 | # include <winsock2.h>
|
---|
27 | # ifdef __cplusplus
|
---|
28 | extern "C" {
|
---|
29 | # endif
|
---|
30 | int inet_aton(const char *cp, struct in_addr *ia);
|
---|
31 | # ifdef __cplusplus
|
---|
32 | }
|
---|
33 | # endif
|
---|
34 | #else
|
---|
35 | # ifdef RT_OS_OS2 /* temporary workaround, see ticket #127 */
|
---|
36 | # include <sys/time.h>
|
---|
37 | # endif
|
---|
38 | # include <sys/select.h>
|
---|
39 | # include <poll.h>
|
---|
40 | # include <arpa/inet.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <VBox/types.h>
|
---|
44 |
|
---|
45 | typedef struct NATState *PNATState;
|
---|
46 | struct mbuf;
|
---|
47 |
|
---|
48 | #ifdef __cplusplus
|
---|
49 | extern "C" {
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | int slirp_init(PNATState *, uint32_t, uint32_t, bool, bool, void *);
|
---|
53 | void slirp_register_statistics(PNATState pData, PPDMDRVINS pDrvIns);
|
---|
54 | void slirp_deregister_statistics(PNATState pData, PPDMDRVINS pDrvIns);
|
---|
55 | void slirp_term(PNATState);
|
---|
56 | void slirp_link_up(PNATState);
|
---|
57 | void slirp_link_down(PNATState);
|
---|
58 |
|
---|
59 | #if defined(RT_OS_WINDOWS)
|
---|
60 | void slirp_select_fill(PNATState pData, int *pndfs);
|
---|
61 |
|
---|
62 | void slirp_select_poll(PNATState pData, int fTimeout, int fIcmp);
|
---|
63 | #else /* RT_OS_WINDOWS */
|
---|
64 | void slirp_select_fill(PNATState pData, int *pnfds, struct pollfd *polls);
|
---|
65 | void slirp_select_poll(PNATState pData, struct pollfd *polls, int ndfs);
|
---|
66 | #endif /* !RT_OS_WINDOWS */
|
---|
67 |
|
---|
68 | void slirp_input(PNATState pData, struct mbuf *m, size_t cbBuf);
|
---|
69 | void slirp_set_ethaddr_and_activate_port_forwarding(PNATState pData, const uint8_t *ethaddr, uint32_t GuestIP);
|
---|
70 |
|
---|
71 | /* you must provide the following functions: */
|
---|
72 | void slirp_arm_fast_timer(void *pvUser);
|
---|
73 | int slirp_can_output(void * pvUser);
|
---|
74 | void slirp_output(void * pvUser, struct mbuf *m, const uint8_t *pkt, int pkt_len);
|
---|
75 | void slirp_urg_output(void *pvUser, struct mbuf *, const uint8_t *pu8Buf, int cb);
|
---|
76 | void slirp_post_sent(PNATState pData, void *pvArg);
|
---|
77 |
|
---|
78 | int slirp_redir(PNATState pData, int is_udp, struct in_addr host_addr,
|
---|
79 | int host_port, struct in_addr guest_addr,
|
---|
80 | int guest_port, const uint8_t *);
|
---|
81 | int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte,
|
---|
82 | int guest_port);
|
---|
83 |
|
---|
84 | void slirp_set_dhcp_TFTP_prefix(PNATState pData, const char *tftpPrefix);
|
---|
85 | void slirp_set_dhcp_TFTP_bootfile(PNATState pData, const char *bootFile);
|
---|
86 | void slirp_set_dhcp_next_server(PNATState pData, const char *nextServer);
|
---|
87 | void slirp_set_dhcp_dns_proxy(PNATState pData, bool fDNSProxy);
|
---|
88 | void slirp_set_rcvbuf(PNATState pData, int kilobytes);
|
---|
89 | void slirp_set_sndbuf(PNATState pData, int kilobytes);
|
---|
90 | void slirp_set_tcp_rcvspace(PNATState pData, int kilobytes);
|
---|
91 | void slirp_set_tcp_sndspace(PNATState pData, int kilobytes);
|
---|
92 |
|
---|
93 | int slirp_set_binding_address(PNATState, char *addr);
|
---|
94 | #ifdef VBOX_WITH_SLIRP_BSD_MBUF
|
---|
95 | void slirp_set_mtu(PNATState, int);
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | #if defined(RT_OS_WINDOWS)
|
---|
99 |
|
---|
100 |
|
---|
101 | /*
|
---|
102 | * ICMP handle state change
|
---|
103 | */
|
---|
104 | # define VBOX_ICMP_EVENT_INDEX 0
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * This event is for
|
---|
108 | * - slirp_input
|
---|
109 | * - slirp_link_up
|
---|
110 | * - slirp_link_down
|
---|
111 | * - wakeup
|
---|
112 | */
|
---|
113 | # define VBOX_WAKEUP_EVENT_INDEX 1
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * UDP/TCP socket state change (socket ready to receive, to send, ...)
|
---|
117 | */
|
---|
118 | # define VBOX_SOCKET_EVENT_INDEX 2
|
---|
119 |
|
---|
120 | /*
|
---|
121 | * The number of events for WSAWaitForMultipleEvents().
|
---|
122 | */
|
---|
123 | # define VBOX_EVENT_COUNT 3
|
---|
124 |
|
---|
125 | HANDLE *slirp_get_events(PNATState pData);
|
---|
126 | void slirp_register_external_event(PNATState pData, HANDLE hEvent, int index);
|
---|
127 | #endif /* RT_OS_WINDOWS */
|
---|
128 |
|
---|
129 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
130 | void slirp_process_queue(PNATState pData);
|
---|
131 | void *slirp_get_queue(PNATState pData);
|
---|
132 | #endif
|
---|
133 |
|
---|
134 | struct mbuf *slirp_ext_m_get(PNATState pData, size_t cbMin, void **ppvBuf, size_t *pcbBuf);
|
---|
135 | void slirp_ext_m_free(PNATState pData, struct mbuf *);
|
---|
136 | #ifndef VBOX_WITH_SLIRP_BSD_MBUF
|
---|
137 | void slirp_push_recv_thread(void *pvUser);
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | /*
|
---|
141 | * Returns the timeout.
|
---|
142 | */
|
---|
143 | unsigned int slirp_get_timeout_ms(PNATState pData);
|
---|
144 |
|
---|
145 | # ifndef RT_OS_WINDOWS
|
---|
146 | /*
|
---|
147 | * Returns the number of sockets.
|
---|
148 | */
|
---|
149 | int slirp_get_nsock(PNATState pData);
|
---|
150 | # endif
|
---|
151 |
|
---|
152 | #ifdef __cplusplus
|
---|
153 | }
|
---|
154 | #endif
|
---|
155 |
|
---|
156 | #endif
|
---|