[Gd-chatter] r11031 - in trunk/libraries: gui-sniffer pcap protocols
hannes at gwydiondylan.org
hannes at gwydiondylan.org
Wed Dec 6 01:54:32 CET 2006
Author: hannes
Date: Wed Dec 6 01:54:29 2006
New Revision: 11031
Modified:
trunk/libraries/gui-sniffer/gui-sniffer.dylan
trunk/libraries/gui-sniffer/library.dylan
trunk/libraries/gui-sniffer/module.dylan
trunk/libraries/pcap/library.dylan
trunk/libraries/pcap/pcap.dylan
trunk/libraries/protocols/cidr.dylan
trunk/libraries/protocols/protocols-library.dylan
Log:
Bug: 7299
*display network config of interfaces in the gui when selecting an interface
Modified: trunk/libraries/gui-sniffer/gui-sniffer.dylan
==============================================================================
--- trunk/libraries/gui-sniffer/gui-sniffer.dylan (original)
+++ trunk/libraries/gui-sniffer/gui-sniffer.dylan Wed Dec 6 01:54:29 2006
@@ -777,7 +777,7 @@
(#key title = "Please specify interface", owner)
=> (interface-name :: false-or(<string>), promiscuous? :: <boolean>)
let devices = find-all-devices();
- let interfaces = make(<list-box>, items: devices);
+ let interfaces = make(<list-box>, items: map(curry(as, <string>), devices));
let promiscuous? = make(<check-box>, items: #("promiscuous"), selection: #[0]);
let interface-selection-dialog
= make(<dialog-frame>,
Modified: trunk/libraries/gui-sniffer/library.dylan
==============================================================================
--- trunk/libraries/gui-sniffer/library.dylan (original)
+++ trunk/libraries/gui-sniffer/library.dylan Wed Dec 6 01:54:29 2006
@@ -14,6 +14,6 @@
use packetizer;
use flow;
use network-flow;
- use interfaces;
use protocols;
+ use interfaces;
end library gui-sniffer;
Modified: trunk/libraries/gui-sniffer/module.dylan
==============================================================================
--- trunk/libraries/gui-sniffer/module.dylan (original)
+++ trunk/libraries/gui-sniffer/module.dylan Wed Dec 6 01:54:29 2006
@@ -31,7 +31,6 @@
use packet-filter;
use network-flow;
use flow;
- use interfaces;
use hex-view;
use ethernet, import: { <ethernet-frame> };
use pcap, import: { make-unix-time, <pcap-packet>, decode-unix-time, timestamp };
@@ -39,4 +38,5 @@
use ipv4, import: { <ipv4-frame>, <tcp-frame>, <udp-frame>, source-port, destination-port, acknowledgement-number };
// Add binding exports here.
use deuce-internals, prefix: "deuce/";
+ use interfaces;
end module gui-sniffer;
Modified: trunk/libraries/pcap/library.dylan
==============================================================================
--- trunk/libraries/pcap/library.dylan (original)
+++ trunk/libraries/pcap/library.dylan Wed Dec 6 01:54:29 2006
@@ -9,9 +9,10 @@
use collection-extensions;
use functional-dylan;
use flow;
+ use network;
use packetizer;
- use protocols, import: { ethernet };
+ use protocols, import: { ethernet, ipv4, cidr };
export interfaces;
end;
@@ -19,6 +20,7 @@
define module interfaces
use common-dylan;
use c-ffi;
+ use winsock2;
use format-out;
use standard-io;
use subseq;
@@ -26,12 +28,17 @@
use machine-words;
use byte-vector;
use flow;
+ use print;
+ use format;
use ethernet, import: { <ethernet-frame> };
+ use ipv4, import: { <ipv4-address> };
+ use cidr, import: { <cidr>, netmask-from-byte-vector };
use packetizer,
import: { parse-frame,
<ethernet-frame>,
assemble-frame,
- packet };
+ packet,
+ <stretchy-vector-subsequence> };
export <ethernet-interface>, interface-name, running?-setter, running?, find-all-devices;
end;
Modified: trunk/libraries/pcap/pcap.dylan
==============================================================================
--- trunk/libraries/pcap/pcap.dylan (original)
+++ trunk/libraries/pcap/pcap.dylan Wed Dec 6 01:54:29 2006
@@ -3,10 +3,11 @@
copyright: (c) 2006, All rights reserved. Free for non-commercial user
+/*
define simple-C-mapped-subtype <C-buffer-offset> (<C-char*>)
export-map <machine-word>, export-function: identity;
end;
-
+*/
define method pcap-receive-callback
(interface, packet :: <pcap-packet-header*>, bytes)
let real-interface = import-c-dylan-object(interface);
@@ -57,13 +58,13 @@
result pcap-t :: <C-void*>;
c-name: "pcap_open_live";
end;
-
+/*
define C-struct <timeval>
slot tv_sec :: <C-int>;
slot tv_usec :: <C-int>;
c-name: "timeval";
end;
-
+*/
define C-struct <pcap-packet-header>
slot ts :: <timeval>;
slot caplen :: <C-int>;
@@ -109,27 +110,89 @@
end;
end;
+define class <device> (<object>)
+ constant slot device-name :: <string>, required-init-keyword: name:;
+ constant slot device-cidrs :: <collection>, required-init-keyword: cidrs:;
+end;
+
+define method print-object (dev :: <device>, stream :: <stream>) => ()
+ format(stream, "%s", as(<string>, dev));
+end;
+define method as (class == <string>, dev :: <device>) => (res :: <string>)
+ 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, str)
+ add!(res, make(<device>, name: str, cidrs: cidrs))
end;
res;
end;
+
+define constant <sockaddr*> = <LPSOCKADDR>;
+define C-struct <pcap-addr>
+ slot next :: <pcap-addr*>;
+ slot address :: <sockaddr*>;
+ slot netmask :: <sockaddr*>;
+ slot broadcast-address :: <sockaddr*>;
+ slot destination-address :: <sockaddr*>;
+ pointer-type-name: <pcap-addr*>;
+ c-name: "pcap_addr";
+end;
+
define C-struct <pcap-if>
slot next :: <pcap-if*>;
slot name :: <C-string>;
slot description :: <C-string>;
- slot addresses :: <C-void*>;
+ slot addresses :: <pcap-addr*>;
slot flags :: <C-unsigned-int>;
pointer-type-name: <pcap-if*>;
c-name: "pcap_if";
Modified: trunk/libraries/protocols/cidr.dylan
==============================================================================
--- trunk/libraries/protocols/cidr.dylan (original)
+++ trunk/libraries/protocols/cidr.dylan Wed Dec 6 01:54:29 2006
@@ -55,3 +55,31 @@
end;
res;
end;
+define constant $dec-to-netmask = make(<vector>, size: 256, fill: #f);
+begin
+ $dec-to-netmask[255] := 7;
+ $dec-to-netmask[254] := 6;
+ $dec-to-netmask[248] := 5;
+ $dec-to-netmask[240] := 4;
+ $dec-to-netmask[224] := 3;
+ $dec-to-netmask[192] := 2;
+ $dec-to-netmask[128] := 1;
+ $dec-to-netmask[0] := 0;
+end;
+
+define function netmask-from-byte-vector (bv :: <collection>) => (res :: <integer>)
+ block (ret)
+ for (ele in bv, j from 0 by 8)
+ unless (ele = 255)
+ let off = $dec-to-netmask[ele];
+ unless (off)
+ format-out("Invalid netmask, returning %d! %=\n", j, ele);
+ ret(j);
+ end;
+ ret(j + off);
+ end;
+ end;
+ 32;
+ end;
+end;
+
Modified: trunk/libraries/protocols/protocols-library.dylan
==============================================================================
--- trunk/libraries/protocols/protocols-library.dylan (original)
+++ trunk/libraries/protocols/protocols-library.dylan Wed Dec 6 01:54:29 2006
@@ -5,6 +5,7 @@
use system;
use packetizer;
use io;
+ use dylan;
export logical-link,
ethernet,
pcap,
@@ -363,16 +364,18 @@
define module cidr
- use common-dylan;
+ use dylan-extensions;
+ use common-dylan, exclude: { format-to-string };
use ipv4, import: { ipv4-address, <ipv4-address> };
use print;
use format;
+ use format-out;
use packetizer;
- use streams;
use common-extensions, exclude: { format-to-string };
export <cidr>,
cidr-network-address, cidr-netmask,
- ip-in-cidr?, broadcast-address;
+ ip-in-cidr?, broadcast-address,
+ netmask-from-byte-vector;
end;
More information about the chatter
mailing list