Put the contents of each CIC range parameter in a REG_REQ in its own tree
[obnox/wireshark/wip.git] / capture_wpcap_packet.c
index 419109906bea948d7eca76c9ec9981c904723c2b..6729e0c8389bb563cb4bc6b3ea3b04d88ccc9307 100644 (file)
@@ -1,13 +1,13 @@
 /* capture_wpcap_packet.c
  * WinPcap-specific interfaces for low-level information (packet.dll).  
  * We load WinPcap at run
- * time, so that we only need one Ethereal binary and one Tethereal binary
+ * time, so that we only need one Wireshark binary and one TShark binary
  * for Windows, regardless of whether WinPcap is installed or not.
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 2001 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
@@ -34,7 +34,6 @@
 #include <glib.h>
 #include <gmodule.h>
 
-#include <wtap.h>
 #include <pcap.h>
 
 /* XXX - yes, I know, I should move cppmagic.h to a generic location. */
 
 #include <epan/value_string.h>
 
+#include <Packet32.h>
+#include <windows.h>
+#include <windowsx.h>
+#include <Ntddndis.h>
+
+#include "capture_wpcap_packet.h"
 
+/* packet32.h requires sockaddr_storage 
+ * whether sockaddr_storage is defined or not depends on the Platform SDK 
+ * version installed. The only one not defining it is the SDK that comes
+ * with MSVC 6.0 (WINVER 0x0400).
+ *
+ * copied from RFC2553 (and slightly modified because of datatypes) ...
+ * XXX - defined more than once, move this to a header file */
+#ifndef WINVER
+#error WINVER not defined ....
+#endif
+#if (WINVER <= 0x0400) && defined(_MSC_VER)
+typedef unsigned short eth_sa_family_t;
 
-#ifndef HAVE_SOCKADDR_STORAGE
-/* packet32.h requires sockaddr_storage (usually defined in Platform SDK)
- * copied from RFC2553 (and slightly modified because of datatypes) ... */
 /*
  * Desired design of maximum size and alignment
  */
 /*
  * Definitions used for sockaddr_storage structure paddings design.
  */
-#define ETH_SS_PAD1SIZE   (ETH_SS_ALIGNSIZE - sizeof (sa_family_t))
-#define ETH_SS_PAD2SIZE   (ETH_SS_MAXSIZE - (sizeof (sa_family_t) + \
+#define ETH_SS_PAD1SIZE   (ETH_SS_ALIGNSIZE - sizeof (eth_sa_family_t))
+#define ETH_SS_PAD2SIZE   (ETH_SS_MAXSIZE - (sizeof (eth_sa_family_t) + \
                               ETH_SS_PAD1SIZE + ETH_SS_ALIGNSIZE))
 
 struct sockaddr_storage {
-    sa_family_t  __ss_family;     /* address family */
+    eth_sa_family_t  __ss_family;     /* address family */
     /* Following fields are implementation specific */
     char      __ss_pad1[ETH_SS_PAD1SIZE];
-              /* 6 byte pad, this is to make implementation
+              /* 6 byte pad, this is to make implementation */
               /* specific pad up to alignment field that */
               /* follows explicit in the data structure */
     gint64 /*int64_t*/   __ss_align;     /* field to force desired structure */
@@ -75,16 +89,9 @@ struct sockaddr_storage {
               /* __ss_pad1, __ss_align fields is 112 */
 };
 /* ... copied from RFC2553 */
-#endif
+#endif /* WINVER */
 
 
-#include <Packet32.h>
-#include <windows.h>
-#include <windowsx.h>
-#include <Ntddndis.h>
-
-#include "capture_wpcap_packet.h"
-
 gboolean has_wpacket = FALSE;
 
 
@@ -231,21 +238,29 @@ wpcap_packet_request(void *adapter, ULONG Oid, int set, char *value, unsigned in
         return 0;
     }
 
+       /* get a buffer suitable for PacketRequest() */
     OidData=GlobalAllocPtr(GMEM_MOVEABLE | GMEM_ZEROINIT,IoCtlBufferLength);
     if (OidData == NULL) {
-        g_warning("packet_link_status failed\n");
+        g_warning("GlobalAllocPtr failed for %u\n", IoCtlBufferLength);
         return 0;
     }
 
     OidData->Oid = Oid;
     OidData->Length = *length;
+    memcpy(OidData->Data, value, *length);
 
     Status = p_PacketRequest(adapter, set, OidData);
 
     if(Status) {
-        g_assert(OidData->Length <= *length);
-        memcpy(value, OidData->Data, OidData->Length);
-        *length = OidData->Length;
+               if(OidData->Length <= *length) {
+                       /* copy value from driver */
+                       memcpy(value, OidData->Data, OidData->Length);
+                       *length = OidData->Length;
+               } else {
+                       /* the driver returned a value that is longer than expected (and longer than the given buffer) */
+                       g_warning("returned oid too long, Oid: 0x%x OidLen:%u MaxLen:%u", Oid, OidData->Length, *length);
+                       Status = FALSE;
+               }
     }
 
     GlobalFreePtr (OidData);
@@ -267,8 +282,7 @@ wpcap_packet_request_uint(void *adapter, ULONG Oid, UINT *value)
 
 
     Status = wpcap_packet_request(adapter, Oid, FALSE /* !set */, (char *) value, &length);
-    if(Status) {
-        g_assert(length == sizeof(UINT));
+    if(Status && length == sizeof(UINT)) {
         return 1;
     } else {
         return 0;
@@ -285,8 +299,7 @@ wpcap_packet_request_ulong(void *adapter, ULONG Oid, ULONG *value)
 
 
     Status = wpcap_packet_request(adapter, Oid, FALSE /* !set */, (char *) value, &length);
-    if(Status) {
-        g_assert(length == sizeof(ULONG));
+    if(Status && length == sizeof(ULONG)) {
         return 1;
     } else {
         return 0;