Ethereal-dev: [ethereal-dev] WIN32 interface list and packet capture patch

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

From: "Paul Welchinski" <paul.welchinski@xxxxxxxxxxxxxxx>
Date: Mon, 20 Mar 2000 14:07:19 -0700
Here is a patch to show the proper interface list in Windows 95/98 as well as allow packet captures on WIN32 operating systems.
 
Index: ethereal/capture.c
===================================================================
RCS file: /cvsroot/ethereal/capture.c,v
retrieving revision 1.98
diff -u -r1.98 capture.c
--- capture.c 2000/02/19 14:00:33 1.98
+++ capture.c 2000/03/20 20:49:42
@@ -513,6 +513,22 @@
   time_t      upd_time, cur_time;
   int         err, inpkts;
   char        errmsg[1024+1];
+
+  // Initialize Windows Socket if we are in a WIN32 OS
+  // This needs to be done before querying the interface for network/netmask
+#ifdef _WIN32
+  WORD wVersionRequested;
+  WSADATA wsaData;
+  wVersionRequested = MAKEWORD( 1, 1 );
+  err = WSAStartup( wVersionRequested, &wsaData );
+  if (err!=0) {
+    snprintf(errmsg, sizeof errmsg,
+      "Couldn't initialize Windows Sockets.");
+ pch=NULL;
+    goto error;
+  }
+#endif
+
 #ifdef linux
   fd_set      set1;
   struct timeval timeout;
Index: ethereal/util.c
===================================================================
RCS file: /cvsroot/ethereal/util.c,v
retrieving revision 1.38
diff -u -r1.38 util.c
--- util.c 2000/03/14 08:26:19 1.38
+++ util.c 2000/03/20 20:49:45
@@ -608,25 +608,45 @@
 get_interface_list(int *err, char *err_str) {
   GList  *il = NULL;
   wchar_t *names;
+  char *win95names;
   char newname[255];
   int i, j, done;
  
   names = (wchar_t *)pcap_lookupdev(err_str);
   i = done = 0;
 
-  if (names)
-     do
-     {
-        j = 0;
-        while (names[i] != 0)
-           newname[j++] = names[i++];
-        i++;
-        if (names[i] == 0)
-           done = 1;
-        newname[j++] = 0;
-        il = g_list_append(il, g_strdup(newname));
-     } while (!done);

+  if (names) {
+  // If names[0] is less than 256 it means the first byte is 0
+  // This implies that we are using unicode characters
+   if (names[0]<256) {
+    do
+    {
+     j = 0;
+     while (names[i] != 0)
+      newname[j++] = names[i++];
+     i++;
+     if (names[i] == 0)
+      done = 1;
+     newname[j++] = 0;
+     il = g_list_append(il, g_strdup(newname));
+    } while (!done);
+   }
+  // Otherwise we are in Windows 95/98 and using ascii(8 bit) characters
+   else {
+    do
+    {
+     win95names=names;
+     j = 0;
+     while (win95names[i] != 0)
+      newname[j++] = win95names[i++];
+     i++;
+     if (win95names[i] == 0)
+      done = 1;
+     newname[j++] = 0;
+     il = g_list_append(il, g_strdup(newname));
+    } while (!done);
+   }
+  }
   return(il);
 }
 #endif

Attachment: my.patch
Description: Binary data