--- Hai <[EMAIL PROTECTED]> wrote:
> Your patch would work, I can test it later. Memcpy could avoid the problem.
> There is a drawback using memcpy because you should put memcpy() everywhere
> in your codes, for everytime you access ip_src.s_addr or ip_src.d_addr
I agree - we want to avoid memcpy. In n2n the strategy is to do it once and
copy out into a local structure once then reuse the local structure. You can
see this with the hdr objects that get passed around for this purpose.
> I do think my way to solve this problem is better, just like it is in the
> kernel driver. A net card driver is general enough because you use the same
> code under different architectures. And it is documented in the driver
> source:
>
> "Big- and Little-Endian byte order as well as 32- and 64-bit archs are
> supported. Weak-ordered memory and non-cache-coherent archs are supported."
That's the compiler's job. I try to write platform independent code. IMO your
patch is not platform independent and so I don't think it should go into
application code that could run on any architecture.
The only use made of the "struct ip" is to perform an IP address comparison.
This is better done with memcmp(). This would be both more efficient and
platform independent.
How about this:
Index: edge.c
===================================================================
--- edge.c (revision 3487)
+++ edge.c (working copy)
@@ -607,10 +607,14 @@
if(!allow_routed_packets) {
if(ntohs(eh->ether_type) == 0x0800) {
+ /* This is an IP packet from the local source address - not forwarded.
*/
+#define ETH_FRAMESIZE 14
+#define IP4_SRCOFFSET 12
+#define IP4_ADDRSIZE 4
/* Note: all elements of the_ip are in network order */
- struct ip *the_ip = (struct ip*)(decrypted_msg+sizeof(struct
ether_header));
-
- if(the_ip->ip_src.s_addr != device.ip_addr) {
+ if( 0 != memcmp( decrypted_msg + ETH_FRAMESIZE + IP4_SRCOFFSET,
+ &(device.ip_addr),
+ IP4_ADDRSIZE ) ) {
/* This is a packet that needs to be routed */
traceEvent(TRACE_INFO, "Discarding routed packet");
return;
--
Rich
Get the name you always wanted with the new y7mail email address.
www.yahoo7.com.au/y7mail
_______________________________________________
Ntop-dev mailing list
[email protected]
http://listgateway.unipi.it/mailman/listinfo/ntop-dev