11 #include <netinet/in.h>
12 #include <arpa/inet.h>
19 typedef struct Slirp Slirp
;
22 SLIRP_POLL_IN
= 1 << 0,
23 SLIRP_POLL_OUT
= 1 << 1,
24 SLIRP_POLL_PRI
= 1 << 2,
25 SLIRP_POLL_ERR
= 1 << 3,
26 SLIRP_POLL_HUP
= 1 << 4,
29 typedef ssize_t (*SlirpWriteCb
)(const void *buf
, size_t len
, void *opaque
);
30 typedef void (*SlirpTimerCb
)(void *opaque
);
31 typedef int (*SlirpAddPollCb
)(int fd
, int events
, void *opaque
);
32 typedef int (*SlirpGetREventsCb
)(int idx
, void *opaque
);
35 * Callbacks from slirp
37 typedef struct SlirpCb
{
39 * Send an ethernet frame to the guest network. The opaque
40 * parameter is the one given to slirp_init(). The function
41 * doesn't need to send all the data and may return <len (no
42 * buffering is done on libslirp side, so the data will be dropped
43 * in this case). <0 reports an IO error.
45 SlirpWriteCb send_packet
;
46 /* Print a message for an error due to guest misbehavior. */
47 void (*guest_error
)(const char *msg
, void *opaque
);
48 /* Return the virtual clock value in nanoseconds */
49 int64_t (*clock_get_ns
)(void *opaque
);
50 /* Create a new timer with the given callback and opaque data */
51 void *(*timer_new
)(SlirpTimerCb cb
, void *cb_opaque
, void *opaque
);
52 /* Remove and free a timer */
53 void (*timer_free
)(void *timer
, void *opaque
);
54 /* Modify a timer to expire at @expire_time */
55 void (*timer_mod
)(void *timer
, int64_t expire_time
, void *opaque
);
56 /* Register a fd for future polling */
57 void (*register_poll_fd
)(int fd
, void *opaque
);
59 void (*unregister_poll_fd
)(int fd
, void *opaque
);
60 /* Kick the io-thread, to signal that new events may be processed */
61 void (*notify
)(void *opaque
);
65 Slirp
*slirp_init(int restricted
, bool in_enabled
, struct in_addr vnetwork
,
66 struct in_addr vnetmask
, struct in_addr vhost
,
68 struct in6_addr vprefix_addr6
, uint8_t vprefix_len
,
69 struct in6_addr vhost6
, const char *vhostname
,
70 const char *tftp_server_name
,
71 const char *tftp_path
, const char *bootfile
,
72 struct in_addr vdhcp_start
, struct in_addr vnameserver
,
73 struct in6_addr vnameserver6
, const char **vdnssearch
,
74 const char *vdomainname
,
75 const SlirpCb
*callbacks
,
77 void slirp_cleanup(Slirp
*slirp
);
79 void slirp_pollfds_fill(Slirp
*slirp
, uint32_t *timeout
,
80 SlirpAddPollCb add_poll
, void *opaque
);
82 void slirp_pollfds_poll(Slirp
*slirp
, int select_error
,
83 SlirpGetREventsCb get_revents
, void *opaque
);
85 void slirp_input(Slirp
*slirp
, const uint8_t *pkt
, int pkt_len
);
87 int slirp_add_hostfwd(Slirp
*slirp
, int is_udp
,
88 struct in_addr host_addr
, int host_port
,
89 struct in_addr guest_addr
, int guest_port
);
90 int slirp_remove_hostfwd(Slirp
*slirp
, int is_udp
,
91 struct in_addr host_addr
, int host_port
);
92 int slirp_add_exec(Slirp
*slirp
, const char *cmdline
,
93 struct in_addr
*guest_addr
, int guest_port
);
94 int slirp_add_guestfwd(Slirp
*slirp
, SlirpWriteCb write_cb
, void *opaque
,
95 struct in_addr
*guest_addr
, int guest_port
);
97 char *slirp_connection_info(Slirp
*slirp
);
99 void slirp_socket_recv(Slirp
*slirp
, struct in_addr guest_addr
,
100 int guest_port
, const uint8_t *buf
, int size
);
101 size_t slirp_socket_can_recv(Slirp
*slirp
, struct in_addr guest_addr
,
107 #endif /* LIBSLIRP_H */