]> git.ozlabs.org Git - ppp.git/blobdiff - pppdump/bsd-comp.c
pppd.8: Document netmask option
[ppp.git] / pppdump / bsd-comp.c
index b08f2b781e4e86d672f7340d6f4168cf559bd955..57f936c5ed0004650f43a928eaf98f66aaa00041 100644 (file)
  */
 
 /*
- * $Id: bsd-comp.c,v 1.1 1999/03/23 03:21:57 paulus Exp $
+ * $Id: bsd-comp.c,v 1.4 2004/01/17 05:47:55 carlsonj Exp $
  */
 
 #include <sys/types.h>
+#include <stdio.h>
+#include <stddef.h>
 #include <stdlib.h>
-#include "ppp_defs.h"
+#include <string.h>
+
 #include "ppp-comp.h"
 
 #if DO_BSD_COMPRESS
@@ -121,15 +124,15 @@ struct bsd_db {
 #define BSD_OVHD       2               /* BSD compress overhead/packet */
 #define BSD_INIT_BITS  BSD_MIN_BITS
 
-static void    *bsd_decomp_alloc __P((u_char *options, int opt_len));
-static void    bsd_free __P((void *state));
-static int     bsd_decomp_init __P((void *state, u_char *options, int opt_len,
-                                    int unit, int hdrlen, int mru, int debug));
-static void    bsd_incomp __P((void *state, u_char *dmsg, int len));
-static int     bsd_decompress __P((void *state, u_char *cmp, int inlen,
-                                   u_char *dmp, int *outlen));
-static void    bsd_reset __P((void *state));
-static void    bsd_comp_stats __P((void *state, struct compstat *stats));
+static void    *bsd_decomp_alloc(u_char *options, int opt_len);
+static void    bsd_free(void *state);
+static int     bsd_decomp_init(void *state, u_char *options, int opt_len,
+                               int unit, int hdrlen, int mru, int debug);
+static void    bsd_incomp(void *state, u_char *dmsg, int len);
+static int     bsd_decompress(void *state, u_char *cmp, int inlen,
+                              u_char *dmp, int *outlen);
+static void    bsd_reset(void *state);
+static void    bsd_comp_stats(void *state, struct compstat *stats);
 
 /*
  * Exported procedures.
@@ -171,8 +174,7 @@ struct compressor ppp_bsd_compress = {
  * clear the dictionary
  */
 static void
-bsd_clear(db)
-    struct bsd_db *db;
+bsd_clear(struct bsd_db *db)
 {
     db->clear_count++;
     db->max_ent = FIRST-1;
@@ -197,8 +199,7 @@ bsd_clear(db)
  * must compute the same ratio.
  */
 static int                             /* 1=output CLEAR */
-bsd_check(db)
-    struct bsd_db *db;
+bsd_check(struct bsd_db *db)
 {
     u_int new_ratio;
 
@@ -238,9 +239,7 @@ bsd_check(db)
  * Return statistics.
  */
 static void
-bsd_comp_stats(state, stats)
-    void *state;
-    struct compstat *stats;
+bsd_comp_stats(void *state, struct compstat *stats)
 {
     struct bsd_db *db = (struct bsd_db *) state;
     u_int out;
@@ -251,22 +250,22 @@ bsd_comp_stats(state, stats)
     stats->comp_packets = db->comp_count;
     stats->inc_bytes = db->incomp_bytes;
     stats->inc_packets = db->incomp_count;
-    stats->ratio = db->in_count;
+
+    u_int ratio = db->in_count;
     out = db->bytes_out;
-    if (stats->ratio <= 0x7fffff)
-       stats->ratio <<= 8;
+    if (ratio <= 0x7fffff)
+       ratio <<= 8;
     else
        out >>= 8;
     if (out != 0)
-       stats->ratio /= out;
+       stats->ratio = ratio / out;
 }
 
 /*
  * Reset state, as on a CCP ResetReq.
  */
 static void
-bsd_reset(state)
-    void *state;
+bsd_reset(void *state)
 {
     struct bsd_db *db = (struct bsd_db *) state;
 
@@ -279,9 +278,7 @@ bsd_reset(state)
  * Allocate space for a (de) compressor.
  */
 static void *
-bsd_alloc(options, opt_len, decomp)
-    u_char *options;
-    int opt_len, decomp;
+bsd_alloc(u_char *options, int opt_len, int decomp)
 {
     int bits;
     u_int newlen, hsize, hshift, maxmaxcode;
@@ -325,7 +322,7 @@ bsd_alloc(options, opt_len, decomp)
     db = (struct bsd_db *) malloc(newlen);
     if (!db)
        return NULL;
-    bzero(db, sizeof(*db) - sizeof(db->dict));
+    memset(db, 0, sizeof(*db) - sizeof(db->dict));
 
     if (!decomp) {
        db->lens = NULL;
@@ -347,8 +344,7 @@ bsd_alloc(options, opt_len, decomp)
 }
 
 static void
-bsd_free(state)
-    void *state;
+bsd_free(void *state)
 {
     struct bsd_db *db = (struct bsd_db *) state;
 
@@ -358,9 +354,7 @@ bsd_free(state)
 }
 
 static void *
-bsd_decomp_alloc(options, opt_len)
-    u_char *options;
-    int opt_len;
+bsd_decomp_alloc(u_char *options, int opt_len)
 {
     return bsd_alloc(options, opt_len, 1);
 }
@@ -369,10 +363,8 @@ bsd_decomp_alloc(options, opt_len)
  * Initialize the database.
  */
 static int
-bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp)
-    struct bsd_db *db;
-    u_char *options;
-    int opt_len, unit, hdrlen, mru, debug, decomp;
+bsd_init(struct bsd_db *db, u_char *options, int opt_len, int unit,
+        int hdrlen, int mru, int debug, int decomp)
 {
     int i;
 
@@ -380,7 +372,7 @@ bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp)
        || options[0] != CI_BSD_COMPRESS || options[1] != CILEN_BSD_COMPRESS
        || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION
        || BSD_NBITS(options[2]) != db->maxbits
-       || decomp && db->lens == NULL)
+       || (decomp && db->lens == NULL))
        return 0;
 
     if (decomp) {
@@ -406,10 +398,8 @@ bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp)
 }
 
 static int
-bsd_decomp_init(state, options, opt_len, unit, hdrlen, mru, debug)
-    void *state;
-    u_char *options;
-    int opt_len, unit, hdrlen, mru, debug;
+bsd_decomp_init(void *state, u_char *options, int opt_len,
+               int unit, int hdrlen, int mru, int debug)
 {
     return bsd_init((struct bsd_db *) state, options, opt_len,
                    unit, hdrlen, mru, debug, 1);
@@ -421,10 +411,7 @@ bsd_decomp_init(state, options, opt_len, unit, hdrlen, mru, debug)
  * incompressible data by pretending to compress the incoming data.
  */
 static void
-bsd_incomp(state, dmsg, mlen)
-    void *state;
-    u_char *dmsg;
-    int mlen;
+bsd_incomp(void *state, u_char *dmsg, int mlen)
 {
     struct bsd_db *db = (struct bsd_db *) state;
     u_int hshift = db->hshift;
@@ -541,10 +528,7 @@ bsd_incomp(state, dmsg, mlen)
  * compression, even though they are detected by inspecting the input.
  */
 static int
-bsd_decompress(state, cmsg, inlen, dmp, outlenp)
-    void *state;
-    u_char *cmsg, *dmp;
-    int inlen, *outlenp;
+bsd_decompress(void *state, u_char *cmsg, int inlen, u_char *dmp, int *outlenp)
 {
     struct bsd_db *db = (struct bsd_db *) state;
     u_int max_ent = db->max_ent;
@@ -553,11 +537,11 @@ bsd_decompress(state, cmsg, inlen, dmp, outlenp)
     u_int n_bits = db->n_bits;
     u_int tgtbitno = 32-n_bits;        /* bitno when we have a code */
     struct bsd_dict *dictp;
-    int explen, i, seq, len;
+    int explen, seq, len;
     u_int incode, oldcode, finchar;
     u_char *p, *rptr, *wptr;
     int ilen;
-    int dlen, space, codelen, extra;
+    int codelen, extra;
 
     rptr = cmsg;
     if (*rptr == 0)
@@ -613,12 +597,12 @@ bsd_decompress(state, cmsg, inlen, dmp, outlenp)
        }
 
        if (incode > max_ent + 2 || incode > db->maxmaxcode
-           || incode > max_ent && oldcode == CLEAR) {
+           || (incode > max_ent && oldcode == CLEAR)) {
            if (db->debug) {
                printf("bsd_decomp%d: bad code 0x%x oldcode=0x%x ",
                       db->unit, incode, oldcode);
-               printf("max_ent=0x%x dlen=%d seqno=%d\n",
-                      max_ent, dlen, db->seqno);
+               printf("max_ent=0x%x seqno=%d\n",
+                      max_ent, db->seqno);
            }
            return DECOMP_FATALERROR;   /* probably a bug */
        }