]> git.ozlabs.org Git - ppp.git/blobdiff - pppdump/deflate.c
pppd.8: Document netmask option
[ppp.git] / pppdump / deflate.c
index 840e2d439cd3a8b315d1eff46be54b4d78a70d32..da7b6c52686cd05f91531a0aa8c02df8492d7de6 100644 (file)
@@ -2,36 +2,46 @@
  * ppp_deflate.c - interface the zlib procedures for Deflate compression
  * and decompression (as used by gzip) to the PPP code.
  *
- * Copyright (c) 1994 The Australian National University.
- * All rights reserved.
+ * Copyright (c) 1994 Paul Mackerras. All rights reserved.
  *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation is hereby granted, provided that the above copyright
- * notice appears in all copies.  This software is provided without any
- * warranty, express or implied. The Australian National University
- * makes no representations about the suitability of this software for
- * any purpose.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
  *
- * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
- * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
- * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
  *
- * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
- * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
- * OR MODIFICATIONS.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
- * $Id: deflate.c,v 1.3 1999/04/16 11:35:59 paulus Exp $
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * 4. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by Paul Mackerras
+ *     <paulus@ozlabs.org>".
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * $Id: deflate.c,v 1.5 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"
 #include "zlib.h"
 
@@ -55,17 +65,17 @@ struct deflate_state {
 
 #define DEFLATE_OVHD   2               /* Deflate overhead/packet */
 
-static void    *z_alloc __P((void *, u_int items, u_int size));
-static void    z_free __P((void *, void *ptr, u_int nb));
-static void    *z_decomp_alloc __P((u_char *options, int opt_len));
-static void    z_decomp_free __P((void *state));
-static int     z_decomp_init __P((void *state, u_char *options, int opt_len,
-                                    int unit, int hdrlen, int mru, int debug));
-static void    z_incomp __P((void *state, u_char *dmsg, int len));
-static int     z_decompress __P((void *state, u_char *cmp, int inlen,
-                                   u_char *dmp, int *outlenp));
-static void    z_decomp_reset __P((void *state));
-static void    z_comp_stats __P((void *state, struct compstat *stats));
+static void    *z_alloc(void *, u_int items, u_int size);
+static void    z_free(void *, void *ptr, u_int nb);
+static void    *z_decomp_alloc(u_char *options, int opt_len);
+static void    z_decomp_free(void *state);
+static int     z_decomp_init(void *state, u_char *options, int opt_len,
+                             int unit, int hdrlen, int mru, int debug);
+static void    z_incomp(void *state, u_char *dmsg, int len);
+static int     z_decompress(void *state, u_char *cmp, int inlen,
+                            u_char *dmp, int *outlenp);
+static void    z_decomp_reset(void *state);
+static void    z_comp_stats(void *state, struct compstat *stats);
 
 /*
  * Procedures exported to if_ppp.c.
@@ -85,26 +95,19 @@ struct compressor ppp_deflate = {
  * Space allocation and freeing routines for use by zlib routines.
  */
 static void *
-z_alloc(notused, items, size)
-    void *notused;
-    u_int items, size;
+z_alloc(void *notused, u_int items, u_int size)
 {
     return malloc(items * size);
 }
 
 static void
-z_free(notused, ptr, nbytes)
-    void *notused;
-    void *ptr;
-    u_int nbytes;
+z_free(void *notused, void *ptr, u_int nbytes)
 {
     free(ptr);
 }
 
 static void
-z_comp_stats(arg, stats)
-    void *arg;
-    struct compstat *stats;
+z_comp_stats(void *arg, struct compstat *stats)
 {
     struct deflate_state *state = (struct deflate_state *) arg;
     u_int out;
@@ -112,21 +115,20 @@ z_comp_stats(arg, stats)
     *stats = state->stats;
     stats->ratio = stats->unc_bytes;
     out = stats->comp_bytes + stats->unc_bytes;
-    if (stats->ratio <= 0x7ffffff)
-       stats->ratio <<= 8;
+    u_int ratio = stats->ratio;
+    if (ratio <= 0x7ffffff)
+       ratio <<= 8;
     else
        out >>= 8;
     if (out != 0)
-       stats->ratio /= out;
+       stats->ratio = ratio / out;
 }
 
 /*
  * Allocate space for a decompressor.
  */
 static void *
-z_decomp_alloc(options, opt_len)
-    u_char *options;
-    int opt_len;
+z_decomp_alloc(u_char *options, int opt_len)
 {
     struct deflate_state *state;
     int w_size;
@@ -158,8 +160,7 @@ z_decomp_alloc(options, opt_len)
 }
 
 static void
-z_decomp_free(arg)
-    void *arg;
+z_decomp_free(void *arg)
 {
     struct deflate_state *state = (struct deflate_state *) arg;
 
@@ -168,10 +169,8 @@ z_decomp_free(arg)
 }
 
 static int
-z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug)
-    void *arg;
-    u_char *options;
-    int opt_len, unit, hdrlen, mru, debug;
+z_decomp_init(void *arg, u_char *options, int opt_len,
+             int unit, int hdrlen, int mru, int debug)
 {
     struct deflate_state *state = (struct deflate_state *) arg;
 
@@ -194,8 +193,7 @@ z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug)
 }
 
 static void
-z_decomp_reset(arg)
-    void *arg;
+z_decomp_reset(void *arg)
 {
     struct deflate_state *state = (struct deflate_state *) arg;
 
@@ -220,15 +218,12 @@ z_decomp_reset(arg)
  * compression, even though they are detected by inspecting the input.
  */
 static int
-z_decompress(arg, mi, inlen, mo, outlenp)
-    void *arg;
-    u_char *mi, *mo;
-    int inlen, *outlenp;
+z_decompress(void *arg, u_char *mi, int inlen, u_char *mo, int *outlenp)
 {
     struct deflate_state *state = (struct deflate_state *) arg;
     u_char *rptr, *wptr;
-    int rlen, olen, ospace;
-    int seq, i, flush, r, decode_proto;
+    int rlen, olen;
+    int seq, r;
 
     rptr = mi;
     if (*rptr == 0)
@@ -292,10 +287,7 @@ z_decompress(arg, mi, inlen, mo, outlenp)
  * Incompressible data has arrived - add it to the history.
  */
 static void
-z_incomp(arg, mi, mlen)
-    void *arg;
-    u_char *mi;
-    int mlen;
+z_incomp(void *arg, u_char *mi, int mlen)
 {
     struct deflate_state *state = (struct deflate_state *) arg;
     u_char *rptr;