]> Git Repo - qemu.git/blame - slirp/libslirp.h
slirp: replace global polling with per-instance & notifier
[qemu.git] / slirp / libslirp.h
CommitLineData
2a6a4076
MA
1#ifndef LIBSLIRP_H
2#define LIBSLIRP_H
f0cbd3ec 3
35ee75f3
MAL
4#include <glib.h>
5#include <stdint.h>
6#include <stdbool.h>
7
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
6dbe553f 15
460fec67
JK
16typedef struct Slirp Slirp;
17
625a526b 18typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque);
07abf6d4 19typedef void (*SlirpTimerCb)(void *opaque);
44b4ff24 20
d846b927
MAL
21/*
22 * Callbacks from slirp
d846b927
MAL
23 */
24typedef struct SlirpCb {
07abf6d4 25 /*
625a526b
MAL
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.
07abf6d4 31 */
625a526b 32 SlirpWriteCb send_packet;
2addc8fb
MAL
33 /* Print a message for an error due to guest misbehavior. */
34 void (*guest_error)(const char *msg);
e6dbff3f
MAL
35 /* Return the virtual clock value in nanoseconds */
36 int64_t (*clock_get_ns)(void);
07abf6d4
MAL
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);
848c7092
MAL
43 /* Register a fd for future polling */
44 void (*register_poll_fd)(int fd);
f6e5aa36
MAL
45 /* Unregister a fd */
46 void (*unregister_poll_fd)(int fd);
c21d9594
MAL
47 /* Kick the io-thread, to signal that new events may be processed */
48 void (*notify)(void);
d846b927
MAL
49} SlirpCb;
50
62c1d2c4 51
0b11c036 52Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
9f8bd042 53 struct in_addr vnetmask, struct in_addr vhost,
0b11c036 54 bool in6_enabled,
7aac531e
YB
55 struct in6_addr vprefix_addr6, uint8_t vprefix_len,
56 struct in6_addr vhost6, const char *vhostname,
0fca92b9 57 const char *tftp_server_name,
7aac531e
YB
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,
62c1d2c4 61 const char *vdomainname,
d846b927 62 const SlirpCb *callbacks,
62c1d2c4 63 void *opaque);
ad0d8c4c 64void slirp_cleanup(Slirp *slirp);
f0cbd3ec 65
1ab67b98 66void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds, uint32_t *timeout);
f0cbd3ec 67
1ab67b98 68void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, int select_error);
f0cbd3ec 69
9f8bd042 70void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
f0cbd3ec 71
9f8bd042
JK
72int slirp_add_hostfwd(Slirp *slirp, int is_udp,
73 struct in_addr host_addr, int host_port,
c92ef6a2 74 struct in_addr guest_addr, int guest_port);
9f8bd042
JK
75int slirp_remove_hostfwd(Slirp *slirp, int is_udp,
76 struct in_addr host_addr, int host_port);
44b4ff24
MAL
77int slirp_add_exec(Slirp *slirp, const char *cmdline,
78 struct in_addr *guest_addr, int guest_port);
79int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque,
bb53fc53 80 struct in_addr *guest_addr, int guest_port);
9bf05444 81
b7f43bf2 82char *slirp_connection_info(Slirp *slirp);
6dbe553f 83
9f8bd042
JK
84void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr,
85 int guest_port, const uint8_t *buf, int size);
86size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr,
87 int guest_port);
31a60e22 88
f0cbd3ec 89#endif
This page took 0.850047 seconds and 4 git commands to generate.