Skip to contentSkip to conversation

ip_tables.h can't be used in C++ programs.

DISCUSSION Ben Greear 2 participants 3 messages Aug 20, 2010

Subsystems (2)
lore
Share & tools
lore

Ben Greear

author
#0 lore raw

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

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#1 lore raw
Quoted 9 lines · Ben Greear

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

Quoted 6 lines

/* 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.

Quoted 5 lines

IPv6 has similar issue....

Thanks,
Ben

Signature · 3 lines
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.
author
#2 lore raw
Quoted 20 lines · Ben Hutchings
Quoted 9 lines · Ben Greear

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

Quoted 6 lines

/* Helper functions */
static __inline__ struct ipt_entry_target *
ipt_get_target(struct ipt_entry *e)

{
          return (void *)e + e->target_offset;
}
Quoted 4 lines

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

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com