]> The Tcpdump Group git mirrors - tcpdump/commitdiff
From Gisle Vanem: make print-esp.c work with more (maybe all?) OpenSSL
authorguy <guy>
Sun, 2 Mar 2003 23:19:33 +0000 (23:19 +0000)
committerguy <guy>
Sun, 2 Mar 2003 23:19:33 +0000 (23:19 +0000)
versions, and changes to make it work on DOS/Windows with various
compilers and C support libraries.

FILES
config.h.in
configure
configure.in
missing/strsep.c [new file with mode: 0644]
print-esp.c
tcpdump-stdinc.h

diff --git a/FILES b/FILES
index 94d3c31242b587b33cc15efebc7b91430fe40093..31592ba813bde48a4cbec67b7783b66a5c956453 100644 (file)
--- a/FILES
+++ b/FILES
@@ -71,6 +71,7 @@ missing/sockstorage.h
 missing/strdup.c
 missing/strlcat.c
 missing/strlcpy.c
 missing/strdup.c
 missing/strlcat.c
 missing/strlcpy.c
+missing/strsep.c
 mkdep
 nameser.h
 netbios.h
 mkdep
 nameser.h
 netbios.h
index 20e04db17818e3cace2befb2a911cc4fa648eb5b..c8fdd2c6d5c9458ccca2284055de4cb4d060fb6c 100644 (file)
 /* Define if you have the strlcpy function.  */
 #undef HAVE_STRLCPY
 
 /* Define if you have the strlcpy function.  */
 #undef HAVE_STRLCPY
 
+/* Define if you have the strsep function.  */
+#undef HAVE_STRSEP
+
 /* Define if you have the vfprintf function.  */
 #undef HAVE_VFPRINTF
 
 /* Define if you have the vfprintf function.  */
 #undef HAVE_VFPRINTF
 
index fbb913499147522eb5fe42f150de45caed161d59..7911b56ac7e4528bc0e3b5bf460e4ba8fa1a3168 100755 (executable)
--- a/configure
+++ b/configure
@@ -2889,7 +2889,7 @@ if test "$missing_includes" = "yes"; then
 fi
 
 
 fi
 
 
-for ac_func in vfprintf strcasecmp strlcat strlcpy strdup
+for ac_func in vfprintf strcasecmp strlcat strlcpy strdup strsep
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:2896: checking for $ac_func" >&5
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:2896: checking for $ac_func" >&5
index 96aefc4b0be66e66f57ac0c43cfb229982835b88..dbc2625d34391c2c02894e5b660d6b5f290e7761 100644 (file)
@@ -1,4 +1,4 @@
-dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.160 2003-02-11 07:41:52 guy Exp $ (LBL)
+dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.161 2003-03-02 23:19:37 guy Exp $ (LBL)
 dnl
 dnl Copyright (c) 1994, 1995, 1996, 1997
 dnl    The Regents of the University of California.  All rights reserved.
 dnl
 dnl Copyright (c) 1994, 1995, 1996, 1997
 dnl    The Regents of the University of California.  All rights reserved.
@@ -6,7 +6,7 @@ dnl
 dnl Process this file with autoconf to produce a configure script.
 dnl
 
 dnl Process this file with autoconf to produce a configure script.
 dnl
 
-AC_REVISION($Revision: 1.160 $)
+AC_REVISION($Revision: 1.161 $)
 AC_PREREQ(2.13)
 AC_INIT(tcpdump.c)
 
 AC_PREREQ(2.13)
 AC_INIT(tcpdump.c)
 
@@ -511,7 +511,7 @@ if test "$missing_includes" = "yes"; then
 fi
 
 
 fi
 
 
-AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup)
+AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup strsep)
 AC_CHECK_FUNCS(ether_ntohost, [
     AC_CACHE_CHECK(for buggy ether_ntohost, ac_cv_buggy_ether_ntohost, [
        AC_TRY_RUN([
 AC_CHECK_FUNCS(ether_ntohost, [
     AC_CACHE_CHECK(for buggy ether_ntohost, ac_cv_buggy_ether_ntohost, [
        AC_TRY_RUN([
diff --git a/missing/strsep.c b/missing/strsep.c
new file mode 100644 (file)
index 0000000..ddad596
--- /dev/null
@@ -0,0 +1,80 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#include <string.h>
+#include <stdio.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strsep.c   8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+strsep(stringp, delim)
+       register char **stringp;
+       register const char *delim;
+{
+       register char *s;
+       register const char *spanp;
+       register int c, sc;
+       char *tok;
+
+       if ((s = *stringp) == NULL)
+               return (NULL);
+       for (tok = s;;) {
+               c = *s++;
+               spanp = delim;
+               do {
+                       if ((sc = *spanp++) == c) {
+                               if (c == 0)
+                                       s = NULL;
+                               else
+                                       s[-1] = 0;
+                               *stringp = s;
+                               return (tok);
+                       }
+               } while (sc != 0);
+       }
+       /* NOTREACHED */
+}
index 5247732f6e814052c40ffc2f5186588570fc915c..47829118960a7dfbfa39bf490b07edaf0aef6fa4 100644 (file)
@@ -23,7 +23,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.33 2003-02-26 18:58:05 mcr Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.34 2003-03-02 23:19:38 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -55,6 +55,11 @@ static const char rcsid[] =
 #include "ip6.h"
 #endif
 
 #include "ip6.h"
 #endif
 
+#if defined(__MINGW32__) || defined(__WATCOMC__)
+#include "addrinfo.h"
+extern char *strsep (char **stringp, const char *delim); /* Missing/strsep.c */
+#endif
+
 #define AVOID_CHURN 1
 #include "interface.h"
 #include "addrtoname.h"
 #define AVOID_CHURN 1
 #include "interface.h"
 #include "addrtoname.h"
@@ -192,13 +197,13 @@ static void esp_print_decode_onesecret(char *line)
     char  fileline[1024];
     char  *nl;
 
     char  fileline[1024];
     char  *nl;
 
-    secretfile=fopen(line, "r");
+    secretfile = fopen(line, FOPEN_READ_TXT);
     if(secretfile == NULL) {
       perror(line);
       exit(3);
     }
     
     if(secretfile == NULL) {
       perror(line);
       exit(3);
     }
     
-    while(fgets(fileline, 1024, secretfile) != NULL) {
+    while(fgets(fileline, sizeof(fileline)-1, secretfile) != NULL) {
 
       /* remove newline from the line */
       nl = strchr(fileline, '\n');
 
       /* remove newline from the line */
       nl = strchr(fileline, '\n');
@@ -467,7 +472,15 @@ esp_print(register const u_char *bp, register const u_char *bp2,
 
                if (espsecret_keylen != 8)
                        goto fail;
 
                if (espsecret_keylen != 8)
                        goto fail;
-#if OPENSSL_VERSION_NUMBER >= 0x00907000L
+
+#if OPENSSL_VERSION_NUMBER >= 0x00908000L
+               DES_set_key_unchecked((const_DES_cblock *)secret, &schedule);
+
+               DES_cbc_encrypt((const unsigned char *)p, p,
+                       (long)(ep - p), &schedule, (DES_cblock *)iv,
+                       DES_DECRYPT);
+
+#elif OPENSSL_VERSION_NUMBER >= 0x00907000L
                DES_set_key_unchecked((DES_cblock *)secret, schedule);
 
                DES_cbc_encrypt((const unsigned char *)p, p,
                DES_set_key_unchecked((DES_cblock *)secret, schedule);
 
                DES_cbc_encrypt((const unsigned char *)p, p,
@@ -557,6 +570,17 @@ esp_print(register const u_char *bp, register const u_char *bp2,
                DES_set_odd_parity((DES_cblock *)secret);
                DES_set_odd_parity((DES_cblock *)(secret + 8));
                DES_set_odd_parity((DES_cblock *)(secret + 16));
                DES_set_odd_parity((DES_cblock *)secret);
                DES_set_odd_parity((DES_cblock *)(secret + 8));
                DES_set_odd_parity((DES_cblock *)(secret + 16));
+#if OPENSSL_VERSION_NUMBER >= 0x00908000L
+               if(DES_set_key_checked((const_DES_cblock *)secret, &s1) != 0) {
+                 printf("failed to schedule key 1\n");
+               }
+               if(DES_set_key_checked((const_DES_cblock *)(secret + 8), &s2)!=0) {
+                 printf("failed to schedule key 2\n");
+               }
+               if(DES_set_key_checked((const_DES_cblock *)(secret + 16), &s3)!=0) {
+                 printf("failed to schedule key 3\n");
+               }
+#else
                if(DES_set_key_checked((DES_cblock *)secret, s1) != 0) {
                  printf("failed to schedule key 1\n");
                }
                if(DES_set_key_checked((DES_cblock *)secret, s1) != 0) {
                  printf("failed to schedule key 1\n");
                }
@@ -566,6 +590,7 @@ esp_print(register const u_char *bp, register const u_char *bp2,
                if(DES_set_key_checked((DES_cblock *)(secret + 16), s3)!=0) {
                  printf("failed to schedule key 3\n");
                }
                if(DES_set_key_checked((DES_cblock *)(secret + 16), s3)!=0) {
                  printf("failed to schedule key 3\n");
                }
+#endif
 
                p = ivoff + ivlen;
                DES_ede3_cbc_encrypt((const unsigned char *)p, p,
 
                p = ivoff + ivlen;
                DES_ede3_cbc_encrypt((const unsigned char *)p, p,
index 7e5049da3b99734dfe9e069600bd25434f38731b..06940c75cd63662116f236fdc5618dde5beaf647 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/tcpdump-stdinc.h,v 1.3 2002-08-05 07:47:24 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/tcpdump-stdinc.h,v 1.4 2003-03-02 23:19:38 guy Exp $ (LBL)
  */
 
 /*
  */
 
 /*
  * differences to this one file.
  */
 
  * differences to this one file.
  */
 
+#ifndef tcpdump_stdinc_h
+#define tcpdump_stdinc_h
+
 #ifdef WIN32
 
 #ifdef WIN32
 
+#include <stdio.h>
 #include <winsock2.h>
 #include "bittypes.h"
 #include <winsock2.h>
 #include "bittypes.h"
+#include <ctype.h>
 #include <time.h>
 #include <io.h>
 #include "IP6_misc.h"
 #include <fcntl.h>
 
 #ifdef __MINGW32__
 #include <time.h>
 #include <io.h>
 #include "IP6_misc.h"
 #include <fcntl.h>
 
 #ifdef __MINGW32__
+#include <stdint.h>
 int* _errno();
 #define errno (*_errno())
 
 int* _errno();
 #define errno (*_errno())
 
@@ -46,6 +52,10 @@ int* _errno();
 
 #endif /* __MINGW32__ */
 
 
 #endif /* __MINGW32__ */
 
+#ifndef toascii
+#define toascii(c) ((c) & 0x7f)
+#endif
+
 #ifndef caddr_t
 typedef char* caddr_t;
 #endif /* caddr_t */
 #ifndef caddr_t
 typedef char* caddr_t;
 #endif /* caddr_t */
@@ -57,7 +67,8 @@ typedef char* caddr_t;
 #define vsnprintf _vsnprintf
 #define RETSIGTYPE void
 
 #define vsnprintf _vsnprintf
 #define RETSIGTYPE void
 
-#ifndef __MINGW32__
+#if !defined(__MINGW32__) && !defined(__WATCOMC__)
+#undef toascii
 #define isascii __isascii
 #define toascii __toascii
 #define stat _stat
 #define isascii __isascii
 #define toascii __toascii
 #define stat _stat
@@ -91,3 +102,17 @@ typedef short ino_t;
 #ifdef INET6
 #include "ip6.h"
 #endif
 #ifdef INET6
 #include "ip6.h"
 #endif
+
+#if defined(WIN32) || defined(MSDOS)
+  #define FOPEN_READ_TXT   "rt"
+  #define FOPEN_READ_BIN   "rb"
+  #define FOPEN_WRITE_TXT  "wt"
+  #define FOPEN_WRITE_BIN  "wb"
+#else
+  #define FOPEN_READ_TXT   "r"
+  #define FOPEN_READ_BIN   FOPEN_READ_BIN
+  #define FOPEN_WRITE_TXT  "w"
+  #define FOPEN_WRITE_BIN  FOPEN_WRITE_TXT
+#endif
+
+#endif /* tcpdump_stdinc_h */