[Gd-chatter] r11703 - in trunk/libraries: network-interfaces registry/x86-freebsd

hannes at gwydiondylan.org hannes at gwydiondylan.org
Sun Feb 24 08:43:03 CET 2008


Author: hannes
Date: Sun Feb 24 08:43:02 2008
New Revision: 11703

Added:
   trunk/libraries/network-interfaces/pcap-library-unix.dylan
      - copied, changed from r11695, trunk/libraries/network-interfaces/pcap-library-win32.dylan
   trunk/libraries/network-interfaces/pcap-unix.dylan   (contents, props changed)
   trunk/libraries/network-interfaces/pcap-unix.hdp
      - copied, changed from r11693, trunk/libraries/network-interfaces/pcap.hdp
   trunk/libraries/network-interfaces/pcap-win32.dylan   (contents, props changed)
Removed:
   trunk/libraries/network-interfaces/pcap.hdp
Modified:
   trunk/libraries/network-interfaces/pcap-library-win32.dylan
   trunk/libraries/network-interfaces/pcap-win32.hdp
   trunk/libraries/network-interfaces/pcap.dylan
   trunk/libraries/registry/x86-freebsd/network-interfaces
Log:
Job: 7299
split the special functionality of windows and unix in separate files

re-enable FreeBSD-support of network-interfaces library


Copied: trunk/libraries/network-interfaces/pcap-library-unix.dylan (from r11695, trunk/libraries/network-interfaces/pcap-library-win32.dylan)
==============================================================================
--- trunk/libraries/network-interfaces/pcap-library-win32.dylan	(original)
+++ trunk/libraries/network-interfaces/pcap-library-unix.dylan	Sun Feb 24 08:43:02 2008
@@ -20,7 +20,8 @@
 define module network-interfaces
   use common-dylan;
   use c-ffi;
-  use winsock2;
+  use unix-sockets, import: { sa-data-array, <timeval>,
+                              <lpsockaddr>, <C-buffer-offset> };
   //use format-out;
   use standard-io;
   use subseq;

Modified: trunk/libraries/network-interfaces/pcap-library-win32.dylan
==============================================================================
--- trunk/libraries/network-interfaces/pcap-library-win32.dylan	(original)
+++ trunk/libraries/network-interfaces/pcap-library-win32.dylan	Sun Feb 24 08:43:02 2008
@@ -20,7 +20,8 @@
 define module network-interfaces
   use common-dylan;
   use c-ffi;
-  use winsock2;
+  use winsock2, import: { sa-data-array, <timeval>,
+                          <lpsockaddr>, <C-buffer-offset> };
   //use format-out;
   use standard-io;
   use subseq;

Added: trunk/libraries/network-interfaces/pcap-unix.dylan
==============================================================================
--- (empty file)
+++ trunk/libraries/network-interfaces/pcap-unix.dylan	Sun Feb 24 08:43:02 2008
@@ -0,0 +1,28 @@
+module: network-interfaces
+
+define method find-all-devices () => (res :: <collection>)
+  let res = make(<stretchy-vector>);
+  let errbuf = make(<byte-vector>);
+  let (errorcode, devices) = pcap-find-all-devices(buffer-offset(errbuf, 0));
+  for (device = devices then device.next,
+       while: device ~= null-pointer(<pcap-if*>))
+    add!(res, make(<device>, name: as(<byte-string>, device.name)))
+  end;
+  res;
+end;
+
+define method initialize
+    (interface :: <ethernet-interface>, #next next-method, #key, #all-keys)
+  => ()
+  next-method();
+  let errbuf = make(<byte-vector>);
+  let res = pcap-open-live(interface.interface-name,
+                           $ethernet-buffer-size,
+                           if (interface.promiscuous?) 1 else 0 end,
+                           $timeout,
+                           buffer-offset(errbuf, 0));
+  if (res ~= null-pointer(<C-void*>))
+    interface.pcap-t := res;
+  end;
+end;
+

Copied: trunk/libraries/network-interfaces/pcap-unix.hdp (from r11693, trunk/libraries/network-interfaces/pcap.hdp)
==============================================================================
--- trunk/libraries/network-interfaces/pcap.hdp	(original)
+++ trunk/libraries/network-interfaces/pcap-unix.hdp	Sun Feb 24 08:43:02 2008
@@ -1,4 +1,5 @@
 library: network-interfaces
-files: pcap-library
+files:	pcap-library-unix
 	pcap
+	pcap-unix
 c-libraries: -lpcap

Added: trunk/libraries/network-interfaces/pcap-win32.dylan
==============================================================================
--- (empty file)
+++ trunk/libraries/network-interfaces/pcap-win32.dylan	Sun Feb 24 08:43:02 2008
@@ -0,0 +1,86 @@
+module: network-interfaces
+
+define method find-all-devices () => (res :: <collection>)
+  let res = make(<stretchy-vector>);
+  let errbuf = make(<byte-vector>);
+  let (errorcode, devices) = pcap-find-all-devices(buffer-offset(errbuf, 0));
+  for (device = devices then device.next, while: device ~= null-pointer(<pcap-if*>))
+    let cidrs = make(<stretchy-vector>);
+    for (ele = device.addresses then ele.next, while: ele ~= null-pointer(<pcap-addr*>))
+//      format-out("GOT as address %= ", ele.address.sa-family-value);
+      local method printme (x)
+              for (f from 2 below 6)
+                //format-out("%X ", sa-data-array(x, f));
+              end;
+              //format-out(" ");
+            end;
+      printme(ele.address);
+      if (null-pointer(<sockaddr*>) ~= ele.netmask)
+       // format-out("netmask "); printme(ele.netmask);
+      end;
+      if (null-pointer(<sockaddr*>) ~= ele.broadcast-address)
+        //format-out("broadcast-address "); printme(ele.broadcast-address);
+      end;
+      if (null-pointer(<sockaddr*>) ~= ele.destination-address)
+        //format-out("destination-address "); printme(ele.destination-address);
+      end;
+      local method get-address (foo :: <pcap-addr*>)
+              let res = make(<stretchy-vector-subsequence>, size: 4);
+              for (i from 2 below 6)
+                res[i - 2] := as(<byte>, sa-data-array(foo.address, i));
+              end;
+              make(<ipv4-address>, data: res);
+            end;
+      local method get-netmask (foo :: <pcap-addr*>)
+              let res = make(<stretchy-vector>);
+              for (i from 2 below 6)
+                add!(res, sa-data-array(foo.netmask, i));
+              end;
+              netmask-from-byte-vector(res);
+            end;
+
+      //format-out("\n");
+      add!(cidrs, concatenate(as(<string>, get-address(ele)), "/", integer-to-string(get-netmask(ele))));
+    end;
+
+    let str = as(<byte-string>, device.description);
+    //XXX: generate a real object, and also return device-name
+    add!(res, make(<device>, name: str, cidrs: cidrs))
+  end;
+  res;
+end;
+
+define method initialize
+    (interface :: <ethernet-interface>, #next next-method, #key, #all-keys)
+  => ()
+  next-method();
+  let errbuf = make(<byte-vector>);
+  block(ret)
+    local method open-interface (name)
+//            format-out("trying interface %s\n", name);
+            let res = pcap-open-live(name,
+                                     $ethernet-buffer-size,
+                                     if (interface.promiscuous?) 1 else 0 end,
+                                     $timeout,
+                                     buffer-offset(errbuf, 0));
+            if (res ~= null-pointer(<C-void*>))
+              interface.pcap-t := res;
+//              format-out("Opened Interface %s\n", name);
+              ret();
+            end;
+          end;
+    //open-interface(interface.interface-name);
+
+//    format-out("trying pcap-find-alldevices\n");
+    let (errorcode, devices) = pcap-find-all-devices(buffer-offset(errbuf, 0));
+//    format-out("errcode %=\n", errorcode);
+    for (device = devices then device.next, while: device ~= null-pointer(<pcap-if*>))
+//      format-out("device %s %s\n", device.name, device.description);
+      if (subsequence-position(device.description, interface.interface-name))
+        open-interface(device.name);
+      end;
+    end;
+    error("Device %s not found", interface.interface-name);
+  end;
+end;
+

Modified: trunk/libraries/network-interfaces/pcap-win32.hdp
==============================================================================
--- trunk/libraries/network-interfaces/pcap-win32.hdp	(original)
+++ trunk/libraries/network-interfaces/pcap-win32.hdp	Sun Feb 24 08:43:02 2008
@@ -1,4 +1,5 @@
 library: network-interfaces
-files: pcap-library-win32
+files:	pcap-library-win32
 	pcap
+	pcap-win32
 c-libraries: wpcap.lib

Modified: trunk/libraries/network-interfaces/pcap.dylan
==============================================================================
--- trunk/libraries/network-interfaces/pcap.dylan	(original)
+++ trunk/libraries/network-interfaces/pcap.dylan	Sun Feb 24 08:43:02 2008
@@ -76,43 +76,9 @@
 define constant $ethernet-buffer-size = 1600;
 define constant $timeout = 100;
 
-define method initialize
-    (interface :: <ethernet-interface>, #next next-method, #key, #all-keys)
-  => ()
-  next-method();
-  let errbuf = make(<byte-vector>);
-  block(ret)
-    local method open-interface (name)
-//            format-out("trying interface %s\n", name);
-            let res = pcap-open-live(name,
-                                     $ethernet-buffer-size,
-                                     if (interface.promiscuous?) 1 else 0 end,
-                                     $timeout,
-                                     buffer-offset(errbuf, 0));
-            if (res ~= null-pointer(<C-void*>))
-              interface.pcap-t := res;
-//              format-out("Opened Interface %s\n", name);
-              ret();
-            end;
-          end;
-    //open-interface(interface.interface-name);
-
-//    format-out("trying pcap-find-alldevices\n");
-    let (errorcode, devices) = pcap-find-all-devices(buffer-offset(errbuf, 0));
-//    format-out("errcode %=\n", errorcode);
-    for (device = devices then device.next, while: device ~= null-pointer(<pcap-if*>))
-//      format-out("device %s %s\n", device.name, device.description);
-      if (subsequence-position(device.description, interface.interface-name))
-        open-interface(device.name);
-      end;
-    end;
-    error("Device %s not found", interface.interface-name);
-  end;
-end;
-
 define class <device> (<object>)
   constant slot device-name :: <string>, required-init-keyword: name:;
-  constant slot device-cidrs :: <collection>, required-init-keyword: cidrs:;
+  constant slot device-cidrs :: <collection>, init-keyword: cidrs:;
 end;
 
 define method print-object (dev :: <device>, stream :: <stream>) => ()
@@ -122,59 +88,6 @@
   format-to-string("%s (%=)", dev.device-name, dev.device-cidrs);
 end;
 
-define method find-all-devices () => (res :: <collection>)
-  let res = make(<stretchy-vector>);
-  let errbuf = make(<byte-vector>);
-  let (errorcode, devices) = pcap-find-all-devices(buffer-offset(errbuf, 0));
-  for (device = devices then device.next, while: device ~= null-pointer(<pcap-if*>))
-    let cidrs = make(<stretchy-vector>);
-    for (ele = device.addresses then ele.next, while: ele ~= null-pointer(<pcap-addr*>))
-//      format-out("GOT as address %= ", ele.address.sa-family-value);
-      local method printme (x)
-              for (f from 2 below 6)
-                //format-out("%X ", sa-data-array(x, f));
-              end;
-              //format-out(" ");
-            end;
-      printme(ele.address);
-      if (null-pointer(<sockaddr*>) ~= ele.netmask)
-       // format-out("netmask "); printme(ele.netmask);
-      end;
-      if (null-pointer(<sockaddr*>) ~= ele.broadcast-address)
-        //format-out("broadcast-address "); printme(ele.broadcast-address);
-      end;
-      if (null-pointer(<sockaddr*>) ~= ele.destination-address)
-        //format-out("destination-address "); printme(ele.destination-address);
-      end;
-      local method get-address (foo :: <pcap-addr*>)
-              let res = make(<stretchy-vector-subsequence>, size: 4);
-              for (i from 2 below 6)
-                res[i - 2] := as(<byte>, sa-data-array(foo.address, i));
-              end;
-              make(<ipv4-address>, data: res);
-            end;
-      local method get-netmask (foo :: <pcap-addr*>)
-              let res = make(<stretchy-vector>);
-              for (i from 2 below 6)
-                add!(res, sa-data-array(foo.netmask, i));
-              end;
-              netmask-from-byte-vector(res);
-            end;
-
-      //format-out("\n");
-      add!(cidrs, concatenate(as(<string>, get-address(ele)), "/", integer-to-string(get-netmask(ele))));
-    end;
-
-    let str = make(<string>, size: device.description.size);
-    //XXX: isn't there a convinience function for converting <C-string> to <string>
-    //XXX: generate a real object, and also return device-name
-    for (ele in device.description, i from 0)
-      str[i] := ele;
-    end;
-    add!(res, make(<device>, name: str, cidrs: cidrs))
-  end;
-  res;
-end;
  
 
 define constant <sockaddr*> = <LPSOCKADDR>;

Modified: trunk/libraries/registry/x86-freebsd/network-interfaces
==============================================================================
--- trunk/libraries/registry/x86-freebsd/network-interfaces	(original)
+++ trunk/libraries/registry/x86-freebsd/network-interfaces	Sun Feb 24 08:43:02 2008
@@ -1 +1 @@
-abstract://dylan/network-interfaces/pcap.hdp
+abstract://dylan/network-interfaces/pcap-unix.hdp



More information about the chatter mailing list