Ethereal-dev: [Ethereal-dev] pcap-util.c patch

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: aferen@xxxxxxxxxxxx (Andrew C. Feren)
Date: 28 Mar 2002 10:19:18 -0500
Since it seems that every windows machine here has 3 or more adapters
I finally had to add code to display the device description in
addition to "\Device\Packet_{BLABLABL-BLAB-BLAB-BLAB-BLABLABLALBA}".

I don't have a win95 machine so that code has not been tested.

I tried a capture and tried saving my interface preferences.
everything seemed to work fine.  Even with the extra text appended to
the displayed strings.

Index: pcap-util.c
===================================================================
RCS file: /cvsroot/ethereal/pcap-util.c,v
retrieving revision 1.3
diff -u -r1.3 pcap-util.c
--- pcap-util.c	2001/11/09 08:16:24	1.3
+++ pcap-util.c	2002/03/28 15:06:01
@@ -390,13 +390,37 @@
   char newname[255];
   int i, j, done;
   
+  /* On Windows pcap_lookupdev is implemented by calling
+   * PacketGetAdapterNames.  According to the documentation I can find
+   * (http://winpcap.polito.it/docs/dll.htm#PacketGetAdapterNames)
+   * this means that:
+   *
+   * On Windows 95x, pcap_lookupdev returns an ASCII string with the
+   * names of the adapters separated by a single ASCII "\0", a double
+   * "\0", followed by the descriptions of the adapters separated by a
+   * single ASCII "\0" . The string is terminated by a double "\0".
+   *
+   * On Windows NTx, pcap_lookupdev returns the names of the adapters,
+   * in UNICODE format, separated by a single UNICODE "\0" (i.e. 2
+   * ASCII "\0"), a double UNICODE "\0", followed by the descriptions
+   * of the adapters, in ASCII format, separated by a single ASCII
+   * "\0" . The string is terminated by a double ASCII "\0".
+   */
   names = (wchar_t *)pcap_lookupdev(err_str);
   i = done = 0;
 
   if (names) {
+	  char* desc = 0;
+	  int desc_pos = 0;
+
 	  if (names[0]<256) { 
 		  /* If names[0] is less than 256 it means the first byte is 0
 		     This implies that we are using unicode characters */
+	          while(*(names+desc_pos) || *(names+desc_pos-1))
+		  	desc_pos++;
+		  desc_pos++;	/* Step over the extra '\0' */
+		  desc = (char*)(names + desc_pos); /* cast *after* addition */
+
 		  do 
 		  { 
 			  j = 0; 
@@ -405,6 +429,14 @@
 			  i++; 
 			  if (names[i] == 0) 
 				  done = 1; 
+
+			  newname[j++] = ' '; 
+			  newname[j++] = '('; 
+			  while (*desc) {
+			    newname[j++] = *desc++; 
+			  }
+			  desc++; 
+			  newname[j++] = ')'; 
 			  newname[j++] = 0; 
 			  il = g_list_append(il, g_strdup(newname)); 
 		  } while (!done); 
@@ -412,15 +444,26 @@
 	  else { 
 		  /* Otherwise we are in Windows 95/98 and using ascii(8 bit)
 		     characters */
+	          win95names=(char *)names; 
+		  while(*(win95names+desc_pos) || *(win95names+desc_pos-1))
+		  	desc_pos++;
+		  desc_pos++;	/* Step over the extra '\0' */
+		  desc = win95names + desc_pos;
+
 		  do 
 		  { 
-			  win95names=(char *)names; 
 			  j = 0; 
 			  while (win95names[i] != 0) 
 				  newname[j++] = win95names[i++]; 
 			  i++; 
 			  if (win95names[i] == 0) 
 				  done = 1; 
+			  newname[j++] = ' '; 
+			  newname[j++] = '('; 
+			  while (*desc) {
+			    newname[j++] = *desc++; 
+			  }
+			  newname[j++] = ')'; 
 			  newname[j++] = 0; 
 			  il = g_list_append(il, g_strdup(newname)); 
 		  } while (!done); 

-- 
-Andrew Feren
 Cetacean Networks, Inc.
 Portsmouth, NH