Modified version of ruby-pcap

git-svn-id: file:///home/svn/framework3/trunk@4107 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2006-11-06 03:05:06 +00:00
parent 568f40f308
commit a8fef97587
47 changed files with 6005 additions and 0 deletions

340
external/ruby-pcapx/COPYING vendored Normal file
View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

145
external/ruby-pcapx/ChangeLog vendored Normal file
View File

@ -0,0 +1,145 @@
2000-08-13 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* version 0.6 released.
* packet.c (packet_match): Packet#=~ added.
* Pcap.c (capture_setfilter): Filter object can be used in
Capture#setfilter.
* lib/pcaplet.rb: invoke gzip when reading /\.gz$/ file.
Pcaplet.new accept options.
* Pcap.c: implement Filter logical operation.
(filter_source): Filter#source added.
2000-08-09 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* Pcap.c (filter_new): use pcap_compile_nopcap() if available.
1999-11-08 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* version 0.5 released.
* Pcap.c: Call Check_SafeStr() before I/O operation.
* lib/pcaplet.rb: Use getopts instead of parseparg.
1999-11-05 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* Filter document added.
1999-11-04 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* Pcap.c (filter_match): datalink and caplen check.
1999-10-30 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* Pcap.c (Init_pcap): added Pcap.{lookupdev,lookupnet}.
1999-10-29 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* Pcap.c: use RTEST instead of Qtrue/Qfalse test.
1999-08-27 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* ip_packet.c (ipaddr_s_new): changed to use gethostbyname().
* icmp_packet.c: icmp_type_info lacks type 31-36 hole.
1999-08-26 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* version 0.4 released.
* ICMPPacket document added.
1999-08-25 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* udp_packet.c: UdpPacket renamed to UDPPacket.
* tcp_packet.c: TcpPacket renamed to TCPPacket.
* ip_packet.c: IpPacket renamed to IPPacket.
1999-08-24 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* icmp_packet.c: ICMP support.
1999-08-18 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* Pcap.c (Init_pcap): PcapStat is now defined as Pcap::Stat.
1999-08-17 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* ip_packet.c (setup_ip_packet): check ip_v == 4
1999-08-14 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* ip_packet.c (setup_ip_packet): ntohs must be used for ip_len.
* packet.c (Init_packet): Packet#udp? added.
1999-07-23 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* extconf.rb: --with-pcap-prefix is changed to --with-pcap-dir
1999-07-14 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* ip_packet.c (Init_ip_packet): IP address is now represented by
new class IPAddress implemented in C. IpAddress is obsolete but
remains for backward compatibility.
1999-07-11 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* Pcap.c (Init_pcap): Capture includes Enumerable.
1999-07-02 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* version 0.3.1 released.
* Pcap.c: Filter class is added.
* tcp_packet.c (tcpp_data): data length bug is fixed.
1999-06-27 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* Pcap.c (capture_loop): improved to be thread-friendly.
1999-05-24 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* version 0.3 released.
* extconf.rb: --with-pcap-prefix option added.
* changed to based on ruby-1.3.x.
1999-04-20 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* version 0.2 released.
1999-04-18 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* UdpPacket documentation added.
1999-02-08 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* udp_packet.c: UDP supprot added.
1998-12-07 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* version 0.1.1 released.
* Document about exception classes added.
* Pcap.c (CheckClass): CheckClass added.
(dumper_dump): check data-link type and caplen.
1998-12-06 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* packet.c: Packet#datalink added.
* English document added.
1998-12-01 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* version 0.1 released.

46
external/ruby-pcapx/MANIFEST vendored Normal file
View File

@ -0,0 +1,46 @@
MANIFEST
README
README.ja
COPYING
ChangeLog
extconf.rb
ruby_pcap.h
Pcap.c
packet.c
ip_packet.c
tcp_packet.c
udp_packet.c
icmp_packet.c
lib/pcap_misc.rb
lib/pcaplet.rb
examples/test.rb
examples/tcpdump.rb
examples/httpdump.rb
doc/index.html
doc/Pcap.html
doc/Capture.html
doc/Pcaplet.html
doc/Packet.html
doc/IPPacket.html
doc/TCPPacket.html
doc/UDPPacket.html
doc/ICMPPacket.html
doc/IPAddress.html
doc/Dumper.html
doc/Filter.html
doc/PcapError.html
doc/TruncatedPacket.html
doc-ja/index.html
doc-ja/Pcap.html
doc-ja/Capture.html
doc-ja/Pcaplet.html
doc-ja/Packet.html
doc-ja/IPPacket.html
doc-ja/TCPPacket.html
doc-ja/UDPPacket.html
doc-ja/ICMPPacket.html
doc-ja/IPAddress.html
doc-ja/Dumper.html
doc-ja/Filter.html
doc-ja/PcapError.html
doc-ja/TruncatedPacket.html

151
external/ruby-pcapx/Makefile vendored Normal file
View File

@ -0,0 +1,151 @@
SHELL = /bin/sh
#### Start of system configuration section. ####
srcdir = .
topdir = /usr/lib/ruby/1.8/i686-linux
hdrdir = $(topdir)
VPATH = $(srcdir):$(topdir):$(hdrdir)
prefix = $(DESTDIR)/usr
exec_prefix = $(DESTDIR)/usr
sitedir = $(DESTDIR)/usr/lib/ruby/site_ruby
rubylibdir = $(libdir)/ruby/$(ruby_version)
archdir = $(rubylibdir)/$(arch)
sbindir = $(exec_prefix)/sbin
datadir = $(DESTDIR)/usr/share
includedir = $(prefix)/include
infodir = $(DESTDIR)/usr/share/info
sysconfdir = $(DESTDIR)/etc
mandir = $(DESTDIR)/usr/share/man
libdir = $(DESTDIR)/usr/lib
sharedstatedir = $(prefix)/com
oldincludedir = $(DESTDIR)/usr/include
sitearchdir = $(sitelibdir)/$(sitearch)
bindir = $(exec_prefix)/bin
localstatedir = $(DESTDIR)/var/lib
sitelibdir = $(sitedir)/$(ruby_version)
libexecdir = $(exec_prefix)/libexec
CC = i686-pc-linux-gnu-gcc
LIBRUBY = $(LIBRUBY_SO)
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -L. -l$(RUBY_SO_NAME)
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
RUBY_EXTCONF_H =
CFLAGS = -fPIC -I/usr/local/include
INCFLAGS = -I. -I. -I/usr/lib/ruby/1.8/i686-linux -I.
CPPFLAGS = -DHAVE_HSTRERROR -DHAVE_PCAP_H -DHAVE_PCAP_COMPILE_NOPCAP
CXXFLAGS = $(CFLAGS)
DLDFLAGS = -L/usr/local/lib
LDSHARED = $(CC) -shared
AR = i686-pc-linux-gnu-ar
EXEEXT =
RUBY_INSTALL_NAME = ruby18
RUBY_SO_NAME = ruby18
arch = i686-linux
sitearch = i686-linux
ruby_version = 1.8
ruby = /usr/bin/ruby18
RUBY = $(ruby)
RM = rm -f
MAKEDIRS = mkdir -p
INSTALL = /bin/install -c
INSTALL_PROG = $(INSTALL) -m 0755
INSTALL_DATA = $(INSTALL) -m 644
COPY = cp
#### End of system configuration section. ####
preload =
libpath = $(libdir)
LIBPATH = -L'$(libdir)' -Wl,-R'$(libdir)'
DEFFILE =
CLEANFILES =
DISTCLEANFILES =
extout =
extout_prefix =
target_prefix =
LOCAL_LIBS =
LIBS = $(LIBRUBYARG_SHARED) -lpcap -ldl -lcrypt -lm -lc
SRCS = Pcap.c packet.c ip_packet.c tcp_packet.c udp_packet.c icmp_packet.c
OBJS = Pcap.o packet.o ip_packet.o tcp_packet.o udp_packet.o icmp_packet.o
TARGET = pcap
DLLIB = $(TARGET).so
EXTSTATIC =
STATIC_LIB =
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
TARGET_SO = $(DLLIB)
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
all: $(DLLIB)
static: $(STATIC_LIB)
clean:
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
distclean: clean
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
realclean: distclean
install: install-so install-rb
install-so: $(RUBYARCHDIR)
install-so: $(RUBYARCHDIR)/$(DLLIB)
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
install-rb: pre-install-rb install-rb-default
install-rb-default: pre-install-rb-default
pre-install-rb: Makefile
pre-install-rb-default: Makefile
pre-install-rb-default: $(RUBYLIBDIR)
install-rb-default: $(RUBYLIBDIR)/pcap_misc.rb
$(RUBYLIBDIR)/pcap_misc.rb: $(srcdir)/lib/pcap_misc.rb
$(INSTALL_DATA) $(srcdir)/lib/pcap_misc.rb $(@D)
install-rb-default: $(RUBYLIBDIR)/pcaplet.rb
$(RUBYLIBDIR)/pcaplet.rb: $(srcdir)/lib/pcaplet.rb
$(INSTALL_DATA) $(srcdir)/lib/pcaplet.rb $(@D)
$(RUBYARCHDIR):
$(MAKEDIRS) $@
$(RUBYLIBDIR):
$(MAKEDIRS) $@
site-install: site-install-so site-install-rb
site-install-so: install-so
site-install-rb: install-rb
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
.cc.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.cxx.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.cpp.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.C.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.c.o:
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
$(DLLIB): $(OBJS)
@-$(RM) $@
$(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
$(OBJS): ruby.h defines.h

796
external/ruby-pcapx/Pcap.c vendored Normal file
View File

@ -0,0 +1,796 @@
/*
* Pcap.c
*
* $Id: Pcap.c,v 1.10 2000/08/13 05:56:31 fukusima Exp $
*
* Copyright (C) 1998-2000 Masaki Fukushima
*/
#include "ruby_pcap.h"
#include "rubysig.h"
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#define DEFAULT_DATALINK DLT_EN10MB
#define DEFAULT_SNAPLEN 68
#define DEFAULT_PROMISC 1
#define DEFAULT_TO_MS 1000
static char pcap_errbuf[PCAP_ERRBUF_SIZE];
VALUE mPcap, rbpcap_convert = Qnil;
VALUE ePcapError;
VALUE eTruncatedPacket;
VALUE cFilter;
static VALUE cCapture;
static VALUE cPcapStat;
static VALUE cDumper;
struct filter_object {
char *expr;
struct bpf_program program;
int datalink;
int snaplen;
VALUE param;
VALUE optimize;
VALUE netmask;
};
#define GetFilter(obj, filter) \
Data_Get_Struct(obj, struct filter_object, filter)
static VALUE
pcap_s_lookupdev(self)
VALUE self;
{
char *dev;
dev = pcap_lookupdev(pcap_errbuf);
if (dev == NULL) {
rb_raise(ePcapError, "%s", pcap_errbuf);
}
return rb_str_new2(dev);
}
static VALUE
pcap_s_lookupnet(self, dev)
VALUE self;
VALUE dev;
{
bpf_u_int32 net, mask, m;
struct in_addr addr;
Check_Type(dev, T_STRING);
if (pcap_lookupnet(STR2CSTR(dev), &net, &mask, pcap_errbuf) == -1) {
rb_raise(ePcapError, "%s", pcap_errbuf);
}
addr.s_addr = net;
m = ntohl(mask);
return rb_ary_new3(2, new_ipaddr(&addr), UINT32_2_NUM(m));
}
static VALUE
pcap_s_convert(self)
VALUE self;
{
return rbpcap_convert;
}
static VALUE
pcap_s_convert_set(self, val)
VALUE self;
{
rbpcap_convert = val;
return Qnil;
}
/*
* Capture object
*/
struct capture_object {
pcap_t *pcap;
bpf_u_int32 netmask;
int dl_type; /* data-link type (DLT_*) */
};
static void
closed_capture()
{
rb_raise(rb_eRuntimeError, "device is already closed");
}
#define GetCapture(obj, cap) {\
Data_Get_Struct(obj, struct capture_object, cap);\
if (cap->pcap == NULL) closed_capture();\
}
/* called from GC */
static void
free_capture(cap)
struct capture_object *cap;
{
DEBUG_PRINT("free_capture");
if (cap->pcap != NULL) {
DEBUG_PRINT("closing capture");
rb_thread_fd_close(pcap_fileno(cap->pcap));
pcap_close(cap->pcap);
cap->pcap = NULL;
}
free(cap);
}
static VALUE
capture_open_live(argc, argv, class)
int argc;
VALUE *argv;
VALUE class;
{
VALUE v_device, v_snaplen, v_promisc, v_to_ms;
char *device;
int snaplen, promisc, to_ms;
int rs;
VALUE self;
struct capture_object *cap;
pcap_t *pcap;
bpf_u_int32 net, netmask;
DEBUG_PRINT("capture_open_live");
/* scan arg */
rs = rb_scan_args(argc, argv, "13", &v_device, &v_snaplen,
&v_promisc, &v_to_ms);
/* device */
Check_SafeStr(v_device);
device = RSTRING(v_device)->ptr;
/* snaplen */
if (rs >= 2) {
Check_Type(v_snaplen, T_FIXNUM);
snaplen = FIX2INT(v_snaplen);
} else {
snaplen = DEFAULT_SNAPLEN;
}
if (snaplen < 0)
rb_raise(rb_eArgError, "invalid snaplen");
/* promisc */
if (rs >= 3) {
promisc = RTEST(v_promisc);
} else {
promisc = DEFAULT_PROMISC;
}
/* to_ms */
if (rs >= 4) {
Check_Type(v_to_ms, T_FIXNUM);
to_ms = FIX2INT(v_to_ms);
} else
to_ms = DEFAULT_TO_MS;
/* open */
pcap = pcap_open_live(device, snaplen, promisc, to_ms, pcap_errbuf);
if (pcap == NULL) {
rb_raise(ePcapError, "%s", pcap_errbuf);
}
if (pcap_lookupnet(device, &net, &netmask, pcap_errbuf) == -1) {
netmask = 0;
rb_warning("cannot lookup net: %s\n", pcap_errbuf);
}
/* setup instance */
self = Data_Make_Struct(class, struct capture_object,
0, free_capture, cap);
cap->pcap = pcap;
cap->netmask = netmask;
cap->dl_type = pcap_datalink(pcap);
return self;
}
static VALUE
capture_open_offline(class, fname)
VALUE class;
VALUE fname;
{
VALUE self;
struct capture_object *cap;
pcap_t *pcap;
DEBUG_PRINT("capture_open_offline");
/* open offline */
Check_SafeStr(fname);
pcap = pcap_open_offline(RSTRING(fname)->ptr, pcap_errbuf);
if (pcap == NULL) {
rb_raise(ePcapError, "%s", pcap_errbuf);
}
/* setup instance */
self = Data_Make_Struct(class, struct capture_object,
0, free_capture, cap);
cap->pcap = pcap;
cap->netmask = 0;
cap->dl_type = pcap_datalink(pcap);
return self;
}
static VALUE
capture_close(self)
VALUE self;
{
struct capture_object *cap;
DEBUG_PRINT("capture_close");
GetCapture(self, cap);
rb_thread_fd_close(pcap_fileno(cap->pcap));
pcap_close(cap->pcap);
cap->pcap = NULL;
return Qnil;
}
static void
handler(cap, pkthdr, data)
struct capture_object *cap;
const struct pcap_pkthdr *pkthdr;
const u_char *data;
{
rb_yield(new_packet(data, pkthdr, cap->dl_type));
}
static VALUE
capture_dispatch(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
VALUE v_cnt;
int cnt;
struct capture_object *cap;
int ret;
DEBUG_PRINT("capture_dispatch");
GetCapture(self, cap);
/* scan arg */
if (rb_scan_args(argc, argv, "01", &v_cnt) >= 1) {
FIXNUM_P(v_cnt);
cnt = FIX2INT(v_cnt);
} else
cnt = -1;
TRAP_BEG;
ret = pcap_dispatch(cap->pcap, cnt, handler, (u_char *)cap);
TRAP_END;
if (ret == -1)
rb_raise(ePcapError, "dispatch: %s", pcap_geterr(cap->pcap));
return INT2FIX(ret);
}
int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *); /* pcap-int.h */
static VALUE
capture_loop(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
VALUE v_cnt;
int cnt;
struct capture_object *cap;
int ret;
DEBUG_PRINT("capture_loop");
GetCapture(self, cap);
/* scan arg */
if (rb_scan_args(argc, argv, "01", &v_cnt) >= 1) {
FIXNUM_P(v_cnt);
cnt = FIX2INT(v_cnt);
} else
cnt = -1;
#if 0
TRAP_BEG;
ret = pcap_loop(cap->pcap, cnt, handler, (u_char *)cap);
TRAP_END;
#else
if (pcap_file(cap->pcap) != NULL) {
TRAP_BEG;
ret = pcap_loop(cap->pcap, cnt, handler, (u_char *)cap);
TRAP_END;
} else {
int fd = pcap_fileno(cap->pcap);
fd_set rset;
struct timeval tm;
FD_ZERO(&rset);
tm.tv_sec = 0;
tm.tv_usec = 0;
for (;;) {
do {
FD_SET(fd, &rset);
if (select(fd+1, &rset, NULL, NULL, &tm) == 0) {
rb_thread_wait_fd(fd);
}
TRAP_BEG;
ret = pcap_read(cap->pcap, 1, handler, (u_char *)cap);
TRAP_END;
} while (ret == 0);
if (ret <= 0)
break;
if (cnt > 0) {
cnt -= ret;
if (cnt <= 0)
break;
}
}
}
#endif
return INT2FIX(ret);
}
static VALUE
capture_setfilter(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
struct capture_object *cap;
VALUE vfilter, optimize;
char *filter;
int opt;
struct bpf_program program;
DEBUG_PRINT("capture_setfilter");
GetCapture(self, cap);
/* scan arg */
if (rb_scan_args(argc, argv, "11", &vfilter, &optimize) == 1) {
optimize = Qtrue;
}
/* check arg */
if (IsKindOf(vfilter, cFilter)) {
struct filter_object *f;
GetFilter(vfilter, f);
filter = f->expr;
} else {
Check_Type(vfilter, T_STRING);
filter = RSTRING(vfilter)->ptr;
}
opt = RTEST(optimize);
/* operation */
if (pcap_compile(cap->pcap, &program, filter,
opt, cap->netmask) < 0)
rb_raise(ePcapError, "setfilter: %s", pcap_geterr(cap->pcap));
if (pcap_setfilter(cap->pcap, &program) < 0)
rb_raise(ePcapError, "setfilter: %s", pcap_geterr(cap->pcap));
return Qnil;
}
static VALUE
capture_datalink(self)
VALUE self;
{
struct capture_object *cap;
DEBUG_PRINT("capture_datalink");
GetCapture(self, cap);
return INT2NUM(pcap_datalink(cap->pcap));
}
static VALUE
capture_snapshot(self)
VALUE self;
{
struct capture_object *cap;
DEBUG_PRINT("capture_snapshot");
GetCapture(self, cap);
return INT2NUM(pcap_snapshot(cap->pcap));
}
static VALUE
capture_stats(self)
VALUE self;
{
struct capture_object *cap;
struct pcap_stat stat;
VALUE v_stat;
DEBUG_PRINT("capture_stats");
GetCapture(self, cap);
if (pcap_stats(cap->pcap, &stat) == -1)
return Qnil;
v_stat = rb_funcall(cPcapStat, rb_intern("new"), 3,
UINT2NUM(stat.ps_recv),
UINT2NUM(stat.ps_drop),
UINT2NUM(stat.ps_ifdrop));
return v_stat;
}
/*
* Dumper object
*/
struct dumper_object {
pcap_dumper_t *pcap_dumper;
int dl_type;
bpf_u_int32 snaplen;
};
static void
closed_dumper()
{
rb_raise(rb_eRuntimeError, "dumper is already closed");
}
#define GetDumper(obj, dumper) {\
Data_Get_Struct(obj, struct dumper_object, dumper);\
if (dumper->pcap_dumper == NULL) closed_dumper();\
}
/* called from GC */
static void
free_dumper(dumper)
struct dumper_object *dumper;
{
DEBUG_PRINT("free_dumper");
if (dumper->pcap_dumper != NULL) {
DEBUG_PRINT("closing dumper");
pcap_dump_close(dumper->pcap_dumper);
dumper->pcap_dumper = NULL;
}
free(dumper);
}
static VALUE
dumper_open(class, v_cap, v_fname)
VALUE class;
VALUE v_cap;
VALUE v_fname;
{
struct dumper_object *dumper;
struct capture_object *cap;
pcap_dumper_t *pcap_dumper;
VALUE self;
DEBUG_PRINT("dumper_open");
CheckClass(v_cap, cCapture);
GetCapture(v_cap, cap);
Check_SafeStr(v_fname);
pcap_dumper = pcap_dump_open(cap->pcap, RSTRING(v_fname)->ptr);
if (pcap_dumper == NULL) {
rb_raise(ePcapError, "dumper_open: %s", pcap_geterr(cap->pcap));
}
self = Data_Make_Struct(class, struct dumper_object, 0,
free_dumper, dumper);
dumper->pcap_dumper = pcap_dumper;
dumper->dl_type = cap->dl_type;
dumper->snaplen = pcap_snapshot(cap->pcap);
return self;
}
static VALUE
dumper_close(self)
VALUE self;
{
struct dumper_object *dumper;
DEBUG_PRINT("dumper_close");
GetDumper(self, dumper);
pcap_dump_close(dumper->pcap_dumper);
dumper->pcap_dumper = NULL;
return Qnil;
}
static VALUE
dumper_dump(self, v_pkt)
VALUE self;
VALUE v_pkt;
{
struct dumper_object *dumper;
struct packet_object *pkt;
DEBUG_PRINT("dumper_dump");
GetDumper(self, dumper);
CheckClass(v_pkt, cPacket);
GetPacket(v_pkt, pkt);
if (pkt->hdr.dl_type != dumper->dl_type)
rb_raise(rb_eArgError, "Cannot dump this packet: data-link type mismatch");
if (pkt->hdr.pkthdr.caplen > dumper->snaplen)
rb_raise(rb_eArgError, "Cannot dump this packet: too large caplen");
pcap_dump((u_char *)dumper->pcap_dumper, &pkt->hdr.pkthdr, pkt->data);
return Qnil;
}
/*
* Filter object
*/
/* called from GC */
static void
mark_filter(filter)
struct filter_object *filter;
{
rb_gc_mark(filter->param);
rb_gc_mark(filter->optimize);
rb_gc_mark(filter->netmask);
}
static void
free_filter(filter)
struct filter_object *filter;
{
free(filter->expr);
free(filter);
/*
* This cause memory leak because filter->program hold some memory.
* We overlook it because libpcap does not implement pcap_freecode().
*/
}
static VALUE
filter_new(argc, argv, class)
int argc;
VALUE *argv;
VALUE class;
{
VALUE self, v_expr, v_optimize, v_capture, v_netmask;
struct filter_object *filter;
struct capture_object *capture;
pcap_t *pcap;
char *expr;
int n, optimize, snaplen, linktype;
bpf_u_int32 netmask;
n = rb_scan_args(argc, argv, "13", &v_expr, &v_capture,
&v_optimize, &v_netmask);
/* filter expression */
Check_Type(v_expr, T_STRING);
expr = STR2CSTR(v_expr);
/* capture object */
if (IsKindOf(v_capture, cCapture)) {
CheckClass(v_capture, cCapture);
GetCapture(v_capture, capture);
pcap = capture->pcap;
} else if (NIL_P(v_capture)) {
/* assume most common case */
snaplen = DEFAULT_SNAPLEN;
linktype = DEFAULT_DATALINK;
pcap = 0;
} else {
snaplen = NUM2INT(rb_funcall(v_capture, rb_intern("[]"), 1, INT2FIX(0)));
linktype = NUM2INT(rb_funcall(v_capture, rb_intern("[]"), 1, INT2FIX(1)));
pcap = 0;
}
/* optimize flag */
optimize = 1;
if (n >= 3) {
optimize = RTEST(v_optimize);
}
/* netmask */
netmask = 0;
if (n >= 4) {
bpf_u_int32 mask = NUM2UINT(v_netmask);
netmask = htonl(mask);
}
filter = (struct filter_object *)xmalloc(sizeof(struct filter_object));
if (pcap) {
if (pcap_compile(pcap, &filter->program, expr, optimize, netmask) < 0)
rb_raise(ePcapError, "%s", pcap_geterr(pcap));
filter->datalink = pcap_datalink(pcap);
filter->snaplen = pcap_snapshot(pcap);
} else {
#ifdef HAVE_PCAP_COMPILE_NOPCAP
if (pcap_compile_nopcap(snaplen, linktype, &filter->program, expr, optimize, netmask) < 0)
/* libpcap-0.5 provides no error report for pcap_compile_nopcap */
rb_raise(ePcapError, "pcap_compile_nopcap error");
filter->datalink = linktype;
filter->snaplen = snaplen;
#else
rb_raise(rb_eArgError, "pcap_compile_nopcap needs libpcap-0.5 or later");
#endif
}
self = Data_Wrap_Struct(class, mark_filter, free_filter, filter);
filter->expr = strdup(expr);
filter->param = v_capture;
filter->optimize = optimize ? Qtrue : Qfalse;
filter->netmask = INT2NUM(ntohl(netmask));
return self;
}
VALUE
filter_match(self, v_pkt)
VALUE self, v_pkt;
{
struct filter_object *filter;
struct packet_object *pkt;
struct pcap_pkthdr *h;
GetFilter(self, filter);
CheckClass(v_pkt, cPacket);
GetPacket(v_pkt, pkt);
h = &pkt->hdr.pkthdr;
if (filter->datalink != pkt->hdr.dl_type)
rb_raise(rb_eRuntimeError, "Incompatible datalink type");
if (filter->snaplen < h->caplen)
rb_raise(rb_eRuntimeError, "Incompatible snaplen");
if (bpf_filter(filter->program.bf_insns, pkt->data, h->len, h->caplen))
return Qtrue;
else
return Qfalse;
}
static VALUE
filter_source(self)
VALUE self;
{
struct filter_object *filter;
GetFilter(self, filter);
return rb_str_new2(filter->expr);
}
static VALUE
new_filter(expr, param, optimize, netmask)
char *expr;
VALUE param, optimize, netmask;
{
return rb_funcall(cFilter,
rb_intern("new"), 4,
rb_str_new2(expr), param, optimize, netmask);
}
static VALUE
filter_or(self, other)
VALUE self, other;
{
struct filter_object *filter, *filter2;
char *expr;
CheckClass(other, cFilter);
GetFilter(self, filter);
GetFilter(other, filter2);
expr = ALLOCA_N(char, strlen(filter->expr) + strlen(filter2->expr) + 16);
sprintf(expr, "( %s ) or ( %s )", filter->expr, filter2->expr);
return new_filter(expr, filter->param, filter->optimize, filter->netmask);
}
static VALUE
filter_and(self, other)
VALUE self, other;
{
struct filter_object *filter, *filter2;
char *expr;
CheckClass(other, cFilter);
GetFilter(self, filter);
GetFilter(other, filter2);
expr = ALLOCA_N(char, strlen(filter->expr) + strlen(filter2->expr) + 16);
sprintf(expr, "( %s ) and ( %s )", filter->expr, filter2->expr);
return new_filter(expr, filter->param, filter->optimize, filter->netmask);
}
static VALUE
filter_not(self)
VALUE self;
{
struct filter_object *filter;
char *expr;
GetFilter(self, filter);
expr = ALLOCA_N(char, strlen(filter->expr) + 16);
sprintf(expr, "not ( %s )", filter->expr);
return new_filter(expr, filter->param, filter->optimize, filter->netmask);
}
/*
* Class definition
*/
void
Init_pcap(void)
{
DEBUG_PRINT("Init_pcap");
/* define module Pcap */
mPcap = rb_define_module("Pcap");
rb_define_module_function(mPcap, "lookupdev", pcap_s_lookupdev, 0);
rb_define_module_function(mPcap, "lookupnet", pcap_s_lookupnet, 1);
rb_global_variable(&rbpcap_convert);
rb_define_singleton_method(mPcap, "convert?", pcap_s_convert, 0);
rb_define_singleton_method(mPcap, "convert=", pcap_s_convert_set, 1);
rb_define_const(mPcap, "DLT_NULL", INT2NUM(DLT_NULL));
rb_define_const(mPcap, "DLT_EN10MB", INT2NUM(DLT_EN10MB));
rb_define_const(mPcap, "DLT_EN3MB", INT2NUM(DLT_EN3MB));
rb_define_const(mPcap, "DLT_AX25", INT2NUM(DLT_AX25));
rb_define_const(mPcap, "DLT_PRONET", INT2NUM(DLT_PRONET));
rb_define_const(mPcap, "DLT_CHAOS", INT2NUM(DLT_CHAOS));
rb_define_const(mPcap, "DLT_IEEE802", INT2NUM(DLT_IEEE802));
rb_define_const(mPcap, "DLT_ARCNET", INT2NUM(DLT_ARCNET));
rb_define_const(mPcap, "DLT_SLIP", INT2NUM(DLT_SLIP));
rb_define_const(mPcap, "DLT_PPP", INT2NUM(DLT_PPP));
rb_define_const(mPcap, "DLT_FDDI", INT2NUM(DLT_FDDI));
rb_define_const(mPcap, "DLT_ATM_RFC1483", INT2NUM(DLT_ATM_RFC1483));
#ifdef DLT_RAW
rb_define_const(mPcap, "DLT_RAW", INT2NUM(DLT_RAW));
rb_define_const(mPcap, "DLT_SLIP_BSDOS", INT2NUM(DLT_SLIP_BSDOS));
rb_define_const(mPcap, "DLT_PPP_BSDOS", INT2NUM(DLT_PPP_BSDOS));
#endif
/* define class Capture */
cCapture = rb_define_class_under(mPcap, "Capture", rb_cObject);
rb_include_module(cCapture, rb_mEnumerable);
rb_define_singleton_method(cCapture, "open_live", capture_open_live, -1);
rb_define_singleton_method(cCapture, "open_offline", capture_open_offline, 1);
rb_define_method(cCapture, "close", capture_close, 0);
rb_define_method(cCapture, "dispatch", capture_dispatch, -1);
rb_define_method(cCapture, "loop", capture_loop, -1);
rb_define_method(cCapture, "each_packet", capture_loop, -1);
rb_define_method(cCapture, "each", capture_loop, -1);
rb_define_method(cCapture, "setfilter", capture_setfilter, -1);
rb_define_method(cCapture, "datalink", capture_datalink, 0);
rb_define_method(cCapture, "snapshot", capture_snapshot, 0);
rb_define_method(cCapture, "snaplen", capture_snapshot, 0);
rb_define_method(cCapture, "stats", capture_stats, 0);
/* define class Dumper */
cDumper = rb_define_class_under(mPcap, "Dumper", rb_cObject);
rb_define_singleton_method(cDumper, "open", dumper_open, 2);
rb_define_method(cDumper, "close", dumper_close, 0);
rb_define_method(cDumper, "dump", dumper_dump, 1);
/* define class Filter */
cFilter = rb_define_class_under(mPcap, "Filter", rb_cObject);
rb_define_singleton_method(cFilter, "new", filter_new, -1);
rb_define_singleton_method(cFilter, "compile", filter_new, -1);
rb_define_method(cFilter, "=~", filter_match, 1);
rb_define_method(cFilter, "===", filter_match, 1);
rb_define_method(cFilter, "source", filter_source, 0);
rb_define_method(cFilter, "|", filter_or, 1);
rb_define_method(cFilter, "&", filter_and, 1);
rb_define_method(cFilter, "~@", filter_not, 0);
/*rb_define_method(cFilter, "&", filter_and, 1);*/
/* define class PcapStat */
cPcapStat = rb_funcall(rb_cStruct, rb_intern("new"), 4,
Qnil,
INT2NUM(rb_intern("recv")),
INT2NUM(rb_intern("drop")),
INT2NUM(rb_intern("ifdrop")));
rb_define_const(mPcap, "Stat", cPcapStat);
/* define exception classes */
ePcapError = rb_define_class_under(mPcap, "PcapError", rb_eStandardError);
eTruncatedPacket = rb_define_class_under(mPcap, "TruncatedPacket", ePcapError);
Init_packet();
rb_f_require(Qnil, rb_str_new2("pcap_misc"));
}

56
external/ruby-pcapx/README vendored Normal file
View File

@ -0,0 +1,56 @@
This is a modified version of Masaki Fukushima's ruby-pcap module.
=========================
= README from ruby-pcap =
=========================
* Introduction
ruby-pcap is a ruby extension to LBL libpcap (Packet Capture library).
This library also includes classes to access TCP/IP header.
* Installation
Requirements:
- ruby-1.4.x
- libpcap (http://www.tcpdump.org/)
Compile:
If ruby supports dynamic link of extension module on your OS,
following commands will install ruby-pcap.
ruby extconf.rb [options]
make
make install
You can specify options when you run 'ruby extconf.rb':
`--with-pcap-dir=PREFIX'
Directory where libpcap is installed. Default is '/usr/local'.
If dynamic link isn't available, you can link ruby-pcap statically
with ruby. Extract ruby-pcap under the directory 'ext' in ruby source
tree, then build ruby.
* Usage
See the documentation under the directory 'doc'.
Directory 'examples' contains some simple scripts.
* Author
Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
ruby-pcap is copyrighted free software by Masaki Fukushima.
You can redistribute it and/or modify it under the terms of
the GPL (GNU GENERAL PUBLIC LICENSE). See COPYING file about GPL.
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. See the GPL for
more details.

147
external/ruby-pcapx/doc-ja/Capture.html vendored Normal file
View File

@ -0,0 +1,147 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Capture</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Capture</H1></DT>
<DD>
パケットキャプチャを表すオブジェクト
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/ja/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>インクルードしているモジュール:</H2></DT>
<DL>
<DT><A HREF="http://www.ruby-lang.org/ja/man-1.4/Enum.html"><CODE>Enumerable</CODE></A></DT>
</DL>
<DT><H2>クラスメソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".open_live"><CODE>open_live(<var>device</var>[, <var>snaplen</var>[, <var>promisc</var>[, <var>to_ms</var>]]])</CODE></A>
<DD>
<p>
デバイスをオープンして <CODE>Capture</CODE> オブジェクトを返
します。
<VAR>snaplen</VAR>, <VAR>promisc</VAR>,
<VAR>to_ms</VAR> のデフォルト値はそれぞれ 68 オクテット,
<CODE>true</CODE>, 1000 ミリ秒です。
</p>
<DT>
<A NAME=".open_offline"><CODE>open_offline(<var>filename</var>)</CODE></A>
<DD>
<p>
<VAR>filename</VAR> で指定されたファイルをオープンして
<CODE>Capture</CODE>オブジェクトを返します。
</p>
</DL>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="close"><CODE>close</CODE></A>
<DD>
<p>
<CODE>Capture</CODE>オブジェクトをクローズします。
</p>
<DT>
<A NAME="datalink"><CODE>datalink</CODE></A>
<DD>
<p>
データリンクのタイプを表す整数を返します。
(<A HREF="Pcap.html#::DLT_EN10MB"><CODE>DLT_EN10MB</CODE></A> 等)
</p>
<DT>
<A NAME="dispatch"><CODE>dispatch([<var>count</var>]) {|<var>packet</var>|...}</CODE></A>
<DD>
<p>
<P>
各パケットに対して繰り返します。ブロックには
<A HREF="Packet.html"><CODE>Packet</CODE></A>かそのサブクラスのインスタンスが渡されます。
</P>
<P>
<VAR>count</VAR> には処理するパケットの最大数を指定します。
<VAR>count</VAR> に -1 を指定するとバッファに入っているパ
ケット全てを処理します。<VAR>count</VAR> に 0 を指定すると
エラーかファイルの終わりかタイムアウトに達するまでパケット
を処理します。
<VAR>count</VAR> のデフォルト値は -1 です。
</P>
</p>
<DT>
<A NAME="each_packet"><CODE>each_packet([<var>count</var>]) {|<var>packet</var>|...}</CODE></A>
<DD>
<DT>
<A NAME="each"><CODE>each([<var>count</var>]) {|<var>packet</var>|...}</CODE></A>
<DD>
<DT>
<A NAME="loop"><CODE>loop([<var>count</var>]) {|<var>packet</var>|...}</CODE></A>
<DD>
<p>
<P>
各パケットに対して繰り返します。ブロックには
<A HREF="Packet.html"><CODE>Packet</CODE></A>かそのサブクラスのインスタンスが渡されます。
</P>
<P>
<VAR>count</VAR> には処理するパケットの最大数を指定します。
<VAR>count</VAR> に負の数を指定するとエラーかファイルの終わ
りに達するまでパケットを処理します。<VAR>count</VAR> のデフォ
ルト値は -1 です。
</P>
</p>
<DT>
<A NAME="snapshot"><CODE>snapshot</CODE></A>
<DD>
<DT>
<A NAME="snaplen"><CODE>snaplen</CODE></A>
<DD>
<p>
snapshot の長さを返します。
</p>
<DT>
<A NAME="setfilter"><CODE>setfilter(<var>filter</var>[, <var>optimize</var>])</CODE></A>
<DD>
<p>
<VAR>filter</VAR> で指定された文字列、または<A HREF="Filter.html"><CODE>Filter</CODE></A>
フィルタとして設定します。
<VAR>optimize</VAR><CODE>true</CODE> の場合は最適化を行
います。<VAR>optimize</VAR> のデフォルト値は
<CODE>true</CODE> です。
</p>
<DT>
<A NAME="stats"><CODE>stats</CODE></A>
<DD>
<p>
パケットキャプチャについての統計を含む <A HREF="http://www.ruby-lang.org/ja/man-1.4/Struct.html"><CODE>Struct</CODE></A>
を返します。構造体は以下のメンバを持ちます。
<BLOCKQUOTE>
<DL COMPACT>
<DT><CODE>recv</CODE></DT><DD>受信したパケットの数</DD><DT><CODE>drop</CODE></DT><DD>取りこぼしたしたパケットの数</DD></DL>
</BLOCKQUOTE>
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

54
external/ruby-pcapx/doc-ja/Dumper.html vendored Normal file
View File

@ -0,0 +1,54 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Dumper</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Dumper</H1></DT>
<DD>
パケットを tcpdump 形式のファイルに書き出すクラス。生成したファイルは
tcpdump や<A HREF="Capture.html#.open_offline"><CODE>Capture.open_offline</CODE></A>を使って読むことができます。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/ja/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>クラスメソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".open"><CODE>open(<var>capture</var>, <var>filename</var>)</CODE></A>
<DD>
<p>
<VAR>capture</VAR>から取り込んだパケットを
<VAR>filename</VAR>に書き出すための<CODE>Dumper</CODE>を返し
ます。
</p>
</DL>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="close"><CODE>close</CODE></A>
<DD>
<p>
<CODE>Dumper</CODE>オブジェクトをクローズします。
</p>
<DT>
<A NAME="dump"><CODE>dump(<var>packet</var>)</CODE></A>
<DD>
<p>
<VAR>packet</VAR>をこの<CODE>Dumper</CODE>に書き出します。
<VAR>packet</VAR>はこの<CODE>Dumper</CODE>をオープンする時に
指定した<A HREF="Capture.html"><CODE>Capture</CODE></A>から取り込まれたものでなければなりま
せん。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

112
external/ruby-pcapx/doc-ja/Filter.html vendored Normal file
View File

@ -0,0 +1,112 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Filter</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Filter</H1></DT>
<DD>
<CODE>Filter</CODE> はパケットが、ある条件にマッチするかど
うかを判定します。<CODE>Filter</CODE> は実際には
<CODE>bpf_program</CODE> へのラッパーとして作られています。
フィルタの記述方法に関しては <CODE>tcpdump(1)</CODE>
を参照して下さい。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/ja/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>クラスメソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".compile"><CODE>compile(<var>expr</var>, <var>capture</var>[, <var>optimize</var>[, <var>netmask</var>]])</CODE></A>
<DD>
<DT>
<A NAME=".new"><CODE>new(<var>expr</var>, <var>capture</var>[, <var>optimize</var>[, <var>netmask</var>]])</CODE></A>
<DD>
<p>
<P>
<CODE>Filter</CODE>オブジェクトを生成します。
<VAR>expr</VAR> はフィルタの文字列です。<VAR>capture</VAR>
<A HREF="Capture.html"><CODE>Capture</CODE></A> オブジェクトです。<VAR>optimize</VAR>
で最適化を行うかどうかを制御します。
<VAR>netmask</VAR> によりローカルネットのネットマスク
を指定します。
</P>
<P>
生成された <CODE>Filter</CODE><VAR>capture</VAR>
から取り込まれたパケットに対してのみ適用できます。
</P>
<P>
<A HREF="http://www.tcpdump.org/"><CODE>libpcap-0.5以降</CODE></A>
を使用している場合には <VAR>capture</VAR>
の部分に、以下の値を指定することもできます。
<BLOCKQUOTE>
<DL COMPACT>
<DT><CODE>[snaplen, datalink]</CODE></DT><DD>配列で必要なパラメータを直接与える</DD><DT>省略 (または<CODE>nil</CODE>)</DT><DD>Ethernetでのデフォルトとみなす
(<CODE>[68, <A HREF="Pcap.html#::DLT_EN10MB"><CODE>DLT_EN10MB</CODE></A>]</CODE>)
</DD></DL>
</BLOCKQUOTE>
</P>
</p>
</DL>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="==="><CODE>self === <var>packet</var></CODE></A>
<DD>
<DT>
<A NAME="=~"><CODE>self =~ <var>packet</var></CODE></A>
<DD>
<p>
<VAR>packet</VAR> がこのフィルタにマッチすればtrueを返
します。
</p>
<DT>
<A NAME="~self"><CODE>~ self</CODE></A>
<DD>
<p>
<CODE>self</CODE>ではない」という条件を表
<CODE>Filter</CODE>を返します。
</p>
<DT>
<A NAME="|"><CODE>self | <var>other</var></CODE></A>
<DD>
<p>
<CODE>self</CODE>または<VAR>other</VAR> 」という条件を表
<CODE>Filter</CODE>を返します。
</p>
<DT>
<A NAME="&amp;"><CODE>self &amp; <var>other</var></CODE></A>
<DD>
<p>
<CODE>self</CODE>かつ<VAR>other</VAR> 」という条件を表
<CODE>Filter</CODE>を返します。
</p>
<DT>
<A NAME="source"><CODE>source</CODE></A>
<DD>
<p>
フィルタの元となった文字列を返します。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

View File

@ -0,0 +1,189 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>ICMPPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>ICMPPacket</H1></DT>
<DD>
<P>
ICMPメッセージを含むパケット。
</P>
<P>
ICMPメッセージのフォーマットはICMPタイプによって異なりま
す。そのため特定のICMPタイプのパケットにしか存在しないフィー
ルドがあります。存在しないフィールドにアクセスしようとす
ると例外が発生します。
</P>
<P>
どのICMPタイプに対しても有効なフィールドは type, code,
cksum です。
</P>
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="IPPacket.html"><CODE>IPPacket</CODE></A></DT></DL></DD>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="icmp_cksum"><CODE>icmp_cksum</CODE></A>
<DD>
<p>
ICMPチェックサムを返します。
</p>
<DT>
<A NAME="icmp_code"><CODE>icmp_code</CODE></A>
<DD>
<p>
ICMPコードを返します。
</p>
<DT>
<A NAME="icmp_data"><CODE>icmp_data</CODE></A>
<DD>
<p>
ICMP_ECHO/ICMP_ECHOREPLYメッセージのデータ部分を
<A HREF="http://www.ruby-lang.org/ja/man-1.4/String.html"><CODE>String</CODE></A>として返します。
</p>
<DT>
<A NAME="icmp_gwaddr"><CODE>icmp_gwaddr</CODE></A>
<DD>
<p>
ICMP_REDIRECTメッセージのゲートウェイアドレスを
<A HREF="IPAddress.html"><CODE>IPAddress</CODE></A>として返します。
</p>
<DT>
<A NAME="icmp_id"><CODE>icmp_id</CODE></A>
<DD>
<p>
識別子を返します。
</p>
<DT>
<A NAME="icmp_ip"><CODE>icmp_ip</CODE></A>
<DD>
<p>
元のIPデータグラムを<A HREF="IPPacket.html"><CODE>IPPacket</CODE></A>として返します。
</p>
<DT>
<A NAME="icmp_lifetime"><CODE>icmp_lifetime</CODE></A>
<DD>
<p>
ICMP_ROUTERADVERTメッセージの有効時間を返します。
</p>
<DT>
<A NAME="icmp_nextmtu"><CODE>icmp_nextmtu</CODE></A>
<DD>
<p>
ICMP_UNREACH_NEEDFRAGメッセージの Next Hop MTU を返しま
す。(参照: rfc1191)
</p>
<DT>
<A NAME="icmp_num_addrs"><CODE>icmp_num_addrs</CODE></A>
<DD>
<p>
ICMP_ROUTERADVERTメッセージのアドレス数を返します。
</p>
<DT>
<A NAME="icmp_otime"><CODE>icmp_otime</CODE></A>
<DD>
<DT>
<A NAME="icmp_rtime"><CODE>icmp_rtime</CODE></A>
<DD>
<DT>
<A NAME="icmp_ttime"><CODE>icmp_ttime</CODE></A>
<DD>
<p>
ICMP_TSTAMP/ICMP_TSTAMPREPLYメッセージのタイムス
タンプを<A HREF="http://www.ruby-lang.org/ja/man-1.4/Time.html"><CODE>Time</CODE></A>として返します。
</p>
<DT>
<A NAME="icmp_pptr"><CODE>icmp_pptr</CODE></A>
<DD>
<p>
ICMP_PARAMPROBメッセージのエラーポインタを返します。
</p>
<DT>
<A NAME="icmp_radv"><CODE>icmp_radv(<var>nth</var>)</CODE></A>
<DD>
<p>
ICMP_ROUTERADVERTメッセージの<VAR>nth</VAR>番目のアドレ
スエントリを返します。返り値は <CODE>[address,
preference]</CODE>なる2要素の配列です。
</p>
<DT>
<A NAME="icmp_seq"><CODE>icmp_seq</CODE></A>
<DD>
<p>
シーケンス番号を返します。
</p>
<DT>
<A NAME="icmp_seqle"><CODE>icmp_seqle</CODE></A>
<DD>
<p>
<P>
リトルエンディアンとして読みとったシーケンス番号を返し
ます。
</P>
<P>
多くの<CODE>ping</CODE>コマンドの実装はシーケンス番
号をホストバイトオーダーで書き込みます。したがって、
リトルエンディアンのホストから送信されたICMPメッセー
ジのシーケンス番号はリトルエンディアンになっている可
能性があります。
</P>
</p>
<DT>
<A NAME="icmp_type"><CODE>icmp_type</CODE></A>
<DD>
<p>
ICMPタイプを返します。
</p>
<DT>
<A NAME="icmp_typestr"><CODE>icmp_typestr</CODE></A>
<DD>
<p>
ICMPタイプを表す文字列を返します。(例: &quot;echo reply&quot;)
</p>
<DT>
<A NAME="icmp_wpa"><CODE>icmp_wpa</CODE></A>
<DD>
<p>
ICMP_ROUTERADVERTメッセージのアドレスエントリ長(単位:
32-bit word)を返します。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

View File

@ -0,0 +1,60 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>IPAddress</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>IPAddress</H1></DT>
<DD>
IP アドレスを表すオブジェクトです。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/ja/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="=="><CODE>self == <var>other</var></CODE></A>
<DD>
<p>
二つの IP アドレスが同じアドレスかどうかを判定します。
</p>
<DT>
<A NAME="hostname"><CODE>hostname</CODE></A>
<DD>
<p>
この IP アドレスに対応するホスト名を返します。
</p>
<DT>
<A NAME="to_i"><CODE>to_i</CODE></A>
<DD>
<p>
IP アドレスの値を整数として返します。
</p>
<DT>
<A NAME="to_num_s"><CODE>to_num_s</CODE></A>
<DD>
<p>
IP アドレスの値を表す文字列を返します。
</p>
<DT>
<A NAME="to_s"><CODE>to_s</CODE></A>
<DD>
<p>
IP アドレスの値を表す文字列かホスト名を返します。どちらを返
すかは<A HREF="Pcap.html#.convert="><CODE>Pcap.convert=</CODE></A> で設定します。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

142
external/ruby-pcapx/doc-ja/IPPacket.html vendored Normal file
View File

@ -0,0 +1,142 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>IPPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>IPPacket</H1></DT>
<DD>
IPヘッダを含むパケット。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="Packet.html"><CODE>Packet</CODE></A></DT></DL></DD>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="ip_data"><CODE>ip_data</CODE></A>
<DD>
<p>
データ部分を<A HREF="http://www.ruby-lang.org/ja/man-1.4/String.html"><CODE>String</CODE></A>として返します。
</p>
<DT>
<A NAME="ip_df?"><CODE>ip_df?</CODE></A>
<DD>
<p>
Don't Fragment ビットが立っているかどうかを返します。
</p>
<DT>
<A NAME="ip_dst"><CODE>ip_dst</CODE></A>
<DD>
<DT>
<A NAME="dst"><CODE>dst</CODE></A>
<DD>
<p>
デスティネーション IP アドレスを<A HREF="IPAddress.html"><CODE>IPAddress</CODE></A> として返します。
</p>
<DT>
<A NAME="ip_flags"><CODE>ip_flags</CODE></A>
<DD>
<p>
IP フラグビットフィールド (3 bit) の値を返します。
</p>
<DT>
<A NAME="ip_hlen"><CODE>ip_hlen</CODE></A>
<DD>
<p>
ヘッダ長を返します。(単位: 4 octets)
</p>
<DT>
<A NAME="ip_id"><CODE>ip_id</CODE></A>
<DD>
<p>
Identification フィールドの値を返します。
</p>
<DT>
<A NAME="ip_len"><CODE>ip_len</CODE></A>
<DD>
<p>
パケット長を返します。(単位: octet)
</p>
<DT>
<A NAME="ip_mf?"><CODE>ip_mf?</CODE></A>
<DD>
<p>
More Fragment ビットが立っているかどうかを返します。
</p>
<DT>
<A NAME="ip_off"><CODE>ip_off</CODE></A>
<DD>
<p>
フラグメントオフセットを返します。
</p>
<DT>
<A NAME="ip_proto"><CODE>ip_proto</CODE></A>
<DD>
<p>
プロトコルフィールドの値を返します。
</p>
<DT>
<A NAME="ip_src"><CODE>ip_src</CODE></A>
<DD>
<DT>
<A NAME="src"><CODE>src</CODE></A>
<DD>
<p>
ソース IP アドレスを<A HREF="IPAddress.html"><CODE>IPAddress</CODE></A> として返します。
</p>
<DT>
<A NAME="ip_sum"><CODE>ip_sum</CODE></A>
<DD>
<p>
チェックサムフィールドの値を返します。
</p>
<DT>
<A NAME="ip_tos"><CODE>ip_tos</CODE></A>
<DD>
<p>
TOSフィールドの値を返します。
</p>
<DT>
<A NAME="ip_ttl"><CODE>ip_ttl</CODE></A>
<DD>
<p>
TTL フィールドの値を返します。
</p>
<DT>
<A NAME="ip_ver"><CODE>ip_ver</CODE></A>
<DD>
<p>
IP バージョンフィールドの値を返します。
</p>
<DT>
<A NAME="to_s"><CODE>to_s</CODE></A>
<DD>
<p>
文字列に変換します。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

101
external/ruby-pcapx/doc-ja/Packet.html vendored Normal file
View File

@ -0,0 +1,101 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Packet</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Packet</H1></DT>
<DD>
<A HREF="Capture.html"><CODE>Capture</CODE></A>によってキャプチャされたパケットのデータ。
<CODE>Packet</CODE>、およびそのサブクラスは<A HREF="http://www.ruby-lang.org/ja/man-1.4/Marshal.html"><CODE>Marshal</CODE></A>に対応
しています。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/ja/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="caplen"><CODE>caplen</CODE></A>
<DD>
<p>
パケットのキャプチャされている部分の長さを返します。
</p>
<DT>
<A NAME="datalink"><CODE>datalink</CODE></A>
<DD>
<p>
データリンクのタイプを表す整数を返します。
(<A HREF="Pcap.html#::DLT_EN10MB"><CODE>DLT_EN10MB</CODE></A> 等)
</p>
<DT>
<A NAME="ip?"><CODE>ip?</CODE></A>
<DD>
<p>
このパケットが<A HREF="IPPacket.html"><CODE>IPPacket</CODE></A>
かそのサブクラスのインスタンスであれば
<CODE>true</CODE> を返します。
</p>
<DT>
<A NAME="len"><CODE>len</CODE></A>
<DD>
<DT>
<A NAME="length"><CODE>length</CODE></A>
<DD>
<DT>
<A NAME="size"><CODE>size</CODE></A>
<DD>
<p>
パケット全体の長さを返します。
</p>
<DT>
<A NAME="raw_data"><CODE>raw_data</CODE></A>
<DD>
<p>
このパケットの先頭からの生データを<A HREF="http://www.ruby-lang.org/ja/man-1.4/String.html"><CODE>String</CODE></A>として返します。
</p>
<DT>
<A NAME="tcp?"><CODE>tcp?</CODE></A>
<DD>
<p>
このパケットが<A HREF="TCPPacket.html"><CODE>TCPPacket</CODE></A>かそのサブクラスのインス
タンスであれば true を返します。
</p>
<DT>
<A NAME="time"><CODE>time</CODE></A>
<DD>
<p>
このパケットのタイムスタンプを <A HREF="http://www.ruby-lang.org/ja/man-1.4/Time.html"><CODE>Time</CODE></A> オブジェク
トとして返します。
</p>
<DT>
<A NAME="time_i"><CODE>time_i</CODE></A>
<DD>
<p>
このパケットのタイムスタンプを整数として返します。
</p>
<DT>
<A NAME="udp?"><CODE>udp?</CODE></A>
<DD>
<p>
このパケットが<A HREF="UDPPacket.html"><CODE>UDPPacket</CODE></A>かそのサブクラスのインス
タンスであれば true を返します。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

111
external/ruby-pcapx/doc-ja/Pcap.html vendored Normal file
View File

@ -0,0 +1,111 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Pcap</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Pcap</H1></DT>
<DD>
pcap 全般に関するメソッドや定数を定義しています。
</DD>
<DT><H2>定数:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="::DLT_NULL"><CODE>DLT_NULL</CODE></A>
<DD>
<DT>
<A NAME="::DLT_EN10MB"><CODE>DLT_EN10MB</CODE></A>
<DD>
<DT>
<A NAME="::DLT_EN3MB"><CODE>DLT_EN3MB</CODE></A>
<DD>
<DT>
<A NAME="::DLT_AX25"><CODE>DLT_AX25</CODE></A>
<DD>
<DT>
<A NAME="::DLT_PRONET"><CODE>DLT_PRONET</CODE></A>
<DD>
<DT>
<A NAME="::DLT_CHAOS"><CODE>DLT_CHAOS</CODE></A>
<DD>
<DT>
<A NAME="::DLT_IEEE802"><CODE>DLT_IEEE802</CODE></A>
<DD>
<DT>
<A NAME="::DLT_ARCNET"><CODE>DLT_ARCNET</CODE></A>
<DD>
<DT>
<A NAME="::DLT_SLIP"><CODE>DLT_SLIP</CODE></A>
<DD>
<DT>
<A NAME="::DLT_PPP"><CODE>DLT_PPP</CODE></A>
<DD>
<DT>
<A NAME="::DLT_FDDI"><CODE>DLT_FDDI</CODE></A>
<DD>
<DT>
<A NAME="::DLT_ATM_RFC1483"><CODE>DLT_ATM_RFC1483</CODE></A>
<DD>
<DT>
<A NAME="::DLT_RAW"><CODE>DLT_RAW</CODE></A>
<DD>
<DT>
<A NAME="::DLT_SLIP_BSDOS"><CODE>DLT_SLIP_BSDOS</CODE></A>
<DD>
<DT>
<A NAME="::DLT_PPP_BSDOS"><CODE>DLT_PPP_BSDOS</CODE></A>
<DD>
<p>
データリンク層の種類を表す定数。
</p>
</DL>
<DT><H2>モジュールメソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".convert="><CODE>convert = <var>bool</var></CODE></A>
<DD>
<p>
<CODE>Pcap</CODE> モジュール中のクラスが IP アドレスなどの数値を
文字列に変換しようとした時の動作を設定します。<CODE>true</CODE>
ならばそのような数値は名前に変換されます。
</p>
<DT>
<A NAME=".convert?"><CODE>convert?</CODE></A>
<DD>
<p>
<CODE>Pcap</CODE> モジュール中のクラスが IP アドレスなどの数値を
文字列に変換しようとした時の動作を返します。<CODE>true</CODE>
ならばそのような数値は名前に変換されます。
</p>
<DT>
<A NAME=".lookupdev"><CODE>lookupdev</CODE></A>
<DD>
<p>
ネットワークデバイス名を返します。
</p>
<DT>
<A NAME=".lookupnet"><CODE>lookupnet(<var>device</var>)</CODE></A>
<DD>
<p>
<CODE>[net, mask]</CODE> なる2要素配列を返します。
<CODE>net</CODE>はネットワーク番号を表す
<A HREF="IPAddress.html"><CODE>IPAddress</CODE></A>です。
<CODE>mask</CODE>はネットマスクを表す<A HREF="http://www.ruby-lang.org/ja/man-1.4/Integer.html"><CODE>Integer</CODE></A>です。
引数<VAR>device</VAR>によりネットワークデバイス名を指定
します。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

View File

@ -0,0 +1,21 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>PcapError</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>PcapError</H1></DT>
<DD>
pcap に関する例外です。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><CODE>StandardError</CODE></DT></DL></DD>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

113
external/ruby-pcapx/doc-ja/Pcaplet.html vendored Normal file
View File

@ -0,0 +1,113 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Pcaplet</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Pcaplet</H1></DT>
<DD>
<P>
<A HREF="Capture.html"><CODE>Capture</CODE></A>を使うパケット処理ツールの雛形を提供するクラスで
す。
使うときは<CODE>'pcaplet'</CODE><CODE>require</CODE>して下
さい。
</P>
<P>
典型的な使い方:
<blockquote>
<pre>require 'pcaplet'
my_tool = Pcaplet.new
my_tool.each_packet {|pkt|
# pkt について処理を行なうコード
}
my_tool.close
</pre>
</blockquote>
</P>
<P>
コマンドラインで指定されたフィルタ、および
以下のコマンドラインオプションを tcpdump と同様に解釈します。
<blockquote>
<pre>-i -r -c -s -n
</pre>
</blockquote>
'<CODE>-r</CODE>' オプションでは、gzipで圧縮されたファイルを読
み込むこともできます。
</P>
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/ja/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>クラスメソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".new"><CODE>new([<var>option</var>])</CODE></A>
<DD>
<p>
<CODE>Pcaplet</CODE>オブジェクトを生成します。コマンドライン
の解析とデバイスのオープンが行なわれます。
<VAR>option</VAR>を指定すると、コマンドラインオプションに
追加されます。
</p>
</DL>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="add_filter"><CODE>add_filter(<var>filter</var>)</CODE></A>
<DD>
<p>
コマンドラインで指定されたフィルタ加えて、さらに
<VAR>filter</VAR>を追加します。実際にはフィルタを以下のよ
うに設定します。
<blockquote>
<pre>&quot;( current_filter ) and ( filter )&quot;
</pre>
</blockquote>
</p>
<DT>
<A NAME="each_packet"><CODE>each_packet {|<var>packet</var>|...}</CODE></A>
<DD>
<DT>
<A NAME="each"><CODE>each {|<var>packet</var>|...}</CODE></A>
<DD>
<p>
各パケットに対して繰り返します。ブロックには
<A HREF="Packet.html"><CODE>Packet</CODE></A>クラスかそのサブクラスのインスタンスが渡されま
す。
</p>
<DT>
<A NAME="capture"><CODE>capture</CODE></A>
<DD>
<p>
内部で使用している <A HREF="Capture.html"><CODE>Capture</CODE></A> オブジェクトを返します。
</p>
<DT>
<A NAME="close"><CODE>close</CODE></A>
<DD>
<p>
デバイスをクローズします。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

View File

@ -0,0 +1,148 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>TCPPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>TCPPacket</H1></DT>
<DD>
TCPヘッダを含むパケット。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="IPPacket.html"><CODE>IPPacket</CODE></A></DT></DL></DD>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="tcp_ack"><CODE>tcp_ack</CODE></A>
<DD>
<p>
Acknowledgement Number を返します。
</p>
<DT>
<A NAME="tcp_data"><CODE>tcp_data</CODE></A>
<DD>
<p>
データ部分を <A HREF="http://www.ruby-lang.org/ja/man-1.4/String.html"><CODE>String</CODE></A> として返します。
</p>
<DT>
<A NAME="tcp_data_len"><CODE>tcp_data_len</CODE></A>
<DD>
<p>
データ部分の長さを返します。
</p>
<DT>
<A NAME="tcp_dport"><CODE>tcp_dport</CODE></A>
<DD>
<DT>
<A NAME="dport"><CODE>dport</CODE></A>
<DD>
<p>
デスティネーションポート番号を返します.
</p>
<DT>
<A NAME="tcp_flags"><CODE>tcp_flags</CODE></A>
<DD>
<p>
TCP フラグフィールドの値 (6 bit) を返します。
</p>
<DT>
<A NAME="tcp_flags_s"><CODE>tcp_flags_s</CODE></A>
<DD>
<p>
TCP フラグフィールドの値 (6 bit) を
<CODE>&quot;.A...F&quot;</CODE> といった形式の文字列として返します。
</p>
<DT>
<A NAME="tcp_fin?"><CODE>tcp_fin?</CODE></A>
<DD>
<DT>
<A NAME="tcp_syn?"><CODE>tcp_syn?</CODE></A>
<DD>
<DT>
<A NAME="tcp_rst?"><CODE>tcp_rst?</CODE></A>
<DD>
<DT>
<A NAME="tcp_psh?"><CODE>tcp_psh?</CODE></A>
<DD>
<DT>
<A NAME="tcp_ack?"><CODE>tcp_ack?</CODE></A>
<DD>
<DT>
<A NAME="tcp_urg?"><CODE>tcp_urg?</CODE></A>
<DD>
<p>
フラグが立っていれば<CODE>true</CODE>を,そうでなければ
<CODE>false</CODE>を返します.
</p>
<DT>
<A NAME="tcp_off"><CODE>tcp_off</CODE></A>
<DD>
<DT>
<A NAME="tcp_hlen"><CODE>tcp_hlen</CODE></A>
<DD>
<p>
TCP データオフセット(TCPヘッダ長)を返します。
</p>
<DT>
<A NAME="tcp_seq"><CODE>tcp_seq</CODE></A>
<DD>
<p>
Sequence Number を返します。
</p>
<DT>
<A NAME="tcp_sum"><CODE>tcp_sum</CODE></A>
<DD>
<p>
Checksum フィールドの値を返します。
</p>
<DT>
<A NAME="tcp_sport"><CODE>tcp_sport</CODE></A>
<DD>
<DT>
<A NAME="sport"><CODE>sport</CODE></A>
<DD>
<p>
ソースポート番号を返します.
</p>
<DT>
<A NAME="tcp_urp"><CODE>tcp_urp</CODE></A>
<DD>
<p>
Urgent Pointer フィールドの値を返します。
</p>
<DT>
<A NAME="tcp_win"><CODE>tcp_win</CODE></A>
<DD>
<p>
Window Size を返します。
</p>
<DT>
<A NAME="to_s"><CODE>to_s</CODE></A>
<DD>
<p>
文字列に変換します。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

View File

@ -0,0 +1,22 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>TruncatedPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>TruncatedPacket</H1></DT>
<DD>
要求されたパケットに関する情報が、キャプチャされたデータ内に
存在しません。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="PcapError.html"><CODE>PcapError</CODE></A></DT></DL></DD>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

View File

@ -0,0 +1,73 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>UDPPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>UDPPacket</H1></DT>
<DD>
UDPヘッダを含むパケット。
</DD>
<DT><H2>スーパークラス:</H2></DT>
<DD><DL><DT><A HREF="IPPacket.html"><CODE>IPPacket</CODE></A></DT></DL></DD>
<DT><H2>メソッド:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="udp_data"><CODE>udp_data</CODE></A>
<DD>
<p>
データ部分を <A HREF="http://www.ruby-lang.org/ja/man-1.4/String.html"><CODE>String</CODE></A> として返します。
</p>
<DT>
<A NAME="udp_dport"><CODE>udp_dport</CODE></A>
<DD>
<DT>
<A NAME="dport"><CODE>dport</CODE></A>
<DD>
<p>
デスティネーションポート番号を返します.
</p>
<DT>
<A NAME="udp_len"><CODE>udp_len</CODE></A>
<DD>
<p>
Lengthフィールドの値を返します。この値はUDPデータグラム
全体の長さ(単位: オクテット)を表します。
</p>
<DT>
<A NAME="udp_sum"><CODE>udp_sum</CODE></A>
<DD>
<p>
Checksum フィールドの値を返します。
</p>
<DT>
<A NAME="udp_sport"><CODE>udp_sport</CODE></A>
<DD>
<DT>
<A NAME="sport"><CODE>sport</CODE></A>
<DD>
<p>
ソースポート番号を返します.
</p>
<DT>
<A NAME="to_s"><CODE>to_s</CODE></A>
<DD>
<p>
文字列に変換します。
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

54
external/ruby-pcapx/doc-ja/index.html vendored Normal file
View File

@ -0,0 +1,54 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Ruby/Pcap Library</title>
</head>
<body bgcolor="ffffff">
<h1>Ruby/Pcap拡張ライブラリ</h1>
LBL の libpcap (Packet Capture library) への ruby インタフェースです。
<h2>モジュール</h2>
<ul>
<li><a href="Pcap.html"><code>Pcap</code></a>
</ul>
<h2>クラス</h2>
以下のクラスは全て <code>Pcap</code> モジュールの下で定義されています。
したがって使用するときは <code>Pcap</code> モジュールを
<code>include</code> するか、もしくは <code>Pcap::Capture</code> のよ
うに参照してください。
<ul>
<li><a href="Capture.html"><code>Capture</code></a>
<li><a href="Pcaplet.html"><code>Pcaplet</code></a>
<li><a href="Packet.html"><code>Packet</code></a>
<ul>
<li><a href="IPPacket.html"><code>IPPacket</code></a>
<ul>
<li><a href="TCPPacket.html"><code>TCPPacket</code></a>
<li><a href="UDPPacket.html"><code>UDPPacket</code></a>
<li><a href="ICMPPacket.html"><code>ICMPPacket</code></a>
</ul>
</ul>
<li><a href="IPAddress.html"><code>IPAddress</code></a>
<li><a href="Dumper.html"><code>Dumper</code></a>
<li><a href="Filter.html"><code>Filter</code></a>
</ul>
<h2>例外</h2>
<ul>
<li><a href="PcapError.html"><code>PcapError</code></a>
<ul>
<li><a href="TruncatedPacket.html"><code>TruncatedPacket</code></a>
</ul>
</ul>
<hr>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">
fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</body> </html>

144
external/ruby-pcapx/doc/Capture.html vendored Normal file
View File

@ -0,0 +1,144 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Capture</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Capture</H1></DT>
<DD>
Packet Capture Object
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/en/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>Included Modules:</H2></DT>
<DL>
<DT><A HREF="http://www.ruby-lang.org/en/man-1.4/Enum.html"><CODE>Enumerable</CODE></A></DT>
</DL>
<DT><H2>Class Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".open_live"><CODE>open_live(<var>device</var>[, <var>snaplen</var>[, <var>promisc</var>[, <var>to_ms</var>]]])</CODE></A>
<DD>
<p>
Open specified device and return <CODE>Capture</CODE>
object.
Default value for <VAR>snaplen</VAR>,
<VAR>promisc</VAR> and <VAR>to_ms</VAR> are 68 octets,
<CODE>true</CODE> and 1000 milliseconds.
</p>
<DT>
<A NAME=".open_offline"><CODE>open_offline(<var>filename</var>)</CODE></A>
<DD>
<p>
Open <VAR>filename</VAR> and return <CODE>Capture</CODE> object.
</p>
</DL>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="close"><CODE>close</CODE></A>
<DD>
<p>
Close <CODE>Capture</CODE> object.
</p>
<DT>
<A NAME="datalink"><CODE>datalink</CODE></A>
<DD>
<p>
Return an integer representing data-link type.
(e.g. <A HREF="Pcap.html#::DLT_EN10MB"><CODE>DLT_EN10MB</CODE></A>)
</p>
<DT>
<A NAME="dispatch"><CODE>dispatch([<var>count</var>]) {|<var>packet</var>|...}</CODE></A>
<DD>
<p>
<P>
Iterate over each packet. The argument given to the block
is an instance of <A HREF="Packet.html"><CODE>Packet</CODE></A> or its sub-class.
</P>
<P>
<VAR>count</VAR> specifies the maximum number of packets to
process. a <VAR>count</VAR> of -1 processes all the packets
received in one buffer. a <VAR>count</VAR> of 0 processes all
packets until an error occurs, EOF is reached, or the read
times out.
Default of <VAR>count</VAR> is -1.
</P>
</p>
<DT>
<A NAME="each_packet"><CODE>each_packet([<var>count</var>]) {|<var>packet</var>|...}</CODE></A>
<DD>
<DT>
<A NAME="each"><CODE>each([<var>count</var>]) {|<var>packet</var>|...}</CODE></A>
<DD>
<DT>
<A NAME="loop"><CODE>loop([<var>count</var>]) {|<var>packet</var>|...}</CODE></A>
<DD>
<p>
<P>
Iterate over each packet. The argument given to the block
is an instance of <A HREF="Packet.html"><CODE>Packet</CODE></A> or its sub-class.
</P>
<P>
<VAR>count</VAR> specifies the maximum number of packets to
process. A negative <VAR>count</VAR> processes packets forever
or until EOF is reached. Default of <VAR>count</VAR> is -1.
</P>
</p>
<DT>
<A NAME="snapshot"><CODE>snapshot</CODE></A>
<DD>
<DT>
<A NAME="snaplen"><CODE>snaplen</CODE></A>
<DD>
<p>
Return the snapshot length.
</p>
<DT>
<A NAME="setfilter"><CODE>setfilter(<var>filter</var>[, <var>optimize</var>])</CODE></A>
<DD>
<p>
Specify <VAR>filter</VAR> as packet filter.
<VAR>filter</VAR> can be a string or a <A HREF="Filter.html"><CODE>Filter</CODE></A> object.
<VAR>optimize</VAR> controls whether optimization is performed.
Default of <VAR>optimize</VAR> is <CODE>true</CODE>.
</p>
<DT>
<A NAME="stats"><CODE>stats</CODE></A>
<DD>
<p>
Return a <A HREF="http://www.ruby-lang.org/en/man-1.4/Struct.html"><CODE>Struct</CODE></A> which represents packet statistics.
This struct has following members.
<BLOCKQUOTE>
<DL COMPACT>
<DT><CODE>recv</CODE></DT><DD>number of received packets</DD><DT><CODE>drop</CODE></DT><DD>number of dropped packets</DD></DL>
</BLOCKQUOTE>
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

52
external/ruby-pcapx/doc/Dumper.html vendored Normal file
View File

@ -0,0 +1,52 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Dumper</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Dumper</H1></DT>
<DD>
Class to dump packets to tcpdump-format file. Generated file
can be read with tcpdump and <A HREF="Capture.html#.open_offline"><CODE>Capture.open_offline</CODE></A>.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/en/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>Class Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".open"><CODE>open(<var>capture</var>, <var>filename</var>)</CODE></A>
<DD>
<p>
Return a <CODE>Dumper</CODE> to dump packets captured by
<VAR>capture</VAR> to <VAR>filename</VAR>.
</p>
</DL>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="close"><CODE>close</CODE></A>
<DD>
<p>
close <CODE>Dumper</CODE>.
</p>
<DT>
<A NAME="dump"><CODE>dump(<var>packet</var>)</CODE></A>
<DD>
<p>
Dump <VAR>packet</VAR> to this <CODE>Dumper</CODE>.
<VAR>packet</VAR> must be a packet captured by
<A HREF="Capture.html"><CODE>Capture</CODE></A> specified when opening this <CODE>Dumper</CODE>.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

109
external/ruby-pcapx/doc/Filter.html vendored Normal file
View File

@ -0,0 +1,109 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Filter</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Filter</H1></DT>
<DD>
<CODE>Filter</CODE> determines whether a packet satisfies
specified condition. Actually <CODE>Filter</CODE> is
wrapper for <CODE>bpf_program</CODE>. For details of filter
expression, see <CODE>tcpdump(1)</CODE>.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/en/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>Class Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".compile"><CODE>compile(<var>expr</var>, <var>capture</var>[, <var>optimize</var>[, <var>netmask</var>]])</CODE></A>
<DD>
<DT>
<A NAME=".new"><CODE>new(<var>expr</var>, <var>capture</var>[, <var>optimize</var>[, <var>netmask</var>]])</CODE></A>
<DD>
<p>
<P>
Create a new <CODE>Filter</CODE> object.
<VAR>expr</VAR> is a filter string. <VAR>capture</VAR>
is a <A HREF="Capture.html"><CODE>Capture</CODE></A> object. <VAR>optimize</VAR>
controls optimization of resulting code.
<VAR>netmask</VAR> specifies the netmask of the local net.
</P>
<P>
Created <CODE>Filter</CODE> can be applied to packets
captured via <VAR>capture</VAR>.
</P>
<P>
If <A HREF="http://www.tcpdump.org/"><CODE>libpcap-0.5 or later</CODE></A>
used, one of following values can be specified
instead of <VAR>capture</VAR>:
<BLOCKQUOTE>
<DL COMPACT>
<DT><CODE>[snaplen, datalink]</CODE></DT><DD>an array containing required parameters</DD><DT>omitted (or <CODE>nil</CODE>)</DT><DD>Ethernet default
(<CODE>[68, <A HREF="Pcap.html#::DLT_EN10MB"><CODE>DLT_EN10MB</CODE></A>]</CODE>)
</DD></DL>
</BLOCKQUOTE>
</P>
</p>
</DL>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="==="><CODE>self === <var>packet</var></CODE></A>
<DD>
<DT>
<A NAME="=~"><CODE>self =~ <var>packet</var></CODE></A>
<DD>
<p>
Return true if <VAR>packet</VAR> matches this filter.
</p>
<DT>
<A NAME="~self"><CODE>~ self</CODE></A>
<DD>
<p>
Return a <CODE>Filter</CODE> which represents
&quot;not <CODE>self</CODE>&quot;.
</p>
<DT>
<A NAME="|"><CODE>self | <var>other</var></CODE></A>
<DD>
<p>
Return a <CODE>Filter</CODE> which represents
&quot;<CODE>self</CODE> or <VAR>other</VAR>&quot;.
</p>
<DT>
<A NAME="&amp;"><CODE>self &amp; <var>other</var></CODE></A>
<DD>
<p>
Return a <CODE>Filter</CODE> which represents
&quot;<CODE>self</CODE> and <VAR>other</VAR>&quot;.
</p>
<DT>
<A NAME="source"><CODE>source</CODE></A>
<DD>
<p>
Returns the orginal string from which the filter is constructed.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

184
external/ruby-pcapx/doc/ICMPPacket.html vendored Normal file
View File

@ -0,0 +1,184 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>ICMPPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>ICMPPacket</H1></DT>
<DD>
<P>
A packet carrying ICMP message.
</P>
ICMP message formats are vary according to ICMP type.
Thus some fields exist in certain types of packet. Any
attempt to access nonexistence field raises an exception.
<P>
</P>
Type, code and cksum fields are valid for any ICMP type.
<P>
</P>
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="IPPacket.html"><CODE>IPPacket</CODE></A></DT></DL></DD>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="icmp_cksum"><CODE>icmp_cksum</CODE></A>
<DD>
<p>
Return ICMP checksum.
</p>
<DT>
<A NAME="icmp_code"><CODE>icmp_code</CODE></A>
<DD>
<p>
Return ICMP code.
</p>
<DT>
<A NAME="icmp_data"><CODE>icmp_data</CODE></A>
<DD>
<p>
Return data portion of ICMP_ECHO/ICMP_ECHOREPLY
messages as <A HREF="http://www.ruby-lang.org/en/man-1.4/String.html"><CODE>String</CODE></A>
</p>
<DT>
<A NAME="icmp_gwaddr"><CODE>icmp_gwaddr</CODE></A>
<DD>
<p>
Return gateway address of ICMP_REDIRECT message as
<A HREF="IPAddress.html"><CODE>IPAddress</CODE></A>.
</p>
<DT>
<A NAME="icmp_id"><CODE>icmp_id</CODE></A>
<DD>
<p>
Return identifier.
</p>
<DT>
<A NAME="icmp_ip"><CODE>icmp_ip</CODE></A>
<DD>
<p>
Return original IP Datagram as <A HREF="IPPacket.html"><CODE>IPPacket</CODE></A>.
</p>
<DT>
<A NAME="icmp_lifetime"><CODE>icmp_lifetime</CODE></A>
<DD>
<p>
Return lifetime of ICMP_ROUTERADVERT message.
</p>
<DT>
<A NAME="icmp_nextmtu"><CODE>icmp_nextmtu</CODE></A>
<DD>
<p>
Return Next Hop MTU of ICMP_UNREACH_NEEDFRAG message
(See rfc1191).
</p>
<DT>
<A NAME="icmp_num_addrs"><CODE>icmp_num_addrs</CODE></A>
<DD>
<p>
Return number of addresses of ICMP_ROUTERADVERT message.
</p>
<DT>
<A NAME="icmp_otime"><CODE>icmp_otime</CODE></A>
<DD>
<DT>
<A NAME="icmp_rtime"><CODE>icmp_rtime</CODE></A>
<DD>
<DT>
<A NAME="icmp_ttime"><CODE>icmp_ttime</CODE></A>
<DD>
<p>
Return timestamp of
ICMP_TSTAMP/ICMP_TSTAMPREPLY message as <A HREF="http://www.ruby-lang.org/en/man-1.4/Time.html"><CODE>Time</CODE></A>.
</p>
<DT>
<A NAME="icmp_pptr"><CODE>icmp_pptr</CODE></A>
<DD>
<p>
Return error pointer of ICMP_PARAMPROB message.
</p>
<DT>
<A NAME="icmp_radv"><CODE>icmp_radv(<var>nth</var>)</CODE></A>
<DD>
<p>
Return <VAR>nth</VAR> address entry of
ICMP_ROUTERADVERT message. Returned value is a two
elements array <CODE>[address, preference]</CODE>.
</p>
<DT>
<A NAME="icmp_seq"><CODE>icmp_seq</CODE></A>
<DD>
<p>
Return sequence number.
</p>
<DT>
<A NAME="icmp_seqle"><CODE>icmp_seqle</CODE></A>
<DD>
<p>
<P>
Return sequence number interpreted as little endian.
</P>
<P>
No small portion of <CODE>ping</CODE> command
implementations write sequence number in host byte
order. Thus the sequence number of ICMP messages
transmitted from little endian host may be in little
endian.
</P>
</p>
<DT>
<A NAME="icmp_type"><CODE>icmp_type</CODE></A>
<DD>
<p>
Return ICMP type.
</p>
<DT>
<A NAME="icmp_typestr"><CODE>icmp_typestr</CODE></A>
<DD>
<p>
Return string describing ICMP type (e.g. &quot;echo reply&quot;).
</p>
<DT>
<A NAME="icmp_wpa"><CODE>icmp_wpa</CODE></A>
<DD>
<p>
Return word per address entry of ICMP_ROUTERADVERT message.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

60
external/ruby-pcapx/doc/IPAddress.html vendored Normal file
View File

@ -0,0 +1,60 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>IPAddress</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>IPAddress</H1></DT>
<DD>
IP Address object.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/en/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="=="><CODE>self == <var>other</var></CODE></A>
<DD>
<p>
Return <CODE>true</CODE> if two addresses are the same address.
</p>
<DT>
<A NAME="hostname"><CODE>hostname</CODE></A>
<DD>
<p>
Return host name correspond to this address.
</p>
<DT>
<A NAME="to_i"><CODE>to_i</CODE></A>
<DD>
<p>
Return the value of IP address as integer.
</p>
<DT>
<A NAME="to_num_s"><CODE>to_num_s</CODE></A>
<DD>
<p>
Return numerical string representation
</p>
<DT>
<A NAME="to_s"><CODE>to_s</CODE></A>
<DD>
<p>
Return numerical string representation or host name.
Behavior of this method is controlled by <A HREF="Pcap.html#.convert="><CODE>Pcap.convert=</CODE></A>.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

142
external/ruby-pcapx/doc/IPPacket.html vendored Normal file
View File

@ -0,0 +1,142 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>IPPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>IPPacket</H1></DT>
<DD>
A packet carrying IP header.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="Packet.html"><CODE>Packet</CODE></A></DT></DL></DD>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="ip_data"><CODE>ip_data</CODE></A>
<DD>
<p>
Return data part as <A HREF="http://www.ruby-lang.org/en/man-1.4/String.html"><CODE>String</CODE></A>.
</p>
<DT>
<A NAME="ip_df?"><CODE>ip_df?</CODE></A>
<DD>
<p>
Return <CODE>true</CODE> if Don't Fragment bit is set.
</p>
<DT>
<A NAME="ip_dst"><CODE>ip_dst</CODE></A>
<DD>
<DT>
<A NAME="dst"><CODE>dst</CODE></A>
<DD>
<p>
Return destination IP address as <A HREF="IPAddress.html"><CODE>IPAddress</CODE></A>.
</p>
<DT>
<A NAME="ip_flags"><CODE>ip_flags</CODE></A>
<DD>
<p>
Return the value of 3-bits IP flag field.
</p>
<DT>
<A NAME="ip_hlen"><CODE>ip_hlen</CODE></A>
<DD>
<p>
Return header length. (Unit: 4 octets)
</p>
<DT>
<A NAME="ip_id"><CODE>ip_id</CODE></A>
<DD>
<p>
Return identification.
</p>
<DT>
<A NAME="ip_len"><CODE>ip_len</CODE></A>
<DD>
<p>
Return total length.
</p>
<DT>
<A NAME="ip_mf?"><CODE>ip_mf?</CODE></A>
<DD>
<p>
Return <CODE>true</CODE> if More Fragment bit is set.
</p>
<DT>
<A NAME="ip_off"><CODE>ip_off</CODE></A>
<DD>
<p>
Return fragment offset.
</p>
<DT>
<A NAME="ip_proto"><CODE>ip_proto</CODE></A>
<DD>
<p>
Return the value of protocol field.
</p>
<DT>
<A NAME="ip_src"><CODE>ip_src</CODE></A>
<DD>
<DT>
<A NAME="src"><CODE>src</CODE></A>
<DD>
<p>
Return source IP address as <A HREF="IPAddress.html"><CODE>IPAddress</CODE></A>.
</p>
<DT>
<A NAME="ip_sum"><CODE>ip_sum</CODE></A>
<DD>
<p>
Return the value of checksum field.
</p>
<DT>
<A NAME="ip_tos"><CODE>ip_tos</CODE></A>
<DD>
<p>
Return the value of TOS field.
</p>
<DT>
<A NAME="ip_ttl"><CODE>ip_ttl</CODE></A>
<DD>
<p>
Return TTL.
</p>
<DT>
<A NAME="ip_ver"><CODE>ip_ver</CODE></A>
<DD>
<p>
Return IP version.
</p>
<DT>
<A NAME="to_s"><CODE>to_s</CODE></A>
<DD>
<p>
Return string representation.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

98
external/ruby-pcapx/doc/Packet.html vendored Normal file
View File

@ -0,0 +1,98 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Packet</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Packet</H1></DT>
<DD>
Packet captured with <A HREF="Capture.html"><CODE>Capture</CODE></A> object.
<CODE>Packet</CODE> and its sub-classes are <A HREF="http://www.ruby-lang.org/en/man-1.4/Marshal.html"><CODE>Marshal</CODE></A> compliant.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/en/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="caplen"><CODE>caplen</CODE></A>
<DD>
<p>
Return captured length.
</p>
<DT>
<A NAME="datalink"><CODE>datalink</CODE></A>
<DD>
<p>
Return an integer representing data-link type.
(e.g. <A HREF="Pcap.html#::DLT_EN10MB"><CODE>DLT_EN10MB</CODE></A>)
</p>
<DT>
<A NAME="ip?"><CODE>ip?</CODE></A>
<DD>
<p>
Return <CODE>true</CODE> if this packet is an instance of
<A HREF="IPPacket.html"><CODE>IPPacket</CODE></A> or its sub-class.
</p>
<DT>
<A NAME="len"><CODE>len</CODE></A>
<DD>
<DT>
<A NAME="length"><CODE>length</CODE></A>
<DD>
<DT>
<A NAME="size"><CODE>size</CODE></A>
<DD>
<p>
Return total length of packet.
</p>
<DT>
<A NAME="raw_data"><CODE>raw_data</CODE></A>
<DD>
<p>
Return raw data of packet as <A HREF="http://www.ruby-lang.org/en/man-1.4/String.html"><CODE>String</CODE></A>.
</p>
<DT>
<A NAME="tcp?"><CODE>tcp?</CODE></A>
<DD>
<p>
Return <CODE>true</CODE> if this packet is an instance of
<A HREF="TCPPacket.html"><CODE>TCPPacket</CODE></A> or its sub-class.
</p>
<DT>
<A NAME="time"><CODE>time</CODE></A>
<DD>
<p>
Return timestamp as <A HREF="http://www.ruby-lang.org/en/man-1.4/Time.html"><CODE>Time</CODE></A>.
</p>
<DT>
<A NAME="time_i"><CODE>time_i</CODE></A>
<DD>
<p>
Return timestamp as integer.
</p>
<DT>
<A NAME="udp?"><CODE>udp?</CODE></A>
<DD>
<p>
Return <CODE>true</CODE> if this packet is an instance of
<A HREF="UDPPacket.html"><CODE>UDPPacket</CODE></A> or its sub-class.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

113
external/ruby-pcapx/doc/Pcap.html vendored Normal file
View File

@ -0,0 +1,113 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Pcap</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Pcap</H1></DT>
<DD>
<CODE>Pcap</CODE> defines general methods and constants related to
pcap.
</DD>
<DT><H2>Constants:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="::DLT_NULL"><CODE>DLT_NULL</CODE></A>
<DD>
<DT>
<A NAME="::DLT_EN10MB"><CODE>DLT_EN10MB</CODE></A>
<DD>
<DT>
<A NAME="::DLT_EN3MB"><CODE>DLT_EN3MB</CODE></A>
<DD>
<DT>
<A NAME="::DLT_AX25"><CODE>DLT_AX25</CODE></A>
<DD>
<DT>
<A NAME="::DLT_PRONET"><CODE>DLT_PRONET</CODE></A>
<DD>
<DT>
<A NAME="::DLT_CHAOS"><CODE>DLT_CHAOS</CODE></A>
<DD>
<DT>
<A NAME="::DLT_IEEE802"><CODE>DLT_IEEE802</CODE></A>
<DD>
<DT>
<A NAME="::DLT_ARCNET"><CODE>DLT_ARCNET</CODE></A>
<DD>
<DT>
<A NAME="::DLT_SLIP"><CODE>DLT_SLIP</CODE></A>
<DD>
<DT>
<A NAME="::DLT_PPP"><CODE>DLT_PPP</CODE></A>
<DD>
<DT>
<A NAME="::DLT_FDDI"><CODE>DLT_FDDI</CODE></A>
<DD>
<DT>
<A NAME="::DLT_ATM_RFC1483"><CODE>DLT_ATM_RFC1483</CODE></A>
<DD>
<DT>
<A NAME="::DLT_RAW"><CODE>DLT_RAW</CODE></A>
<DD>
<DT>
<A NAME="::DLT_SLIP_BSDOS"><CODE>DLT_SLIP_BSDOS</CODE></A>
<DD>
<DT>
<A NAME="::DLT_PPP_BSDOS"><CODE>DLT_PPP_BSDOS</CODE></A>
<DD>
<p>
Data-link type constants.
</p>
</DL>
<DT><H2>Module Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".convert="><CODE>convert = <var>bool</var></CODE></A>
<DD>
<p>
Set the behavior of classes under module <CODE>Pcap</CODE>
when they convert IP address or other numbers to string.
Value <CODE>true</CODE> means that the numbers are converted
to their symbolic name.
</p>
<DT>
<A NAME=".convert?"><CODE>convert?</CODE></A>
<DD>
<p>
Return the behavior of classes under module <CODE>Pcap</CODE>
when they convert IP address or other numbers to string.
Value <CODE>true</CODE> means that the numbers are converted
to their symbolic name.
</p>
<DT>
<A NAME=".lookupdev"><CODE>lookupdev</CODE></A>
<DD>
<p>
Return a name of network device.
</p>
<DT>
<A NAME=".lookupnet"><CODE>lookupnet(<var>device</var>)</CODE></A>
<DD>
<p>
Return a two-element array
<CODE>[net, mask]</CODE>.
<CODE>net</CODE> is network number as <A HREF="IPAddress.html"><CODE>IPAddress</CODE></A>.
<CODE>mask</CODE> is netmask as <A HREF="http://www.ruby-lang.org/en/man-1.4/Integer.html"><CODE>Integer</CODE></A>.
Argument <VAR>device</VAR> is network device name.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

21
external/ruby-pcapx/doc/PcapError.html vendored Normal file
View File

@ -0,0 +1,21 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>PcapError</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>PcapError</H1></DT>
<DD>
Exception about pcap.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><CODE>StandardError</CODE></DT></DL></DD>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

108
external/ruby-pcapx/doc/Pcaplet.html vendored Normal file
View File

@ -0,0 +1,108 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>Pcaplet</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>Pcaplet</H1></DT>
<DD>
<P>
<CODE>Pcaplet</CODE> provides a template for packet monitoring tool
using <A HREF="Capture.html"><CODE>Capture</CODE></A>.
You need to <CODE>require 'pcaplet'</CODE> to use this class.
</P>
<P>
Typical usage:
<blockquote>
<pre>require 'pcaplet'
my_tool = Pcaplet.new
my_tool.each_packet {|pkt|
# code for processing pkt
}
my_tool.close
</pre>
</blockquote>
</P>
<P>
<CODE>Pcaplet</CODE> interprets filter expression specified in
command line and following command line options as tcpdump does.
<blockquote>
<pre>-i -r -c -s -n
</pre>
</blockquote>
'<CODE>-r</CODE>' option can handle gzipped file.
</P>
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="http://www.ruby-lang.org/en/man-1.4/Object.html"><CODE>Object</CODE></A></DT></DL></DD>
<DT><H2>Class Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME=".new"><CODE>new([<var>option</var>])</CODE></A>
<DD>
<p>
Generate <CODE>Pcaplet</CODE> instance. Command line
analysis and device open is performed.
<VAR>option</VAR> is added to command line options.
</p>
</DL>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="add_filter"><CODE>add_filter(<var>filter</var>)</CODE></A>
<DD>
<p>
Add <VAR>filter</VAR> to the filter specified in command line.
Filter is set as follows.
<blockquote>
<pre>&quot;( current_filter ) and ( filter )&quot;
</pre>
</blockquote>
</p>
<DT>
<A NAME="each_packet"><CODE>each_packet {|<var>packet</var>|...}</CODE></A>
<DD>
<DT>
<A NAME="each"><CODE>each {|<var>packet</var>|...}</CODE></A>
<DD>
<p>
Iterate over each packet. The argument given to the block
is an instance of <A HREF="Packet.html"><CODE>Packet</CODE></A> or its sub-class.
</p>
<DT>
<A NAME="capture"><CODE>capture</CODE></A>
<DD>
<p>
Return <A HREF="Capture.html"><CODE>Capture</CODE></A> object which is used internally.
</p>
<DT>
<A NAME="close"><CODE>close</CODE></A>
<DD>
<p>
Close underlying device.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

147
external/ruby-pcapx/doc/TCPPacket.html vendored Normal file
View File

@ -0,0 +1,147 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>TCPPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>TCPPacket</H1></DT>
<DD>
A packet carrying TCP header.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="IPPacket.html"><CODE>IPPacket</CODE></A></DT></DL></DD>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="tcp_ack"><CODE>tcp_ack</CODE></A>
<DD>
<p>
Return acknowledgement number.
</p>
<DT>
<A NAME="tcp_data"><CODE>tcp_data</CODE></A>
<DD>
<p>
Return data part as <A HREF="http://www.ruby-lang.org/en/man-1.4/String.html"><CODE>String</CODE></A>.
</p>
<DT>
<A NAME="tcp_data_len"><CODE>tcp_data_len</CODE></A>
<DD>
<p>
Return length of data part.
</p>
<DT>
<A NAME="tcp_dport"><CODE>tcp_dport</CODE></A>
<DD>
<DT>
<A NAME="dport"><CODE>dport</CODE></A>
<DD>
<p>
Return destination port number.
</p>
<DT>
<A NAME="tcp_flags"><CODE>tcp_flags</CODE></A>
<DD>
<p>
Return the value of 6-bits flag field.
</p>
<DT>
<A NAME="tcp_flags_s"><CODE>tcp_flags_s</CODE></A>
<DD>
<p>
Return the value of 6-bits flag field as string like
<CODE>&quot;.A...F&quot;</CODE>.
</p>
<DT>
<A NAME="tcp_fin?"><CODE>tcp_fin?</CODE></A>
<DD>
<DT>
<A NAME="tcp_syn?"><CODE>tcp_syn?</CODE></A>
<DD>
<DT>
<A NAME="tcp_rst?"><CODE>tcp_rst?</CODE></A>
<DD>
<DT>
<A NAME="tcp_psh?"><CODE>tcp_psh?</CODE></A>
<DD>
<DT>
<A NAME="tcp_ack?"><CODE>tcp_ack?</CODE></A>
<DD>
<DT>
<A NAME="tcp_urg?"><CODE>tcp_urg?</CODE></A>
<DD>
<p>
Return <CODE>true</CODE> if flag is set.
</p>
<DT>
<A NAME="tcp_off"><CODE>tcp_off</CODE></A>
<DD>
<DT>
<A NAME="tcp_hlen"><CODE>tcp_hlen</CODE></A>
<DD>
<p>
Return TCP data offset (header length). (Unit: 4-octets)
</p>
<DT>
<A NAME="tcp_seq"><CODE>tcp_seq</CODE></A>
<DD>
<p>
Return sequence number.
</p>
<DT>
<A NAME="tcp_sum"><CODE>tcp_sum</CODE></A>
<DD>
<p>
Return the value of checksum field.
</p>
<DT>
<A NAME="tcp_sport"><CODE>tcp_sport</CODE></A>
<DD>
<DT>
<A NAME="sport"><CODE>sport</CODE></A>
<DD>
<p>
Return source port number.
</p>
<DT>
<A NAME="tcp_urp"><CODE>tcp_urp</CODE></A>
<DD>
<p>
Return urgent pointer.
</p>
<DT>
<A NAME="tcp_win"><CODE>tcp_win</CODE></A>
<DD>
<p>
Return window size.
</p>
<DT>
<A NAME="to_s"><CODE>to_s</CODE></A>
<DD>
<p>
Return string representation.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

View File

@ -0,0 +1,22 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>TruncatedPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>TruncatedPacket</H1></DT>
<DD>
Requested packet information is not available because necessary data
is truncated out of capture buffer.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="PcapError.html"><CODE>PcapError</CODE></A></DT></DL></DD>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

73
external/ruby-pcapx/doc/UDPPacket.html vendored Normal file
View File

@ -0,0 +1,73 @@
<HTML>
<!-- THIS FILE IS GENERATED FROM ANOTHER SOURCE FILE -->
<HEAD>
<TITLE>UDPPacket</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DL>
<DT><H1>UDPPacket</H1></DT>
<DD>
A packet carrying UDP header.
</DD>
<DT><H2>Super Class:</H2></DT>
<DD><DL><DT><A HREF="IPPacket.html"><CODE>IPPacket</CODE></A></DT></DL></DD>
<DT><H2>Methods:</H2></DT>
<DL COMPACT>
<DT>
<A NAME="udp_data"><CODE>udp_data</CODE></A>
<DD>
<p>
Return data part as <A HREF="http://www.ruby-lang.org/en/man-1.4/String.html"><CODE>String</CODE></A>.
</p>
<DT>
<A NAME="udp_dport"><CODE>udp_dport</CODE></A>
<DD>
<DT>
<A NAME="dport"><CODE>dport</CODE></A>
<DD>
<p>
Return destination port number.
</p>
<DT>
<A NAME="udp_len"><CODE>udp_len</CODE></A>
<DD>
<p>
Return value of length field. This value represents
the length in octets of this UDP datagram.
</p>
<DT>
<A NAME="udp_sum"><CODE>udp_sum</CODE></A>
<DD>
<p>
Return the value of checksum field.
</p>
<DT>
<A NAME="udp_sport"><CODE>udp_sport</CODE></A>
<DD>
<DT>
<A NAME="sport"><CODE>sport</CODE></A>
<DD>
<p>
Return source port number.
</p>
<DT>
<A NAME="to_s"><CODE>to_s</CODE></A>
<DD>
<p>
Return string representation.
</p>
</DL>
</DL>
<HR>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</BODY>
</HTML>

53
external/ruby-pcapx/doc/index.html vendored Normal file
View File

@ -0,0 +1,53 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Ruby/Pcap Library</title>
</head>
<body bgcolor="ffffff">
<h1>Ruby/Pcap extension library</h1>
Ruby interface to LBL libpcap (Packet Capture library).
<h2>Modules</h2>
<ul>
<li><a href="Pcap.html"><code>Pcap</code></a>
</ul>
<h2>Classes</h2>
Following classes are defined under module <code>Pcap</code>.
When you use these classes, you need to <code>include</code> module
<code>Pcap</code> or refer them like <code>Pcap::Capture</code>.
<ul>
<li><a href="Capture.html"><code>Capture</code></a>
<li><a href="Pcaplet.html"><code>Pcaplet</code></a>
<li><a href="Packet.html"><code>Packet</code></a>
<ul>
<li><a href="IPPacket.html"><code>IPPacket</code></a>
<ul>
<li><a href="TCPPacket.html"><code>TCPPacket</code></a>
<li><a href="UDPPacket.html"><code>UDPPacket</code></a>
<li><a href="ICMPPacket.html"><code>ICMPPacket</code></a>
</ul>
</ul>
<li><a href="IPAddress.html"><code>IPAddress</code></a>
<li><a href="Dumper.html"><code>Dumper</code></a>
<li><a href="Filter.html"><code>Filter</code></a>
</ul>
<h2>Exceptions</h2>
<ul>
<li><a href="PcapError.html"><code>PcapError</code></a>
<ul>
<li><a href="TruncatedPacket.html"><code>TruncatedPacket</code></a>
</ul>
</ul>
<hr>
<P ALIGN="RIGHT">
<A HREF="mailto:fukusima@goto.info.waseda.ac.jp">
fukusima@goto.info.waseda.ac.jp</A><BR>
</P>
</body> </html>

26
external/ruby-pcapx/examples/httpdump.rb vendored Executable file
View File

@ -0,0 +1,26 @@
#!/usr/local/bin/ruby
require 'pcaplet'
httpdump = Pcaplet.new('-s 1500')
HTTP_REQUEST = Pcap::Filter.new('tcp and dst port 80', httpdump.capture)
HTTP_RESPONSE = Pcap::Filter.new('tcp and src port 80', httpdump.capture)
httpdump.add_filter(HTTP_REQUEST | HTTP_RESPONSE)
httpdump.each_packet {|pkt|
data = pkt.tcp_data
case pkt
when HTTP_REQUEST
if data and data =~ /^GET\s+(\S+)/
path = $1
host = pkt.dst.to_s
host << ":#{pkt.dst_port}" if pkt.dport != 80
s = "#{pkt.src}:#{pkt.sport} > GET http://#{host}#{path}"
end
when HTTP_RESPONSE
if data and data =~ /^(HTTP\/.*)$/
status = $1
s = "#{pkt.dst}:#{pkt.dport} < #{status}"
end
end
puts s if s
}

25
external/ruby-pcapx/examples/tcpdump.rb vendored Executable file
View File

@ -0,0 +1,25 @@
#!/usr/local/bin/ruby
require 'pcaplet'
include Pcap
class Time
# tcpdump style format
def to_s
sprintf "%0.2d:%0.2d:%0.2d.%0.6d", hour, min, sec, tv_usec
end
end
pcaplet = Pcaplet.new
pcaplet.each_packet { |pkt|
print "#{pkt.time} #{pkt}"
if pkt.tcp?
print " (#{pkt.tcp_data_len})"
print " ack #{pkt.tcp_ack}" if pkt.tcp_ack?
print " win #{pkt.tcp_win}"
end
if pkt.ip?
print " (DF)" if pkt.ip_df?
end
print "\n"
}
pcaplet.close

10
external/ruby-pcapx/examples/test.rb vendored Executable file
View File

@ -0,0 +1,10 @@
#!/usr/local/bin/ruby
require 'pcap'
dev = Pcap.lookupdev
cap = Pcap::Capture.open_live(dev)
cap.setfilter("ip")
cap.loop do |pkt|
print pkt, "\n"
end
cap.close

16
external/ruby-pcapx/extconf.rb vendored Normal file
View File

@ -0,0 +1,16 @@
require 'mkmf'
pcap_dir = with_config("pcap-dir", "/usr/local")
pcap_includedir = with_config("pcap-includedir", pcap_dir + "/include")
pcap_libdir = with_config("pcap-libdir", pcap_dir + "/lib")
$CFLAGS = "-I#{pcap_includedir}"
$LDFLAGS = "-L#{pcap_libdir}"
have_library("socket", "socket")
have_library("xnet", "gethostbyname")
have_func("hstrerror")
if have_header("pcap.h") && have_library("pcap", "pcap_open_live")
have_func("pcap_compile_nopcap")
create_makefile("pcap")
end

444
external/ruby-pcapx/icmp_packet.c vendored Normal file
View File

@ -0,0 +1,444 @@
/*
* icmp_packet.c
*
* $Id: icmp_packet.c,v 1.1.1.1 1999/10/27 09:54:38 fukusima Exp $
*
* Copyright (C) 1999 Masaki Fukushima
*/
#include "ruby_pcap.h"
/* rfc1256 */
#ifndef ICMP_ROUTERADVERT
#define ICMP_ROUTERADVERT 9
#endif
#ifndef ICMP_ROUTERSOLICIT
#define ICMP_ROUTERSOLICIT 10
#endif
/* rfc1393 */
#ifndef ICMP_TROUTE
#define ICMP_TROUTE 30
#endif
/* rfc1788 */
#ifndef ICMP_DOMAIN
#define ICMP_DOMAIN 37
#endif
#ifndef ICMP_DOMAINREPLY
#define ICMP_DOMAINREPLY 38
#endif
/* rfc1700 */
#ifndef ICMP_UNREACH_NET_UNKNOWN
#define ICMP_UNREACH_NET_UNKNOWN 6
#endif
#ifndef ICMP_UNREACH_HOST_UNKNOWN
#define ICMP_UNREACH_HOST_UNKNOWN 7
#endif
#ifndef ICMP_UNREACH_ISOLATED
#define ICMP_UNREACH_ISOLATED 8
#endif
#ifndef ICMP_UNREACH_NET_PROHIB
#define ICMP_UNREACH_NET_PROHIB 9
#endif
#ifndef ICMP_UNREACH_HOST_PROHIB
#define ICMP_UNREACH_HOST_PROHIB 10
#endif
#ifndef ICMP_UNREACH_TOSNET
#define ICMP_UNREACH_TOSNET 11
#endif
#ifndef ICMP_UNREACH_TOSHOST
#define ICMP_UNREACH_TOSHOST 12
#endif
/* rfc1716 */
#ifndef ICMP_UNREACH_FILTER_PROHIB
#define ICMP_UNREACH_FILTER_PROHIB 13
#endif
#ifndef ICMP_UNREACH_HOST_PRECEDENCE
#define ICMP_UNREACH_HOST_PRECEDENCE 14
#endif
#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
#endif
#ifndef ICMP_PARAMPROB_OPTABSENT
#define ICMP_PARAMPROB_OPTABSENT 1
#endif
#define ICMP_HDR(pkt) ((struct icmp *)LAYER4_HDR(pkt))
#define ICMP_DATA(pkt) ((u_char *)LAYER5_HDR(pkt))
#define ICMP_DATALEN(pkt) \
(ntohs(IP_HDR(pkt)->ip_len) - (IP_HDR(pkt)->ip_hl * 4 + 8))
#define ICMP_CAPLEN(pkt) (pkt->hdr.pkthdr.caplen - pkt->hdr.layer4_off)
VALUE cICMPPacket;
#define CheckTruncateICMP(pkt, need) \
CheckTruncate(pkt, pkt->hdr.layer4_off, need, "truncated ICMP")
struct icmp_type_info {
char *name;
VALUE klass;
};
static struct icmp_type_info icmp_types[] = {
{/* 0 */ "echo reply" },
{},{},
{/* 3 */ "unreachable" },
{/* 4 */ "source quench" },
{/* 5 */ "redirect" },
{},{},
{/* 8 */ "echo request" },
{/* 9 */ "router advertisement" },
{/* 10 */ "router solicitation" },
{/* 11 */ "time exceeded" },
{/* 12 */ "parameter problem" },
{/* 13 */ "time stamp request" },
{/* 14 */ "time stamp reply" },
{/* 15 */ "information request" },
{/* 16 */ "information reply" },
{/* 17 */ "address mask request" },
{/* 18 */ "address mask reply" },
{},{},{},{},{},{},{},{},{},{},{},
{/* 30 */ "traceroute" },
{},{},{},{},{},{},
{/* 37 */ "domain name request" },
{/* 38 */ "domain name reply" }
#define ICMP_TYPE_MAX 38
};
VALUE
setup_icmp_packet(pkt, tl_len)
struct packet_object *pkt;
int tl_len;
{
VALUE klass = cICMPPacket;
if (tl_len >= 1) {
struct icmp *icmp = ICMP_HDR(pkt);
if (icmp->icmp_type <= ICMP_TYPE_MAX
&& icmp_types[icmp->icmp_type].klass) {
klass = icmp_types[icmp->icmp_type].klass;
}
}
return klass;
}
#define ICMPP_METHOD(func, need, val) \
static VALUE\
(func)(self)\
VALUE self;\
{\
struct packet_object *pkt;\
struct icmp *icmp;\
GetPacket(self, pkt);\
CheckTruncateICMP(pkt, (need));\
icmp = ICMP_HDR(pkt);\
return (val);\
}
/*
* Common methods (icmp_type independent)
*/
ICMPP_METHOD(icmpp_type, 1, INT2FIX(icmp->icmp_type))
ICMPP_METHOD(icmpp_code, 2, INT2FIX(icmp->icmp_code))
ICMPP_METHOD(icmpp_cksum, 4, INT2FIX(ntohs(icmp->icmp_cksum)))
ICMPP_METHOD(icmpp_typestr, 1,
(icmp->icmp_type <= ICMP_TYPE_MAX
&&icmp_types[icmp->icmp_type].name)
? rb_str_new2(icmp_types[icmp->icmp_type].name)
: rb_obj_as_string(INT2FIX(icmp->icmp_type)))
/*
* icmp_type specific methods
*/
ICMPP_METHOD(icmpp_pptr, 5, INT2FIX(icmp->icmp_pptr))
ICMPP_METHOD(icmpp_gwaddr, 8, new_ipaddr(&icmp->icmp_gwaddr))
ICMPP_METHOD(icmpp_id, 6, INT2FIX(ntohs(icmp->icmp_id)))
ICMPP_METHOD(icmpp_seq, 8, INT2FIX(ntohs(icmp->icmp_seq)))
#ifdef WORDS_BIGENDIAN
ICMPP_METHOD(icmpp_seqle, 8, INT2FIX(((0x00ff&icmp->icmp_seq)<<8) +
(icmp->icmp_seq >> 8)))
#else
ICMPP_METHOD(icmpp_seqle, 8, INT2FIX(icmp->icmp_seq))
#endif
/* rfc1191 */
struct mtu_discovery {
u_short unused;
u_short nextmtu;
};
#define MTUD(icmp) ((struct mtu_discovery *)&icmp->icmp_void)
static VALUE
icmpp_nextmtu(self)
VALUE self;
{
struct packet_object *pkt;
struct icmp *icmp;
GetPacket(self, pkt);
CheckTruncateICMP(pkt, 8);
icmp = ICMP_HDR(pkt);
if (icmp->icmp_code != ICMP_UNREACH_NEEDFRAG)
rb_raise(rb_eRuntimeError, "not ICMP_UNREACH_NEEDFRAG");
return INT2FIX(ntohs(MTUD(icmp)->nextmtu));
}
/* rfc1256 */
struct ih_rdiscovery {
u_char num_addrs;
u_char wpa;
u_short lifetime;
};
#define IHRD(icmp) ((struct ih_rdiscovery *)&icmp->icmp_void)
struct id_rdiscovery {
struct in_addr ird_addr;
long ird_pref;
};
#define IDRD(icmp) ((struct id_rdiscovery *)icmp->icmp_data)
ICMPP_METHOD(icmpp_num_addrs, 5, INT2FIX(IHRD(icmp)->num_addrs))
ICMPP_METHOD(icmpp_wpa, 6, INT2FIX(IHRD(icmp)->wpa))
ICMPP_METHOD(icmpp_lifetime, 8, INT2FIX(ntohs(IHRD(icmp)->lifetime)))
static VALUE
icmpp_radv(self, ind)
VALUE self, ind;
{
struct packet_object *pkt;
struct icmp *icmp;
int i = NUM2INT(ind);
VALUE ary;
GetPacket(self, pkt);
CheckTruncateICMP(pkt, 5);
if (i > IHRD(icmp)->num_addrs)
rb_raise(rb_eRuntimeError, "num_addrs = %d, requested radv(%d)",
(int)IHRD(icmp)->num_addrs, i);
CheckTruncateICMP(pkt, 8 + i*8);
icmp = ICMP_HDR(pkt);
ary = rb_ary_new();
rb_ary_push(ary, new_ipaddr(&IDRD(icmp)->ird_addr));
rb_ary_push(ary, INT2NUM(ntohl(IDRD(icmp)->ird_pref)));
return ary;
}
#define time_new_msec(t) rb_time_new((t)/1000, (t)%1000 * 1000)
ICMPP_METHOD(icmpp_otime, 12, time_new_msec(ntohl(icmp->icmp_otime)))
ICMPP_METHOD(icmpp_rtime, 16, time_new_msec(ntohl(icmp->icmp_rtime)))
ICMPP_METHOD(icmpp_ttime, 20, time_new_msec(ntohl(icmp->icmp_ttime)))
static VALUE
icmpp_ip(self)
VALUE self;
{
struct packet_object *pkt;
struct icmp *icmp;
struct pcap_pkthdr pkthdr;
GetPacket(self, pkt);
CheckTruncateICMP(pkt, 9);
icmp = ICMP_HDR(pkt);
pkthdr.caplen = ICMP_CAPLEN(pkt) - 8;
pkthdr.len = 0;
pkthdr.ts.tv_sec = 0;
pkthdr.ts.tv_usec = 0;
return new_packet((char *)&icmp->icmp_ip, &pkthdr, DLT_RAW);
}
ICMPP_METHOD(icmpp_mask, 12, UINT32_2_NUM(ntohl(icmp->icmp_mask)))
ICMPP_METHOD(icmpp_data, 9, rb_str_new(icmp->icmp_data, ICMP_CAPLEN(pkt)-8))
/* rfc1393 */
struct traceroute {
u_short ohc;
u_short rhc;
u_long lspeed;
u_long lmtu;
};
#define TROUTE(icmp) ((struct traceroute *)icmp->icmp_data)
ICMPP_METHOD(icmpp_ohc, 10, INT2FIX(ntohs(TROUTE(icmp)->ohc)))
ICMPP_METHOD(icmpp_rhc, 12, INT2FIX(ntohs(TROUTE(icmp)->rhc)))
ICMPP_METHOD(icmpp_lspeed, 16, UINT32_2_NUM(ntohl(TROUTE(icmp)->lspeed)))
ICMPP_METHOD(icmpp_lmtu, 20, UINT32_2_NUM(ntohl(TROUTE(icmp)->lmtu)))
/* rfc1788 */
struct domain_reply {
u_long ttl;
char names[1];
};
#define DOMAIN(icmp) ((struct domain_reply *)icmp->icmp_data)
ICMPP_METHOD(icmpp_ttl, 12, UINT32_2_NUM(ntohl(DOMAIN(icmp)->ttl)))
void
Init_icmp_packet(void)
{
VALUE klass;
rb_define_const(mPcap, "ICMP_ECHOREPLY", INT2NUM(ICMP_ECHOREPLY));
rb_define_const(mPcap, "ICMP_UNREACH", INT2NUM(ICMP_UNREACH));
rb_define_const(mPcap, "ICMP_SOURCEQUENCH",INT2NUM(ICMP_SOURCEQUENCH));
rb_define_const(mPcap, "ICMP_REDIRECT", INT2NUM(ICMP_REDIRECT));
rb_define_const(mPcap, "ICMP_ECHO", INT2NUM(ICMP_ECHO));
rb_define_const(mPcap, "ICMP_TIMXCEED", INT2NUM(ICMP_TIMXCEED));
rb_define_const(mPcap, "ICMP_PARAMPROB", INT2NUM(ICMP_PARAMPROB));
rb_define_const(mPcap, "ICMP_TSTAMP", INT2NUM(ICMP_TSTAMP));
rb_define_const(mPcap, "ICMP_TSTAMPREPLY", INT2NUM(ICMP_TSTAMPREPLY));
rb_define_const(mPcap, "ICMP_IREQ", INT2NUM(ICMP_IREQ));
rb_define_const(mPcap, "ICMP_IREQREPLY", INT2NUM(ICMP_IREQREPLY));
rb_define_const(mPcap, "ICMP_MASKREQ", INT2NUM(ICMP_MASKREQ));
rb_define_const(mPcap, "ICMP_MASKREPLY", INT2NUM(ICMP_MASKREPLY));
/* UNREACH codes */
rb_define_const(mPcap, "ICMP_UNREACH_NET", INT2NUM(ICMP_UNREACH_NET));
rb_define_const(mPcap, "ICMP_UNREACH_HOST", INT2NUM(ICMP_UNREACH_HOST));
rb_define_const(mPcap, "ICMP_UNREACH_PROTOCOL", INT2NUM(ICMP_UNREACH_PROTOCOL));
rb_define_const(mPcap, "ICMP_UNREACH_PORT", INT2NUM(ICMP_UNREACH_PORT));
rb_define_const(mPcap, "ICMP_UNREACH_NEEDFRAG", INT2NUM(ICMP_UNREACH_NEEDFRAG));
rb_define_const(mPcap, "ICMP_UNREACH_SRCFAIL", INT2NUM(ICMP_UNREACH_SRCFAIL));
rb_define_const(mPcap, "ICMP_UNREACH_NET_UNKNOWN", INT2NUM(ICMP_UNREACH_NET_UNKNOWN));
rb_define_const(mPcap, "ICMP_UNREACH_HOST_UNKNOWN", INT2NUM(ICMP_UNREACH_HOST_UNKNOWN));
rb_define_const(mPcap, "ICMP_UNREACH_ISOLATED", INT2NUM(ICMP_UNREACH_ISOLATED));
rb_define_const(mPcap, "ICMP_UNREACH_NET_PROHIB", INT2NUM(ICMP_UNREACH_NET_PROHIB));
rb_define_const(mPcap, "ICMP_UNREACH_HOST_PROHIB", INT2NUM(ICMP_UNREACH_HOST_PROHIB));
rb_define_const(mPcap, "ICMP_UNREACH_TOSNET", INT2NUM(ICMP_UNREACH_TOSNET));
rb_define_const(mPcap, "ICMP_UNREACH_TOSHOST", INT2NUM(ICMP_UNREACH_TOSHOST));
rb_define_const(mPcap, "ICMP_UNREACH_FILTER_PROHIB", INT2NUM(ICMP_UNREACH_FILTER_PROHIB));
rb_define_const(mPcap, "ICMP_UNREACH_HOST_PRECEDENCE", INT2NUM(ICMP_UNREACH_HOST_PRECEDENCE));
rb_define_const(mPcap, "ICMP_UNREACH_PRECEDENCE_CUTOFF", INT2NUM(ICMP_UNREACH_PRECEDENCE_CUTOFF));
/* REDIRECT codes */
rb_define_const(mPcap, "ICMP_REDIRECT_NET", INT2NUM(ICMP_REDIRECT_NET));
rb_define_const(mPcap, "ICMP_REDIRECT_HOST", INT2NUM(ICMP_REDIRECT_HOST));
rb_define_const(mPcap, "ICMP_REDIRECT_TOSNET", INT2NUM(ICMP_REDIRECT_TOSNET));
rb_define_const(mPcap, "ICMP_REDIRECT_TOSHOST", INT2NUM(ICMP_REDIRECT_TOSHOST));
/* TIMEXCEED codes */
rb_define_const(mPcap, "ICMP_TIMXCEED_INTRANS", INT2NUM(ICMP_TIMXCEED_INTRANS));
rb_define_const(mPcap, "ICMP_TIMXCEED_REASS", INT2NUM(ICMP_TIMXCEED_REASS));
/* PARAMPROB code */
rb_define_const(mPcap, "ICMP_PARAMPROB_OPTABSENT", INT2NUM(ICMP_PARAMPROB_OPTABSENT));
cICMPPacket = rb_define_class_under(mPcap, "ICMPPacket", cIPPacket);
rb_define_method(cICMPPacket, "icmp_type", icmpp_type, 0);
rb_define_method(cICMPPacket, "icmp_typestr", icmpp_typestr, 0);
rb_define_method(cICMPPacket, "icmp_code", icmpp_code, 0);
rb_define_method(cICMPPacket, "icmp_cksum", icmpp_cksum, 0);
klass = rb_define_class_under(mPcap, "ICMPEchoReply", cICMPPacket);
icmp_types[ICMP_ECHOREPLY].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
rb_define_method(klass, "icmp_seqle", icmpp_seqle, 0);
rb_define_method(klass, "icmp_data", icmpp_data, 0);
klass = rb_define_class_under(mPcap, "ICMPUnreach", cICMPPacket);
icmp_types[ICMP_UNREACH].klass = klass;
rb_define_method(klass, "icmp_nextmtu", icmpp_nextmtu, 0);
rb_define_method(klass, "icmp_ip", icmpp_ip, 0);
klass = rb_define_class_under(mPcap, "ICMPSourceQuench", cICMPPacket);
icmp_types[ICMP_SOURCEQUENCH].klass = klass;
rb_define_method(klass, "icmp_ip", icmpp_ip, 0);
klass = rb_define_class_under(mPcap, "ICMPRedirect", cICMPPacket);
icmp_types[ICMP_REDIRECT].klass = klass;
rb_define_method(klass, "icmp_gwaddr", icmpp_gwaddr, 0);
rb_define_method(klass, "icmp_ip", icmpp_ip, 0);
klass = rb_define_class_under(mPcap, "ICMPEcho", cICMPPacket);
icmp_types[ICMP_ECHO].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
rb_define_method(klass, "icmp_seqle", icmpp_seqle, 0);
rb_define_method(klass, "icmp_data", icmpp_data, 0);
klass = rb_define_class_under(mPcap, "ICMPRouterAdvert", cICMPPacket);
icmp_types[ICMP_ROUTERADVERT].klass = klass;
rb_define_method(klass, "icmp_num_addrs", icmpp_num_addrs, 0);
rb_define_method(klass, "icmp_wpa", icmpp_wpa, 0);
rb_define_method(klass, "icmp_lifetime", icmpp_lifetime, 0);
rb_define_method(klass, "icmp_radv", icmpp_radv, 1);
klass = rb_define_class_under(mPcap, "ICMPRouterSolicit", cICMPPacket);
icmp_types[ICMP_ROUTERSOLICIT].klass = klass;
klass = rb_define_class_under(mPcap, "ICMPTimxceed", cICMPPacket);
icmp_types[ICMP_TIMXCEED].klass = klass;
rb_define_method(klass, "icmp_ip", icmpp_ip, 0);
klass = rb_define_class_under(mPcap, "ICMPParamProb", cICMPPacket);
icmp_types[ICMP_PARAMPROB].klass = klass;
rb_define_method(klass, "icmp_pptr", icmpp_pptr, 0);
rb_define_method(klass, "icmp_ip", icmpp_ip, 0);
klass = rb_define_class_under(mPcap, "ICMPTStamp", cICMPPacket);
icmp_types[ICMP_TSTAMP].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
rb_define_method(klass, "icmp_otime", icmpp_otime, 0);
rb_define_method(klass, "icmp_rtime", icmpp_rtime, 0);
rb_define_method(klass, "icmp_ttime", icmpp_ttime, 0);
klass = rb_define_class_under(mPcap, "ICMPTStampReply", cICMPPacket);
icmp_types[ICMP_TSTAMPREPLY].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
rb_define_method(klass, "icmp_otime", icmpp_otime, 0);
rb_define_method(klass, "icmp_rtime", icmpp_rtime, 0);
rb_define_method(klass, "icmp_ttime", icmpp_ttime, 0);
klass = rb_define_class_under(mPcap, "ICMPIReq", cICMPPacket);
icmp_types[ICMP_IREQ].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
klass = rb_define_class_under(mPcap, "ICMPIReqReply", cICMPPacket);
icmp_types[ICMP_IREQREPLY].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
klass = rb_define_class_under(mPcap, "ICMPMaskReq", cICMPPacket);
icmp_types[ICMP_MASKREQ].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
/*rb_define_method(klass, "icmp_mask", icmpp_mask, 0);*/
klass = rb_define_class_under(mPcap, "ICMPMaskReply", cICMPPacket);
icmp_types[ICMP_MASKREPLY].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
/*rb_define_method(klass, "icmp_mask", icmpp_mask, 0);*/
klass = rb_define_class_under(mPcap, "ICMPTRoute", cICMPPacket);
icmp_types[ICMP_TROUTE].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_ohc", icmpp_ohc, 0);
rb_define_method(klass, "icmp_rhc", icmpp_rhc, 0);
rb_define_method(klass, "icmp_lspeed", icmpp_lspeed, 0);
rb_define_method(klass, "icmp_lmtu", icmpp_lmtu, 0);
klass = rb_define_class_under(mPcap, "ICMPDomain", cICMPPacket);
icmp_types[ICMP_DOMAIN].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
klass = rb_define_class_under(mPcap, "ICMPDomainReply", cICMPPacket);
icmp_types[ICMP_DOMAINREPLY].klass = klass;
rb_define_method(klass, "icmp_id", icmpp_id, 0);
rb_define_method(klass, "icmp_seq", icmpp_seq, 0);
rb_define_method(klass, "icmp_ttl", icmpp_ttl, 0);
/*rb_define_method(klass, "icmp_names", icmpp_names, 0);*/
}

342
external/ruby-pcapx/ip_packet.c vendored Normal file
View File

@ -0,0 +1,342 @@
/*
* ip_packet.c
*
* $Id: ip_packet.c,v 1.1.1.1 1999/10/27 09:54:38 fukusima Exp $
*
* Copyright (C) 1998, 1999 Masaki Fukushima
*/
#include "ruby_pcap.h"
#include <netdb.h>
VALUE cIPPacket;
static VALUE cIPAddress;
#define CheckTruncateIp(pkt, need) \
CheckTruncate(pkt, pkt->hdr.layer3_off, need, "truncated IP")
VALUE
setup_ip_packet(pkt, nl_len)
struct packet_object *pkt;
int nl_len;
{
VALUE class;
DEBUG_PRINT("setup_ip_packet");
if (nl_len > 0 && IP_HDR(pkt)->ip_v != 4) {
return cPacket;
}
class = cIPPacket;
nl_len = MIN(nl_len, ntohs(IP_HDR(pkt)->ip_len));
if (nl_len > 20) {
int hl = IP_HDR(pkt)->ip_hl * 4;
int tl_len = nl_len - hl;
if (tl_len > 0) {
pkt->hdr.layer4_off = pkt->hdr.layer3_off + hl;
/* if this is fragment zero, setup upper layer */
if ((ntohs(IP_HDR(pkt)->ip_off) & IP_OFFMASK) == 0) {
switch (IP_HDR(pkt)->ip_p) {
case IPPROTO_TCP:
class = setup_tcp_packet(pkt, tl_len);
break;
case IPPROTO_UDP:
class = setup_udp_packet(pkt, tl_len);
break;
case IPPROTO_ICMP:
class = setup_icmp_packet(pkt, tl_len);
break;
}
}
}
}
return class;
}
#define IPP_METHOD(func, need, val) \
static VALUE\
(func)(self)\
VALUE self;\
{\
struct packet_object *pkt;\
struct ip *ip;\
\
DEBUG_PRINT(#func);\
GetPacket(self, pkt);\
CheckTruncateIp(pkt, (need));\
ip = IP_HDR(pkt);\
return (val);\
}
IPP_METHOD(ipp_ver, 1, INT2FIX(ip->ip_v))
IPP_METHOD(ipp_hlen, 1, INT2FIX(ip->ip_hl))
IPP_METHOD(ipp_tos, 2, INT2FIX(ip->ip_tos))
IPP_METHOD(ipp_len, 4, INT2FIX(ntohs(ip->ip_len)))
IPP_METHOD(ipp_id, 6, INT2FIX(ntohs(ip->ip_id)))
IPP_METHOD(ipp_flags, 8, INT2FIX((ntohs(ip->ip_off) & ~IP_OFFMASK) >> 13))
IPP_METHOD(ipp_df, 8, ntohs(ip->ip_off) & IP_DF ? Qtrue : Qfalse)
IPP_METHOD(ipp_mf, 8, ntohs(ip->ip_off) & IP_MF ? Qtrue : Qfalse)
IPP_METHOD(ipp_off, 8, INT2FIX(ntohs(ip->ip_off) & IP_OFFMASK))
IPP_METHOD(ipp_ttl, 9, INT2FIX(ip->ip_ttl))
IPP_METHOD(ipp_proto, 10, INT2FIX(ip->ip_p))
IPP_METHOD(ipp_sum, 12, INT2FIX(ntohs(ip->ip_sum)))
IPP_METHOD(ipp_src, 16, new_ipaddr(&ip->ip_src))
IPP_METHOD(ipp_dst, 20, new_ipaddr(&ip->ip_dst))
static VALUE
ipp_sumok(self)
VALUE self;
{
struct packet_object *pkt;
struct ip *ip;
int hlen, i, sum;
unsigned short *ipus;
GetPacket(self, pkt);
CheckTruncateIp(pkt, 20);
ip = IP_HDR(pkt);
hlen = ip->ip_hl * 4;
CheckTruncateIp(pkt, hlen);
ipus = (unsigned short *)ip;
sum = 0;
hlen /= 2; /* 16-bit word */
for (i = 0; i < hlen; i++) {
sum += ntohs(ipus[i]);
sum = (sum & 0xffff) + (sum >> 16);
}
if (sum == 0xffff)
return Qtrue;
return Qfalse;
}
static VALUE
ipp_data(self)
VALUE self;
{
struct packet_object *pkt;
struct ip *ip;
int len, hlen;
DEBUG_PRINT("ipp_data");
GetPacket(self, pkt);
CheckTruncateIp(pkt, 20);
ip = IP_HDR(pkt);
hlen = ip->ip_hl * 4;
len = pkt->hdr.pkthdr.caplen - pkt->hdr.layer3_off - hlen;
return rb_str_new((u_char *)ip + hlen, len);
}
/*
* IPAddress
*/
/* IPv4 adress (32bit) is stored by immediate value */
#if SIZEOF_VOIDP < 4
# error IPAddress assumes sizeof(void *) >= 4
#endif
#define GetIPAddress(obj, addr) {\
Check_Type(obj, T_DATA);\
addr = (struct in_addr *)&(DATA_PTR(obj));\
}
VALUE
new_ipaddr(addr)
struct in_addr *addr;
{
VALUE self;
self = Data_Wrap_Struct(cIPAddress, 0, 0, (void *)addr->s_addr);
return self;
}
#ifndef INADDR_NONE
# define INADDR_NONE (0xffffffff)
#endif
static VALUE
ipaddr_s_new(self, val)
VALUE self, val;
{
struct in_addr addr;
struct hostent *hent;
char *hname;
switch(TYPE(val)) {
case T_STRING:
hname = RSTRING(val)->ptr;
hent = gethostbyname(hname);
if (hent == NULL) {
extern int h_errno;
switch (h_errno) {
case HOST_NOT_FOUND:
rb_raise(ePcapError, "host not found: %s", hname);
break;
default:
#ifdef HAVE_HSTRERROR
rb_raise(ePcapError, (char *)hstrerror(h_errno));
#else
rb_raise(ePcapError, "host not found: %s", hname);
#endif
}
}
addr = *(struct in_addr *)hent->h_addr;
break;
case T_FIXNUM:
case T_BIGNUM:
addr.s_addr = htonl(NUM2ULONG(val));
break;
default:
rb_raise(rb_eTypeError, "String or Integer required");
}
return new_ipaddr(&addr);
}
static VALUE
ipaddr_to_i(self)
VALUE self;
{
struct in_addr *addr;
GetIPAddress(self, addr);
return UINT32_2_NUM(ntohl(addr->s_addr));
}
static VALUE
ipaddr_num_s(self)
VALUE self;
{
struct in_addr *addr;
GetIPAddress(self, addr);
return rb_str_new2(inet_ntoa(*addr));
}
static VALUE
ipaddr_hostname(self)
VALUE self;
{
struct in_addr *addr;
struct hostent *host;
GetIPAddress(self, addr);
host = gethostbyaddr((char *)&addr->s_addr, sizeof addr->s_addr, AF_INET);
if (host == NULL)
return ipaddr_num_s(self);
return rb_str_new2(host->h_name);
}
static VALUE
ipaddr_to_s(self)
VALUE self;
{
if (RTEST(rbpcap_convert))
return ipaddr_hostname(self);
else
return ipaddr_num_s(self);
}
static VALUE
ipaddr_equal(self, other)
VALUE self, other;
{
struct in_addr *addr1;
struct in_addr *addr2;
GetIPAddress(self, addr1);
if (rb_class_of(other) == cIPAddress) {
GetIPAddress(other, addr2);
if (addr1->s_addr == addr2->s_addr)
return Qtrue;
}
return Qfalse;
}
static VALUE
ipaddr_hash(self)
VALUE self;
{
struct in_addr *addr;
GetIPAddress(self, addr);
return INT2FIX(ntohl(addr->s_addr));
}
static VALUE
ipaddr_dump(self, limit)
VALUE self;
VALUE limit;
{
struct in_addr *addr;
GetIPAddress(self, addr);
return rb_str_new((char *)addr, sizeof addr);
}
static VALUE
ipaddr_s_load(klass, str)
VALUE klass;
VALUE str;
{
struct in_addr addr;
int i;
if (RSTRING(str)->len != sizeof addr) {
rb_raise(rb_eArgError, "dump format error (IPAddress)");
}
for (i = 0; i < sizeof addr; i++) {
((char *)&addr)[i] = RSTRING(str)->ptr[i];
}
return new_ipaddr(&addr);
}
void
Init_ip_packet(void)
{
DEBUG_PRINT("Init_ip_packet");
cIPPacket = rb_define_class_under(mPcap, "IPPacket", cPacket);
rb_define_method(cIPPacket, "ip_ver", ipp_ver, 0);
rb_define_method(cIPPacket, "ip_hlen", ipp_hlen, 0);
rb_define_method(cIPPacket, "ip_tos", ipp_tos, 0);
rb_define_method(cIPPacket, "ip_len", ipp_len, 0);
rb_define_method(cIPPacket, "ip_id", ipp_id, 0);
rb_define_method(cIPPacket, "ip_flags", ipp_flags, 0);
rb_define_method(cIPPacket, "ip_df?", ipp_df, 0);
rb_define_method(cIPPacket, "ip_mf?", ipp_mf, 0);
rb_define_method(cIPPacket, "ip_off", ipp_off, 0);
rb_define_method(cIPPacket, "ip_ttl", ipp_ttl, 0);
rb_define_method(cIPPacket, "ip_proto", ipp_proto, 0);
rb_define_method(cIPPacket, "ip_sum", ipp_sum, 0);
rb_define_method(cIPPacket, "ip_sumok?", ipp_sumok, 0);
rb_define_method(cIPPacket, "ip_src", ipp_src, 0);
rb_define_method(cIPPacket, "src", ipp_src, 0);
rb_define_method(cIPPacket, "ip_dst", ipp_dst, 0);
rb_define_method(cIPPacket, "dst", ipp_dst, 0);
rb_define_method(cIPPacket, "ip_data", ipp_data, 0);
cIPAddress = rb_define_class_under(mPcap, "IPAddress", rb_cObject);
rb_define_singleton_method(cIPAddress, "new", ipaddr_s_new, 1);
rb_define_method(cIPAddress, "to_i", ipaddr_to_i, 0);
rb_define_method(cIPAddress, "to_s", ipaddr_to_s, 0);
rb_define_method(cIPAddress, "num_s", ipaddr_num_s, 0);
rb_define_method(cIPAddress, "to_num_s", ipaddr_num_s, 0); /* BWC */
rb_define_method(cIPAddress, "hostname", ipaddr_hostname, 0);
rb_define_method(cIPAddress, "sym_s", ipaddr_hostname, 0);
rb_define_method(cIPAddress, "==", ipaddr_equal, 1);
rb_define_method(cIPAddress, "===", ipaddr_equal, 1);
rb_define_method(cIPAddress, "eql?", ipaddr_equal, 1);
rb_define_method(cIPAddress, "hash", ipaddr_hash, 0);
rb_define_method(cIPAddress, "_dump", ipaddr_dump, 1);
rb_define_singleton_method(cIPAddress, "_load", ipaddr_s_load, 1);
Init_tcp_packet();
Init_udp_packet();
Init_icmp_packet();
}

116
external/ruby-pcapx/lib/pcap_misc.rb vendored Normal file
View File

@ -0,0 +1,116 @@
module Pcap
class Packet
def to_s
'Some packet'
end
def inspect
"#<#{type}: #{self}>"
end
end
class IPPacket
def to_s
"#{ip_src} > #{ip_dst}"
end
end
class TCPPacket
def tcp_data_len
ip_len - 4 * (ip_hlen + tcp_hlen)
end
def tcp_flags_s
return \
(tcp_urg? ? 'U' : '.') +
(tcp_ack? ? 'A' : '.') +
(tcp_psh? ? 'P' : '.') +
(tcp_rst? ? 'R' : '.') +
(tcp_syn? ? 'S' : '.') +
(tcp_fin? ? 'F' : '.')
end
def to_s
"#{src}:#{sport} > #{dst}:#{dport} #{tcp_flags_s}"
end
end
class UDPPacket
def to_s
"#{src}:#{sport} > #{dst}:#{dport} len #{udp_len} sum #{udp_sum}"
end
end
class ICMPPacket
def to_s
"#{src} > #{dst}: icmp: #{icmp_typestr}"
end
end
#
# Backword compatibility
#
IpPacket = IPPacket
IpAddress = IPAddress
TcpPacket = TCPPacket
UdpPacket = UDPPacket
# IpAddress is now obsolete.
# New class IPAddress is implemented in C.
=begin
class IpAddress
def initialize(a)
raise AurgumentError unless a.is_a?(Integer)
@addr = a
end
def to_i
return @addr
end
def ==(other)
@addr == other.to_i
end
alias === ==
alias eql? ==
def to_num_s
return ((@addr >> 24) & 0xff).to_s + "." +
((@addr >> 16) & 0xff).to_s + "." +
((@addr >> 8) & 0xff).to_s + "." +
(@addr & 0xff).to_s;
end
def hostname
addr = self.to_num_s
# "require 'socket'" is here because of the order of
# ext initialization in static linked binary
require 'socket'
begin
return Socket.gethostbyname(addr)[0]
rescue SocketError
return addr
end
end
def to_s
if Pcap.convert?
return hostname
else
return to_num_s
end
end
end
=end
end
class Time
# tcpdump style format
def tcpdump
sprintf "%0.2d:%0.2d:%0.2d.%0.6d", hour, min, sec, tv_usec
end
end
autoload :Pcaplet, 'pcaplet'

113
external/ruby-pcapx/lib/pcaplet.rb vendored Normal file
View File

@ -0,0 +1,113 @@
require 'pcap'
require 'getopts'
def pcaplet_usage()
$stderr.print <<END
Usage: #{File.basename $0} [ -dnv ] [ -i interface | -r file ]
#{' ' * File.basename($0).length} [ -c count ] [ -s snaplen ] [ filter ]
Options:
-n do not convert address to name
-d debug mode
-v verbose mode
END
end
module Pcap
class Pcaplet
def usage(status, msg = nil)
$stderr.puts msg if msg
pcaplet_usage
exit(status)
end
def initialize(args = nil)
if args
ARGV[0,0] = args.split(/\s+/)
end
usage(1) unless getopts("dnv", "i:", "r:", "c:-1", "s:68")
$DEBUG |= $OPT_d
$VERBOSE |= $OPT_v
@device = $OPT_i
@rfile = $OPT_r
Pcap.convert = !$OPT_n
@count = $OPT_c.to_i
@snaplen = $OPT_s.to_i
@filter = ARGV.join(' ')
# check option consistency
usage(1) if @device && @rfile
if !@device and !@rfile
@device = Pcap.lookupdev
end
# open
begin
if @device
@capture = Capture.open_live(@device, @snaplen)
elsif @rfile
if @rfile !~ /\.gz$/
@capture = Capture.open_offline(@rfile)
else
$stdin = IO.popen("gzip -dc < #@rfile", 'r')
@capture = Capture.open_offline('-')
end
end
@capture.setfilter(@filter)
rescue PcapError, ArgumentError
$stdout.flush
$stderr.puts $!
exit(1)
end
end
attr('capture')
def add_filter(f)
if @filter == nil || @filter =~ /^\s*$/ # if empty
@filter = f
else
f = f.source if f.is_a? Filter
@filter = "( #{@filter} ) and ( #{f} )"
end
@capture.setfilter(@filter)
end
def each_packet(&block)
begin
duplicated = (RUBY_PLATFORM =~ /linux/ && @device == "lo")
unless duplicated
@capture.loop(@count, &block)
else
flip = true
@capture.loop(@count) do |pkt|
flip = (! flip)
next if flip
block.call pkt
end
end
rescue Interrupt
$stdout.flush
$stderr.puts("Interrupted.")
$stderr.puts $@.join("\n\t") if $DEBUG
ensure
# print statistics if live
if @device
stat = @capture.stats
if stat
$stderr.print("#{stat.recv} packets received by filter\n");
$stderr.print("#{stat.drop} packets dropped by kernel\n");
end
end
end
end
alias each each_packet
def close
@capture.close
end
end
end
Pcaplet = Pcap::Pcaplet

327
external/ruby-pcapx/packet.c vendored Normal file
View File

@ -0,0 +1,327 @@
/*
* packet.c
*
* $Id: packet.c,v 1.4 2000/08/13 06:56:15 fukusima Exp $
*
* Copyright (C) 1998-2000 Masaki Fukushima
*/
#include "ruby.h"
#include "ruby_pcap.h"
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#define DL_HDR(pkt) ((u_char *)LAYER2_HDR(pkt))
#define DL_DATA(pkt) ((u_char *)LAYER3_HDR(pkt))
VALUE cPacket;
static VALUE mMarshal;
int id_load;
int id_dump;
/* called from GC */
static void
free_packet(pkt)
struct packet_object *pkt;
{
DEBUG_PRINT("free_packet");
free(pkt);
}
/* called from GC */
static void
mark_packet(pkt)
struct packet_object *pkt;
{
DEBUG_PRINT("mark_packet");
if (pkt->udata != Qnil)
rb_gc_mark(pkt->udata);
}
struct datalink_type {
int type;
int nltype_off; /* offset of network-layer type field */
int nl_off; /* offset of network-layer header */
};
/* supported datalink types */
static struct datalink_type datalinks[] = {
{ DLT_NULL, -2, 4 },
{ DLT_EN10MB, 12, 14 },
{ DLT_IEEE802, 20, 22 },
{ DLT_SLIP, -2, 16 },
{ DLT_PPP, 2, 4 },
#ifndef PCAP_FDDIPAD
{ DLT_FDDI, 19, 21 }, /* 10: DLT_FDDI */
#else
{ DLT_FDDI, 19 + PCAP_FDDIPAD, 21 + PCAP_FDDIPAD },
#endif
{ DLT_ATM_RFC1483, 6, 8 },
{ DLT_RAW, -2, 0 },
{ DLT_SLIP_BSDOS, -2, 24 },
{ DLT_PPP_BSDOS, -2, 24 },
{ DLT_IEEE802_11, -1 -1 },
{ DLT_IEEE802_11_RADIO, -1, -1 }, /* radiotap is padded to 64 bytes */
{ DLT_IEEE802_11_RADIO_AVS, -1, -1 },
{ DLT_LINUX_SLL, -1, -1 },
{ DLT_PRISM_HEADER, -1, -1 },
{ DLT_AIRONET_HEADER, -1, -1 },
{ 255, 0, 0 }
};
VALUE
new_packet(data, pkthdr, dl_type)
const u_char *data;
const struct pcap_pkthdr *pkthdr;
int dl_type;
{
VALUE class;
struct packet_object *pkt;
int nl_off, nl_len, nltype_off, nl_type, pad, i;
int t = -1;
DEBUG_PRINT("new_packet");
// This is slow and needs to be rewritten
for (i = 0; datalinks[i].type != 255; i++) {
if (datalinks[i].type == dl_type) {
t = i;
break;
}
}
/* check nework layer type and offset */
if (t == -1)
rb_raise(ePcapError, "Unknown data-link type (%d)", dl_type);
nltype_off = datalinks[dl_type].nltype_off;
nl_off = datalinks[dl_type].nl_off;
/* parse the DLT header to figure it out */
if (nltype_off == -1) {
switch(dl_type) {
case DLT_LINUX_SLL:
default:
break;
}
/* assume this is raw IP */
} else if (nltype_off == -2) {
nl_type = ETHERTYPE_IP;
} else {
/* assume Ether Type value */
nl_type = ntohs(*(u_short *)(data + nltype_off));
}
/* alloc memory and setup packet_object */
pad = nl_off % 4; /* align network layer header */
pkt = xmalloc(sizeof(*pkt) + pad + pkthdr->caplen);
pkt->hdr.version = PACKET_MARSHAL_VERSION;
pkt->hdr.flags = 0;
pkt->hdr.dl_type = dl_type;
pkt->hdr.layer3_off = OFF_NONEXIST;
pkt->hdr.layer4_off = OFF_NONEXIST;
pkt->hdr.layer5_off = OFF_NONEXIST;
pkt->hdr.pkthdr = *pkthdr;
pkt->data = (u_char *)pkt + sizeof(*pkt) + pad;
pkt->udata = Qnil;
memcpy(pkt->data, data, pkthdr->caplen);
nl_len = pkthdr->caplen - nl_off;
if (nl_off >= 0 && nl_len > 0)
pkt->hdr.layer3_off = nl_off;
/* setup upper layer */
class = cPacket;
if (pkt->hdr.layer3_off != OFF_NONEXIST) {
switch (nl_type) {
case ETHERTYPE_IP:
class = setup_ip_packet(pkt, nl_len);
break;
}
}
#if DEBUG
if (ruby_debug && TYPE(class) != T_CLASS) {
rb_fatal("not class");
}
#endif
return Data_Wrap_Struct(class, mark_packet, free_packet, pkt);
}
static VALUE
packet_load(class, str)
VALUE class;
VALUE str;
{
struct packet_object *pkt = NULL;
struct packet_object_header *hdr;
int version;
u_char *str_ptr;
DEBUG_PRINT("packet_load");
str_ptr = RSTRING(str)->ptr;
hdr = (struct packet_object_header *)str_ptr;
version = hdr->version;
if (version == PACKET_MARSHAL_VERSION) {
bpf_u_int32 caplen;
u_short layer3_off;
int pad;
caplen = ntohl(hdr->pkthdr.caplen);
layer3_off = ntohs(hdr->layer3_off);
pad = layer3_off % 4; /* align network layer header */
pkt = (struct packet_object *)xmalloc(sizeof(*pkt) + pad + caplen);
pkt->hdr.version = PACKET_MARSHAL_VERSION;
pkt->hdr.flags = hdr->flags;
pkt->hdr.dl_type = hdr->dl_type;
pkt->hdr.layer3_off = ntohs(hdr->layer3_off);
pkt->hdr.layer4_off = ntohs(hdr->layer4_off);
pkt->hdr.layer5_off = ntohs(hdr->layer5_off);
pkt->hdr.pkthdr.ts.tv_sec = ntohl(hdr->pkthdr.ts.tv_sec);
pkt->hdr.pkthdr.ts.tv_usec = ntohl(hdr->pkthdr.ts.tv_usec);
pkt->hdr.pkthdr.caplen = ntohl(hdr->pkthdr.caplen);
pkt->hdr.pkthdr.len = ntohl(hdr->pkthdr.len);
pkt->data = (u_char *)pkt + sizeof(*pkt) + pad;
memcpy(pkt->data, str_ptr + sizeof(*hdr), caplen);
if (PKTFLAG_TEST(pkt, POH_UDATA)) {
int l = sizeof(*hdr) + caplen;
VALUE ustr = rb_str_substr(str, l, RSTRING(str)->len - l);
pkt->udata = rb_funcall(mMarshal, id_load, 1, ustr);
} else {
pkt->udata = Qnil;
}
PKTFLAG_SET(pkt, POH_UDATA, (pkt->udata != Qnil));
} else {
rb_raise(rb_eArgError, "unknown packet marshal version(0x%x)", version);
}
if (pkt != NULL)
return Data_Wrap_Struct(class, mark_packet, free_packet, pkt);
else
return Qnil;
}
static VALUE
packet_dump(self, limit)
VALUE self;
VALUE limit;
{
struct packet_object *pkt;
struct packet_object_header hdr;
VALUE str;
DEBUG_PRINT("packet_dump");
GetPacket(self, pkt);
hdr.version = PACKET_MARSHAL_VERSION;
hdr.flags = pkt->hdr.flags;
hdr.dl_type = pkt->hdr.dl_type;
hdr.layer3_off = htons(pkt->hdr.layer3_off);
hdr.layer4_off = htons(pkt->hdr.layer4_off);
hdr.layer5_off = htons(pkt->hdr.layer5_off);
hdr.pkthdr.ts.tv_sec = htonl(pkt->hdr.pkthdr.ts.tv_sec);
hdr.pkthdr.ts.tv_usec = htonl(pkt->hdr.pkthdr.ts.tv_usec);
hdr.pkthdr.caplen = htonl(pkt->hdr.pkthdr.caplen);
hdr.pkthdr.len = htonl(pkt->hdr.pkthdr.len);
str = rb_str_new((char *)&hdr, sizeof(hdr));
rb_str_cat(str, pkt->data, pkt->hdr.pkthdr.caplen);
if (pkt->udata != Qnil) {
VALUE ustr;
ustr = rb_funcall(mMarshal, id_dump, 1, pkt->udata);
rb_str_concat(str, ustr);
}
return str;
}
static VALUE
packet_set_udata(self, val)
VALUE self;
VALUE val;
{
struct packet_object *pkt;
DEBUG_PRINT("packet_set_udata");
GetPacket(self, pkt);
pkt->udata = val;
PKTFLAG_SET(pkt, POH_UDATA, (val != Qnil));
return val;
}
static VALUE
packet_match(self, expr)
VALUE self;
VALUE expr;
{
if (IsKindOf(expr, cFilter)) {
return filter_match(expr, self);
}
rb_raise(rb_eArgError, "Not Filter");
}
#define PACKET_METHOD(func, val) \
static VALUE\
(func)(self)\
VALUE self;\
{\
struct packet_object *pkt;\
\
DEBUG_PRINT(#func);\
GetPacket(self, pkt);\
return (val);\
}
PACKET_METHOD(packet_get_udata, pkt->udata);
PACKET_METHOD(packet_datalink, INT2FIX(pkt->hdr.dl_type));
PACKET_METHOD(packet_ip, rb_obj_is_kind_of(self, cIPPacket));
PACKET_METHOD(packet_tcp, rb_obj_is_kind_of(self, cTCPPacket));
PACKET_METHOD(packet_udp, rb_obj_is_kind_of(self, cUDPPacket));
PACKET_METHOD(packet_length, UINT32_2_NUM(pkt->hdr.pkthdr.len));
PACKET_METHOD(packet_caplen, UINT32_2_NUM(pkt->hdr.pkthdr.caplen));
PACKET_METHOD(packet_time, rb_time_new(pkt->hdr.pkthdr.ts.tv_sec,
pkt->hdr.pkthdr.ts.tv_usec));
PACKET_METHOD(packet_time_i, rb_int2inum(pkt->hdr.pkthdr.ts.tv_sec));
PACKET_METHOD(packet_raw_data, rb_str_new(pkt->data, pkt->hdr.pkthdr.caplen));
void
Init_packet(void)
{
DEBUG_PRINT("Init_packet");
/* define class Packet */
cPacket = rb_define_class_under(mPcap, "Packet", rb_cObject);
rb_define_singleton_method(cPacket, "_load", packet_load, 1);
rb_define_method(cPacket, "_dump", packet_dump, 1);
/* marshal backward compatibility */
rb_define_singleton_method(cPacket, "_load_from", packet_load, 1);
rb_define_method(cPacket, "_dump_to", packet_dump, 1);
rb_define_method(cPacket, "udata", packet_get_udata, 0);
rb_define_method(cPacket, "udata=", packet_set_udata, 1);
rb_define_method(cPacket, "datalink", packet_datalink, 0);
rb_define_method(cPacket, "ip?", packet_ip, 0);
rb_define_method(cPacket, "tcp?", packet_tcp, 0);
rb_define_method(cPacket, "udp?", packet_udp, 0);
rb_define_method(cPacket, "length", packet_length, 0);
rb_define_method(cPacket, "size", packet_length, 0);
rb_define_method(cPacket, "caplen", packet_caplen, 0);
rb_define_method(cPacket, "time", packet_time, 0);
rb_define_method(cPacket, "time_i", packet_time_i, 0);
rb_define_method(cPacket, "raw_data", packet_raw_data, 0);
rb_define_method(cPacket, "=~", packet_match, 1);
/* mMarshal in ruby/marshal.c is static. Why? */
mMarshal = rb_eval_string("Marshal");
id_load = rb_intern("load");
id_dump = rb_intern("dump");
Init_ip_packet();
}

133
external/ruby-pcapx/ruby_pcap.h vendored Normal file
View File

@ -0,0 +1,133 @@
/*
* ruby_pcap.h
*
* $Id: ruby_pcap.h,v 1.4 2000/08/13 06:56:15 fukusima Exp $
*
* Copyright (C) 1998-2000 Masaki Fukushima
*/
#ifndef RUBY_PCAP_H
#define RUBY_PCAP_H
#include "ruby.h"
#include <pcap.h>
#include <stdio.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#ifndef IP_OFFMASK
# define IP_OFFMASK 0x1fff
#endif
#ifdef linux
# define __FAVOR_BSD
#endif
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>
#include <sys/socket.h>
#include <netdb.h>
#ifdef DEBUG
# define DEBUG_PRINT(x) \
((RTEST(ruby_debug) && RTEST(ruby_verbose))?\
(fprintf(stderr, "%s\n", x),fflush(stderr)) : 0)
#else
# define DEBUG_PRINT(x) (0)
#endif
#define UINT32_2_NUM(i) rb_uint2inum(i)
#ifndef UINT2NUM
# define UINT2NUM(i) rb_uint2inum(i)
#endif
#define MIN(x, y) ((x)<(y) ? (x) : (y))
#define PACKET_MARSHAL_VERSION 1
/* ruby config.h defines WORDS_BIGENDIAN if big-endian */
struct packet_object_header {
#ifdef WORDS_BIGENDIAN
u_char version:4; /* marshal format version */
u_char flags:4; /* flags */
#else
u_char flags:4; /* flags */
u_char version:4; /* marshal format version */
#endif
#define POH_UDATA 0x01 /* flag: user data exists */
#define POH_RSVD1 0x02 /* (reserved) */
#define POH_RSVD2 0x03 /* (reserved) */
#define POH_RSVD3 0x04 /* (reserved) */
u_char dl_type; /* data-link type (DLT_*) */
u_short layer3_off; /* layer 3 header offset */
u_short layer4_off; /* layer 4 header offset */
u_short layer5_off; /* layer 5 header offset */
#define OFF_NONEXIST 0xffff /* offset value for non-existent layer */
struct pcap_pkthdr pkthdr; /* pcap packet header */
};
struct packet_object {
struct packet_object_header hdr; /* packet object header */
u_char *data; /* packet data */
VALUE udata; /* user data */
};
#define PKTFLAG_TEST(pkt, flag) ((pkt)->hdr.flags & (flag))
#define PKTFLAG_SET(pkt, flag, val) \
((val) ? ((pkt)->hdr.flags |= (flag)) : ((pkt)->hdr.flags &= ~(flag)))
#define LAYER2_HDR(pkt) ((pkt)->data)
#define LAYER3_HDR(pkt) ((pkt)->data + (pkt)->hdr.layer3_off)
#define LAYER4_HDR(pkt) ((pkt)->data + (pkt)->hdr.layer4_off)
#define LAYER5_HDR(pkt) ((pkt)->data + (pkt)->hdr.layer5_off)
#define GetPacket(obj, pkt) Data_Get_Struct(obj, struct packet_object, pkt)
#define Caplen(pkt, from) ((pkt)->hdr.pkthdr.caplen - (from))
#define CheckTruncate(pkt, from, need, emsg) (\
(from) + (need) > (pkt)->hdr.pkthdr.caplen ? \
rb_raise(eTruncatedPacket, (emsg)) : 0 \
)
#define IsKindOf(v, class) RTEST(rb_obj_is_kind_of(v, class))
#define CheckClass(v, class) ((IsKindOf(v, class)) ? 0 :\
rb_raise(rb_eTypeError, "wrong type %s (expected %s)",\
rb_class2name(CLASS_OF(v)), rb_class2name(class)))
/* Pcap.c */
extern VALUE mPcap, rbpcap_convert;
extern VALUE ePcapError;
extern VALUE eTruncatedPacket;
extern VALUE cFilter;
void Init_pcap(void);
VALUE filter_match(VALUE self, VALUE v_pkt);
/* packet.c */
extern VALUE cPacket;
void Init_packet(void);
VALUE new_packet(const u_char *, const struct pcap_pkthdr *, int);
/* ip_packet.c */
#define IP_HDR(pkt) ((struct ip *)LAYER3_HDR(pkt))
#define IP_DATA(pkt) ((u_char *)LAYER4_HDR(pkt))
extern VALUE cIPPacket;
void Init_ip_packet(void);
VALUE setup_ip_packet(struct packet_object *, int);
VALUE new_ipaddr(struct in_addr *);
/* tcp_packet.c */
extern VALUE cTCPPacket;
void Init_tcp_packet(void);
VALUE setup_tcp_packet(struct packet_object *, int);
/* udp_packet.c */
extern VALUE cUDPPacket;
void Init_udp_packet(void);
VALUE setup_udp_packet(struct packet_object *, int);
/* icmp_packet.c */
extern VALUE cICMPPacket;
void Init_icmp_packet(void);
VALUE setup_icmp_packet(struct packet_object *, int);
#endif /* RUBY_PCAP_H */

121
external/ruby-pcapx/tcp_packet.c vendored Normal file
View File

@ -0,0 +1,121 @@
/*
* tcp_packet.c
*
* $Id: tcp_packet.c,v 1.1.1.1 1999/10/27 09:54:38 fukusima Exp $
*
* Copyright (C) 1998, 1999 Masaki Fukushima
*/
#include "ruby_pcap.h"
#include <limits.h>
#define TCP_HDR(pkt) ((struct tcphdr *)LAYER4_HDR(pkt))
#define TCP_DATA(pkt) ((u_char *)LAYER5_HDR(pkt))
#define TCP_DATALEN(pkt) (ntohs(IP_HDR(pkt)->ip_len) - \
(IP_HDR(pkt)->ip_hl + TCP_HDR(pkt)->th_off) * 4)
VALUE cTCPPacket;
#define CheckTruncateTcp(pkt, need) \
CheckTruncate(pkt, pkt->hdr.layer4_off, need, "truncated TCP")
VALUE
setup_tcp_packet(pkt, tl_len)
struct packet_object *pkt;
int tl_len;
{
VALUE class;
DEBUG_PRINT("setup_tcp_packet");
class = cTCPPacket;
if (tl_len > 20) {
int hl = TCP_HDR(pkt)->th_off * 4;
int layer5_len = tl_len - hl;
if (layer5_len > 0) {
pkt->hdr.layer5_off = pkt->hdr.layer4_off + hl;
/* upper layer */
}
}
return class;
}
#define TCPP_METHOD(func, need, val) \
static VALUE\
(func)(self)\
VALUE self;\
{\
struct packet_object *pkt;\
struct tcphdr *tcp;\
DEBUG_PRINT(#func);\
GetPacket(self, pkt);\
CheckTruncateTcp(pkt, (need));\
tcp = TCP_HDR(pkt);\
return (val);\
}
TCPP_METHOD(tcpp_sport, 2, INT2FIX(ntohs(tcp->th_sport)))
TCPP_METHOD(tcpp_dport, 4, INT2FIX(ntohs(tcp->th_dport)))
TCPP_METHOD(tcpp_seq, 8, UINT32_2_NUM(ntohl(tcp->th_seq)))
TCPP_METHOD(tcpp_acknum, 12, UINT32_2_NUM(ntohl(tcp->th_ack)))
TCPP_METHOD(tcpp_off, 13, INT2FIX(tcp->th_off))
TCPP_METHOD(tcpp_flags, 14, INT2FIX(tcp->th_flags))
TCPP_METHOD(tcpp_win, 16, INT2FIX(ntohs(tcp->th_win)))
TCPP_METHOD(tcpp_sum, 18, INT2FIX(ntohs(tcp->th_sum)))
TCPP_METHOD(tcpp_urp, 20, INT2FIX(ntohs(tcp->th_urp)))
#define TCPP_FLAG(func, flag) \
TCPP_METHOD(func, 14, (tcp->th_flags & flag) ? Qtrue : Qfalse)
TCPP_FLAG(tcpp_fin, TH_FIN)
TCPP_FLAG(tcpp_syn, TH_SYN)
TCPP_FLAG(tcpp_rst, TH_RST)
TCPP_FLAG(tcpp_psh, TH_PUSH)
TCPP_FLAG(tcpp_ack, TH_ACK)
TCPP_FLAG(tcpp_urg, TH_URG)
static VALUE
tcpp_data(self)
VALUE self;
{
struct packet_object *pkt;
VALUE v_len;
int len;
DEBUG_PRINT("tcpp_data");
GetPacket(self, pkt);
if (pkt->hdr.layer5_off == OFF_NONEXIST) return Qnil;
len = MIN(Caplen(pkt, pkt->hdr.layer5_off), TCP_DATALEN(pkt));
if (len < 1) return Qnil;
return rb_str_new(TCP_DATA(pkt), len);
}
void
Init_tcp_packet(void)
{
DEBUG_PRINT("Init_tcp_packet");
/* define class TcpPacket */
cTCPPacket = rb_define_class_under(mPcap, "TCPPacket", cIPPacket);
rb_define_method(cTCPPacket, "tcp_sport", tcpp_sport, 0);
rb_define_method(cTCPPacket, "sport", tcpp_sport, 0);
rb_define_method(cTCPPacket, "tcp_dport", tcpp_dport, 0);
rb_define_method(cTCPPacket, "dport", tcpp_dport, 0);
rb_define_method(cTCPPacket, "tcp_seq", tcpp_seq, 0);
rb_define_method(cTCPPacket, "tcp_ack", tcpp_acknum, 0);
rb_define_method(cTCPPacket, "tcp_off", tcpp_off, 0);
rb_define_method(cTCPPacket, "tcp_hlen", tcpp_off, 0);
rb_define_method(cTCPPacket, "tcp_flags", tcpp_flags, 0);
rb_define_method(cTCPPacket, "tcp_win", tcpp_win, 0);
rb_define_method(cTCPPacket, "tcp_sum", tcpp_sum, 0);
rb_define_method(cTCPPacket, "tcp_urp", tcpp_urp, 0);
rb_define_method(cTCPPacket, "tcp_fin?", tcpp_fin, 0);
rb_define_method(cTCPPacket, "tcp_syn?", tcpp_syn, 0);
rb_define_method(cTCPPacket, "tcp_rst?", tcpp_rst, 0);
rb_define_method(cTCPPacket, "tcp_psh?", tcpp_psh, 0);
rb_define_method(cTCPPacket, "tcp_ack?", tcpp_ack, 0);
rb_define_method(cTCPPacket, "tcp_urg?", tcpp_urg, 0);
rb_define_method(cTCPPacket, "tcp_data", tcpp_data, 0);
}

29
external/ruby-pcapx/test.rb vendored Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__))
require 'pcaplet'
include Pcap
class Time
# tcpdump style format
def to_s
sprintf "%0.2d:%0.2d:%0.2d.%0.6d", hour, min, sec, tv_usec
end
end
pcaplet = Pcaplet.new('-i ath0 ')
pcaplet.each_packet { |pkt|
print "#{pkt.time} #{pkt}"
if pkt.tcp?
print " (#{pkt.tcp_data_len})"
print " ack #{pkt.tcp_ack}" if pkt.tcp_ack?
print " win #{pkt.tcp_win}"
end
if pkt.ip?
print " (DF)" if pkt.ip_df?
end
print "\n"
}
pcaplet.close

96
external/ruby-pcapx/udp_packet.c vendored Normal file
View File

@ -0,0 +1,96 @@
/*
* udp_packet.c
*
* $Id: udp_packet.c,v 1.1.1.1 1999/10/27 09:54:38 fukusima Exp $
*
* Copyright (C) 1999 Masaki Fukushima
*/
#include "ruby_pcap.h"
#include <limits.h>
#define UDP_HDR(pkt) ((struct udphdr *)LAYER4_HDR(pkt))
#define UDP_DATA(pkt) ((u_char *)LAYER5_HDR(pkt))
#define UDP_LENGTH(pkt) (ntohs(UDP_HDR(pkt)->uh_ulen))
VALUE cUDPPacket;
#define CheckTruncateUdp(pkt, need) \
CheckTruncate(pkt, pkt->hdr.layer4_off, need, "truncated UDP")
VALUE
setup_udp_packet(pkt, tl_len)
struct packet_object *pkt;
int tl_len;
{
VALUE class;
DEBUG_PRINT("setup_udp_packet");
class = cUDPPacket;
if (tl_len > 8) {
int hl = 8;
int layer5_len;
tl_len = MIN(tl_len, UDP_LENGTH(pkt));
layer5_len = tl_len - hl;
if (layer5_len > 0) {
pkt->hdr.layer5_off = pkt->hdr.layer4_off + hl;
/* upper layer */
}
}
return class;
}
#define UDPP_METHOD(func, need, val) \
static VALUE\
(func)(self)\
VALUE self;\
{\
struct packet_object *pkt;\
struct udphdr *udp;\
DEBUG_PRINT(#func);\
GetPacket(self, pkt);\
CheckTruncateUdp(pkt, (need));\
udp = UDP_HDR(pkt);\
return (val);\
}
UDPP_METHOD(udpp_sport, 2, INT2FIX(ntohs(udp->uh_sport)))
UDPP_METHOD(udpp_dport, 4, INT2FIX(ntohs(udp->uh_dport)))
UDPP_METHOD(udpp_len, 6, INT2FIX(ntohs(udp->uh_ulen)))
UDPP_METHOD(udpp_sum, 8, INT2FIX(ntohs(udp->uh_sum)))
static VALUE
udpp_data(self)
VALUE self;
{
struct packet_object *pkt;
int len;
DEBUG_PRINT("udpp_data");
GetPacket(self, pkt);
CheckTruncateUdp(pkt, 8);
if (pkt->hdr.layer5_off == OFF_NONEXIST) return Qnil;
len = MIN(Caplen(pkt, pkt->hdr.layer5_off), UDP_LENGTH(pkt)-8);
return rb_str_new(UDP_DATA(pkt), len);
}
void
Init_udp_packet(void)
{
DEBUG_PRINT("Init_udp_packet");
/* define class UdpPacket */
cUDPPacket = rb_define_class_under(mPcap, "UDPPacket", cIPPacket);
rb_define_method(cUDPPacket, "udp_sport", udpp_sport, 0);
rb_define_method(cUDPPacket, "sport", udpp_sport, 0);
rb_define_method(cUDPPacket, "udp_dport", udpp_dport, 0);
rb_define_method(cUDPPacket, "dport", udpp_dport, 0);
rb_define_method(cUDPPacket, "udp_len", udpp_len, 0);
rb_define_method(cUDPPacket, "udp_sum", udpp_sum, 0);
rb_define_method(cUDPPacket, "udp_data", udpp_data, 0);
}