slirp: replace qemu_notify_event() with a callback
[qemu/ar7.git] / slirp / libslirp.h
blob679a25422b97552bf52d9a931a20fdd28b3035a4
1 #ifndef LIBSLIRP_H
2 #define LIBSLIRP_H
4 #include "qemu-common.h"
6 typedef struct Slirp Slirp;
8 typedef int (*SlirpWriteCb)(const void *buf, size_t len, void *opaque);
9 typedef void (*SlirpTimerCb)(void *opaque);
12 * Callbacks from slirp
14 typedef struct SlirpCb {
16 * Send an ethernet frame to the guest network. The opaque parameter
17 * is the one given to slirp_init().
19 void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
20 /* Print a message for an error due to guest misbehavior. */
21 void (*guest_error)(const char *msg);
22 /* Return the virtual clock value in nanoseconds */
23 int64_t (*clock_get_ns)(void);
24 /* Create a new timer with the given callback and opaque data */
25 void *(*timer_new)(SlirpTimerCb cb, void *opaque);
26 /* Remove and free a timer */
27 void (*timer_free)(void *timer);
28 /* Modify a timer to expire at @expire_time */
29 void (*timer_mod)(void *timer, int64_t expire_time);
30 /* Register a fd for future polling */
31 void (*register_poll_fd)(int fd);
32 /* Unregister a fd */
33 void (*unregister_poll_fd)(int fd);
34 /* Kick the io-thread, to signal that new events may be processed */
35 void (*notify)(void);
36 } SlirpCb;
39 Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
40 struct in_addr vnetmask, struct in_addr vhost,
41 bool in6_enabled,
42 struct in6_addr vprefix_addr6, uint8_t vprefix_len,
43 struct in6_addr vhost6, const char *vhostname,
44 const char *tftp_server_name,
45 const char *tftp_path, const char *bootfile,
46 struct in_addr vdhcp_start, struct in_addr vnameserver,
47 struct in6_addr vnameserver6, const char **vdnssearch,
48 const char *vdomainname,
49 const SlirpCb *callbacks,
50 void *opaque);
51 void slirp_cleanup(Slirp *slirp);
53 void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
55 void slirp_pollfds_poll(GArray *pollfds, int select_error);
57 void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
59 int slirp_add_hostfwd(Slirp *slirp, int is_udp,
60 struct in_addr host_addr, int host_port,
61 struct in_addr guest_addr, int guest_port);
62 int slirp_remove_hostfwd(Slirp *slirp, int is_udp,
63 struct in_addr host_addr, int host_port);
64 int slirp_add_exec(Slirp *slirp, const char *cmdline,
65 struct in_addr *guest_addr, int guest_port);
66 int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque,
67 struct in_addr *guest_addr, int guest_port);
69 char *slirp_connection_info(Slirp *slirp);
71 void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr,
72 int guest_port, const uint8_t *buf, int size);
73 size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr,
74 int guest_port);
76 #endif