slirp: improve send_packet() callback
[qemu/ar7.git] / slirp / libslirp.h
blob8e5d4ed11b5e7a0f59fad76f6fd95c752a95ca2d
1 #ifndef LIBSLIRP_H
2 #define LIBSLIRP_H
4 #include <glib.h>
5 #include <stdint.h>
6 #include <stdbool.h>
8 #ifdef _WIN32
9 #include <winsock2.h>
10 #include <in6addr.h>
11 #else
12 #include <netinet/in.h>
13 #include <arpa/inet.h>
14 #endif
16 typedef struct Slirp Slirp;
18 typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque);
19 typedef void (*SlirpTimerCb)(void *opaque);
22 * Callbacks from slirp
24 typedef struct SlirpCb {
26 * Send an ethernet frame to the guest network. The opaque
27 * parameter is the one given to slirp_init(). The function
28 * doesn't need to send all the data and may return <len (no
29 * buffering is done on libslirp side, so the data will be dropped
30 * in this case). <0 reports an IO error.
32 SlirpWriteCb send_packet;
33 /* Print a message for an error due to guest misbehavior. */
34 void (*guest_error)(const char *msg);
35 /* Return the virtual clock value in nanoseconds */
36 int64_t (*clock_get_ns)(void);
37 /* Create a new timer with the given callback and opaque data */
38 void *(*timer_new)(SlirpTimerCb cb, void *opaque);
39 /* Remove and free a timer */
40 void (*timer_free)(void *timer);
41 /* Modify a timer to expire at @expire_time */
42 void (*timer_mod)(void *timer, int64_t expire_time);
43 /* Register a fd for future polling */
44 void (*register_poll_fd)(int fd);
45 /* Unregister a fd */
46 void (*unregister_poll_fd)(int fd);
47 /* Kick the io-thread, to signal that new events may be processed */
48 void (*notify)(void);
49 } SlirpCb;
52 Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
53 struct in_addr vnetmask, struct in_addr vhost,
54 bool in6_enabled,
55 struct in6_addr vprefix_addr6, uint8_t vprefix_len,
56 struct in6_addr vhost6, const char *vhostname,
57 const char *tftp_server_name,
58 const char *tftp_path, const char *bootfile,
59 struct in_addr vdhcp_start, struct in_addr vnameserver,
60 struct in6_addr vnameserver6, const char **vdnssearch,
61 const char *vdomainname,
62 const SlirpCb *callbacks,
63 void *opaque);
64 void slirp_cleanup(Slirp *slirp);
66 void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
68 void slirp_pollfds_poll(GArray *pollfds, int select_error);
70 void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
72 int slirp_add_hostfwd(Slirp *slirp, int is_udp,
73 struct in_addr host_addr, int host_port,
74 struct in_addr guest_addr, int guest_port);
75 int slirp_remove_hostfwd(Slirp *slirp, int is_udp,
76 struct in_addr host_addr, int host_port);
77 int slirp_add_exec(Slirp *slirp, const char *cmdline,
78 struct in_addr *guest_addr, int guest_port);
79 int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque,
80 struct in_addr *guest_addr, int guest_port);
82 char *slirp_connection_info(Slirp *slirp);
84 void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr,
85 int guest_port, const uint8_t *buf, int size);
86 size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr,
87 int guest_port);
89 #endif