netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: Ben Greear <greearb@candelatech.com>
Cc: NetDev <netdev@vger.kernel.org>
Subject: Re: ip_tables.h can't be used in C++ programs.
Date: Sat, 21 Aug 2010 00:17:09 +0100	[thread overview]
Message-ID: <1282346230.3454.193.camel@localhost> (raw)
In-Reply-To: <4C6ECF67.3040508@candelatech.com>

On Fri, 2010-08-20 at 11:54 -0700, Ben Greear wrote:
> This method returns void* but is defined to return
> a pointer to struct ipt_entry_target.
> 
> This will not compile under g++ (or, I'm unable to figure out
> how to make it work w/out editing the header file).
> 
> Any reason this shouldn't be changed to:
> 
>   return (struct ipt_entry_target*)e + e->target_offset;

Because that multiplies the offset by sizeof(struct ipt_entry_target)!

> /* Helper functions */
> static __inline__ struct ipt_entry_target *
> ipt_get_target(struct ipt_entry *e)
> {
>          return (void *)e + e->target_offset;
> }

For extra unportability, this is relying on the gcc extension for void
pointer arithmetic.  Try something like:

	return (struct ipt_entry_target *)((char *)e + e->target_offset);

Ben.

> IPv6 has similar issue....
> 
> Thanks,
> Ben
> 

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


  reply	other threads:[~2010-08-20 23:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-20 18:54 ip_tables.h can't be used in C++ programs Ben Greear
2010-08-20 23:17 ` Ben Hutchings [this message]
2010-08-20 23:42   ` Ben Greear

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1282346230.3454.193.camel@localhost \
    --to=bhutchings@solarflare.com \
    --cc=greearb@candelatech.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).