1 | /* $Id: libslirp.h 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NAT - slirp interface.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
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 |
|
---|
18 | #ifndef _LIBSLIRP_H
|
---|
19 | #define _LIBSLIRP_H
|
---|
20 |
|
---|
21 | #ifdef RT_OS_WINDOWS
|
---|
22 | # include <winsock2.h>
|
---|
23 | # ifdef __cplusplus
|
---|
24 | extern "C" {
|
---|
25 | # endif
|
---|
26 | int inet_aton(const char *cp, struct in_addr *ia);
|
---|
27 | # ifdef __cplusplus
|
---|
28 | }
|
---|
29 | # endif
|
---|
30 | #else
|
---|
31 | # ifdef RT_OS_OS2 /* temporary workaround, see ticket #127 */
|
---|
32 | # include <sys/time.h>
|
---|
33 | # endif
|
---|
34 | # include <sys/select.h>
|
---|
35 | # include <poll.h>
|
---|
36 | # include <arpa/inet.h>
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #include <VBox/types.h>
|
---|
40 | #include <VBox/vmm/dbgf.h>
|
---|
41 |
|
---|
42 | typedef struct NATState *PNATState;
|
---|
43 | struct mbuf;
|
---|
44 |
|
---|
45 | #ifdef __cplusplus
|
---|
46 | extern "C" {
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | int slirp_init(PNATState *, uint32_t, uint32_t, bool, bool, int, int, void *);
|
---|
50 | void slirp_register_statistics(PNATState pData, PPDMDRVINS pDrvIns);
|
---|
51 | void slirp_deregister_statistics(PNATState pData, PPDMDRVINS pDrvIns);
|
---|
52 | void slirp_term(PNATState);
|
---|
53 | void slirp_link_up(PNATState);
|
---|
54 | void slirp_link_down(PNATState);
|
---|
55 |
|
---|
56 | #if defined(RT_OS_WINDOWS)
|
---|
57 | void slirp_select_fill(PNATState pData, int *pndfs);
|
---|
58 |
|
---|
59 | void slirp_select_poll(PNATState pData, int fTimeout, int fIcmp);
|
---|
60 | #else /* RT_OS_WINDOWS */
|
---|
61 | void slirp_select_fill(PNATState pData, int *pnfds, struct pollfd *polls);
|
---|
62 | void slirp_select_poll(PNATState pData, struct pollfd *polls, int ndfs);
|
---|
63 | #endif /* !RT_OS_WINDOWS */
|
---|
64 |
|
---|
65 | void slirp_input(PNATState pData, struct mbuf *m, size_t cbBuf);
|
---|
66 | void slirp_set_ethaddr_and_activate_port_forwarding(PNATState pData, const uint8_t *ethaddr, uint32_t GuestIP);
|
---|
67 |
|
---|
68 | /* you must provide the following functions: */
|
---|
69 | void slirp_arm_fast_timer(void *pvUser);
|
---|
70 | int slirp_can_output(void * pvUser);
|
---|
71 | void slirp_output(void * pvUser, struct mbuf *m, const uint8_t *pkt, int pkt_len);
|
---|
72 | void slirp_output_pending(void * pvUser);
|
---|
73 | void slirp_urg_output(void *pvUser, struct mbuf *, const uint8_t *pu8Buf, int cb);
|
---|
74 | void slirp_post_sent(PNATState pData, void *pvArg);
|
---|
75 |
|
---|
76 | int slirp_add_redirect(PNATState pData, int is_udp, struct in_addr host_addr,
|
---|
77 | int host_port, struct in_addr guest_addr,
|
---|
78 | int guest_port, const uint8_t *);
|
---|
79 | int slirp_remove_redirect(PNATState pData, int is_udp, struct in_addr host_addr,
|
---|
80 | int host_port, struct in_addr guest_addr,
|
---|
81 | int guest_port);
|
---|
82 | int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte,
|
---|
83 | int guest_port);
|
---|
84 |
|
---|
85 | void slirp_set_dhcp_TFTP_prefix(PNATState pData, const char *tftpPrefix);
|
---|
86 | void slirp_set_dhcp_TFTP_bootfile(PNATState pData, const char *bootFile);
|
---|
87 | void slirp_set_dhcp_next_server(PNATState pData, const char *nextServer);
|
---|
88 | void slirp_set_dhcp_dns_proxy(PNATState pData, bool fDNSProxy);
|
---|
89 | void slirp_set_rcvbuf(PNATState pData, int kilobytes);
|
---|
90 | void slirp_set_sndbuf(PNATState pData, int kilobytes);
|
---|
91 | void slirp_set_tcp_rcvspace(PNATState pData, int kilobytes);
|
---|
92 | void slirp_set_tcp_sndspace(PNATState pData, int kilobytes);
|
---|
93 |
|
---|
94 | int slirp_set_binding_address(PNATState, char *addr);
|
---|
95 | void slirp_set_mtu(PNATState, int);
|
---|
96 | void slirp_info(PNATState pData, PCDBGFINFOHLP pHlp, const char *pszArgs);
|
---|
97 | void slirp_set_somaxconn(PNATState pData, int iSoMaxConn);
|
---|
98 |
|
---|
99 | #if defined(RT_OS_WINDOWS)
|
---|
100 |
|
---|
101 |
|
---|
102 | /*
|
---|
103 | * ICMP handle state change
|
---|
104 | */
|
---|
105 | # define VBOX_ICMP_EVENT_INDEX 0
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * This event is for
|
---|
109 | * - slirp_input
|
---|
110 | * - slirp_link_up
|
---|
111 | * - slirp_link_down
|
---|
112 | * - wakeup
|
---|
113 | */
|
---|
114 | # define VBOX_WAKEUP_EVENT_INDEX 1
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * UDP/TCP socket state change (socket ready to receive, to send, ...)
|
---|
118 | */
|
---|
119 | # define VBOX_SOCKET_EVENT_INDEX 2
|
---|
120 |
|
---|
121 | /*
|
---|
122 | * The number of events for WSAWaitForMultipleEvents().
|
---|
123 | */
|
---|
124 | # define VBOX_EVENT_COUNT 3
|
---|
125 |
|
---|
126 | HANDLE *slirp_get_events(PNATState pData);
|
---|
127 | void slirp_register_external_event(PNATState pData, HANDLE hEvent, int index);
|
---|
128 | #endif /* RT_OS_WINDOWS */
|
---|
129 |
|
---|
130 | struct mbuf *slirp_ext_m_get(PNATState pData, size_t cbMin, void **ppvBuf, size_t *pcbBuf);
|
---|
131 | void slirp_ext_m_free(PNATState pData, struct mbuf *, uint8_t *pu8Buf);
|
---|
132 |
|
---|
133 | /*
|
---|
134 | * Returns the timeout.
|
---|
135 | */
|
---|
136 | unsigned int slirp_get_timeout_ms(PNATState pData);
|
---|
137 |
|
---|
138 | # ifndef RT_OS_WINDOWS
|
---|
139 | /*
|
---|
140 | * Returns the number of sockets.
|
---|
141 | */
|
---|
142 | int slirp_get_nsock(PNATState pData);
|
---|
143 | # endif
|
---|
144 |
|
---|
145 | #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
|
---|
146 | void slirp_add_host_resolver_mapping(PNATState pData, const char *pszHostName, const char *pszHostNamePattern, uint32_t u32HostIP);
|
---|
147 | #endif
|
---|
148 |
|
---|
149 | #ifdef __cplusplus
|
---|
150 | }
|
---|
151 | #endif
|
---|
152 |
|
---|
153 | #endif
|
---|