12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

set intf [$pf1 open readonly]puts "pf1 configured on interface $intf"set filt "(ip src host foobar) <strong>and</strong> (not ether broadcast)"set nbytes [$pf1 filter $filt]puts "filter compiled to $nbytes bytes"puts "drops: [$pf1 pdrops], pkts: [$pf1 pkts]"This example first determines the name of the local system which will be used in co<strong>ns</strong>tructing a BPF/libpcap filter predic<strong>at</strong>e.<strong>The</strong> new Network/Pcap/Live call cre<strong>at</strong>es an i<strong>ns</strong>tance of the pcap network object for capturing live traffic. <strong>The</strong>promisc_ flag tells the packet filter whether it should configure the undelying interface in promiscuous mode (if it is supported).<strong>The</strong> open call activ<strong>at</strong>es the packet filter, <strong>and</strong> may be specified as readonly, writeonly, or readwrite. Itretur<strong>ns</strong> the name of the network interface the filter is associ<strong>at</strong>ed with. <strong>The</strong> open call takes an optional extra parameter (notillustr<strong>at</strong>ed) indic<strong>at</strong>ing the name of the interface to use in cases where a particular interface should be used on a multi-homedhost. <strong>The</strong> filter method is used to cre<strong>at</strong>e a BPF-comp<strong>at</strong>ible packet filter program which is loaded into the underlying BPFmachinery. <strong>The</strong> filter method retur<strong>ns</strong> the number of bytes used by the filter predic<strong>at</strong>e. <strong>The</strong> pdrops <strong>and</strong> pkts methodsare available for st<strong>at</strong>istics collection. <strong>The</strong>y report the number of packets dropped by the filter due to buffer exhaustion <strong>and</strong> thetotal number of packets th<strong>at</strong> arrived <strong>at</strong> the filter, respectively (not the number of packets accepted by the filter).44.4.2 IP Network Objects<strong>The</strong>se objects provide raw access to the IP protocol, <strong>and</strong> allow the complete specific<strong>at</strong>ion of IP packets (including header).<strong>The</strong> implement<strong>at</strong>ion makes use of a raw socket. In most UNIX systems, access to such sockets requires super-user privileges.In addition, the interface to raw sockets is somewh<strong>at</strong> less st<strong>and</strong>ard than other types of sockets. <strong>The</strong> class Network/IPprovides raw IP functionality plus a base class from which other network objects implementing higher-layer protocols arederived.Configur<strong>at</strong>ion <strong>The</strong> configur<strong>at</strong>ion of a raw IP network object is compar<strong>at</strong>ively simple. <strong>The</strong> object is not associ<strong>at</strong>ed withany particular physical network interface; the system’s IP routing capability will be used to emit the specified d<strong>at</strong>agram outwhichever interface is required to reach the destin<strong>at</strong>ion address contained in the header. Here is an example of configuring anIP object:set ipnet [new Network/IP]$ipnet open writeonly...$ipnet close<strong>The</strong> IP network object supports only the open <strong>and</strong> close methods.44.4.3 IP/UDP Network Objects<strong>The</strong>se objects provide access to the system’s UDP implement<strong>at</strong>ion along with support for IP multicast group membershipoper<strong>at</strong>io<strong>ns</strong>. IN PROGRESS386

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!