From 98c63057d2144fb81681580cd84c13c93794c96e Mon Sep 17 00:00:00 2001 From: Guillaume Subiron Date: Tue, 15 Mar 2016 10:31:20 +0100 Subject: slirp: Factorizing tcpiphdr structure with an union This patch factorizes the tcpiphdr structure to put the IPv4 fields in an union, for addition of version 6 in further patch. Using some macros, retrocompatibility of the existing code is assured. This patch also fixes the SLIRP_MSIZE and margin computation in various functions, and makes them compatible with the new tcpiphdr structure, whose size will be bigger than sizeof(struct tcphdr) + sizeof(struct ip) Signed-off-by: Guillaume Subiron Signed-off-by: Samuel Thibault Reviewed-by: Thomas Huth --- slirp/tcp_output.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'slirp/tcp_output.c') diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c index 34e4d2e5d4..7fc6a87397 100644 --- a/slirp/tcp_output.c +++ b/slirp/tcp_output.c @@ -448,15 +448,23 @@ send: */ m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */ - { + struct tcpiphdr tcpiph_save = *(mtod(m, struct tcpiphdr *)); + m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr) + - sizeof(struct ip); + m->m_len -= sizeof(struct tcpiphdr) - sizeof(struct tcphdr) + - sizeof(struct ip); + struct ip *ip = mtod(m, struct ip *); - ((struct ip *)ti)->ip_len = m->m_len; + ip->ip_len = m->m_len; + ip->ip_dst = tcpiph_save.ti_dst; + ip->ip_src = tcpiph_save.ti_src; + ip->ip_p = tcpiph_save.ti_pr; - ((struct ip *)ti)->ip_ttl = IPDEFTTL; - ((struct ip *)ti)->ip_tos = so->so_iptos; + ip->ip_ttl = IPDEFTTL; + ip->ip_tos = so->so_iptos; error = ip_output(so, m); - } + if (error) { out: return (error); -- cgit 1.4.1