From patchwork Wed Oct 21 23:15:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pizzolato X-Patchwork-Id: 534171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BEF1B140787 for ; Thu, 22 Oct 2015 13:11:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infocomm.com header.i=@infocomm.com header.b=TAghqokF; dkim-atps=neutral Received: from localhost ([::1]:55270 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zp5Lb-0000ZX-S4 for incoming@patchwork.ozlabs.org; Wed, 21 Oct 2015 22:11:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zp39v-0003kE-6I for qemu-devel@nongnu.org; Wed, 21 Oct 2015 19:51:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zp39s-0001dX-3z for qemu-devel@nongnu.org; Wed, 21 Oct 2015 19:51:07 -0400 Received: from mail.alohasunset.com ([50.242.79.171]:16990) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zp39r-0001cp-Kp for qemu-devel@nongnu.org; Wed, 21 Oct 2015 19:51:04 -0400 Received: from ASSP-nospam ([127.0.0.1]) by alohasunset.com with MailEnable ESMTP; Wed, 21 Oct 2015 16:15:14 -0700 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=infocomm.com; h=from:to:cc:date:subject:message-id:content-type:content-transfer-encoding:mime-version; s=key2048; bh=RLKJh4BP92cMZ6NWOMZObrWGFqI=; b=TAghqokFsN9SJQBZSk8wzwA4foXTJ1F2pFXRlMgMff60RlDzIke0XFLTRwIgoNywO4YA /BhNvvUspf2SX3wnJck59RQWkErqoLj9N+oq2LBAhGohdxWBCErjM0Whr7Uo+Z8VqPZU uf2eJMEJZewfTQ3C06574YxXEOpGIyVWtUx2BpPwPe6CMIpyYVlOS/wEdTDskHRG/eJD uHRqbwkz+HnlmU9+9sydVuLsELAKbCdbc/9QPXNBcf1KuebKFQc55T8QDku587c9VlVL uMRy0wYvoIsyaQLhV5QU+PquE18zwbdL00rUmmNCt8Gb1+x9QNMDfiZ77X0TmlfZY/rA Og== Received: from 127.0.0.1 ([127.0.0.1] helo=REDROOF2.alohasunset.com) by ASSP-nospam id ClHB=KZ=infocomm.com=mark; Wed, 21 Oct 2015 16:15:14 -0700 Received: from REDROOF2.alohasunset.com ([fe80::581e:47de:dd30:7f56]) by REDROOF2.alohasunset.com ([fe80::581e:47de:dd30:7f56%11]) with mapi; Wed, 21 Oct 2015 16:15:14 -0700 From: Mark Pizzolato To: "qemu-devel@nongnu.org" Date: Wed, 21 Oct 2015 16:15:13 -0700 Thread-Topic: [PATCH 2/5] slirp: Changes needed to build with a pre C99 C compiler Thread-Index: AdEMVNw8FdTzlyuTRbWZ8z2MWdToUg== Message-ID: <03006E3FC39B5A48AB9DBCCC101090A823806F4084@REDROOF2.alohasunset.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 50.242.79.171 X-Mailman-Approved-At: Wed, 21 Oct 2015 22:09:08 -0400 Cc: "jan.kiszka@siemens.com" , "sw@weilnetz.de" Subject: [Qemu-devel] [PATCH 2/5] slirp: Changes needed to build with a pre C99 C compiler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 +#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