[PATCH] fletcher checksum: this MIGTH help w.r.t the endian problem.
Joakim Tjernlund
Joakim.Tjernlund at transmode.se
Fri Apr 23 08:22:56 CEST 2010
Not tested at all.
---
proto/ospf/lsalib.c | 21 ++-------------------
1 files changed, 2 insertions(+), 19 deletions(-)
diff --git a/proto/ospf/lsalib.c b/proto/ospf/lsalib.c
index 35f02dc..b8fd97d 100644
--- a/proto/ospf/lsalib.c
+++ b/proto/ospf/lsalib.c
@@ -180,29 +180,12 @@ buf_dump(const char *hdr, const byte *buf, int blen)
#define MODX 4102
#define LSA_CHECKSUM_OFFSET 15
-/* FIXME This is VERY uneficient, I have huge endianity problems */
void
lsasum_calculate(struct ospf_lsa_header *h, void *body)
{
u16 length = h->length;
- // log(L_WARN "Checksum %R %R %d start (len %d)", h->id, h->rt, h->type, length);
- htonlsah(h, h);
- htonlsab(body, body, length - sizeof(struct ospf_lsa_header));
-
- /*
- char buf[1024];
- memcpy(buf, h, sizeof(struct ospf_lsa_header));
- memcpy(buf + sizeof(struct ospf_lsa_header), body, length - sizeof(struct ospf_lsa_header));
- buf_dump("CALC", buf, length);
- */
-
(void) lsasum_check(h, body);
-
- // log(L_WARN "Checksum result %4x", h->checksum);
-
- ntohlsah(h, h);
- ntohlsab(body, body, length - sizeof(struct ospf_lsa_header));
}
/*
@@ -250,8 +233,8 @@ lsasum_check(struct ospf_lsa_header *h, void *body)
c0 %= 255;
c1 %= 255;
}
-
- x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
+ /* the (int) cast is need to ensure % is signed */
+ x = (int)((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
if (x <= 0)
x += 255;
y = 510 - c0 - x;
--
1.6.4.4
More information about the Bird-users
mailing list