netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ip_tables.h can't be used in C++ programs.
@ 2010-08-20 18:54 Ben Greear
  2010-08-20 23:17 ` Ben Hutchings
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Greear @ 2010-08-20 18:54 UTC (permalink / raw)
  To: NetDev

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;


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


IPv6 has similar issue....

Thanks,
Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ip_tables.h can't be used in C++ programs.
  2010-08-20 18:54 ip_tables.h can't be used in C++ programs Ben Greear
@ 2010-08-20 23:17 ` Ben Hutchings
  2010-08-20 23:42   ` Ben Greear
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Hutchings @ 2010-08-20 23:17 UTC (permalink / raw)
  To: Ben Greear; +Cc: NetDev

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ip_tables.h can't be used in C++ programs.
  2010-08-20 23:17 ` Ben Hutchings
@ 2010-08-20 23:42   ` Ben Greear
  0 siblings, 0 replies; 3+ messages in thread
From: Ben Greear @ 2010-08-20 23:42 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: NetDev

On 08/20/2010 04:17 PM, Ben Hutchings wrote:
> 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);

That compiles fine for me, would be great to get something like
that upstream!

Take it easy,
Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-20 23:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-20 18:54 ip_tables.h can't be used in C++ programs Ben Greear
2010-08-20 23:17 ` Ben Hutchings
2010-08-20 23:42   ` Ben Greear

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).