[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/5] slirp: Changes needed to build with a pre C99 C
From: |
Mark Pizzolato |
Subject: |
[Qemu-devel] [PATCH 2/5] slirp: Changes needed to build with a pre C99 C compiler |
Date: |
Wed, 21 Oct 2015 16:15:13 -0700 |
Some windows environments will compile with other than GCC (i.e. Visual Studio).
- C99 structures and array initializers had crept in over time.
Changed code to use pre C99 syntax in misc.c and slirp.c
- ip.h and slirp.h have packed structure definitions. Add
support for non GCC packet declaration syntax
Signed-off-by: Mark Pizzolato <address@hidden>
---
slirp/ip.h | 39 +++++++++++++++++++++++++++++++--------
slirp/misc.c | 25 ++++++++++++++-----------
slirp/slirp.c | 30 ++++++++++--------------------
slirp/slirp.h | 8 ++++++--
slirp/slirp_config.h | 2 ++
5 files changed, 63 insertions(+), 41 deletions(-)
diff --git a/slirp/ip.h b/slirp/ip.h
index e2ee5e3..662ac6c 100644
--- a/slirp/ip.h
+++ b/slirp/ip.h
@@ -59,6 +59,21 @@
typedef uint32_t n_long; /* long as received from the net */
+#ifdef _MSC_VER
+# define PACKED_BEGIN __pragma( pack(push, 1) )
+# define PACKED_END __pragma( pack(pop) )
+# define QEMU_PACKED
+#else
+# define PACKED_BEGIN
+#if defined(_WIN32)
+# define PACKED_END __attribute__((gcc_struct, packed))
+# define QEMU_PACKED __attribute__((gcc_struct, packed))
+#else
+# define PACKED_END __attribute__((packed))
+# define QEMU_PACKED __attribute__((packed))
+#endif
+#endif
+
/*
* Definitions for internet protocol version 4.
* Per RFC 791, September 1981.
@@ -68,6 +83,7 @@ typedef uint32_t n_long; /* long as received
from the net */
/*
* Structure of an internet header, naked of options.
*/
+PACKED_BEGIN
struct ip {
#ifdef HOST_WORDS_BIGENDIAN
uint8_t ip_v:4, /* version */
@@ -87,7 +103,7 @@ struct ip {
uint8_t ip_p; /* protocol */
uint16_t ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
-} QEMU_PACKED;
+} PACKED_END;
#define IP_MAXPACKET 65535 /* maximum packet size */
@@ -131,6 +147,7 @@ struct ip {
/*
* Time stamp option structure.
*/
+PACKED_BEGIN
struct ip_timestamp {
uint8_t ipt_code; /* IPOPT_TS */
uint8_t ipt_len; /* size of structure (variable) */
@@ -149,7 +166,7 @@ struct ip_timestamp {
n_long ipt_time;
} ipt_ta[1];
} ipt_timestamp;
-} QEMU_PACKED;
+} PACKED_END;
/* flag bits for ipt_flg */
#define IPOPT_TS_TSONLY 0 /* timestamps only */
@@ -175,16 +192,18 @@ struct ip_timestamp {
#define IP_MSS 576 /* default maximum segment size
*/
+PACKED_BEGIN
#if SIZEOF_CHAR_P == 4
struct mbuf_ptr {
struct mbuf *mptr;
uint32_t dummy;
-} QEMU_PACKED;
+} PACKED_END;
#else
struct mbuf_ptr {
struct mbuf *mptr;
-} QEMU_PACKED;
+} PACKED_END;
#endif
+
struct qlink {
void *next, *prev;
};
@@ -192,6 +211,7 @@ struct qlink {
/*
* Overlay for ip header used by other protocols (tcp, udp).
*/
+PACKED_BEGIN
struct ipovly {
struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */
uint8_t ih_x1; /* (unused) */
@@ -199,7 +219,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 */
-} QEMU_PACKED;
+} PACKED_END;
/*
* Ip reassembly queue structure. Each fragment
@@ -208,6 +228,7 @@ struct ipovly {
* be reclaimed if memory becomes tight.
* size 28 bytes
*/
+PACKED_BEGIN
struct ipq {
struct qlink frag_link; /* to ip headers of
fragments */
struct qlink ip_link; /* to other reass
headers */
@@ -215,17 +236,18 @@ struct ipq {
uint8_t ipq_p; /* protocol of this fragment */
uint16_t ipq_id; /* sequence id for reassembly */
struct in_addr ipq_src,ipq_dst;
-} QEMU_PACKED;
+} PACKED_END;
/*
* Ip header, when holding a fragment.
*
* Note: ipf_link must be at same offset as frag_link above
*/
+PACKED_BEGIN
struct ipasfrag {
struct qlink ipf_link;
struct ip ipf_ip;
-} QEMU_PACKED;
+} PACKED_END;
#define ipf_off ipf_ip.ip_off
#define ipf_tos ipf_ip.ip_tos
@@ -241,9 +263,10 @@ struct ipasfrag {
*/
#define MAX_IPOPTLEN 40
+PACKED_BEGIN
struct ipoption {
struct in_addr ipopt_dst; /* first-hop dst if source routed */
int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
-} QEMU_PACKED;
+} PACKED_END;
#endif
diff --git a/slirp/misc.c b/slirp/misc.c
index 578e8b2..6ec3954 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -231,18 +231,21 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
void slirp_connection_info(Slirp *slirp, Monitor *mon)
{
+#if (TCPS_CLOSED != 0) || (TCPS_TIME_WAIT != 10)
+#error unexpected TCPS symbol values
+#endif
const char * const tcpstates[] = {
- [TCPS_CLOSED] = "CLOSED",
- [TCPS_LISTEN] = "LISTEN",
- [TCPS_SYN_SENT] = "SYN_SENT",
- [TCPS_SYN_RECEIVED] = "SYN_RCVD",
- [TCPS_ESTABLISHED] = "ESTABLISHED",
- [TCPS_CLOSE_WAIT] = "CLOSE_WAIT",
- [TCPS_FIN_WAIT_1] = "FIN_WAIT_1",
- [TCPS_CLOSING] = "CLOSING",
- [TCPS_LAST_ACK] = "LAST_ACK",
- [TCPS_FIN_WAIT_2] = "FIN_WAIT_2",
- [TCPS_TIME_WAIT] = "TIME_WAIT",
+ /* [TCPS_CLOSED] = */ "CLOSED",
+ /* [TCPS_LISTEN] = */ "LISTEN",
+ /* [TCPS_SYN_SENT] = */ "SYN_SENT",
+ /* [TCPS_SYN_RECEIVED] = */ "SYN_RCVD",
+ /* [TCPS_ESTABLISHED] = */ "ESTABLISHED",
+ /* [TCPS_CLOSE_WAIT] = */ "CLOSE_WAIT",
+ /* [TCPS_FIN_WAIT_1] = */ "FIN_WAIT_1",
+ /* [TCPS_CLOSING] = */ "CLOSING",
+ /* [TCPS_LAST_ACK] = */ "LAST_ACK",
+ /* [TCPS_FIN_WAIT_2] = */ "FIN_WAIT_2",
+ /* [TCPS_TIME_WAIT] = */ "TIME_WAIT",
};
struct in_addr dst_addr;
struct sockaddr_in src;
diff --git a/slirp/slirp.c b/slirp/slirp.c
index d18faa8..8b6fa95 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -335,10 +335,8 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
* Set for reading sockets which are accepting
*/
if (so->so_state & SS_FACCEPTCONN) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_IN | G_IO_HUP | G_IO_ERR,
- };
+ GPollFD pfd = { so->s, G_IO_IN | G_IO_HUP | G_IO_ERR, 0 };
+
so->pollfds_idx = pollfds->len;
g_array_append_val(pollfds, pfd);
continue;
@@ -348,10 +346,8 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
* Set for writing sockets which are connecting
*/
if (so->so_state & SS_ISFCONNECTING) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_OUT | G_IO_ERR,
- };
+ GPollFD pfd = { so->s, G_IO_OUT | G_IO_ERR, 0 };
+
so->pollfds_idx = pollfds->len;
g_array_append_val(pollfds, pfd);
continue;
@@ -375,10 +371,8 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
}
if (events) {
- GPollFD pfd = {
- .fd = so->s,
- .events = events,
- };
+ GPollFD pfd = { so->s, events, 0 };
+
so->pollfds_idx = pollfds->len;
g_array_append_val(pollfds, pfd);
}
@@ -416,10 +410,8 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
* (XXX <= 4 ?)
*/
if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <= 4) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_IN | G_IO_HUP | G_IO_ERR,
- };
+ GPollFD pfd = { so->s, G_IO_IN | G_IO_HUP | G_IO_ERR, 0 };
+
so->pollfds_idx = pollfds->len;
g_array_append_val(pollfds, pfd);
}
@@ -447,10 +439,8 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
}
if (so->so_state & SS_ISFCONNECTED) {
- GPollFD pfd = {
- .fd = so->s,
- .events = G_IO_IN | G_IO_HUP | G_IO_ERR,
- };
+ GPollFD pfd = { so->s, G_IO_IN | G_IO_HUP | G_IO_ERR, 0 };
+
so->pollfds_idx = pollfds->len;
g_array_append_val(pollfds, pfd);
}
diff --git a/slirp/slirp.h b/slirp/slirp.h
index 6589d7e..d20dfa2 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -5,7 +5,9 @@
#include "slirp_config.h"
#ifdef _WIN32
+#ifndef _MSC_VER
# include <inttypes.h>
+#endif
typedef char *caddr_t;
@@ -167,12 +169,14 @@ void free(void *ptr);
#define ARPOP_REQUEST 1 /* ARP request */
#define ARPOP_REPLY 2 /* ARP reply */
+PACKED_BEGIN
struct ethhdr {
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
unsigned char h_source[ETH_ALEN]; /* source ether addr */
unsigned short h_proto; /* packet type ID field */
-};
+} PACKED_END;
+PACKED_BEGIN
struct arphdr {
unsigned short ar_hrd; /* format of hardware address */
unsigned short ar_pro; /* format of protocol address */
@@ -187,7 +191,7 @@ struct arphdr {
uint32_t ar_sip; /* sender IP address */
unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
uint32_t ar_tip; /* target IP address */
-} QEMU_PACKED;
+} PACKED_END;
#define ARP_TABLE_SIZE 16
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 896d802..42658db 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -52,7 +52,9 @@
#undef DUMMY_PPP
/* Define if you have unistd.h */
+#ifndef _MSC_VER
#define HAVE_UNISTD_H
+#endif
/* Define if you have stdlib.h */
#define HAVE_STDLIB_H
--
1.9.5.msysgit.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH 2/5] slirp: Changes needed to build with a pre C99 C compiler,
Mark Pizzolato <=