Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Aug 2013 11:37:08 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r255530 - soc2013/dpl/head/lib/libzcap
Message-ID:  <201308051137.r75Bb8l4017243@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Mon Aug  5 11:37:08 2013
New Revision: 255530
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255530

Log:
  Added crc32.
  

Modified:
  soc2013/dpl/head/lib/libzcap/commands.c
  soc2013/dpl/head/lib/libzcap/crc32.c

Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c	Mon Aug  5 10:38:34 2013	(r255529)
+++ soc2013/dpl/head/lib/libzcap/commands.c	Mon Aug  5 11:37:08 2013	(r255530)
@@ -39,33 +39,6 @@
 extern pid;
 extern nvlist_t *sendCommand(nvlist_t *);
 
-int
-zcapcmd_deflate( strm, flush )
-z_streamp strm;
-int flush;
-{
-	nvlist_t *nvl, *args, *result;
-	
-	if (pid == 0)
-		startChild();
-
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
-		return (NULL);
-	}
-	nvlist_add_number(nvl, "command", ZCAPCMD_);
-
-	nvlist_add_binary(args, "strm", strm, sizeof(z_streamp));
-	nvlist_add_number(args, "flush", flush);
-	nvlist_add_nvlist(nvl, "args", args);
-
-	result = sendCommand(nvl);
-	int ret = nvlist_take_number(result, "result");
-	nvlist_destroy(result);
-	return(ret)
-}
-
 uLong
 zcapcmd_compressBound( adler1, adler2, len2 )
 	uLong adler1;
@@ -156,7 +129,36 @@
 }
 
 uLong
-zcapcmd_adler32_combine( crc1, crc2, len2 )
+zcapcmd_crcr32(crc, buf, len)
+	uLong crc;
+	const Bytef *buf;
+	uInt len;
+{
+	nvlist_t *nvl, *args, *result;
+	uLong ret;
+	
+	if (pid == 0)
+		startChild();
+	if( (args = nvlist_create(0)) == NULL ||
+		(nvl = nvlist_create(0)) == NULL ) {
+		perror("nvlist_create");
+		return (NULL);
+	}
+	nvlist_add_number(nvl, "command", ZCAPCMD_ADLER32);
+	nvlist_add_number(args, "crc", crc);
+	nvlist_add_binary(args, "buf", *buf, len);
+	nvlist_add_number(args, "len", len);
+	nvlist_add_nvlist(nvl, "args", args);
+
+	result = sendCommand(nvl);
+
+	ret = nvlist_take_number(result, "result");
+	nvlist_destroy(result);
+	return(ret);
+}
+
+uLong
+zcapcmd_crc32_combine( crc1, crc2, len2 )
 	uLong crc1;
 	uLong crc2;
 	z_off64_t len2;

Modified: soc2013/dpl/head/lib/libzcap/crc32.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/crc32.c	Mon Aug  5 10:38:34 2013	(r255529)
+++ soc2013/dpl/head/lib/libzcap/crc32.c	Mon Aug  5 11:37:08 2013	(r255530)
@@ -201,6 +201,7 @@
 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
 
 /* ========================================================================= */
+zcapcmd_crc32(unsigned long crc, const unsigned char FAR *buf, uInt len);
 unsigned long ZEXPORT crc32(crc, buf, len)
     unsigned long crc;
     const unsigned char FAR *buf;
@@ -208,31 +209,16 @@
 {
     if (buf == Z_NULL) return 0UL;
 
-#ifdef DYNAMIC_CRC_TABLE
-    if (crc_table_empty)
-        make_crc_table();
-#endif /* DYNAMIC_CRC_TABLE */
-
-#ifdef BYFOUR
-    if (sizeof(void *) == sizeof(ptrdiff_t)) {
-        z_crc_t endian;
-
-        endian = 1;
-        if (*((unsigned char *)(&endian)))
-            return crc32_little(crc, buf, len);
-        else
-            return crc32_big(crc, buf, len);
-    }
-#endif /* BYFOUR */
-    crc = crc ^ 0xffffffffUL;
-    while (len >= 8) {
-        DO8;
-        len -= 8;
-    }
-    if (len) do {
-        DO1;
-    } while (--len);
-    return crc ^ 0xffffffffUL;
+	/* Send packets of 1MB size at most. */
+	if ((sizeof(*buf)*len) > (1024*1024)) {
+ 		while( (len -= (1024*1024)) > 0) {
+ 			buf += (1024*1024)/sizeof(*buf);
+			crc = zcapcmd_crc32(crc, buf, len);
+		}
+	} else {
+		crc = zcapcmd_crc32( crc, buf, len);
+	}
+	return crc;
 }
 
 #ifdef BYFOUR



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308051137.r75Bb8l4017243>