]> The Tcpdump Group git mirrors - libpcap/commitdiff
Implemented pcap_hopen_offline(). This "internal" function allows us to
authorgianluca <gianluca>
Mon, 6 Oct 2008 15:27:32 +0000 (15:27 +0000)
committergianluca <gianluca>
Mon, 6 Oct 2008 15:27:32 +0000 (15:27 +0000)
support pcap_fopen_offline() on windows platforms (where FILE* handles cannot
be passed on DLL boundaries).

pcap-stdinc.h
pcap/pcap.h
savefile.c

index 68c146d2908e0049dd4542884af434a51449ec1a..32b52d8ff0821794d5681837be03ae33704ef1aa 100644 (file)
@@ -28,7 +28,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * @(#) $Header: /tcpdump/master/libpcap/pcap-stdinc.h,v 1.10 2007-09-27 17:59:45 gianluca Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-stdinc.h,v 1.11 2008-10-06 15:27:32 gianluca Exp $ (LBL)
  */
 
 #define SIZEOF_CHAR 1
 #define vsnprintf _vsnprintf
 #define strdup _strdup
 #define inline __inline 
+
+#ifdef __MINGW32__
+#include <stdint.h>
+#else /*__MINGW32__*/
+/* MSVC compiler */
+#ifndef _UINTPTR_T_DEFINED
+#ifdef  _WIN64
+typedef unsigned __int64    uintptr_t;
+#else
+typedef _W64 unsigned int   uintptr_t;
+#endif
+#define _UINTPTR_T_DEFINED
+#endif
+
+#ifndef _INTPTR_T_DEFINED
+#ifdef  _WIN64
+typedef __int64    intptr_t;
+#else
+typedef _W64 int   intptr_t;
+#endif
+#define _INTPTR_T_DEFINED
+#endif 
+
+#endif /*__MINGW32__*/
index 2175308038fc5050ed74504ed60c5c49664b02b9..29d5a4e331f93fef107b7cc10503b82881564b6f 100644 (file)
@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * @(#) $Header: /tcpdump/master/libpcap/pcap/pcap.h,v 1.14 2008-07-01 08:02:33 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap/pcap.h,v 1.15 2008-10-06 15:27:32 gianluca Exp $ (LBL)
  */
 
 #ifndef lib_pcap_pcap_h
@@ -268,7 +268,18 @@ int        pcap_activate(pcap_t *);
 pcap_t *pcap_open_live(const char *, int, int, int, char *);
 pcap_t *pcap_open_dead(int, int);
 pcap_t *pcap_open_offline(const char *, char *);
+#if defined(WIN32)
+pcap_t  *pcap_hopen_offline(intptr_t, char *);
+#if !defined(LIBPCAP_EXPORTS)
+#define pcap_fopen_offline(f,b) \
+       pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)
+#else /*LIBPCAP_EXPORTS*/
+static pcap_t *pcap_fopen_offline(FILE *, char *);
+#endif
+#else /*WIN32*/
 pcap_t *pcap_fopen_offline(FILE *, char *);
+#endif /*WIN32*/
+
 void   pcap_close(pcap_t *);
 int    pcap_loop(pcap_t *, int, pcap_handler, u_char *);
 int    pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
index db9ed54c572d763f63c2d08c87791433fe8946e5..2624e2f8b0893ca28be29d9f96557c823849380e 100644 (file)
@@ -30,7 +30,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.177 2008-09-22 20:14:19 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.178 2008-10-06 15:27:32 gianluca Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -1154,6 +1154,33 @@ pcap_open_offline(const char *fname, char *errbuf)
        return (p);
 }
 
+#ifdef WIN32
+pcap_t* pcap_hopen_offline(intptr_t osfd, char *errbuf)
+{
+       int fd;
+       FILE *file;
+
+       fd = _open_osfhandle(osfd, _O_RDONLY);
+       if ( fd < 0 ) 
+       {
+               snprintf(errbuf, PCAP_ERRBUF_SIZE, pcap_strerror(errno));
+               return NULL;
+       }
+
+       file = _fdopen(fd, "rb");
+       if ( file == NULL ) 
+       {
+               snprintf(errbuf, PCAP_ERRBUF_SIZE, pcap_strerror(errno));
+               return NULL;
+       }
+
+       return pcap_fopen_offline(file, errbuf);
+}
+#endif
+
+#ifdef WIN32
+static
+#endif
 pcap_t *
 pcap_fopen_offline(FILE *fp, char *errbuf)
 {