Some packet_list.h -> main_packet_list.h changes.
[obnox/wireshark/wip.git] / capture_wpcap_packet.c
index 7034b5d9e26c14295355141758d66103d6a6f6b2..d26da5f8f4fdfb59f8d89d5186a47be468533db3 100644 (file)
@@ -1,7 +1,7 @@
 /* capture_wpcap_packet.c
  * WinPcap-specific interfaces for low-level information (packet.dll).  
  * We load WinPcap at run
 /* 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 Wireshark binary and one Twireshark 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$
  * for Windows, regardless of whether WinPcap is installed or not.
  *
  * $Id$
 
 
 
 
 
 
-#ifndef HAVE_SOCKADDR_STORAGE
-/* packet32.h requires sockaddr_storage (usually defined in Platform SDK)
+/* packet32.h requires sockaddr_storage 
+ * wether 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 */
  * copied from RFC2553 (and slightly modified because of datatypes) ...
  * XXX - defined more than once, move this to a header file */
+#if (WINVER <= 0x0400) && defined(_MSC_VER)
 typedef unsigned short eth_sa_family_t;
 
 /*
 typedef unsigned short eth_sa_family_t;
 
 /*
@@ -78,7 +82,7 @@ struct sockaddr_storage {
               /* __ss_pad1, __ss_align fields is 112 */
 };
 /* ... copied from RFC2553 */
               /* __ss_pad1, __ss_align fields is 112 */
 };
 /* ... copied from RFC2553 */
-#endif
+#endif /* WINVER */
 
 
 #include <Packet32.h>
 
 
 #include <Packet32.h>
@@ -234,9 +238,10 @@ wpcap_packet_request(void *adapter, ULONG Oid, int set, char *value, unsigned in
         return 0;
     }
 
         return 0;
     }
 
+       /* get a buffer suitable for PacketRequest() */
     OidData=GlobalAllocPtr(GMEM_MOVEABLE | GMEM_ZEROINIT,IoCtlBufferLength);
     if (OidData == NULL) {
     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;
     }
 
         return 0;
     }
 
@@ -247,9 +252,15 @@ wpcap_packet_request(void *adapter, ULONG Oid, int set, char *value, unsigned in
     Status = p_PacketRequest(adapter, set, OidData);
 
     if(Status) {
     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);
     }
 
     GlobalFreePtr (OidData);