aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build24
-rw-r--r--src/bootp.c2
-rw-r--r--src/debug.h31
-rw-r--r--src/ip.h19
-rw-r--r--src/ip6.h13
-rw-r--r--src/ip6_icmp.c5
-rw-r--r--src/ip6_icmp.h27
-rw-r--r--src/libslirp.h38
-rw-r--r--src/main.h4
-rw-r--r--src/misc.c4
-rw-r--r--src/ncsi-pkt.h96
-rw-r--r--src/ncsi.c2
-rw-r--r--src/slirp.c11
-rw-r--r--src/slirp.h3
-rw-r--r--src/state.c19
-rw-r--r--src/tcp.h2
-rw-r--r--src/tftp.c6
-rw-r--r--src/tftp.h6
-rw-r--r--src/util.c8
-rw-r--r--src/util.h30
-rw-r--r--src/vmstate.c4
-rw-r--r--src/vmstate.h7
-rw-r--r--test/ncsitest.c18
-rw-r--r--test/pingtest.c2
24 files changed, 255 insertions, 126 deletions
diff --git a/meson.build b/meson.build
index 435f331..7e7d818 100644
--- a/meson.build
+++ b/meson.build
@@ -16,14 +16,22 @@ conf.set('SLIRP_MAJOR_VERSION', major_version)
conf.set('SLIRP_MINOR_VERSION', minor_version)
conf.set('SLIRP_MICRO_VERSION', micro_version)
-full_version = run_command('build-aux/git-version-gen',
- '@0@/.tarball-version'.format(meson.current_source_dir()),
- check : true).stdout().strip()
-if full_version.startswith('UNKNOWN')
+cc = meson.get_compiler('c')
+
+if cc.get_argument_syntax() != 'msvc'
+ r = run_command('build-aux/git-version-gen',
+ '@0@/.tarball-version'.format(meson.current_source_dir()),
+ check : false)
+
+ full_version = r.stdout().strip()
+ if r.returncode() != 0 or full_version.startswith('UNKNOWN')
+ full_version = meson.project_version()
+ elif not full_version.startswith(meson.project_version())
+ error('meson.build project version @0@ does not match git-describe output @1@'
+ .format(meson.project_version(), full_version))
+ endif
+else
full_version = meson.project_version()
-elif not full_version.startswith(meson.project_version())
- error('meson.build project version @0@ does not match git-describe output @1@'
- .format(meson.project_version(), full_version))
endif
conf.set_quoted('SLIRP_VERSION_STRING', full_version + get_option('version_suffix'))
@@ -53,7 +61,6 @@ host_system = host_machine.system()
glib_dep = dependency('glib-2.0')
-cc = meson.get_compiler('c')
add_project_arguments(cc.get_supported_arguments('-Wmissing-prototypes', '-Wstrict-prototypes',
'-Wredundant-decls', '-Wundef', '-Wwrite-strings'),
language: 'c', native: false)
@@ -77,6 +84,7 @@ endif
cargs = [
'-DG_LOG_DOMAIN="Slirp"',
+ '-DBUILDING_LIBSLIRP',
]
if cc.check_header('valgrind/valgrind.h')
diff --git a/src/bootp.c b/src/bootp.c
index a0eb17a..147955f 100644
--- a/src/bootp.c
+++ b/src/bootp.c
@@ -38,7 +38,7 @@
static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE };
-#define DPRINTF(fmt, ...) DEBUG_CALL(fmt, ##__VA_ARGS__)
+#define DPRINTF(...) DEBUG_RAW_CALL(__VA_ARGS__)
static BOOTPClient *get_new_addr(Slirp *slirp, struct in_addr *paddr,
const uint8_t *macaddr)
diff --git a/src/debug.h b/src/debug.h
index 0f9f3ef..f4da00c 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -14,45 +14,52 @@
extern int slirp_debug;
-#define DEBUG_CALL(fmt, ...) \
+#define DEBUG_CALL(name) \
do { \
if (G_UNLIKELY(slirp_debug & DBG_CALL)) { \
- g_debug(fmt "...", ##__VA_ARGS__); \
+ g_debug(name "..."); \
} \
} while (0)
-#define DEBUG_VERBOSE_CALL(fmt, ...) \
+#define DEBUG_VERBOSE_CALL(name) \
do { \
if (G_UNLIKELY(slirp_debug & DBG_VERBOSE_CALL)) { \
- g_debug(fmt "...", ##__VA_ARGS__); \
+ g_debug(name "..."); \
} \
} while (0)
-#define DEBUG_ARG(fmt, ...) \
+#define DEBUG_RAW_CALL(...) \
do { \
if (G_UNLIKELY(slirp_debug & DBG_CALL)) { \
- g_debug(" " fmt, ##__VA_ARGS__); \
+ g_debug(__VA_ARGS__); \
} \
} while (0)
-#define DEBUG_MISC(fmt, ...) \
+#define DEBUG_ARG(...) \
+ do { \
+ if (G_UNLIKELY(slirp_debug & DBG_CALL)) { \
+ g_debug(" " __VA_ARGS__); \
+ } \
+ } while (0)
+
+#define DEBUG_MISC(...) \
do { \
if (G_UNLIKELY(slirp_debug & DBG_MISC)) { \
- g_debug(fmt, ##__VA_ARGS__); \
+ g_debug(__VA_ARGS__); \
} \
} while (0)
-#define DEBUG_ERROR(fmt, ...) \
+#define DEBUG_ERROR(...) \
do { \
if (G_UNLIKELY(slirp_debug & DBG_ERROR)) { \
- g_debug(fmt, ##__VA_ARGS__); \
+ g_debug(__VA_ARGS__); \
} \
} while (0)
-#define DEBUG_TFTP(fmt, ...) \
+#define DEBUG_TFTP(...) \
do { \
if (G_UNLIKELY(slirp_debug & DBG_TFTP)) { \
- g_debug(fmt, ##__VA_ARGS__); \
+ g_debug(__VA_ARGS__); \
} \
} while (0)
diff --git a/src/ip.h b/src/ip.h
index e5d4aa8..bfe1d36 100644
--- a/src/ip.h
+++ b/src/ip.h
@@ -71,8 +71,9 @@ typedef uint32_t n_long; /* long as received from the net */
/*
* Structure of an internet header, naked of options.
*/
+SLIRP_PACKED_BEGIN
struct ip {
-#if G_BYTE_ORDER == G_BIG_ENDIAN
+#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
uint8_t ip_v : 4, /* version */
ip_hl : 4; /* header length */
#else
@@ -90,7 +91,7 @@ struct ip {
uint8_t ip_p; /* protocol */
uint16_t ip_sum; /* checksum */
struct in_addr ip_src, ip_dst; /* source and dest address */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
#define IP_MAXPACKET 65535 /* maximum packet size */
@@ -134,11 +135,12 @@ struct ip {
/*
* Time stamp option structure.
*/
+SLIRP_PACKED_BEGIN
struct ip_timestamp {
uint8_t ipt_code; /* IPOPT_TS */
uint8_t ipt_len; /* size of structure (variable) */
uint8_t ipt_ptr; /* index of current entry */
-#if G_BYTE_ORDER == G_BIG_ENDIAN
+#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
uint8_t ipt_oflw : 4, /* overflow counter */
ipt_flg : 4; /* flags, see below */
#else
@@ -152,7 +154,7 @@ struct ip_timestamp {
n_long ipt_time;
} ipt_ta[1];
} ipt_timestamp;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* flag bits for ipt_flg */
#define IPOPT_TS_TSONLY 0 /* timestamps only */
@@ -179,14 +181,16 @@ struct ip_timestamp {
#define IP_MSS 576 /* default maximum segment size */
#if GLIB_SIZEOF_VOID_P == 4
+SLIRP_PACKED_BEGIN
struct mbuf_ptr {
struct mbuf *mptr;
uint32_t dummy;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
#else
+SLIRP_PACKED_BEGIN
struct mbuf_ptr {
struct mbuf *mptr;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
#endif
struct qlink {
void *next, *prev;
@@ -195,6 +199,7 @@ struct qlink {
/*
* Overlay for ip header used by other protocols (tcp, udp).
*/
+SLIRP_PACKED_BEGIN
struct ipovly {
struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */
uint8_t ih_x1; /* (unused) */
@@ -202,7 +207,7 @@ struct ipovly {
uint16_t ih_len; /* protocol length */
struct in_addr ih_src; /* source internet address */
struct in_addr ih_dst; /* destination internet address */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/*
* Ip reassembly queue structure. Each fragment
diff --git a/src/ip6.h b/src/ip6.h
index 0630309..96d3e2f 100644
--- a/src/ip6.h
+++ b/src/ip6.h
@@ -176,14 +176,15 @@ static inline void in6_compute_ethaddr(struct in6_addr ip,
* Structure of an internet header, naked of options.
*/
struct ip6 {
-#if G_BYTE_ORDER == G_BIG_ENDIAN
- uint32_t ip_v : 4, /* version */
- ip_tc_hi : 4, /* traffic class */
- ip_tc_lo : 4, ip_fl_hi : 4, /* flow label */
- ip_fl_lo : 16;
+#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
+ uint8_t ip_v : 4, /* version */
+ ip_tc_hi : 4; /* traffic class */
+ uint8_t ip_tc_lo : 4, ip_fl_hi : 4; /* flow label */
#else
- uint32_t ip_tc_hi : 4, ip_v : 4, ip_fl_hi : 4, ip_tc_lo : 4, ip_fl_lo : 16;
+ uint8_t ip_tc_hi : 4, ip_v : 4;
+ uint8_t ip_fl_hi : 4, ip_tc_lo : 4;
#endif
+ uint16_t ip_fl_lo;
uint16_t ip_pl; /* payload length */
uint8_t ip_nh; /* next header */
uint8_t ip_hl; /* hop limit */
diff --git a/src/ip6_icmp.c b/src/ip6_icmp.c
index 0d7ee69..3168457 100644
--- a/src/ip6_icmp.c
+++ b/src/ip6_icmp.c
@@ -294,8 +294,9 @@ static void ndp_send_na(Slirp *slirp, struct ip6 *ip, struct icmp6 *icmp)
ricmp->icmp6_nna.R = NDP_IsRouter;
ricmp->icmp6_nna.S = !IN6_IS_ADDR_MULTICAST(&rip->ip_dst);
ricmp->icmp6_nna.O = 1;
- ricmp->icmp6_nna.reserved_hi = 0;
- ricmp->icmp6_nna.reserved_lo = 0;
+ ricmp->icmp6_nna.reserved_1 = 0;
+ ricmp->icmp6_nna.reserved_2 = 0;
+ ricmp->icmp6_nna.reserved_3 = 0;
ricmp->icmp6_nna.target = icmp->icmp6_nns.target;
/* Build NDP option */
diff --git a/src/ip6_icmp.h b/src/ip6_icmp.h
index 9f378f1..9ae6266 100644
--- a/src/ip6_icmp.h
+++ b/src/ip6_icmp.h
@@ -35,7 +35,7 @@ struct ndp_rs { /* Router Solicitation Message */
struct ndp_ra { /* Router Advertisement Message */
uint8_t chl; /* Cur Hop Limit */
-#if G_BYTE_ORDER == G_BIG_ENDIAN
+#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
uint8_t M : 1, O : 1, reserved : 6;
#else
uint8_t reserved : 6, O : 1, M : 1;
@@ -55,14 +55,16 @@ struct ndp_ns { /* Neighbor Solicitation Message */
G_STATIC_ASSERT(sizeof(struct ndp_ns) == 20);
struct ndp_na { /* Neighbor Advertisement Message */
-#if G_BYTE_ORDER == G_BIG_ENDIAN
- uint32_t R : 1, /* Router Flag */
+#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
+ uint8_t R : 1, /* Router Flag */
S : 1, /* Solicited Flag */
O : 1, /* Override Flag */
- reserved_hi : 5, reserved_lo : 24;
+ reserved_1 : 5
#else
- uint32_t reserved_hi : 5, O : 1, S : 1, R : 1, reserved_lo : 24;
+ uint8_t reserved_1 : 5, O : 1, S : 1, R : 1;
#endif
+ uint8_t reserved_2;
+ uint16_t reserved_3;
struct in6_addr target; /* Target Address */
};
@@ -115,15 +117,17 @@ G_STATIC_ASSERT(sizeof(struct icmp6) == 40);
/*
* NDP Options
*/
+SLIRP_PACKED_BEGIN
struct ndpopt {
uint8_t ndpopt_type; /* Option type */
uint8_t ndpopt_len; /* /!\ In units of 8 octets */
union {
unsigned char linklayer_addr[6]; /* Source/Target Link-layer */
#define ndpopt_linklayer ndpopt_body.linklayer_addr
- struct prefixinfo { /* Prefix Information */
+ SLIRP_PACKED_BEGIN
+ struct prefixinfo { /* Prefix Information */
uint8_t prefix_length;
-#if G_BYTE_ORDER == G_BIG_ENDIAN
+#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
uint8_t L : 1, A : 1, reserved1 : 6;
#else
uint8_t reserved1 : 6, A : 1, L : 1;
@@ -132,16 +136,17 @@ struct ndpopt {
uint32_t pref_lt; /* Preferred Lifetime */
uint32_t reserved2;
struct in6_addr prefix;
- } SLIRP_PACKED prefixinfo;
+ } SLIRP_PACKED_END prefixinfo;
#define ndpopt_prefixinfo ndpopt_body.prefixinfo
- struct rdnss {
+ SLIRP_PACKED_BEGIN
+ struct rdnss {
uint16_t reserved;
uint32_t lifetime;
struct in6_addr addr;
- } SLIRP_PACKED rdnss;
+ } SLIRP_PACKED_END rdnss;
#define ndpopt_rdnss ndpopt_body.rdnss
} ndpopt_body;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* NDP options type */
#define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */
diff --git a/src/libslirp.h b/src/libslirp.h
index 3afad21..63a9600 100644
--- a/src/libslirp.h
+++ b/src/libslirp.h
@@ -10,9 +10,18 @@
#include <winsock2.h>
#include <ws2tcpip.h>
#include <in6addr.h>
+typedef int slirp_ssize_t;
+#ifdef BUILDING_LIBSLIRP
+# define SLIRP_EXPORT __declspec(dllexport)
#else
+# define SLIRP_EXPORT __declspec(dllimport)
+#endif
+#else
+#include <sys/types.h>
+typedef ssize_t slirp_ssize_t;
#include <netinet/in.h>
#include <arpa/inet.h>
+#define SLIRP_EXPORT
#endif
#include "libslirp-version.h"
@@ -33,8 +42,8 @@ enum {
SLIRP_POLL_HUP = 1 << 4,
};
-typedef ssize_t (*SlirpReadCb)(void *buf, size_t len, void *opaque);
-typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque);
+typedef slirp_ssize_t (*SlirpReadCb)(void *buf, size_t len, void *opaque);
+typedef slirp_ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque);
typedef void (*SlirpTimerCb)(void *opaque);
typedef int (*SlirpAddPollCb)(int fd, int events, void *opaque);
typedef int (*SlirpGetREventsCb)(int idx, void *opaque);
@@ -152,9 +161,11 @@ typedef struct SlirpConfig {
} SlirpConfig;
/* Create a new instance of a slirp stack */
+SLIRP_EXPORT
Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks,
void *opaque);
/* slirp_init is deprecated in favor of slirp_new */
+SLIRP_EXPORT
Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
struct in_addr vnetmask, struct in_addr vhost,
bool in6_enabled, struct in6_addr vprefix_addr6,
@@ -166,6 +177,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
const char *vdomainname, const SlirpCb *callbacks,
void *opaque);
/* Shut down an instance of a slirp stack */
+SLIRP_EXPORT
void slirp_cleanup(Slirp *slirp);
/* This is called by the application when it is about to sleep through poll().
@@ -175,6 +187,7 @@ void slirp_cleanup(Slirp *slirp);
* time. slirp_pollfds_fill calls add_poll for each file descriptor
* that should be monitored along the sleep. The opaque pointer is passed as
* such to add_poll, and add_poll returns an index. */
+SLIRP_EXPORT
void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout,
SlirpAddPollCb add_poll, void *opaque);
@@ -184,45 +197,55 @@ void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout,
* slirp_pollfds_fill call, to know whether the descriptor is available for
* read/write/etc. (SLIRP_POLL_*)
* select_error should be passed 1 if poll() returned an error. */
+SLIRP_EXPORT
void slirp_pollfds_poll(Slirp *slirp, int select_error,
SlirpGetREventsCb get_revents, void *opaque);
/* This is called by the application when the guest emits a packet on the
* guest network, to be interpreted by slirp. */
+SLIRP_EXPORT
void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
/* This is called by the application when a timer expires, if it provides
* the timer_new_opaque callback. It is not needed if the application only
* uses timer_new. */
+SLIRP_EXPORT
void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque);
/* These set up / remove port forwarding between a host port in the real world
* and the guest network. */
+SLIRP_EXPORT
int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
int host_port, struct in_addr guest_addr, int guest_port);
+SLIRP_EXPORT
int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
int host_port);
#define SLIRP_HOSTFWD_UDP 1
#define SLIRP_HOSTFWD_V6ONLY 2
+SLIRP_EXPORT
int slirp_add_hostxfwd(Slirp *slirp,
const struct sockaddr *haddr, socklen_t haddrlen,
const struct sockaddr *gaddr, socklen_t gaddrlen,
int flags);
+SLIRP_EXPORT
int slirp_remove_hostxfwd(Slirp *slirp,
const struct sockaddr *haddr, socklen_t haddrlen,
int flags);
/* Set up port forwarding between a port in the guest network and a
* command running on the host */
+SLIRP_EXPORT
int slirp_add_exec(Slirp *slirp, const char *cmdline,
struct in_addr *guest_addr, int guest_port);
/* Set up port forwarding between a port in the guest network and a
* Unix port on the host */
+SLIRP_EXPORT
int slirp_add_unix(Slirp *slirp, const char *unixsock,
struct in_addr *guest_addr, int guest_port);
/* Set up port forwarding between a port in the guest network and a
* callback that will receive the data coming from the port */
+SLIRP_EXPORT
int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque,
struct in_addr *guest_addr, int guest_port);
@@ -231,37 +254,46 @@ int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque,
/* This is called by the application for a guestfwd, to determine how much data
* can be received by the forwarded port through a call to slirp_socket_recv. */
+SLIRP_EXPORT
size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr,
int guest_port);
/* This is called by the application for a guestfwd, to provide the data to be
* sent on the forwarded port */
+SLIRP_EXPORT
void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port,
const uint8_t *buf, int size);
/* Remove entries added by slirp_add_exec, slirp_add_unix or slirp_add_guestfwd */
+SLIRP_EXPORT
int slirp_remove_guestfwd(Slirp *slirp, struct in_addr guest_addr,
int guest_port);
/* Return a human-readable state of the slirp stack */
+SLIRP_EXPORT
char *slirp_connection_info(Slirp *slirp);
/* Return a human-readable state of the NDP/ARP tables */
+SLIRP_EXPORT
char *slirp_neighbor_info(Slirp *slirp);
/* Save the slirp state through the write_cb. The opaque pointer is passed as
* such to the write_cb. */
-void slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque);
+SLIRP_EXPORT
+int slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque);
/* Returns the version of the slirp state, to be saved along the state */
+SLIRP_EXPORT
int slirp_state_version(void);
/* Load the slirp state through the read_cb. The opaque pointer is passed as
* such to the read_cb. The version should be given as it was obtained from
* slirp_state_version when slirp_state_save was called. */
+SLIRP_EXPORT
int slirp_state_load(Slirp *s, int version_id, SlirpReadCb read_cb,
void *opaque);
/* Return the version of the slirp implementation */
+SLIRP_EXPORT
const char *slirp_version_string(void);
#ifdef __cplusplus
diff --git a/src/main.h b/src/main.h
index 3b3f883..2e7f21a 100644
--- a/src/main.h
+++ b/src/main.h
@@ -6,11 +6,13 @@
#ifndef SLIRP_MAIN_H
#define SLIRP_MAIN_H
+#include "libslirp.h"
+
extern unsigned curtime;
extern struct in_addr loopback_addr;
extern unsigned long loopback_mask;
int if_encap(Slirp *slirp, struct mbuf *ifm);
-ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags);
+slirp_ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags);
#endif
diff --git a/src/misc.c b/src/misc.c
index 9a506fc..0d43e43 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -8,7 +8,7 @@
#include <sys/un.h>
#endif
-inline void slirp_insque(void *a, void *b)
+void slirp_insque(void *a, void *b)
{
register struct slirp_quehead *element = (struct slirp_quehead *)a;
register struct slirp_quehead *head = (struct slirp_quehead *)b;
@@ -19,7 +19,7 @@ inline void slirp_insque(void *a, void *b)
(struct slirp_quehead *)element;
}
-inline void slirp_remque(void *a)
+void slirp_remque(void *a)
{
register struct slirp_quehead *element = (struct slirp_quehead *)a;
((struct slirp_quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
diff --git a/src/ncsi-pkt.h b/src/ncsi-pkt.h
index 9dd167c..27bedf6 100644
--- a/src/ncsi-pkt.h
+++ b/src/ncsi-pkt.h
@@ -40,6 +40,7 @@
#define __be32 uint32_t
#define __be16 uint16_t
+SLIRP_PACKED_BEGIN
struct ncsi_pkt_hdr {
unsigned char mc_id; /* Management controller ID */
unsigned char revision; /* NCSI version - 0x01 */
@@ -49,64 +50,73 @@ struct ncsi_pkt_hdr {
unsigned char channel; /* Network controller ID */
__be16 length; /* Payload length */
__be32 reserved1[2]; /* Reserved */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_pkt_hdr {
struct ncsi_pkt_hdr common; /* Common NCSI packet header */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_pkt_hdr {
struct ncsi_pkt_hdr common; /* Common NCSI packet header */
__be16 code; /* Response code */
__be16 reason; /* Response reason */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
+SLIRP_PACKED_BEGIN
struct ncsi_aen_pkt_hdr {
struct ncsi_pkt_hdr common; /* Common NCSI packet header */
unsigned char reserved2[3]; /* Reserved */
unsigned char type; /* AEN packet type */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* NCSI common command packet */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
__be32 checksum; /* Checksum */
unsigned char pad[26];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Select Package */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_sp_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
unsigned char reserved[3]; /* Reserved */
unsigned char hw_arbitration; /* HW arbitration */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Disable Channel */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_dc_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
unsigned char reserved[3]; /* Reserved */
unsigned char ald; /* Allow link down */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Reset Channel */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_rc_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
__be32 reserved; /* Reserved */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* AEN Enable */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_ae_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
unsigned char reserved[3]; /* Reserved */
@@ -114,18 +124,20 @@ struct ncsi_cmd_ae_pkt {
__be32 mode; /* AEN working mode */
__be32 checksum; /* Checksum */
unsigned char pad[18];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Set Link */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_sl_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
__be32 mode; /* Link working mode */
__be32 oem_mode; /* OEM link mode */
__be32 checksum; /* Checksum */
unsigned char pad[18];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Set VLAN Filter */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_svf_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
__be16 reserved; /* Reserved */
@@ -135,18 +147,20 @@ struct ncsi_cmd_svf_pkt {
unsigned char enable; /* Enable or disable */
__be32 checksum; /* Checksum */
unsigned char pad[14];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Enable VLAN */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_ev_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
unsigned char reserved[3]; /* Reserved */
unsigned char mode; /* VLAN filter mode */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Set MAC Address */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_sma_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
unsigned char mac[6]; /* MAC address */
@@ -154,57 +168,64 @@ struct ncsi_cmd_sma_pkt {
unsigned char at_e; /* Addr type and operation */
__be32 checksum; /* Checksum */
unsigned char pad[18];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Enable Broadcast Filter */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_ebf_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
__be32 mode; /* Filter mode */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Enable Global Multicast Filter */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_egmf_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
__be32 mode; /* Global MC mode */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Set NCSI Flow Control */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_snfc_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
unsigned char reserved[3]; /* Reserved */
unsigned char mode; /* Flow control mode */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* OEM Request Command as per NCSI Specification */
+SLIRP_PACKED_BEGIN
struct ncsi_cmd_oem_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
__be32 mfr_id; /* Manufacture ID */
unsigned char data[]; /* OEM Payload Data */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* OEM Response Packet as per NCSI Specification */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_oem_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Command header */
__be32 mfr_id; /* Manufacture ID */
unsigned char data[]; /* Payload data */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Mellanox Response Data */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_oem_mlx_pkt {
unsigned char cmd_rev; /* Command Revision */
unsigned char cmd; /* Command ID */
unsigned char param; /* Parameter */
unsigned char optional; /* Optional data */
unsigned char data[]; /* Data */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get Link Status */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gls_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 status; /* Link status */
@@ -212,9 +233,10 @@ struct ncsi_rsp_gls_pkt {
__be32 oem_status; /* OEM link status */
__be32 checksum;
unsigned char pad[10];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get Version ID */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gvi_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 ncsi_version; /* NCSI version */
@@ -225,9 +247,10 @@ struct ncsi_rsp_gvi_pkt {
__be16 pci_ids[4]; /* PCI IDs */
__be32 mf_id; /* Manufacture ID */
__be32 checksum;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get Capabilities */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gc_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 cap; /* Capabilities */
@@ -243,9 +266,10 @@ struct ncsi_rsp_gc_pkt {
unsigned char vlan_mode; /* VLAN mode */
unsigned char channel_cnt; /* Channel count */
__be32 checksum; /* Checksum */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get Parameters */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gp_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
unsigned char mac_cnt; /* Number of MAC addr */
@@ -264,9 +288,10 @@ struct ncsi_rsp_gp_pkt {
unsigned char mac[6]; /* Supported MAC addr */
__be16 vlan; /* Supported VLAN tags */
__be32 checksum; /* Checksum */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get Controller Packet Statistics */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gcps_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 cnt_hi; /* Counter cleared */
@@ -311,9 +336,10 @@ struct ncsi_rsp_gcps_pkt {
__be32 rx_runt_pkts; /* Rx error runt packets */
__be32 rx_jabber_pkts; /* Rx error jabber packets */
__be32 checksum; /* Checksum */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get NCSI Statistics */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gns_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 rx_cmds; /* Rx NCSI commands */
@@ -324,9 +350,10 @@ struct ncsi_rsp_gns_pkt {
__be32 tx_pkts; /* Tx NCSI packets */
__be32 tx_aen_pkts; /* Tx AEN packets */
__be32 checksum; /* Checksum */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get NCSI Pass-through Statistics */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gnpts_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 tx_pkts; /* Tx packets */
@@ -339,45 +366,50 @@ struct ncsi_rsp_gnpts_pkt {
__be32 rx_us_err; /* Rx undersize errors */
__be32 rx_os_err; /* Rx oversize errors */
__be32 checksum; /* Checksum */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get package status */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gps_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 status; /* Hardware arbitration status */
__be32 checksum;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* Get package UUID */
+SLIRP_PACKED_BEGIN
struct ncsi_rsp_gpuuid_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
unsigned char uuid[16]; /* UUID */
__be32 checksum;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* AEN: Link State Change */
+SLIRP_PACKED_BEGIN
struct ncsi_aen_lsc_pkt {
struct ncsi_aen_pkt_hdr aen; /* AEN header */
__be32 status; /* Link status */
__be32 oem_status; /* OEM link status */
__be32 checksum; /* Checksum */
unsigned char pad[14];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* AEN: Configuration Required */
+SLIRP_PACKED_BEGIN
struct ncsi_aen_cr_pkt {
struct ncsi_aen_pkt_hdr aen; /* AEN header */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* AEN: Host Network Controller Driver Status Change */
+SLIRP_PACKED_BEGIN
struct ncsi_aen_hncdsc_pkt {
struct ncsi_aen_pkt_hdr aen; /* AEN header */
__be32 status; /* Status */
__be32 checksum; /* Checksum */
unsigned char pad[18];
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
/* NCSI packet revision */
#define NCSI_PKT_REVISION 0x01
diff --git a/src/ncsi.c b/src/ncsi.c
index adb3398..738d83d 100644
--- a/src/ncsi.c
+++ b/src/ncsi.c
@@ -318,7 +318,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
/* Add the optional checksum at the end of the frame. */
checksum = ncsi_calculate_checksum((uint8_t *)rnh, ncsi_rsp_len);
- pchecksum = (uint32_t *)((void *)rnh + ncsi_rsp_len);
+ pchecksum = (uint32_t *)((char *)rnh + ncsi_rsp_len);
*pchecksum = htonl(checksum);
ncsi_rsp_len += 4;
diff --git a/src/slirp.c b/src/slirp.c
index 54056c9..3dff500 100644
--- a/src/slirp.c
+++ b/src/slirp.c
@@ -158,7 +158,7 @@ static void print_dns_v6_address(struct in6_addr address)
DEBUG_ERROR("Failed to stringify IPv6 address for logging.");
return;
}
- DEBUG_CALL("IPv6 DNS server found: %s", address_str);
+ DEBUG_RAW_CALL("IPv6 DNS server found: %s", address_str);
}
// Gets the first valid DNS resolver with an IPv6 address.
@@ -532,7 +532,7 @@ static void ra_timer_handler_cb(void *opaque)
{
Slirp *slirp = opaque;
- return ra_timer_handler(slirp, NULL);
+ ra_timer_handler(slirp, NULL);
}
void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque)
@@ -541,7 +541,8 @@ void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque)
switch (id) {
case SLIRP_TIMER_RA:
- return ra_timer_handler(slirp, cb_opaque);
+ ra_timer_handler(slirp, cb_opaque);
+ return;
default:
abort();
}
@@ -1511,7 +1512,7 @@ int slirp_remove_guestfwd(Slirp *slirp, struct in_addr guest_addr,
htons(guest_port));
}
-ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags)
+slirp_ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags)
{
if (so->s == -1 && so->guestfwd) {
/* XXX this blocks entire thread. Rewrite to use
@@ -1587,7 +1588,7 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port,
void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len)
{
- ssize_t ret = slirp->cb->send_packet(buf, len, slirp->opaque);
+ slirp_ssize_t ret = slirp->cb->send_packet(buf, len, slirp->opaque);
if (ret < 0) {
g_critical("Failed to send packet, ret: %ld", (long)ret);
diff --git a/src/slirp.h b/src/slirp.h
index e413867..1fe7293 100644
--- a/src/slirp.h
+++ b/src/slirp.h
@@ -67,6 +67,7 @@ struct ethhdr {
unsigned short h_proto; /* packet type ID field */
};
+SLIRP_PACKED_BEGIN
struct slirp_arphdr {
unsigned short ar_hrd; /* format of hardware address */
unsigned short ar_pro; /* format of protocol address */
@@ -81,7 +82,7 @@ struct slirp_arphdr {
uint32_t ar_sip; /* sender IP address */
uint8_t ar_tha[ETH_ALEN]; /* target hardware address */
uint32_t ar_tip; /* target IP address */
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
#define ARP_TABLE_SIZE 16
diff --git a/src/state.c b/src/state.c
index 8708547..d5689ba 100644
--- a/src/state.c
+++ b/src/state.c
@@ -26,6 +26,8 @@
#include "vmstate.h"
#include "stream.h"
+#ifdef HAVE_VMSTATE
+
static int slirp_tcp_post_load(void *opaque, int version)
{
tcp_template((struct tcpcb *)opaque);
@@ -307,7 +309,7 @@ static const VMStateDescription vmstate_slirp = {
VMSTATE_END_OF_LIST() }
};
-void slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
+int slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
{
struct gfwd_list *ex_ptr;
SlirpOStream f = {
@@ -330,6 +332,8 @@ void slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
slirp_ostream_write_u8(&f, 0);
slirp_vmstate_save_state(&f, &vmstate_slirp, slirp);
+
+ return 0;
}
@@ -373,6 +377,19 @@ int slirp_state_load(Slirp *slirp, int version_id, SlirpReadCb read_cb,
return slirp_vmstate_load_state(&f, &vmstate_slirp, slirp, version_id);
}
+#else /* HAVE_VMSTATE */
+int slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque)
+{
+ return -ENOSYS;
+}
+
+int slirp_state_load(Slirp *slirp, int version_id, SlirpReadCb read_cb,
+ void *opaque)
+{
+ return -ENOSYS;
+}
+#endif /* HAVE_VMSTATE */
+
int slirp_state_version(void)
{
return 4;
diff --git a/src/tcp.h b/src/tcp.h
index 70a9760..f678eae 100644
--- a/src/tcp.h
+++ b/src/tcp.h
@@ -55,7 +55,7 @@ struct tcphdr {
uint16_t th_dport; /* destination port */
tcp_seq th_seq; /* sequence number */
tcp_seq th_ack; /* acknowledgement number */
-#if G_BYTE_ORDER == G_BIG_ENDIAN
+#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
uint8_t th_off : 4, /* data offset */
th_x2 : 4; /* (unused) */
#else
diff --git a/src/tftp.c b/src/tftp.c
index a19c889..a109401 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -333,7 +333,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
return;
}
- if (strcasecmp(&tp->x.tp_buf[k], "octet") != 0) {
+ if (g_ascii_strcasecmp(&tp->x.tp_buf[k], "octet") != 0) {
tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
return;
}
@@ -377,7 +377,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
value = &tp->x.tp_buf[k];
k += strlen(value) + 1;
- if (strcasecmp(key, "tsize") == 0) {
+ if (g_ascii_strcasecmp(key, "tsize") == 0) {
int tsize = atoi(value);
struct stat stat_p;
@@ -393,7 +393,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
option_name[nb_options] = "tsize";
option_value[nb_options] = tsize;
nb_options++;
- } else if (strcasecmp(key, "blksize") == 0) {
+ } else if (g_ascii_strcasecmp(key, "blksize") == 0) {
int blksize = atoi(value);
/* Accept blksize up to our maximum size */
diff --git a/src/tftp.h b/src/tftp.h
index cafab03..ccbe208 100644
--- a/src/tftp.h
+++ b/src/tftp.h
@@ -20,11 +20,13 @@
#define TFTP_FILENAME_MAX 512
#define TFTP_BLOCKSIZE_MAX 1428
+SLIRP_PACKED_BEGIN
struct tftphdr {
struct udphdr udp;
uint16_t tp_op;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
+SLIRP_PACKED_BEGIN
struct tftp_t {
struct tftphdr hdr;
union {
@@ -38,7 +40,7 @@ struct tftp_t {
} tp_error;
char tp_buf[TFTP_BLOCKSIZE_MAX + 2];
} x;
-} SLIRP_PACKED;
+} SLIRP_PACKED_END;
struct tftp_session {
Slirp *slirp;
diff --git a/src/util.c b/src/util.c
index e6bccbe..8267f0c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -303,7 +303,7 @@ int slirp_getsockname_wrap(int sockfd, struct sockaddr *addr, int *addrlen)
}
#undef send
-ssize_t slirp_send_wrap(int sockfd, const void *buf, size_t len, int flags)
+slirp_ssize_t slirp_send_wrap(int sockfd, const void *buf, size_t len, int flags)
{
int ret;
ret = send(sockfd, buf, len, flags);
@@ -314,7 +314,7 @@ ssize_t slirp_send_wrap(int sockfd, const void *buf, size_t len, int flags)
}
#undef sendto
-ssize_t slirp_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
+slirp_ssize_t slirp_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *addr, int addrlen)
{
int ret;
@@ -326,7 +326,7 @@ ssize_t slirp_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
}
#undef recv
-ssize_t slirp_recv_wrap(int sockfd, void *buf, size_t len, int flags)
+slirp_ssize_t slirp_recv_wrap(int sockfd, void *buf, size_t len, int flags)
{
int ret;
ret = recv(sockfd, buf, len, flags);
@@ -337,7 +337,7 @@ ssize_t slirp_recv_wrap(int sockfd, void *buf, size_t len, int flags)
}
#undef recvfrom
-ssize_t slirp_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
+slirp_ssize_t slirp_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *addr, int *addrlen)
{
int ret;
diff --git a/src/util.h b/src/util.h
index 07654ec..7d96770 100644
--- a/src/util.h
+++ b/src/util.h
@@ -30,10 +30,8 @@
#include <stdio.h>
#include <assert.h>
#include <errno.h>
-#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
#include <inttypes.h>
#ifdef _WIN32
@@ -41,15 +39,24 @@
#include <windows.h>
#include <ws2tcpip.h>
#else
+#include <unistd.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#endif
+#include "libslirp.h"
+
+#ifdef __GNUC__
+#define SLIRP_PACKED_BEGIN
#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
-#define SLIRP_PACKED __attribute__((gcc_struct, packed))
+#define SLIRP_PACKED_END __attribute__((gcc_struct, packed))
#else
-#define SLIRP_PACKED __attribute__((packed))
+#define SLIRP_PACKED_END __attribute__((packed))
+#endif
+#elif defined(_MSC_VER)
+#define SLIRP_PACKED_BEGIN __pragma(pack(push, 1))
+#define SLIRP_PACKED_END __pragma(pack(pop))
#endif
#ifndef DIV_ROUND_UP
@@ -57,11 +64,8 @@
#endif
#ifndef container_of
-#define container_of(ptr, type, member) \
- __extension__({ \
- void *__mptr = (void *)(ptr); \
- ((type *)(__mptr - offsetof(type, member))); \
- })
+#define container_of(ptr, type, member) \
+ ((type *) (((char *)(ptr)) - offsetof(type, member)))
#endif
#ifndef G_SIZEOF_MEMBER
@@ -133,14 +137,14 @@ int slirp_getpeername_wrap(int fd, struct sockaddr *addr, int *addrlen);
#define getsockname slirp_getsockname_wrap
int slirp_getsockname_wrap(int fd, struct sockaddr *addr, int *addrlen);
#define send slirp_send_wrap
-ssize_t slirp_send_wrap(int fd, const void *buf, size_t len, int flags);
+slirp_ssize_t slirp_send_wrap(int fd, const void *buf, size_t len, int flags);
#define sendto slirp_sendto_wrap
-ssize_t slirp_sendto_wrap(int fd, const void *buf, size_t len, int flags,
+slirp_ssize_t slirp_sendto_wrap(int fd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, int addrlen);
#define recv slirp_recv_wrap
-ssize_t slirp_recv_wrap(int fd, void *buf, size_t len, int flags);
+slirp_ssize_t slirp_recv_wrap(int fd, void *buf, size_t len, int flags);
#define recvfrom slirp_recvfrom_wrap
-ssize_t slirp_recvfrom_wrap(int fd, void *buf, size_t len, int flags,
+slirp_ssize_t slirp_recvfrom_wrap(int fd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, int *addrlen);
#define closesocket slirp_closesocket_wrap
int slirp_closesocket_wrap(int fd);
diff --git a/src/vmstate.c b/src/vmstate.c
index 68cc172..c7fc5a3 100644
--- a/src/vmstate.c
+++ b/src/vmstate.c
@@ -45,6 +45,8 @@
#include "stream.h"
#include "vmstate.h"
+#ifdef HAVE_VMSTATE
+
static int get_nullptr(SlirpIStream *f, void *pv, size_t size,
const VMStateField *field)
{
@@ -442,3 +444,5 @@ int slirp_vmstate_load_state(SlirpIStream *f, const VMStateDescription *vmsd,
}
return ret;
}
+
+#endif /* HAVE_VMSTATE */
diff --git a/src/vmstate.h b/src/vmstate.h
index e3e2459..64dd256 100644
--- a/src/vmstate.h
+++ b/src/vmstate.h
@@ -39,6 +39,9 @@
#ifndef VMSTATE_H_
#define VMSTATE_H_
+#ifdef __GNUC__
+#define HAVE_VMSTATE 1
+
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
@@ -392,4 +395,6 @@ extern const VMStateInfo slirp_vmstate_info_tmp;
.flags = VMS_END, \
}
-#endif
+#endif /* __GNUC__ */
+
+#endif /* VMSTATE_H_ */
diff --git a/test/ncsitest.c b/test/ncsitest.c
index c763af2..f5ee0b5 100644
--- a/test/ncsitest.c
+++ b/test/ncsitest.c
@@ -41,7 +41,7 @@ static void test_ncsi_get_version_id(Slirp *slirp)
};
slirp_input(slirp, command, sizeof(command));
- const struct ncsi_rsp_gvi_pkt *gvi = slirp->opaque + ETH_HLEN;
+ const struct ncsi_rsp_gvi_pkt *gvi = (const struct ncsi_rsp_gvi_pkt *) ((const char*) slirp->opaque + ETH_HLEN);
assert(ntohs(gvi->rsp.code) == NCSI_PKT_RSP_C_COMPLETED);
assert(ntohs(gvi->rsp.code) == NCSI_PKT_RSP_R_NO_ERROR);
@@ -78,7 +78,7 @@ static void test_ncsi_oem_mlx_unsupported_command(Slirp *slirp)
0x00, /* Parameter */
0x00, /* Optional data */
};
- const struct ncsi_rsp_oem_pkt *oem = slirp->opaque + ETH_HLEN;
+ const struct ncsi_rsp_oem_pkt *oem = (const struct ncsi_rsp_oem_pkt *) ((const char*) slirp->opaque + ETH_HLEN);
slirp->mfr_id = 0x00000000;
slirp_input(slirp, command, sizeof(command));
@@ -124,7 +124,7 @@ static void test_ncsi_oem_mlx_gma(Slirp *slirp)
0x1b, /* Parameter */
0x00, /* Optional data */
};
- const struct ncsi_rsp_oem_pkt *oem = slirp->opaque + ETH_HLEN;
+ const struct ncsi_rsp_oem_pkt *oem = (const struct ncsi_rsp_oem_pkt *) ((const char*) slirp->opaque + ETH_HLEN);
memset(slirp->oob_eth_addr, 0, ETH_ALEN);
slirp->mfr_id = 0x8119;
@@ -148,7 +148,7 @@ static void test_ncsi_oem_mlx_gma(Slirp *slirp)
assert(oem->data[MLX_GMA_STATUS_OFFSET] == 1);
}
-static ssize_t send_packet(const void *buf, size_t len, void *opaque)
+static slirp_ssize_t send_packet(const void *buf, size_t len, void *opaque)
{
assert(len <= NCSI_RESPONSE_CAPACITY);
memcpy(opaque, buf, len);
@@ -157,13 +157,15 @@ static ssize_t send_packet(const void *buf, size_t len, void *opaque)
int main(int argc, char *argv[])
{
- SlirpConfig config = {};
- SlirpCb callbacks = {};
+ SlirpConfig config = {
+ .version = SLIRP_CONFIG_VERSION_MAX,
+ };
+ SlirpCb callbacks = {
+ .send_packet = send_packet,
+ };
Slirp *slirp = NULL;
uint8_t ncsi_response[NCSI_RESPONSE_CAPACITY];
- config.version = SLIRP_CONFIG_VERSION_MAX;
- callbacks.send_packet = send_packet;
slirp = slirp_new(&config, &callbacks, ncsi_response);
test_ncsi_get_version_id(slirp);
diff --git a/test/pingtest.c b/test/pingtest.c
index 8607db6..247a5b1 100644
--- a/test/pingtest.c
+++ b/test/pingtest.c
@@ -85,7 +85,7 @@ static void checksum(uint8_t *data, size_t size, uint8_t *cksum) {
/* This is called when receiving a packet from the virtual network, for the
* guest */
-static ssize_t send_packet(const void *buf, size_t len, void *opaque) {
+static slirp_ssize_t send_packet(const void *buf, size_t len, void *opaque) {
const uint8_t *data = buf;
assert(len >= 14);