X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=modules%2Fvjcompress.c;h=32a9c93e97cf9ea52eb35a89d4427b1d58d6b80a;hp=dd633512b9b9abdf56958f6d086b7aed46d86d57;hb=344df78d925b7a47fe56c2544d12218380423699;hpb=026086301efc23af5da50eec535f5348a2b90d60 diff --git a/modules/vjcompress.c b/modules/vjcompress.c index dd63351..32a9c93 100644 --- a/modules/vjcompress.c +++ b/modules/vjcompress.c @@ -24,13 +24,33 @@ * so that the entire packet being decompressed doesn't have * to be in contiguous memory (just the compressed header). * - * $Id: vjcompress.c,v 1.3 1994/11/30 05:31:00 paulus Exp $ + * $Id: vjcompress.c,v 1.5 1995/05/19 03:48:34 paulus Exp $ */ #include #include + +#ifdef __svr4__ +#ifndef __GNUC__ +#include /* for ntohl, etc. */ +#else +/* make sure we don't get the gnu "fixed" one! */ +#include "/usr/include/sys/byteorder.h" +#endif +#endif + +#ifdef __osf__ +#include +#endif #include + +#ifdef __aix4__ +#define _NETINET_IN_SYSTM_H_ +typedef u_long n_long; +#else #include +#endif + #include #include @@ -50,6 +70,15 @@ #define ovbcopy bcopy #endif +#ifdef __osf__ +#define getip_hl(base) (((base).ip_vhl)&0xf) +#define getth_off(base) ((((base).th_xoff)&0xf0)>>4) + +#else +#define getip_hl(base) ((base).ip_hl) +#define getth_off(base) ((base).th_off) +#endif + void vj_compress_init(comp, max_state) struct vjcompress *comp; @@ -104,7 +133,7 @@ vj_compress_init(comp, max_state) (f) = htonl(ntohl(f) + ((cp[1] << 8) | cp[2])); \ cp += 3; \ } else { \ - (f) = htonl(ntohl(f) + (u_long)*cp++); \ + (f) = htonl(ntohl(f) + (u_int32_t)*cp++); \ } \ } @@ -113,7 +142,7 @@ vj_compress_init(comp, max_state) (f) = htons(ntohs(f) + ((cp[1] << 8) | cp[2])); \ cp += 3; \ } else { \ - (f) = htons(ntohs(f) + (u_long)*cp++); \ + (f) = htons(ntohs(f) + (u_int32_t)*cp++); \ } \ } @@ -122,7 +151,7 @@ vj_compress_init(comp, max_state) (f) = htons((cp[1] << 8) | cp[2]); \ cp += 3; \ } else { \ - (f) = htons((u_long)*cp++); \ + (f) = htons((u_int32_t)*cp++); \ } \ } @@ -135,7 +164,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) u_char **vjhdrp; { register struct cstate *cs = comp->last_cs->cs_next; - register u_int hlen = ip->ip_hl; + register u_int hlen = getip_hl(*ip); register struct tcphdr *oth; register struct tcphdr *th; register u_int deltaS, deltaA; @@ -165,7 +194,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) INCR(vjs_packets); if (ip->ip_src.s_addr != cs->cs_ip.ip_src.s_addr || ip->ip_dst.s_addr != cs->cs_ip.ip_dst.s_addr || - *(int *)th != ((int *)&cs->cs_ip)[cs->cs_ip.ip_hl]) { + *(int *)th != ((int *)&cs->cs_ip)[getip_hl(cs->cs_ip)]) { /* * Wasn't the first -- search for it. * @@ -186,7 +215,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) INCR(vjs_searches); if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr && ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr - && *(int *)th == ((int *)&cs->cs_ip)[cs->cs_ip.ip_hl]) + && *(int *)th == ((int *)&cs->cs_ip)[getip_hl(cs->cs_ip)]) goto found; } while (cs != lastcs); @@ -200,7 +229,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) */ INCR(vjs_misses); comp->last_cs = lcs; - hlen += th->th_off; + hlen += getth_off(*th); hlen <<= 2; if (hlen > mlen) return (TYPE_IP); @@ -232,7 +261,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) */ oth = (struct tcphdr *)&((int *)&cs->cs_ip)[hlen]; deltaS = hlen; - hlen += th->th_off; + hlen += getth_off(*th); hlen <<= 2; if (hlen > mlen) return (TYPE_IP); @@ -240,9 +269,9 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) if (((u_short *)ip)[0] != ((u_short *)&cs->cs_ip)[0] || ((u_short *)ip)[3] != ((u_short *)&cs->cs_ip)[3] || ((u_short *)ip)[4] != ((u_short *)&cs->cs_ip)[4] || - th->th_off != oth->th_off || + getth_off(*th) != getth_off(*oth) || (deltaS > 5 && BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) || - (th->th_off > 5 && BCMP(th + 1, oth + 1, (th->th_off - 5) << 2))) + (getth_off(*th) > 5 && BCMP(th + 1, oth + 1, (getth_off(*th) - 5) << 2))) goto uncompressed; /* @@ -409,8 +438,8 @@ vj_uncompress_uncomp(buf, comp) cs = &comp->rstate[comp->last_recv = ip->ip_p]; comp->flags &=~ VJF_TOSS; ip->ip_p = IPPROTO_TCP; - hlen = ip->ip_hl; - hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off; + hlen = getip_hl(*ip); + hlen += getth_off(*((struct tcphdr *)&((int *)ip)[hlen])); hlen <<= 2; BCOPY(ip, &cs->cs_ip, hlen); cs->cs_hlen = hlen; @@ -462,7 +491,7 @@ vj_uncompress_tcp(buf, buflen, total_len, comp, hdrp, hlenp) } } cs = &comp->rstate[comp->last_recv]; - hlen = cs->cs_ip.ip_hl << 2; + hlen = getip_hl(cs->cs_ip) << 2; th = (struct tcphdr *)&((u_char *)&cs->cs_ip)[hlen]; th->th_sum = htons((*cp << 8) | cp[1]); cp += 2;