提交ledset
This commit is contained in:
parent
b41b4705e6
commit
5e68b7c2a9
|
@ -0,0 +1,73 @@
|
||||||
|
# This file is used to ignore files which are generated
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
*~
|
||||||
|
*.autosave
|
||||||
|
*.a
|
||||||
|
*.core
|
||||||
|
*.moc
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*_pch.h.cpp
|
||||||
|
*_resource.rc
|
||||||
|
*.qm
|
||||||
|
.#*
|
||||||
|
*.*#
|
||||||
|
core
|
||||||
|
!core/
|
||||||
|
tags
|
||||||
|
.DS_Store
|
||||||
|
.directory
|
||||||
|
*.debug
|
||||||
|
Makefile*
|
||||||
|
*.prl
|
||||||
|
*.app
|
||||||
|
moc_*.cpp
|
||||||
|
ui_*.h
|
||||||
|
qrc_*.cpp
|
||||||
|
Thumbs.db
|
||||||
|
*.res
|
||||||
|
*.rc
|
||||||
|
/.qmake.cache
|
||||||
|
/.qmake.stash
|
||||||
|
|
||||||
|
# qtcreator generated files
|
||||||
|
*.pro.user*
|
||||||
|
|
||||||
|
# xemacs temporary files
|
||||||
|
*.flc
|
||||||
|
|
||||||
|
# Vim temporary files
|
||||||
|
.*.swp
|
||||||
|
|
||||||
|
# Visual Studio generated files
|
||||||
|
*.ib_pdb_index
|
||||||
|
*.idb
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.vcproj
|
||||||
|
*vcproj.*.*.user
|
||||||
|
*.ncb
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.vcxproj
|
||||||
|
*vcxproj.*
|
||||||
|
|
||||||
|
# MinGW generated files
|
||||||
|
*.Debug
|
||||||
|
*.Release
|
||||||
|
|
||||||
|
# Python byte code
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
# --------
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
|
@ -0,0 +1,10 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
SUBDIRS = basic_dump basic_dump_ex iflist pcap_filter pktdump_ex readfile readfile_ex savedump sendpack UDPdump
|
||||||
|
|
||||||
|
all clean install uninstall: ${SUBDIRS}
|
||||||
|
for subdir in ${SUBDIRS}; do \
|
||||||
|
echo "Entering $$subdir"; \
|
||||||
|
(cd $$subdir && ${MAKE} $@) \
|
||||||
|
done;
|
|
@ -0,0 +1,137 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "UDPdump"=.\UDPdump\UDPdump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "basic_dump"=.\basic_dump\basic_dump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "basic_dump_ex"=.\basic_dump_ex\basic_dump_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "iflist"=.\iflist\iflist.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "pcap_filter"=.\pcap_filter\pcap_filter.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "pktdump_ex"=.\pktdump_ex\pktdump_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "readfile"=.\readfile\readfile.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "readfile_ex"=.\readfile_ex\readfile_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "savedump"=.\savedump\savedump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "sendpack"=.\sendpack\sendpack.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Loris Degioanni
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = udpdump.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap -lwsock32
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o udpdump.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} udpdump.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="UDPdump" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=UDPdump - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "UDPdump.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "UDPdump.mak" CFG="UDPdump - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "UDPdump - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "UDPdump - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "UDPdump - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "UDPdump - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "UDPdump - Win32 Release"
|
||||||
|
# Name "UDPdump - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\udpdump.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "UDPdump"=.\UDPdump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,242 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/*
|
||||||
|
* we do not want the warnings about the old deprecated and unsecure CRT functions
|
||||||
|
* since these examples can be compiled under *nix as well
|
||||||
|
*/
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
/* 4 bytes IP address */
|
||||||
|
typedef struct ip_address
|
||||||
|
{
|
||||||
|
u_char byte1;
|
||||||
|
u_char byte2;
|
||||||
|
u_char byte3;
|
||||||
|
u_char byte4;
|
||||||
|
}ip_address;
|
||||||
|
|
||||||
|
/* IPv4 header */
|
||||||
|
typedef struct ip_header
|
||||||
|
{
|
||||||
|
u_char ver_ihl; // Version (4 bits) + Internet header length (4 bits)
|
||||||
|
u_char tos; // Type of service
|
||||||
|
u_short tlen; // Total length
|
||||||
|
u_short identification; // Identification
|
||||||
|
u_short flags_fo; // Flags (3 bits) + Fragment offset (13 bits)
|
||||||
|
u_char ttl; // Time to live
|
||||||
|
u_char proto; // Protocol
|
||||||
|
u_short crc; // Header checksum
|
||||||
|
ip_address saddr; // Source address
|
||||||
|
ip_address daddr; // Destination address
|
||||||
|
u_int op_pad; // Option + Padding
|
||||||
|
}ip_header;
|
||||||
|
|
||||||
|
/* UDP header*/
|
||||||
|
typedef struct udp_header
|
||||||
|
{
|
||||||
|
u_short sport; // Source port
|
||||||
|
u_short dport; // Destination port
|
||||||
|
u_short len; // Datagram length
|
||||||
|
u_short crc; // Checksum
|
||||||
|
}udp_header;
|
||||||
|
|
||||||
|
/* prototype of the packet handler */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
u_int netmask;
|
||||||
|
char packet_filter[] = "ip and udp";
|
||||||
|
struct bpf_program fcode;
|
||||||
|
|
||||||
|
/* Retrieve the device list */
|
||||||
|
if(pcap_findalldevs(&alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf("%d", &inum);
|
||||||
|
|
||||||
|
/* Check if the user specified a valid adapter */
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nAdapter number out of range.\n");
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the adapter */
|
||||||
|
if ((adhandle= pcap_open_live(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on all the MACs.
|
||||||
|
1, // promiscuous mode (nonzero means promiscuous)
|
||||||
|
1000, // read timeout
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check the link layer. We support only Ethernet for simplicity. */
|
||||||
|
if(pcap_datalink(adhandle) != DLT_EN10MB)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nThis program works only on Ethernet networks.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(d->addresses != NULL)
|
||||||
|
/* Retrieve the mask of the first address of the interface */
|
||||||
|
netmask=((struct sockaddr_in *)(d->addresses->netmask))->sin_addr.S_un.S_addr;
|
||||||
|
else
|
||||||
|
/* If the interface is without addresses we suppose to be in a C class network */
|
||||||
|
netmask=0xffffff;
|
||||||
|
|
||||||
|
|
||||||
|
//compile the filter
|
||||||
|
if (pcap_compile(adhandle, &fcode, packet_filter, 1, netmask) <0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the filter
|
||||||
|
if (pcap_setfilter(adhandle, &fcode)<0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError setting the filter.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nlistening on %s...\n", d->description);
|
||||||
|
|
||||||
|
/* At this point, we don't need any more the device list. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/* start the capture */
|
||||||
|
pcap_loop(adhandle, 0, packet_handler, NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback function invoked by libpcap for every incoming packet */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
struct tm *ltime;
|
||||||
|
char timestr[16];
|
||||||
|
ip_header *ih;
|
||||||
|
udp_header *uh;
|
||||||
|
u_int ip_len;
|
||||||
|
u_short sport,dport;
|
||||||
|
time_t local_tv_sec;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unused parameter
|
||||||
|
*/
|
||||||
|
(VOID)(param);
|
||||||
|
|
||||||
|
/* convert the timestamp to readable format */
|
||||||
|
local_tv_sec = header->ts.tv_sec;
|
||||||
|
ltime=localtime(&local_tv_sec);
|
||||||
|
strftime( timestr, sizeof timestr, "%H:%M:%S", ltime);
|
||||||
|
|
||||||
|
/* print timestamp and length of the packet */
|
||||||
|
printf("%s.%.6d len:%d ", timestr, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
/* retireve the position of the ip header */
|
||||||
|
ih = (ip_header *) (pkt_data +
|
||||||
|
14); //length of ethernet header
|
||||||
|
|
||||||
|
/* retireve the position of the udp header */
|
||||||
|
ip_len = (ih->ver_ihl & 0xf) * 4;
|
||||||
|
uh = (udp_header *) ((u_char*)ih + ip_len);
|
||||||
|
|
||||||
|
/* convert from network byte order to host byte order */
|
||||||
|
sport = ntohs( uh->sport );
|
||||||
|
dport = ntohs( uh->dport );
|
||||||
|
|
||||||
|
/* print ip addresses and udp ports */
|
||||||
|
printf("%d.%d.%d.%d.%d -> %d.%d.%d.%d.%d\n",
|
||||||
|
ih->saddr.byte1,
|
||||||
|
ih->saddr.byte2,
|
||||||
|
ih->saddr.byte3,
|
||||||
|
ih->saddr.byte4,
|
||||||
|
sport,
|
||||||
|
ih->daddr.byte1,
|
||||||
|
ih->daddr.byte2,
|
||||||
|
ih->daddr.byte3,
|
||||||
|
ih->daddr.byte4,
|
||||||
|
dport);
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = basic_dump.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o basic_dump.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} basic_dump.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,109 @@
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/*
|
||||||
|
* we do not want the warnings about the old deprecated and unsecure CRT functions
|
||||||
|
* since these examples can be compiled under *nix as well
|
||||||
|
*/
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
/* prototype of the packet handler */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
|
||||||
|
/* Retrieve the device list */
|
||||||
|
if(pcap_findalldevs(&alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf("%d", &inum);
|
||||||
|
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the device */
|
||||||
|
/* Open the adapter */
|
||||||
|
if ((adhandle= pcap_open_live(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on all the MACs.
|
||||||
|
1, // promiscuous mode (nonzero means promiscuous)
|
||||||
|
1000, // read timeout
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nlistening on %s...\n", d->description);
|
||||||
|
|
||||||
|
/* At this point, we don't need any more the device list. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/* start the capture */
|
||||||
|
pcap_loop(adhandle, 0, packet_handler, NULL);
|
||||||
|
|
||||||
|
pcap_close(adhandle);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Callback function invoked by libpcap for every incoming packet */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
struct tm *ltime;
|
||||||
|
char timestr[16];
|
||||||
|
time_t local_tv_sec;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unused parameters
|
||||||
|
*/
|
||||||
|
(VOID)(param);
|
||||||
|
(VOID)(pkt_data);
|
||||||
|
|
||||||
|
/* convert the timestamp to readable format */
|
||||||
|
local_tv_sec = header->ts.tv_sec;
|
||||||
|
ltime=localtime(&local_tv_sec);
|
||||||
|
strftime( timestr, sizeof timestr, "%H:%M:%S", ltime);
|
||||||
|
|
||||||
|
printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="basic_dump" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=basic_dump - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "basic_dump.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "basic_dump.mak" CFG="basic_dump - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "basic_dump - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "basic_dump - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "basic_dump - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "basic_dump - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "basic_dump - Win32 Release"
|
||||||
|
# Name "basic_dump - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\basic_dump.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "basic_dump"=.\basic_dump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = basic_dump_ex.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o basic_dump_ex.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} basic_dump_ex.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,106 @@
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/*
|
||||||
|
* we do not want the warnings about the old deprecated and unsecure CRT functions
|
||||||
|
* since these examples can be compiled under *nix as well
|
||||||
|
*/
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle;
|
||||||
|
int res;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
struct tm *ltime;
|
||||||
|
char timestr[16];
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
time_t local_tv_sec;
|
||||||
|
|
||||||
|
|
||||||
|
/* Retrieve the device list */
|
||||||
|
if(pcap_findalldevs(&alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf("%d", &inum);
|
||||||
|
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the adapter */
|
||||||
|
if ((adhandle= pcap_open_live(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on all the MACs.
|
||||||
|
1, // promiscuous mode (nonzero means promiscuous)
|
||||||
|
1000, // read timeout
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nlistening on %s...\n", d->description);
|
||||||
|
|
||||||
|
/* At this point, we don't need any more the device list. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/* Retrieve the packets */
|
||||||
|
while((res = pcap_next_ex( adhandle, &header, &pkt_data)) >= 0){
|
||||||
|
|
||||||
|
if(res == 0)
|
||||||
|
/* Timeout elapsed */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* convert the timestamp to readable format */
|
||||||
|
local_tv_sec = header->ts.tv_sec;
|
||||||
|
ltime=localtime(&local_tv_sec);
|
||||||
|
strftime( timestr, sizeof timestr, "%H:%M:%S", ltime);
|
||||||
|
|
||||||
|
printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res == -1){
|
||||||
|
printf("Error reading the packets: %s\n", pcap_geterr(adhandle));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pcap_close(adhandle);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="basic_dump_ex" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=basic_dump_ex - Win32 Release
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "basic_dump_ex.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "basic_dump_ex.mak" CFG="basic_dump_ex - Win32 Release"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "basic_dump_ex - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "basic_dump_ex - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "basic_dump_ex - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "basic_dump_ex - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "basic_dump_ex - Win32 Release"
|
||||||
|
# Name "basic_dump_ex - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\basic_dump_ex.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "basic_dump_ex"=.\basic_dump_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = iflist.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o iflist.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} iflist.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,172 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/*
|
||||||
|
* we do not want the warnings about the old deprecated and unsecure CRT functions
|
||||||
|
* since these examples can be compiled under *nix as well
|
||||||
|
*/
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#else
|
||||||
|
#include <winsock.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Function prototypes
|
||||||
|
void ifprint(pcap_if_t *d);
|
||||||
|
char *iptos(u_long in);
|
||||||
|
char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen);
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE+1];
|
||||||
|
|
||||||
|
/* Retrieve the device list */
|
||||||
|
if(pcap_findalldevs(&alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scan the list printing every entry */
|
||||||
|
for(d=alldevs;d;d=d->next)
|
||||||
|
{
|
||||||
|
ifprint(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Print all the available information on the given interface */
|
||||||
|
void ifprint(pcap_if_t *d)
|
||||||
|
{
|
||||||
|
pcap_addr_t *a;
|
||||||
|
char ip6str[128];
|
||||||
|
|
||||||
|
/* Name */
|
||||||
|
printf("%s\n",d->name);
|
||||||
|
|
||||||
|
/* Description */
|
||||||
|
if (d->description)
|
||||||
|
printf("\tDescription: %s\n",d->description);
|
||||||
|
|
||||||
|
/* Loopback Address*/
|
||||||
|
printf("\tLoopback: %s\n",(d->flags & PCAP_IF_LOOPBACK)?"yes":"no");
|
||||||
|
|
||||||
|
/* IP addresses */
|
||||||
|
for(a=d->addresses;a;a=a->next) {
|
||||||
|
printf("\tAddress Family: #%d\n",a->addr->sa_family);
|
||||||
|
|
||||||
|
switch(a->addr->sa_family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
printf("\tAddress Family Name: AF_INET\n");
|
||||||
|
if (a->addr)
|
||||||
|
printf("\tAddress: %s\n",iptos(((struct sockaddr_in *)a->addr)->sin_addr.s_addr));
|
||||||
|
if (a->netmask)
|
||||||
|
printf("\tNetmask: %s\n",iptos(((struct sockaddr_in *)a->netmask)->sin_addr.s_addr));
|
||||||
|
if (a->broadaddr)
|
||||||
|
printf("\tBroadcast Address: %s\n",iptos(((struct sockaddr_in *)a->broadaddr)->sin_addr.s_addr));
|
||||||
|
if (a->dstaddr)
|
||||||
|
printf("\tDestination Address: %s\n",iptos(((struct sockaddr_in *)a->dstaddr)->sin_addr.s_addr));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AF_INET6:
|
||||||
|
printf("\tAddress Family Name: AF_INET6\n");
|
||||||
|
#ifndef __MINGW32__ /* Cygnus doesn't have IPv6 */
|
||||||
|
if (a->addr)
|
||||||
|
printf("\tAddress: %s\n", ip6tos(a->addr, ip6str, sizeof(ip6str)));
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("\tAddress Family Name: Unknown\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* From tcptraceroute, convert a numeric IP address to a string */
|
||||||
|
#define IPTOSBUFFERS 12
|
||||||
|
char *iptos(u_long in)
|
||||||
|
{
|
||||||
|
static char output[IPTOSBUFFERS][3*4+3+1];
|
||||||
|
static short which;
|
||||||
|
u_char *p;
|
||||||
|
|
||||||
|
p = (u_char *)∈
|
||||||
|
which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);
|
||||||
|
sprintf(output[which], "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
|
||||||
|
return output[which];
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef __MINGW32__ /* Cygnus doesn't have IPv6 */
|
||||||
|
char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen)
|
||||||
|
{
|
||||||
|
socklen_t sockaddrlen;
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
sockaddrlen = sizeof(struct sockaddr_in6);
|
||||||
|
#else
|
||||||
|
sockaddrlen = sizeof(struct sockaddr_storage);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if(getnameinfo(sockaddr,
|
||||||
|
sockaddrlen,
|
||||||
|
address,
|
||||||
|
addrlen,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
NI_NUMERICHOST) != 0) address = NULL;
|
||||||
|
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="iflist" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=iflist - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "iflist.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "iflist.mak" CFG="iflist - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "iflist - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "iflist - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "iflist - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "iflist - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "iflist - Win32 Release"
|
||||||
|
# Name "iflist - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\iflist.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "iflist"=.\iflist.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = pcap_filter.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o pf.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} pf.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,179 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#define MAX_PRINT 80
|
||||||
|
#define MAX_LINE 16
|
||||||
|
|
||||||
|
|
||||||
|
void usage();
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
char *source = NULL;
|
||||||
|
char *ofilename = NULL;
|
||||||
|
char *filter = NULL;
|
||||||
|
int i;
|
||||||
|
pcap_dumper_t *dumpfile;
|
||||||
|
struct bpf_program fcode;
|
||||||
|
bpf_u_int32 NetMask;
|
||||||
|
int res;
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse parameters */
|
||||||
|
for(i=1;i < argc; i+= 2)
|
||||||
|
{
|
||||||
|
switch (argv[i] [1])
|
||||||
|
{
|
||||||
|
case 's':
|
||||||
|
{
|
||||||
|
source=argv[i+1];
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'o':
|
||||||
|
{
|
||||||
|
ofilename=argv[i+1];
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
{
|
||||||
|
filter=argv[i+1];
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// open a capture from the network
|
||||||
|
if (source != NULL)
|
||||||
|
{
|
||||||
|
if ((fp = pcap_open_live(source, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on all the MACs.
|
||||||
|
1, // promiscuous mode (nonzero means promiscuous)
|
||||||
|
1000, // read timeout
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter.\n");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else usage();
|
||||||
|
|
||||||
|
if (filter != NULL)
|
||||||
|
{
|
||||||
|
// We should loop through the adapters returned by the pcap_findalldevs_ex()
|
||||||
|
// in order to locate the correct one.
|
||||||
|
//
|
||||||
|
// Let's do things simpler: we suppose to be in a C class network ;-)
|
||||||
|
NetMask=0xffffff;
|
||||||
|
|
||||||
|
//compile the filter
|
||||||
|
if(pcap_compile(fp, &fcode, filter, 1, NetMask) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError compiling filter: wrong syntax.\n");
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the filter
|
||||||
|
if(pcap_setfilter(fp, &fcode)<0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError setting the filter\n");
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//open the dump file
|
||||||
|
if (ofilename != NULL)
|
||||||
|
{
|
||||||
|
dumpfile= pcap_dump_open(fp, ofilename);
|
||||||
|
|
||||||
|
if (dumpfile == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError opening output file\n");
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
return -5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else usage();
|
||||||
|
|
||||||
|
//start the capture
|
||||||
|
while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(res == 0)
|
||||||
|
/* Timeout elapsed */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//save the packet on the dump file
|
||||||
|
pcap_dump((unsigned char *) dumpfile, header, pkt_data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
pcap_dump_close(dumpfile);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void usage()
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("\npf - Generic Packet Filter.\n");
|
||||||
|
printf("\nUsage:\npf -s source -o output_file_name [-f filter_string]\n\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="pcap_filter" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=pcap_filter - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "pcap_filter.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "pcap_filter.mak" CFG="pcap_filter - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "pcap_filter - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "pcap_filter - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "pcap_filter - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386 /out:"Release/pf.exe"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "pcap_filter - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/pf.exe" /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "pcap_filter - Win32 Release"
|
||||||
|
# Name "pcap_filter - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\pcap_filter.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "pcap_filter"=.\pcap_filter.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = pktdump_ex.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o pktdump_ex.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} pktdump_ex.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/*
|
||||||
|
* we do not want the warnings about the old deprecated and unsecure CRT functions
|
||||||
|
* since these examples can be compiled under *nix as well
|
||||||
|
*/
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#define LINE_LEN 16
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs, *d;
|
||||||
|
pcap_t *fp;
|
||||||
|
u_int inum, i=0;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
int res;
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
|
||||||
|
printf("pktdump_ex: prints the packets of the network using WinPcap.\n");
|
||||||
|
printf(" Usage: pktdump_ex [-s source]\n\n"
|
||||||
|
" Examples:\n"
|
||||||
|
" pktdump_ex -s file.acp\n"
|
||||||
|
" pktdump_ex -s \\Device\\NPF_{C8736017-F3C3-4373-94AC-9A34B7DAD998}\n\n");
|
||||||
|
|
||||||
|
if(argc < 3)
|
||||||
|
{
|
||||||
|
printf("\nNo adapter selected: printing the device list:\n");
|
||||||
|
/* The user didn't provide a packet source: Retrieve the local device list */
|
||||||
|
if(pcap_findalldevs(&alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s\n ", ++i, d->name);
|
||||||
|
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf("%d", &inum);
|
||||||
|
|
||||||
|
if (inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for (d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the adapter */
|
||||||
|
if ((fp = pcap_open_live(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on all the MACs.
|
||||||
|
1, // promiscuous mode (nonzero means promiscuous)
|
||||||
|
1000, // read timeout
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError opening adapter\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Do not check for the switch type ('-s') */
|
||||||
|
if ((fp = pcap_open_live(argv[2], // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on all the MACs.
|
||||||
|
1, // promiscuous mode (nonzero means promiscuous)
|
||||||
|
1000, // read timeout
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError opening adapter\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the packets */
|
||||||
|
while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(res == 0)
|
||||||
|
/* Timeout elapsed */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* print pkt timestamp and pkt len */
|
||||||
|
printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
/* Print the packet */
|
||||||
|
for (i=1; (i < header->caplen + 1 ) ; i++)
|
||||||
|
{
|
||||||
|
printf("%.2x ", pkt_data[i-1]);
|
||||||
|
if ( (i % LINE_LEN) == 0) printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res == -1)
|
||||||
|
{
|
||||||
|
printf("Error reading the packets: %s\n", pcap_geterr(fp));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="pktdump_ex" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=pktdump_ex - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "pktdump_ex.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "pktdump_ex.mak" CFG="pktdump_ex - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "pktdump_ex - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "pktdump_ex - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "pktdump_ex - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "pktdump_ex - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "pktdump_ex - Win32 Release"
|
||||||
|
# Name "pktdump_ex - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\pktdump_ex.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "pktdump_ex"=.\pktdump_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = readfile.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o readfile.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} readfile.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,61 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#define LINE_LEN 16
|
||||||
|
|
||||||
|
void dispatcher_handler(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
|
||||||
|
if(argc != 2)
|
||||||
|
{
|
||||||
|
printf("usage: %s filename", argv[0]);
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the capture file */
|
||||||
|
if ((fp = pcap_open_offline(argv[1], // name of the device
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the file %s.\n", argv[1]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read and dispatch packets until EOF is reached */
|
||||||
|
pcap_loop(fp, 0, dispatcher_handler, NULL);
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void dispatcher_handler(u_char *temp1,
|
||||||
|
const struct pcap_pkthdr *header,
|
||||||
|
const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
u_int i=0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unused variable
|
||||||
|
*/
|
||||||
|
(VOID*)temp1;
|
||||||
|
|
||||||
|
/* print pkt timestamp and pkt len */
|
||||||
|
printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
/* Print the packet */
|
||||||
|
for (i=1; (i < header->caplen + 1 ) ; i++)
|
||||||
|
{
|
||||||
|
printf("%.2x ", pkt_data[i-1]);
|
||||||
|
if ( (i % LINE_LEN) == 0) printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="readfile" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=readfile - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "readfile.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "readfile.mak" CFG="readfile - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "readfile - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "readfile - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "readfile - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "readfile - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "readfile - Win32 Release"
|
||||||
|
# Name "readfile - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\readfile.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "readfile"=.\readfile.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = readfile_ex.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o readfile_ex.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} readfile_ex.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,56 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#define LINE_LEN 16
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
u_int i=0;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
if(argc != 2)
|
||||||
|
{
|
||||||
|
printf("usage: %s filename", argv[0]);
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the capture file */
|
||||||
|
if ((fp = pcap_open_offline(argv[1], // name of the device
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the file %s.\n", argv[1]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieve the packets from the file */
|
||||||
|
while((res = pcap_next_ex(fp, &header, &pkt_data)) >= 0)
|
||||||
|
{
|
||||||
|
/* print pkt timestamp and pkt len */
|
||||||
|
printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
/* Print the packet */
|
||||||
|
for (i=1; (i < header->caplen + 1 ) ; i++)
|
||||||
|
{
|
||||||
|
printf("%.2x ", pkt_data[i-1]);
|
||||||
|
if ( (i % LINE_LEN) == 0) printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (res == -1)
|
||||||
|
{
|
||||||
|
printf("Error reading the packets: %s\n", pcap_geterr(fp));
|
||||||
|
}
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="readfile_ex" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=readfile_ex - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "readfile_ex.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "readfile_ex.mak" CFG="readfile_ex - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "readfile_ex - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "readfile_ex - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "readfile_ex - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "readfile_ex - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "readfile_ex - Win32 Release"
|
||||||
|
# Name "readfile_ex - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\readfile_ex.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "readfile_ex"=.\readfile_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = savedump.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o savedump.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} savedump.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,111 @@
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/*
|
||||||
|
* we do not want the warnings about the old deprecated and unsecure CRT functions
|
||||||
|
* since these examples can be compiled under *nix as well
|
||||||
|
*/
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
/* prototype of the packet handler */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
pcap_dumper_t *dumpfile;
|
||||||
|
|
||||||
|
|
||||||
|
/* Check command line */
|
||||||
|
if(argc != 2)
|
||||||
|
{
|
||||||
|
printf("usage: %s filename", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieve the device list on the local machine */
|
||||||
|
if (pcap_findalldevs(&alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf("%d", &inum);
|
||||||
|
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
|
||||||
|
/* Open the adapter */
|
||||||
|
if ((adhandle= pcap_open_live(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on all the MACs.
|
||||||
|
1, // promiscuous mode (nonzero means promiscuous)
|
||||||
|
1000, // read timeout
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the dump file */
|
||||||
|
dumpfile = pcap_dump_open(adhandle, argv[1]);
|
||||||
|
|
||||||
|
if(dumpfile==NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError opening output file\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nlistening on %s... Press Ctrl+C to stop...\n", d->description);
|
||||||
|
|
||||||
|
/* At this point, we no longer need the device list. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/* start the capture */
|
||||||
|
pcap_loop(adhandle, 0, packet_handler, (unsigned char *)dumpfile);
|
||||||
|
|
||||||
|
pcap_close(adhandle);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback function invoked by libpcap for every incoming packet */
|
||||||
|
void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
/* save the packet on the dump file */
|
||||||
|
pcap_dump(dumpfile, header, pkt_data);
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="savedump" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=savedump - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "savedump.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "savedump.mak" CFG="savedump - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "savedump - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "savedump - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "savedump - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "savedump - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "savedump - Win32 Release"
|
||||||
|
# Name "savedump - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\savedump.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "savedump"=.\savedump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Makefile for cygwin gcc
|
||||||
|
# Nate Lawson <nate@rootlabs.com>
|
||||||
|
|
||||||
|
PCAP_PATH = ../../lib
|
||||||
|
CFLAGS = -g -O -mno-cygwin -I ../../include
|
||||||
|
|
||||||
|
OBJS = sendpack.o
|
||||||
|
LIBS = -L ${PCAP_PATH} -lwpcap
|
||||||
|
|
||||||
|
all: ${OBJS}
|
||||||
|
${CC} ${CFLAGS} -o sendpack.exe ${OBJS} ${LIBS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${OBJS} sendpack.exe
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c -o $*.o $<
|
|
@ -0,0 +1,68 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
u_char packet[100];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Check the validity of the command line */
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
printf("usage: %s interface", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the adapter */
|
||||||
|
if ((fp = pcap_open_live(argv[1], // name of the device
|
||||||
|
65536, // portion of the packet to capture. It doesn't matter in this case
|
||||||
|
1, // promiscuous mode (nonzero means promiscuous)
|
||||||
|
1000, // read timeout
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", argv[1]);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Supposing to be on ethernet, set mac destination to 1:1:1:1:1:1 */
|
||||||
|
packet[0]=1;
|
||||||
|
packet[1]=1;
|
||||||
|
packet[2]=1;
|
||||||
|
packet[3]=1;
|
||||||
|
packet[4]=1;
|
||||||
|
packet[5]=1;
|
||||||
|
|
||||||
|
/* set mac source to 2:2:2:2:2:2 */
|
||||||
|
packet[6]=2;
|
||||||
|
packet[7]=2;
|
||||||
|
packet[8]=2;
|
||||||
|
packet[9]=2;
|
||||||
|
packet[10]=2;
|
||||||
|
packet[11]=2;
|
||||||
|
|
||||||
|
/* Fill the rest of the packet */
|
||||||
|
for(i=12;i<100;i++)
|
||||||
|
{
|
||||||
|
packet[i]= (u_char)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send down the packet */
|
||||||
|
if (pcap_sendpacket(fp, // Adapter
|
||||||
|
packet, // buffer with the packet
|
||||||
|
100 // size
|
||||||
|
) != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError sending the packet: %s\n", pcap_geterr(fp));
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="sendpack" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=sendpack - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "sendpack.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "sendpack.mak" CFG="sendpack - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "sendpack - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "sendpack - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "sendpack - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "sendpack - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "sendpack - Win32 Release"
|
||||||
|
# Name "sendpack - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\sendpack.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "sendpack"=.\sendpack.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,221 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "GetMacAddress"=".\PacketDriver\GetMacAddress\GetMacAddress.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "TestPacketCapture"=".\PacketDriver\TestPacketCapture\TestPacketCapture.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "TestPacketSend"=".\PacketDriver\TestPacketSend\TestPacketSend.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "UDPdump"=".\UDPdump\UDPdump.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "UserBridge"=".\UserLevelBridge\UserBridge.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "basic_dump"=".\misc\basic_dump.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "basic_dump_ex"=".\misc\basic_dump_ex.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "iflist"=".\iflist\iflist.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "pcap_filter"=".\pcap_filter\pcap_filter.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "pktdump_ex"=".\pktdump_ex\pktdump_ex.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "readfile"=".\misc\readfile.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "readfile_ex"=".\misc\readfile_ex.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "savedump"=".\misc\savedump.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "sendcap"=".\sendcap\sendcap.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "sendpack"=".\misc\sendpack.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "smp_1"=".\smp_1\smp_1.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "tcptop"=".\tcptop\tcptop.dsp" - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <conio.h>
|
||||||
|
#include "..\..\..\Include\packet32.h"
|
||||||
|
#include <ntddndis.h>
|
||||||
|
|
||||||
|
#define Max_Num_Adapter 10
|
||||||
|
char AdapterList[Max_Num_Adapter][1024];
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
LPADAPTER lpAdapter = 0;
|
||||||
|
int i;
|
||||||
|
DWORD dwErrorCode;
|
||||||
|
char AdapterName[8192];
|
||||||
|
char *temp,*temp1;
|
||||||
|
int AdapterNum=0,Open;
|
||||||
|
ULONG AdapterLength;
|
||||||
|
PPACKET_OID_DATA OidData;
|
||||||
|
BOOLEAN Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Obtain the name of the adapters installed on this machine
|
||||||
|
//
|
||||||
|
|
||||||
|
printf("Packet.dll test application. Library version:%s\n", PacketGetVersion());
|
||||||
|
|
||||||
|
printf("Adapters installed:\n");
|
||||||
|
i=0;
|
||||||
|
|
||||||
|
AdapterLength = sizeof(AdapterName);
|
||||||
|
|
||||||
|
if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE){
|
||||||
|
printf("Unable to retrieve the list of the adapters!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
temp=AdapterName;
|
||||||
|
temp1=AdapterName;
|
||||||
|
|
||||||
|
while ((*temp!='\0')||(*(temp-1)!='\0'))
|
||||||
|
{
|
||||||
|
if (*temp=='\0')
|
||||||
|
{
|
||||||
|
memcpy(AdapterList[i],temp1,temp-temp1);
|
||||||
|
temp1=temp+1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
temp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
AdapterNum=i;
|
||||||
|
for (i=0;i<AdapterNum;i++)
|
||||||
|
printf("\n%d- %s\n",i+1,AdapterList[i]);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
printf("Select the number of the adapter to open : ");
|
||||||
|
scanf_s("%d",&Open);
|
||||||
|
if (Open>AdapterNum) printf("\nThe number must be smaller than %d",AdapterNum);
|
||||||
|
} while (Open>AdapterNum);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Open the selected adapter
|
||||||
|
//
|
||||||
|
|
||||||
|
lpAdapter = PacketOpenAdapter(AdapterList[Open-1]);
|
||||||
|
|
||||||
|
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
|
||||||
|
{
|
||||||
|
dwErrorCode=GetLastError();
|
||||||
|
printf("Unable to open the adapter, Error Code : %lx\n",dwErrorCode);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Allocate a buffer to get the MAC adress
|
||||||
|
//
|
||||||
|
|
||||||
|
OidData = malloc(6 + sizeof(PACKET_OID_DATA));
|
||||||
|
if (OidData == NULL)
|
||||||
|
{
|
||||||
|
printf("error allocating memory!\n");
|
||||||
|
PacketCloseAdapter(lpAdapter);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve the adapter MAC querying the NIC driver
|
||||||
|
//
|
||||||
|
|
||||||
|
OidData->Oid = OID_802_3_CURRENT_ADDRESS;
|
||||||
|
|
||||||
|
OidData->Length = 6;
|
||||||
|
ZeroMemory(OidData->Data, 6);
|
||||||
|
|
||||||
|
Status = PacketRequest(lpAdapter, FALSE, OidData);
|
||||||
|
if(Status)
|
||||||
|
{
|
||||||
|
printf("The MAC address of the adapter is %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
|
||||||
|
(OidData->Data)[0],
|
||||||
|
(OidData->Data)[1],
|
||||||
|
(OidData->Data)[2],
|
||||||
|
(OidData->Data)[3],
|
||||||
|
(OidData->Data)[4],
|
||||||
|
(OidData->Data)[5]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("error retrieving the MAC address of the adapter!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
free(OidData);
|
||||||
|
PacketCloseAdapter(lpAdapter);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="GetMacAddress" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=GetMacAddress - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "GetMacAddress.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "GetMacAddress.mak" CFG="GetMacAddress - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "GetMacAddress - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "GetMacAddress - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "GetMacAddress - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "GetMacAddress - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "GetMacAddress - Win32 Release"
|
||||||
|
# Name "GetMacAddress - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\GetMacAddress.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\..\lib\Packet.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,244 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <conio.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "..\..\..\Include\packet32.h"
|
||||||
|
#include <ntddndis.h>
|
||||||
|
|
||||||
|
#define Max_Num_Adapter 10
|
||||||
|
|
||||||
|
// Prototypes
|
||||||
|
|
||||||
|
void PrintPackets(LPPACKET lpPacket);
|
||||||
|
|
||||||
|
char AdapterList[Max_Num_Adapter][1024];
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
//define a pointer to an ADAPTER structure
|
||||||
|
|
||||||
|
LPADAPTER lpAdapter = 0;
|
||||||
|
|
||||||
|
//define a pointer to a PACKET structure
|
||||||
|
|
||||||
|
LPPACKET lpPacket;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
DWORD dwErrorCode;
|
||||||
|
|
||||||
|
//ascii strings
|
||||||
|
char AdapterName[8192]; // string that contains a list of the network adapters
|
||||||
|
char *temp,*temp1;
|
||||||
|
|
||||||
|
|
||||||
|
int AdapterNum=0,Open;
|
||||||
|
ULONG AdapterLength;
|
||||||
|
|
||||||
|
char buffer[256000]; // buffer to hold the data coming from the driver
|
||||||
|
|
||||||
|
struct bpf_stat stat;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Obtain the name of the adapters installed on this machine
|
||||||
|
//
|
||||||
|
printf("Packet.dll test application. Library version:%s\n", PacketGetVersion());
|
||||||
|
|
||||||
|
printf("Adapters installed:\n");
|
||||||
|
i=0;
|
||||||
|
|
||||||
|
AdapterLength = sizeof(AdapterName);
|
||||||
|
|
||||||
|
if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE){
|
||||||
|
printf("Unable to retrieve the list of the adapters!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
temp=AdapterName;
|
||||||
|
temp1=AdapterName;
|
||||||
|
|
||||||
|
while ((*temp!='\0')||(*(temp-1)!='\0'))
|
||||||
|
{
|
||||||
|
if (*temp=='\0')
|
||||||
|
{
|
||||||
|
memcpy(AdapterList[i],temp1,temp-temp1);
|
||||||
|
temp1=temp+1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
temp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
AdapterNum=i;
|
||||||
|
for (i=0;i<AdapterNum;i++)
|
||||||
|
printf("\n%d- %s\n",i+1,AdapterList[i]);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
printf("Select the number of the adapter to open : ");
|
||||||
|
scanf_s("%d",&Open);
|
||||||
|
if (Open>AdapterNum) printf("\nThe number must be smaller than %d",AdapterNum);
|
||||||
|
} while (Open>AdapterNum);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lpAdapter = PacketOpenAdapter(AdapterList[Open-1]);
|
||||||
|
|
||||||
|
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
|
||||||
|
{
|
||||||
|
dwErrorCode=GetLastError();
|
||||||
|
printf("Unable to open the adapter, Error Code : %lx\n",dwErrorCode);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the network adapter in promiscuous mode
|
||||||
|
|
||||||
|
if(PacketSetHwFilter(lpAdapter,NDIS_PACKET_TYPE_PROMISCUOUS)==FALSE){
|
||||||
|
printf("Warning: unable to set promiscuous mode!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// set a 512K buffer in the driver
|
||||||
|
if(PacketSetBuff(lpAdapter,512000)==FALSE){
|
||||||
|
printf("Unable to set the kernel buffer!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set a 1 second read timeout
|
||||||
|
if(PacketSetReadTimeout(lpAdapter,1000)==FALSE){
|
||||||
|
printf("Warning: unable to set the read tiemout!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//allocate and initialize a packet structure that will be used to
|
||||||
|
//receive the packets.
|
||||||
|
if((lpPacket = PacketAllocatePacket())==NULL){
|
||||||
|
printf("\nError: failed to allocate the LPPACKET structure.");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
PacketInitPacket(lpPacket,(char*)buffer,256000);
|
||||||
|
|
||||||
|
//main capture loop
|
||||||
|
while(!_kbhit())
|
||||||
|
{
|
||||||
|
// capture the packets
|
||||||
|
if(PacketReceivePacket(lpAdapter,lpPacket,TRUE)==FALSE){
|
||||||
|
printf("Error: PacketReceivePacket failed");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintPackets(lpPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//print the capture statistics
|
||||||
|
if(PacketGetStats(lpAdapter,&stat)==FALSE){
|
||||||
|
printf("Warning: unable to get stats from the kernel!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("\n\n%d packets received.\n%d Packets lost",stat.bs_recv,stat.bs_drop);
|
||||||
|
|
||||||
|
PacketFreePacket(lpPacket);
|
||||||
|
|
||||||
|
// close the adapter and exit
|
||||||
|
|
||||||
|
PacketCloseAdapter(lpAdapter);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this function prints the content of a block of packets received from the driver
|
||||||
|
|
||||||
|
void PrintPackets(LPPACKET lpPacket)
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG i, j, ulLines, ulen, ulBytesReceived;
|
||||||
|
char *pChar, *pLine, *base;
|
||||||
|
char *buf;
|
||||||
|
u_int off=0;
|
||||||
|
u_int tlen,tlen1;
|
||||||
|
struct bpf_hdr *hdr;
|
||||||
|
|
||||||
|
ulBytesReceived = lpPacket->ulBytesReceived;
|
||||||
|
|
||||||
|
|
||||||
|
buf = lpPacket->Buffer;
|
||||||
|
|
||||||
|
off=0;
|
||||||
|
|
||||||
|
while(off<ulBytesReceived){
|
||||||
|
if(_kbhit())return;
|
||||||
|
hdr=(struct bpf_hdr *)(buf+off);
|
||||||
|
tlen1=hdr->bh_datalen;
|
||||||
|
tlen=hdr->bh_caplen;
|
||||||
|
printf("Packet length, captured portion: %ld, %ld\n", tlen1, tlen);
|
||||||
|
off+=hdr->bh_hdrlen;
|
||||||
|
|
||||||
|
ulLines = (tlen + 15) / 16;
|
||||||
|
|
||||||
|
pChar =(char*)(buf+off);
|
||||||
|
base=pChar;
|
||||||
|
off=Packet_WORDALIGN(off+tlen);
|
||||||
|
|
||||||
|
for ( i=0; i<ulLines; i++ )
|
||||||
|
{
|
||||||
|
|
||||||
|
pLine =pChar;
|
||||||
|
|
||||||
|
printf( "%08lx : ", pChar-base );
|
||||||
|
|
||||||
|
ulen=tlen;
|
||||||
|
ulen = ( ulen > 16 ) ? 16 : ulen;
|
||||||
|
tlen -= ulen;
|
||||||
|
|
||||||
|
for ( j=0; j<ulen; j++ )
|
||||||
|
printf( "%02x ", *(BYTE *)pChar++ );
|
||||||
|
|
||||||
|
if ( ulen < 16 )
|
||||||
|
printf( "%*s", (16-ulen)*3, " " );
|
||||||
|
|
||||||
|
pChar = pLine;
|
||||||
|
|
||||||
|
for ( j=0; j<ulen; j++, pChar++ )
|
||||||
|
printf( "%c", isprint( (unsigned char)*pChar ) ? *pChar : '.' );
|
||||||
|
|
||||||
|
printf( "\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( "\n" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="TestPacketCapture" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=TestPacketCapture - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "TestPacketCapture.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "TestPacketCapture.mak" CFG="TestPacketCapture - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "TestPacketCapture - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "TestPacketCapture - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "TestPacketCapture - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "TestPacketCapture - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "TestPacketCapture - Win32 Release"
|
||||||
|
# Name "TestPacketCapture - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\TestPacketCapture.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\..\lib\Packet.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,235 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <conio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "..\..\..\Include\packet32.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define Max_Num_Adapter 10
|
||||||
|
|
||||||
|
// Prototypes
|
||||||
|
|
||||||
|
void PrintPackets(LPPACKET lpPacket);
|
||||||
|
|
||||||
|
char AdapterList[Max_Num_Adapter][8192];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char packetbuff[5000];
|
||||||
|
|
||||||
|
// define a pointer to a ADAPTER structure
|
||||||
|
|
||||||
|
LPADAPTER lpAdapter = 0;
|
||||||
|
|
||||||
|
// define a pointer to a PACKET structure
|
||||||
|
|
||||||
|
LPPACKET lpPacket;
|
||||||
|
|
||||||
|
int i,npacks,Snaplen;
|
||||||
|
DWORD dwErrorCode;
|
||||||
|
|
||||||
|
//ascii strings
|
||||||
|
char AdapterName[8192]; // string that contains a list of the network adapters
|
||||||
|
char *temp,*temp1;
|
||||||
|
|
||||||
|
int AdapterNum=0,Open;
|
||||||
|
ULONG AdapterLength;
|
||||||
|
|
||||||
|
float cpu_time;
|
||||||
|
|
||||||
|
printf("Traffic Generator v 0.9999\nCopyright 1999 Loris Degioanni (loris@netgroup-serv.polito.it)");
|
||||||
|
printf("\nSends a set of packets to the network using packet.dll API.\n");
|
||||||
|
|
||||||
|
if (argc == 1){
|
||||||
|
printf("\n\n Usage: TestpacketSend [-i adapter] -n npacks -s size");
|
||||||
|
printf("\n size is between 60 and 1514\n\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AdapterName[0]=0;
|
||||||
|
|
||||||
|
//get the command line parameters
|
||||||
|
for(i=1;i<argc;i+=2){
|
||||||
|
|
||||||
|
switch (argv[i] [1])
|
||||||
|
{
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
sscanf_s(argv[i+1],"%s",AdapterName);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'n':
|
||||||
|
sscanf_s(argv[i+1],"%d",&npacks);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
sscanf_s(argv[i+1],"%d",&Snaplen);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(AdapterName[0]==0){
|
||||||
|
|
||||||
|
//
|
||||||
|
// Obtain the name of the adapters installed on this machine
|
||||||
|
//
|
||||||
|
printf("Adapters installed:\n");
|
||||||
|
i=0;
|
||||||
|
|
||||||
|
AdapterLength = sizeof(AdapterName);
|
||||||
|
|
||||||
|
if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE){
|
||||||
|
printf("Unable to retrieve the list of the adapters!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
temp=AdapterName;
|
||||||
|
temp1=AdapterName;
|
||||||
|
|
||||||
|
while ((*temp!='\0')||(*(temp-1)!='\0'))
|
||||||
|
{
|
||||||
|
if (*temp=='\0')
|
||||||
|
{
|
||||||
|
memcpy(AdapterList[i],temp1,temp-temp1);
|
||||||
|
temp1=temp+1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
temp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
AdapterNum=i;
|
||||||
|
for (i=0;i<AdapterNum;i++)
|
||||||
|
printf("\n%d- %s\n",i+1,AdapterList[i]);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
printf("Select the number of the adapter to open : ");scanf_s("%d",&Open);
|
||||||
|
if (Open>AdapterNum) printf("\nThe number must be smaller than %d",AdapterNum);
|
||||||
|
} while (Open>AdapterNum);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lpAdapter = PacketOpenAdapter(AdapterList[Open-1]);
|
||||||
|
|
||||||
|
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
|
||||||
|
{
|
||||||
|
dwErrorCode=GetLastError();
|
||||||
|
printf("Unable to open the driver, Error Code : %lx\n",dwErrorCode);
|
||||||
|
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
lpAdapter = PacketOpenAdapter(AdapterName);
|
||||||
|
|
||||||
|
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
|
||||||
|
{
|
||||||
|
dwErrorCode=GetLastError();
|
||||||
|
printf("Unable to open the driver, Error Code : %lx\n",dwErrorCode);
|
||||||
|
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if((lpPacket = PacketAllocatePacket())==NULL){
|
||||||
|
printf("\nError:failed to allocate the LPPACKET structure.");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
packetbuff[0]=1;
|
||||||
|
packetbuff[1]=1;
|
||||||
|
packetbuff[2]=1;
|
||||||
|
packetbuff[3]=1;
|
||||||
|
packetbuff[4]=1;
|
||||||
|
packetbuff[5]=1;
|
||||||
|
|
||||||
|
packetbuff[6]=2;
|
||||||
|
packetbuff[7]=2;
|
||||||
|
packetbuff[8]=2;
|
||||||
|
packetbuff[9]=2;
|
||||||
|
packetbuff[10]=2;
|
||||||
|
packetbuff[11]=2;
|
||||||
|
|
||||||
|
for(i=12;i<1514;i++){
|
||||||
|
packetbuff[i]= (char)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketInitPacket(lpPacket,packetbuff,Snaplen);
|
||||||
|
// capture the packet
|
||||||
|
|
||||||
|
|
||||||
|
if(PacketSetNumWrites(lpAdapter,npacks)==FALSE){
|
||||||
|
printf("warning: Unable to send more than one packet in a single write!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\nGenerating %d packets...",npacks);
|
||||||
|
|
||||||
|
cpu_time = (float)clock ();
|
||||||
|
|
||||||
|
if(PacketSendPacket(lpAdapter,lpPacket,TRUE)==FALSE){
|
||||||
|
printf("Error sending the packets!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu_time = (clock() - cpu_time)/CLK_TCK;
|
||||||
|
|
||||||
|
printf ("\n\nElapsed time: %5.3f\n", cpu_time);
|
||||||
|
printf ("\nTotal packets generated = %d", npacks);
|
||||||
|
printf ("\nTotal bytes generated = %d", (Snaplen+24)*npacks);
|
||||||
|
printf ("\nTotal bits generated = %d", (Snaplen+24)*npacks*8);
|
||||||
|
printf ("\nAverage packets per second = %d", (int)((double)npacks/cpu_time));
|
||||||
|
printf ("\nAverage bytes per second = %d", (int)((double)((Snaplen+24)*npacks)/cpu_time));
|
||||||
|
printf ("\nAverage bits per second = %d", (int)((double)((Snaplen+24)*npacks*8)/cpu_time));
|
||||||
|
printf ("\n");
|
||||||
|
|
||||||
|
PacketFreePacket(lpPacket);
|
||||||
|
|
||||||
|
// close the adapter and exit
|
||||||
|
|
||||||
|
PacketCloseAdapter(lpAdapter);
|
||||||
|
return (0);
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="TestPacketSend" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=TestPacketSend - Win32 Release
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "TestPacketSend.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "TestPacketSend.mak" CFG="TestPacketSend - Win32 Release"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "TestPacketSend - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "TestPacketSend - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "TestPacketSend - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /pdb:"Release/TestPacketSend.exe" /machine:I386
|
||||||
|
# SUBTRACT LINK32 /pdb:none
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "TestPacketSend - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "TestPacketSend - Win32 Release"
|
||||||
|
# Name "TestPacketSend - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\TestPacketSend.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\..\lib\Packet.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,2 @@
|
||||||
|
These files use the packet.dll API instead of wpcap.dll.
|
||||||
|
The use of packet.dll API is strongly discouraged.
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="UDPdump" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=UDPdump - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "UDPdump.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "UDPdump.mak" CFG="UDPdump - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "UDPdump - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "UDPdump - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "UDPdump - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "UDPdump - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "UDPdump - Win32 Release"
|
||||||
|
# Name "UDPdump - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\udpdump.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "UDPdump"=.\UDPdump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,230 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
/* 4 bytes IP address */
|
||||||
|
typedef struct ip_address{
|
||||||
|
u_char byte1;
|
||||||
|
u_char byte2;
|
||||||
|
u_char byte3;
|
||||||
|
u_char byte4;
|
||||||
|
}ip_address;
|
||||||
|
|
||||||
|
/* IPv4 header */
|
||||||
|
typedef struct ip_header{
|
||||||
|
u_char ver_ihl; // Version (4 bits) + Internet header length (4 bits)
|
||||||
|
u_char tos; // Type of service
|
||||||
|
u_short tlen; // Total length
|
||||||
|
u_short identification; // Identification
|
||||||
|
u_short flags_fo; // Flags (3 bits) + Fragment offset (13 bits)
|
||||||
|
u_char ttl; // Time to live
|
||||||
|
u_char proto; // Protocol
|
||||||
|
u_short crc; // Header checksum
|
||||||
|
ip_address saddr; // Source address
|
||||||
|
ip_address daddr; // Destination address
|
||||||
|
u_int op_pad; // Option + Padding
|
||||||
|
}ip_header;
|
||||||
|
|
||||||
|
/* UDP header*/
|
||||||
|
typedef struct udp_header{
|
||||||
|
u_short sport; // Source port
|
||||||
|
u_short dport; // Destination port
|
||||||
|
u_short len; // Datagram length
|
||||||
|
u_short crc; // Checksum
|
||||||
|
}udp_header;
|
||||||
|
|
||||||
|
/* prototype of the packet handler */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
u_int netmask;
|
||||||
|
char packet_filter[] = "ip and udp";
|
||||||
|
struct bpf_program fcode;
|
||||||
|
|
||||||
|
/* Retrieve the device list */
|
||||||
|
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf_s("%d", &inum);
|
||||||
|
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the adapter */
|
||||||
|
if ( (adhandle= pcap_open(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on all the MACs.
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
|
||||||
|
1000, // read timeout
|
||||||
|
NULL, // remote authentication
|
||||||
|
errbuf // error buffer
|
||||||
|
) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check the link layer. We support only Ethernet for simplicity. */
|
||||||
|
if(pcap_datalink(adhandle) != DLT_EN10MB)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nThis program works only on Ethernet networks.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(d->addresses != NULL)
|
||||||
|
/* Retrieve the mask of the first address of the interface */
|
||||||
|
netmask=((struct sockaddr_in *)(d->addresses->netmask))->sin_addr.S_un.S_addr;
|
||||||
|
else
|
||||||
|
/* If the interface is without addresses we suppose to be in a C class network */
|
||||||
|
netmask=0xffffff;
|
||||||
|
|
||||||
|
|
||||||
|
//compile the filter
|
||||||
|
if (pcap_compile(adhandle, &fcode, packet_filter, 1, netmask) <0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the filter
|
||||||
|
if (pcap_setfilter(adhandle, &fcode)<0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError setting the filter.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nlistening on %s...\n", d->description);
|
||||||
|
|
||||||
|
/* At this point, we don't need any more the device list. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/* start the capture */
|
||||||
|
pcap_loop(adhandle, 0, packet_handler, NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback function invoked by libpcap for every incoming packet */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
struct tm ltime;
|
||||||
|
char timestr[16];
|
||||||
|
ip_header *ih;
|
||||||
|
udp_header *uh;
|
||||||
|
u_int ip_len;
|
||||||
|
u_short sport,dport;
|
||||||
|
time_t local_tv_sec;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unused variable
|
||||||
|
*/
|
||||||
|
(VOID)(param);
|
||||||
|
|
||||||
|
/* convert the timestamp to readable format */
|
||||||
|
local_tv_sec = header->ts.tv_sec;
|
||||||
|
localtime_s(<ime, &local_tv_sec);
|
||||||
|
strftime( timestr, sizeof timestr, "%H:%M:%S", <ime);
|
||||||
|
|
||||||
|
/* print timestamp and length of the packet */
|
||||||
|
printf("%s.%.6d len:%d ", timestr, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
/* retireve the position of the ip header */
|
||||||
|
ih = (ip_header *) (pkt_data +
|
||||||
|
14); //length of ethernet header
|
||||||
|
|
||||||
|
/* retireve the position of the udp header */
|
||||||
|
ip_len = (ih->ver_ihl & 0xf) * 4;
|
||||||
|
uh = (udp_header *) ((u_char*)ih + ip_len);
|
||||||
|
|
||||||
|
/* convert from network byte order to host byte order */
|
||||||
|
sport = ntohs( uh->sport );
|
||||||
|
dport = ntohs( uh->dport );
|
||||||
|
|
||||||
|
/* print ip addresses and udp ports */
|
||||||
|
printf("%d.%d.%d.%d.%d -> %d.%d.%d.%d.%d\n",
|
||||||
|
ih->saddr.byte1,
|
||||||
|
ih->saddr.byte2,
|
||||||
|
ih->saddr.byte3,
|
||||||
|
ih->saddr.byte4,
|
||||||
|
sport,
|
||||||
|
ih->daddr.byte1,
|
||||||
|
ih->daddr.byte2,
|
||||||
|
ih->daddr.byte3,
|
||||||
|
ih->daddr.byte4,
|
||||||
|
dport);
|
||||||
|
}
|
|
@ -0,0 +1,467 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005 - 2006
|
||||||
|
* CACE Technologies, Davis, CA
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of CACE Technologies nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This simple program implements a user-level bridge.
|
||||||
|
* It opens two adapters specified by the user and starts two threads.
|
||||||
|
* The first thread receives packets from adapter 1 and sends them down to
|
||||||
|
* adapter 2. The second thread does the same, but in the opposite
|
||||||
|
* direction.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
/* Storage data structure used to pass parameters to the threads */
|
||||||
|
typedef struct _in_out_adapters
|
||||||
|
{
|
||||||
|
unsigned int state; /* Some simple state information */
|
||||||
|
pcap_t *input_adapter;
|
||||||
|
pcap_t *output_adapter;
|
||||||
|
}in_out_adapters;
|
||||||
|
|
||||||
|
/* Prototypes */
|
||||||
|
DWORD WINAPI CaptureAndForwardThread(LPVOID lpParameter);
|
||||||
|
void ctrlc_handler(int sig);
|
||||||
|
|
||||||
|
/* This prevents the two threads to mess-up when they do printfs */
|
||||||
|
CRITICAL_SECTION print_cs;
|
||||||
|
|
||||||
|
/* Thread handlers. Global because we wait on the threads from the CTRL+C handler */
|
||||||
|
HANDLE threads[2];
|
||||||
|
|
||||||
|
/* This global variable tells the forwarder threads they must terminate */
|
||||||
|
volatile int kill_forwaders = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum1, inum2;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle1, *adhandle2;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
u_int netmask1, netmask2;
|
||||||
|
char packet_filter[256];
|
||||||
|
struct bpf_program fcode;
|
||||||
|
in_out_adapters couple0, couple1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retrieve the device list
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. ", ++i);
|
||||||
|
if (d->description)
|
||||||
|
printf("%s\n", d->description);
|
||||||
|
else
|
||||||
|
printf("<unknown adapter>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get input from the user
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Get the filter*/
|
||||||
|
printf("\nSpecify filter (hit return for no filter):");
|
||||||
|
|
||||||
|
fgets(packet_filter, sizeof(packet_filter), stdin);
|
||||||
|
|
||||||
|
/* Get the first interface number*/
|
||||||
|
printf("\nEnter the number of the first interface to use (1-%d):",i);
|
||||||
|
scanf_s("%d", &inum1);
|
||||||
|
|
||||||
|
if(inum1 < 1 || inum1 > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the second interface number*/
|
||||||
|
printf("Enter the number of the first interface to use (1-%d):",i);
|
||||||
|
scanf_s("%d", &inum2);
|
||||||
|
|
||||||
|
if(inum2 < 1 || inum2 > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inum1 == inum2 )
|
||||||
|
{
|
||||||
|
printf("\nCannot bridge packets on the same interface.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open the specified couple of adapters
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Jump to the first selected adapter */
|
||||||
|
for(d = alldevs, i = 0; i< inum1 - 1 ;d = d->next, i++);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open the first adapter.
|
||||||
|
* *NOTICE* the flags we are using, they are important for the behavior of the prgram:
|
||||||
|
* - PCAP_OPENFLAG_PROMISCUOUS: tells the adapter to go in promiscuous mode.
|
||||||
|
* This means that we are capturing all the traffic, not only the one to or from
|
||||||
|
* this machine.
|
||||||
|
* - PCAP_OPENFLAG_NOCAPTURE_LOCAL: prevents the adapter from capturing again the packets
|
||||||
|
* transmitted by itself. This avoids annoying loops.
|
||||||
|
* - PCAP_OPENFLAG_MAX_RESPONSIVENESS: configures the adapter to provide minimum latency,
|
||||||
|
* at the cost of higher CPU usage.
|
||||||
|
*/
|
||||||
|
if((adhandle1 = pcap_open(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on every link layer.
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS | // flags. We specify that we don't want to capture loopback packets, and that the driver should deliver us the packets as fast as possible
|
||||||
|
PCAP_OPENFLAG_NOCAPTURE_LOCAL |
|
||||||
|
PCAP_OPENFLAG_MAX_RESPONSIVENESS,
|
||||||
|
500, // read timeout
|
||||||
|
NULL, // remote authentication
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->description);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(d->addresses != NULL)
|
||||||
|
{
|
||||||
|
/* Retrieve the mask of the first address of the interface */
|
||||||
|
netmask1 = ((struct sockaddr_in *)(d->addresses->netmask))->sin_addr.S_un.S_addr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* If the interface is without addresses we suppose to be in a C class network */
|
||||||
|
netmask1 = 0xffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the second selected adapter */
|
||||||
|
for(d = alldevs, i = 0; i< inum2 - 1 ;d = d->next, i++);
|
||||||
|
|
||||||
|
/* Open the second adapter */
|
||||||
|
if((adhandle2 = pcap_open(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 grants that the whole packet will be captured on every link layer.
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS | // flags. We specify that we don't want to capture loopback packets, and that the driver should deliver us the packets as fast as possible
|
||||||
|
PCAP_OPENFLAG_NOCAPTURE_LOCAL |
|
||||||
|
PCAP_OPENFLAG_MAX_RESPONSIVENESS,
|
||||||
|
500, // read timeout
|
||||||
|
NULL, // remote authentication
|
||||||
|
errbuf // error buffer
|
||||||
|
)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->description);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(d->addresses != NULL)
|
||||||
|
{
|
||||||
|
/* Retrieve the mask of the first address of the interface */
|
||||||
|
netmask2 = ((struct sockaddr_in *)(d->addresses->netmask))->sin_addr.S_un.S_addr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* If the interface is without addresses we suppose to be in a C class network */
|
||||||
|
netmask2 = 0xffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compile and set the filters
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* compile the filter for the first adapter */
|
||||||
|
if (pcap_compile(adhandle1, &fcode, packet_filter, 1, netmask1) <0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
|
||||||
|
|
||||||
|
/* Close the adapters */
|
||||||
|
pcap_close(adhandle1);
|
||||||
|
pcap_close(adhandle2);
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the filter for the first adapter*/
|
||||||
|
if (pcap_setfilter(adhandle1, &fcode)<0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError setting the filter.\n");
|
||||||
|
|
||||||
|
/* Close the adapters */
|
||||||
|
pcap_close(adhandle1);
|
||||||
|
pcap_close(adhandle2);
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* compile the filter for the second adapter */
|
||||||
|
if (pcap_compile(adhandle2, &fcode, packet_filter, 1, netmask2) <0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
|
||||||
|
|
||||||
|
/* Close the adapters */
|
||||||
|
pcap_close(adhandle1);
|
||||||
|
pcap_close(adhandle2);
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the filter for the second adapter*/
|
||||||
|
if (pcap_setfilter(adhandle2, &fcode)<0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError setting the filter.\n");
|
||||||
|
|
||||||
|
/* Close the adapters */
|
||||||
|
pcap_close(adhandle1);
|
||||||
|
pcap_close(adhandle2);
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* At this point, we don't need the device list any more. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start the threads that will forward the packets
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Initialize the critical section that will be used by the threads for console output */
|
||||||
|
InitializeCriticalSection(&print_cs);
|
||||||
|
|
||||||
|
/* Init input parameters of the threads */
|
||||||
|
couple0.state = 0;
|
||||||
|
couple0.input_adapter = adhandle1;
|
||||||
|
couple0.output_adapter = adhandle2;
|
||||||
|
couple1.state = 1;
|
||||||
|
couple1.input_adapter = adhandle2;
|
||||||
|
couple1.output_adapter = adhandle1;
|
||||||
|
|
||||||
|
/* Start first thread */
|
||||||
|
if((threads[0] = CreateThread(
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
CaptureAndForwardThread,
|
||||||
|
&couple0,
|
||||||
|
0,
|
||||||
|
NULL)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error creating the first forward thread");
|
||||||
|
|
||||||
|
/* Close the adapters */
|
||||||
|
pcap_close(adhandle1);
|
||||||
|
pcap_close(adhandle2);
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Start second thread */
|
||||||
|
if((threads[1] = CreateThread(
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
CaptureAndForwardThread,
|
||||||
|
&couple1,
|
||||||
|
0,
|
||||||
|
NULL)) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error creating the second forward thread");
|
||||||
|
|
||||||
|
/* Kill the first thread. Not very gentle at all...*/
|
||||||
|
TerminateThread(threads[0], 0);
|
||||||
|
|
||||||
|
/* Close the adapters */
|
||||||
|
pcap_close(adhandle1);
|
||||||
|
pcap_close(adhandle2);
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Install a CTRL+C handler that will do the cleanups on exit
|
||||||
|
*/
|
||||||
|
signal(SIGINT, ctrlc_handler);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Done!
|
||||||
|
* Wait for the Greek calends...
|
||||||
|
*/
|
||||||
|
printf("\nStart bridging the two adapters...\n", d->description);
|
||||||
|
Sleep(INFINITE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* Forwarding thread.
|
||||||
|
* Gets the packets from the input adapter and sends them to the output one.
|
||||||
|
*******************************************************************/
|
||||||
|
DWORD WINAPI CaptureAndForwardThread(LPVOID lpParameter)
|
||||||
|
{
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
int res = 0;
|
||||||
|
in_out_adapters* ad_couple = lpParameter;
|
||||||
|
unsigned int n_fwd = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop receiving packets from the first input adapter
|
||||||
|
*/
|
||||||
|
|
||||||
|
while((!kill_forwaders) && (res = pcap_next_ex(ad_couple->input_adapter, &header, &pkt_data)) >= 0)
|
||||||
|
{
|
||||||
|
if(res != 0) /* Note: res=0 means "read timeout elapsed"*/
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Print something, just to show when we have activity.
|
||||||
|
* BEWARE: acquiring a critical section and printing strings with printf
|
||||||
|
* is something inefficient that you seriously want to avoid in your packet loop!
|
||||||
|
* However, since this is a *sample program*, we privilege visual output to efficiency.
|
||||||
|
*/
|
||||||
|
EnterCriticalSection(&print_cs);
|
||||||
|
|
||||||
|
if(ad_couple->state == 0)
|
||||||
|
printf(">> Len: %u\n", header->caplen);
|
||||||
|
else
|
||||||
|
printf("<< Len: %u\n", header->caplen);
|
||||||
|
|
||||||
|
LeaveCriticalSection(&print_cs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send the just received packet to the output adaper
|
||||||
|
*/
|
||||||
|
if(pcap_sendpacket(ad_couple->output_adapter, pkt_data, header->caplen) != 0)
|
||||||
|
{
|
||||||
|
EnterCriticalSection(&print_cs);
|
||||||
|
|
||||||
|
printf("Error sending a %u bytes packets on interface %u: %s\n",
|
||||||
|
header->caplen,
|
||||||
|
ad_couple->state,
|
||||||
|
pcap_geterr(ad_couple->output_adapter));
|
||||||
|
|
||||||
|
LeaveCriticalSection(&print_cs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n_fwd++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We're out of the main loop. Check the reason.
|
||||||
|
*/
|
||||||
|
if(res < 0)
|
||||||
|
{
|
||||||
|
EnterCriticalSection(&print_cs);
|
||||||
|
|
||||||
|
printf("Error capturing the packets: %s\n", pcap_geterr(ad_couple->input_adapter));
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
LeaveCriticalSection(&print_cs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EnterCriticalSection(&print_cs);
|
||||||
|
|
||||||
|
printf("End of bridging on interface %u. Forwarded packets:%u\n",
|
||||||
|
ad_couple->state,
|
||||||
|
n_fwd);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
LeaveCriticalSection(&print_cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* CTRL+C hanlder.
|
||||||
|
* We order the threads to die and then we patiently wait for their
|
||||||
|
* suicide.
|
||||||
|
*******************************************************************/
|
||||||
|
void ctrlc_handler(int sig)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* unused variable
|
||||||
|
*/
|
||||||
|
(VOID)(sig);
|
||||||
|
|
||||||
|
kill_forwaders = 1;
|
||||||
|
|
||||||
|
WaitForMultipleObjects(2,
|
||||||
|
threads,
|
||||||
|
TRUE, /* Wait for all the handles */
|
||||||
|
5000); /* Timeout */
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="UserBridge" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=UserBridge - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "UserBridge.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "UserBridge.mak" CFG="UserBridge - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "UserBridge - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "UserBridge - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "UserBridge - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "UserBridge - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "UserBridge - Win32 Release"
|
||||||
|
# Name "UserBridge - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\UserBridge.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "UserBridge"=.\UserBridge.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,176 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#else
|
||||||
|
#include <winsock.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Function prototypes
|
||||||
|
void ifprint(pcap_if_t *d);
|
||||||
|
char *iptos(u_long in);
|
||||||
|
char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen);
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE+1];
|
||||||
|
char source[PCAP_ERRBUF_SIZE+1];
|
||||||
|
|
||||||
|
printf("Enter the device you want to list:\n"
|
||||||
|
"rpcap:// ==> lists interfaces in the local machine\n"
|
||||||
|
"rpcap://hostname:port ==> lists interfaces in a remote machine\n"
|
||||||
|
" (rpcapd daemon must be up and running\n"
|
||||||
|
" and it must accept 'null' authentication)\n"
|
||||||
|
"file://foldername ==> lists all pcap files in the give folder\n\n"
|
||||||
|
"Enter your choice: ");
|
||||||
|
|
||||||
|
fgets(source, PCAP_ERRBUF_SIZE, stdin);
|
||||||
|
source[PCAP_ERRBUF_SIZE] = '\0';
|
||||||
|
|
||||||
|
/* Retrieve the interfaces list */
|
||||||
|
if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scan the list printing every entry */
|
||||||
|
for(d=alldevs;d;d=d->next)
|
||||||
|
{
|
||||||
|
ifprint(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Print all the available information on the given interface */
|
||||||
|
void ifprint(pcap_if_t *d)
|
||||||
|
{
|
||||||
|
pcap_addr_t *a;
|
||||||
|
char ip6str[128];
|
||||||
|
|
||||||
|
/* Name */
|
||||||
|
printf("%s\n",d->name);
|
||||||
|
|
||||||
|
/* Description */
|
||||||
|
if (d->description)
|
||||||
|
printf("\tDescription: %s\n",d->description);
|
||||||
|
|
||||||
|
/* Loopback Address*/
|
||||||
|
printf("\tLoopback: %s\n",(d->flags & PCAP_IF_LOOPBACK)?"yes":"no");
|
||||||
|
|
||||||
|
/* IP addresses */
|
||||||
|
for(a=d->addresses;a;a=a->next) {
|
||||||
|
printf("\tAddress Family: #%d\n",a->addr->sa_family);
|
||||||
|
|
||||||
|
switch(a->addr->sa_family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
printf("\tAddress Family Name: AF_INET\n");
|
||||||
|
if (a->addr)
|
||||||
|
printf("\tAddress: %s\n",iptos(((struct sockaddr_in *)a->addr)->sin_addr.s_addr));
|
||||||
|
if (a->netmask)
|
||||||
|
printf("\tNetmask: %s\n",iptos(((struct sockaddr_in *)a->netmask)->sin_addr.s_addr));
|
||||||
|
if (a->broadaddr)
|
||||||
|
printf("\tBroadcast Address: %s\n",iptos(((struct sockaddr_in *)a->broadaddr)->sin_addr.s_addr));
|
||||||
|
if (a->dstaddr)
|
||||||
|
printf("\tDestination Address: %s\n",iptos(((struct sockaddr_in *)a->dstaddr)->sin_addr.s_addr));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AF_INET6:
|
||||||
|
printf("\tAddress Family Name: AF_INET6\n");
|
||||||
|
if (a->addr)
|
||||||
|
printf("\tAddress: %s\n", ip6tos(a->addr, ip6str, sizeof(ip6str)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("\tAddress Family Name: Unknown\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* From tcptraceroute, convert a numeric IP address to a string */
|
||||||
|
#define IPTOSBUFFERS 12
|
||||||
|
char *iptos(u_long in)
|
||||||
|
{
|
||||||
|
static char output[IPTOSBUFFERS][3*4+3+1];
|
||||||
|
static short which;
|
||||||
|
u_char *p;
|
||||||
|
|
||||||
|
p = (u_char *)∈
|
||||||
|
which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);
|
||||||
|
_snprintf_s(output[which], sizeof(output[which]), sizeof(output[which]),"%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
|
||||||
|
return output[which];
|
||||||
|
}
|
||||||
|
|
||||||
|
char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen)
|
||||||
|
{
|
||||||
|
socklen_t sockaddrlen;
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
sockaddrlen = sizeof(struct sockaddr_in6);
|
||||||
|
#else
|
||||||
|
sockaddrlen = sizeof(struct sockaddr_storage);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if(getnameinfo(sockaddr,
|
||||||
|
sockaddrlen,
|
||||||
|
address,
|
||||||
|
addrlen,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
NI_NUMERICHOST) != 0) address = NULL;
|
||||||
|
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="iflist" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=iflist - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "iflist.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "iflist.mak" CFG="iflist - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "iflist - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "iflist - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "iflist - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "iflist - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "iflist - Win32 Release"
|
||||||
|
# Name "iflist - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\iflist.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "iflist"=.\iflist.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "basic_dump"=.\basic_dump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "basic_dump_ex"=.\basic_dump_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "readfile"=.\readfile.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "readfile_ex"=.\readfile_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "savedump"=.\savedump.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "sendpack"=.\sendpack.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
/* prototype of the packet handler */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
|
||||||
|
/* Retrieve the device list on the local machine */
|
||||||
|
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf_s("%d", &inum);
|
||||||
|
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the device */
|
||||||
|
if ( (adhandle= pcap_open(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture
|
||||||
|
// 65536 guarantees that the whole packet will be captured on all the link layers
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
|
||||||
|
1000, // read timeout
|
||||||
|
NULL, // authentication on the remote machine
|
||||||
|
errbuf // error buffer
|
||||||
|
) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nlistening on %s...\n", d->description);
|
||||||
|
|
||||||
|
/* At this point, we don't need any more the device list. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/* start the capture */
|
||||||
|
pcap_loop(adhandle, 0, packet_handler, NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Callback function invoked by libpcap for every incoming packet */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
struct tm ltime;
|
||||||
|
char timestr[16];
|
||||||
|
time_t local_tv_sec;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unused variables
|
||||||
|
*/
|
||||||
|
(VOID)(param);
|
||||||
|
(VOID)(pkt_data);
|
||||||
|
|
||||||
|
/* convert the timestamp to readable format */
|
||||||
|
local_tv_sec = header->ts.tv_sec;
|
||||||
|
localtime_s(<ime, &local_tv_sec);
|
||||||
|
strftime( timestr, sizeof timestr, "%H:%M:%S", <ime);
|
||||||
|
|
||||||
|
printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="basic_dump" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=basic_dump - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "basic_dump.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "basic_dump.mak" CFG="basic_dump - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "basic_dump - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "basic_dump - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "basic_dump - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "basic_dump - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "basic_dump - Win32 Release"
|
||||||
|
# Name "basic_dump - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\basic_dump.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,99 @@
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle;
|
||||||
|
int res;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
struct tm ltime;
|
||||||
|
char timestr[16];
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
time_t local_tv_sec;
|
||||||
|
|
||||||
|
|
||||||
|
/* Retrieve the device list on the local machine */
|
||||||
|
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf_s("%d", &inum);
|
||||||
|
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the device */
|
||||||
|
if ( (adhandle= pcap_open(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture.
|
||||||
|
// 65536 guarantees that the whole packet will be captured on all the link layers
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
|
||||||
|
1000, // read timeout
|
||||||
|
NULL, // authentication on the remote machine
|
||||||
|
errbuf // error buffer
|
||||||
|
) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nlistening on %s...\n", d->description);
|
||||||
|
|
||||||
|
/* At this point, we don't need any more the device list. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/* Retrieve the packets */
|
||||||
|
while((res = pcap_next_ex( adhandle, &header, &pkt_data)) >= 0){
|
||||||
|
|
||||||
|
if(res == 0)
|
||||||
|
/* Timeout elapsed */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* convert the timestamp to readable format */
|
||||||
|
local_tv_sec = header->ts.tv_sec;
|
||||||
|
localtime_s(<ime, &local_tv_sec);
|
||||||
|
strftime( timestr, sizeof timestr, "%H:%M:%S", <ime);
|
||||||
|
|
||||||
|
printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res == -1){
|
||||||
|
printf("Error reading the packets: %s\n", pcap_geterr(adhandle));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="basic_dump_ex" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=basic_dump_ex - Win32 Release
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "basic_dump_ex.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "basic_dump_ex.mak" CFG="basic_dump_ex - Win32 Release"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "basic_dump_ex - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "basic_dump_ex - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "basic_dump_ex - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "basic_dump_ex - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "basic_dump_ex - Win32 Release"
|
||||||
|
# Name "basic_dump_ex - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\basic_dump_ex.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,78 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#define LINE_LEN 16
|
||||||
|
|
||||||
|
void dispatcher_handler(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
char source[PCAP_BUF_SIZE];
|
||||||
|
|
||||||
|
if(argc != 2){
|
||||||
|
|
||||||
|
printf("usage: %s filename", argv[0]);
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create the source string according to the new WinPcap syntax */
|
||||||
|
if ( pcap_createsrcstr( source, // variable that will keep the source string
|
||||||
|
PCAP_SRC_FILE, // we want to open a file
|
||||||
|
NULL, // remote host
|
||||||
|
NULL, // port on the remote host
|
||||||
|
argv[1], // name of the file we want to open
|
||||||
|
errbuf // error buffer
|
||||||
|
) != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError creating a source string\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the capture file */
|
||||||
|
if ( (fp= pcap_open(source, // name of the device
|
||||||
|
65536, // portion of the packet to capture
|
||||||
|
// 65536 guarantees that the whole packet will be captured on all the link layers
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
|
||||||
|
1000, // read timeout
|
||||||
|
NULL, // authentication on the remote machine
|
||||||
|
errbuf // error buffer
|
||||||
|
) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the file %s.\n", source);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read and dispatch packets until EOF is reached
|
||||||
|
pcap_loop(fp, 0, dispatcher_handler, NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void dispatcher_handler(u_char *temp1,
|
||||||
|
const struct pcap_pkthdr *header, const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
u_int i=0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unused variable
|
||||||
|
*/
|
||||||
|
(VOID)temp1;
|
||||||
|
|
||||||
|
/* print pkt timestamp and pkt len */
|
||||||
|
printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
/* Print the packet */
|
||||||
|
for (i=1; (i < header->caplen + 1 ) ; i++)
|
||||||
|
{
|
||||||
|
printf("%.2x ", pkt_data[i-1]);
|
||||||
|
if ( (i % LINE_LEN) == 0) printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="readfile" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=readfile - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "readfile.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "readfile.mak" CFG="readfile - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "readfile - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "readfile - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "readfile - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "readfile - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "readfile - Win32 Release"
|
||||||
|
# Name "readfile - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\readfile.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,73 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#define LINE_LEN 16
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
char source[PCAP_BUF_SIZE];
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
u_int i=0;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
if(argc != 2)
|
||||||
|
{
|
||||||
|
printf("usage: %s filename", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create the source string according to the new WinPcap syntax */
|
||||||
|
if ( pcap_createsrcstr( source, // variable that will keep the source string
|
||||||
|
PCAP_SRC_FILE, // we want to open a file
|
||||||
|
NULL, // remote host
|
||||||
|
NULL, // port on the remote host
|
||||||
|
argv[1], // name of the file we want to open
|
||||||
|
errbuf // error buffer
|
||||||
|
) != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError creating a source string\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the capture file */
|
||||||
|
if ( (fp= pcap_open(source, // name of the device
|
||||||
|
65536, // portion of the packet to capture
|
||||||
|
// 65536 guarantees that the whole packet will be captured on all the link layers
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
|
||||||
|
1000, // read timeout
|
||||||
|
NULL, // authentication on the remote machine
|
||||||
|
errbuf // error buffer
|
||||||
|
) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the file %s.\n", source);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieve the packets from the file */
|
||||||
|
while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)
|
||||||
|
{
|
||||||
|
/* print pkt timestamp and pkt len */
|
||||||
|
printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
/* Print the packet */
|
||||||
|
for (i=1; (i < header->caplen + 1 ) ; i++)
|
||||||
|
{
|
||||||
|
printf("%.2x ", pkt_data[i-1]);
|
||||||
|
if ( (i % LINE_LEN) == 0) printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (res == -1)
|
||||||
|
{
|
||||||
|
printf("Error reading the packets: %s\n", pcap_geterr(fp));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="readfile_ex" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=readfile_ex - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "readfile_ex.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "readfile_ex.mak" CFG="readfile_ex - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "readfile_ex - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "readfile_ex - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "readfile_ex - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "readfile_ex - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "readfile_ex - Win32 Release"
|
||||||
|
# Name "readfile_ex - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\readfile_ex.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,104 @@
|
||||||
|
#include "pcap.h"
|
||||||
|
|
||||||
|
/* prototype of the packet handler */
|
||||||
|
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs;
|
||||||
|
pcap_if_t *d;
|
||||||
|
int inum;
|
||||||
|
int i=0;
|
||||||
|
pcap_t *adhandle;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
pcap_dumper_t *dumpfile;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Check command line */
|
||||||
|
if(argc != 2)
|
||||||
|
{
|
||||||
|
printf("usage: %s filename", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieve the device list on the local machine */
|
||||||
|
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf_s("%d", &inum);
|
||||||
|
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
|
||||||
|
/* Open the device */
|
||||||
|
if ( (adhandle= pcap_open(d->name, // name of the device
|
||||||
|
65536, // portion of the packet to capture
|
||||||
|
// 65536 guarantees that the whole packet will be captured on all the link layers
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
|
||||||
|
1000, // read timeout
|
||||||
|
NULL, // authentication on the remote machine
|
||||||
|
errbuf // error buffer
|
||||||
|
) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the dump file */
|
||||||
|
dumpfile = pcap_dump_open(adhandle, argv[1]);
|
||||||
|
|
||||||
|
if(dumpfile==NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError opening output file\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nlistening on %s... Press Ctrl+C to stop...\n", d->description);
|
||||||
|
|
||||||
|
/* At this point, we no longer need the device list. Free it */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
|
||||||
|
/* start the capture */
|
||||||
|
pcap_loop(adhandle, 0, packet_handler, (unsigned char *)dumpfile);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback function invoked by libpcap for every incoming packet */
|
||||||
|
void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
/* save the packet on the dump file */
|
||||||
|
pcap_dump(dumpfile, header, pkt_data);
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="savedump" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=savedump - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "savedump.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "savedump.mak" CFG="savedump - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "savedump - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "savedump - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "savedump - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "savedump - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "savedump - Win32 Release"
|
||||||
|
# Name "savedump - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\savedump.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,64 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
|
||||||
|
void main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
u_char packet[100];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Check the validity of the command line */
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
printf("usage: %s interface (e.g. 'rpcap://eth0')", argv[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the output device */
|
||||||
|
if ( (fp= pcap_open(argv[1], // name of the device
|
||||||
|
100, // portion of the packet to capture (only the first 100 bytes)
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
|
||||||
|
1000, // read timeout
|
||||||
|
NULL, // authentication on the remote machine
|
||||||
|
errbuf // error buffer
|
||||||
|
) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", argv[1]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Supposing to be on ethernet, set mac destination to 1:1:1:1:1:1 */
|
||||||
|
packet[0]=1;
|
||||||
|
packet[1]=1;
|
||||||
|
packet[2]=1;
|
||||||
|
packet[3]=1;
|
||||||
|
packet[4]=1;
|
||||||
|
packet[5]=1;
|
||||||
|
|
||||||
|
/* set mac source to 2:2:2:2:2:2 */
|
||||||
|
packet[6]=2;
|
||||||
|
packet[7]=2;
|
||||||
|
packet[8]=2;
|
||||||
|
packet[9]=2;
|
||||||
|
packet[10]=2;
|
||||||
|
packet[11]=2;
|
||||||
|
|
||||||
|
/* Fill the rest of the packet */
|
||||||
|
for(i=12;i<100;i++)
|
||||||
|
{
|
||||||
|
packet[i]=(u_char)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send down the packet */
|
||||||
|
if (pcap_sendpacket(fp, packet, 100 /* size */) != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError sending the packet: %s\n", pcap_geterr(fp));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="sendpack" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=sendpack - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "sendpack.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "sendpack.mak" CFG="sendpack - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "sendpack - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "sendpack - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "sendpack - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "sendpack - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /I "D:/Program Files/Microsoft Platform SDK/include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ws2_32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "sendpack - Win32 Release"
|
||||||
|
# Name "sendpack - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\sendpack.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,169 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#define MAX_PRINT 80
|
||||||
|
#define MAX_LINE 16
|
||||||
|
|
||||||
|
|
||||||
|
void usage();
|
||||||
|
|
||||||
|
|
||||||
|
void main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
char *source=NULL;
|
||||||
|
char *ofilename=NULL;
|
||||||
|
char *filter=NULL;
|
||||||
|
int i;
|
||||||
|
pcap_dumper_t *dumpfile;
|
||||||
|
struct bpf_program fcode;
|
||||||
|
bpf_u_int32 NetMask;
|
||||||
|
int res;
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=1;i < argc; i+= 2)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (argv[i] [1])
|
||||||
|
{
|
||||||
|
case 's':
|
||||||
|
{
|
||||||
|
source=argv[i+1];
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'o':
|
||||||
|
{
|
||||||
|
ofilename=argv[i+1];
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
{
|
||||||
|
filter=argv[i+1];
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// open a capture from the network
|
||||||
|
if (source != NULL)
|
||||||
|
{
|
||||||
|
if ( (fp= pcap_open(source,
|
||||||
|
1514 /*snaplen*/,
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS /*flags*/,
|
||||||
|
20 /*read timeout*/,
|
||||||
|
NULL /* remote authentication */,
|
||||||
|
errbuf)
|
||||||
|
) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else usage();
|
||||||
|
|
||||||
|
if (filter != NULL)
|
||||||
|
{
|
||||||
|
// We should loop through the adapters returned by the pcap_findalldevs_ex()
|
||||||
|
// in order to locate the correct one.
|
||||||
|
//
|
||||||
|
// Let's do things simpler: we suppose to be in a C class network ;-)
|
||||||
|
NetMask=0xffffff;
|
||||||
|
|
||||||
|
//compile the filter
|
||||||
|
if(pcap_compile(fp, &fcode, filter, 1, NetMask) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError compiling filter: wrong syntax.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the filter
|
||||||
|
if(pcap_setfilter(fp, &fcode)<0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError setting the filter\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//open the dump file
|
||||||
|
if (ofilename != NULL)
|
||||||
|
{
|
||||||
|
dumpfile= pcap_dump_open(fp, ofilename);
|
||||||
|
|
||||||
|
if (dumpfile == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError opening output file\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else usage();
|
||||||
|
|
||||||
|
//start the capture
|
||||||
|
while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(res == 0)
|
||||||
|
/* Timeout elapsed */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//save the packet on the dump file
|
||||||
|
pcap_dump((unsigned char *) dumpfile, header, pkt_data);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void usage()
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("\npf - Generic Packet Filter.\n");
|
||||||
|
printf("\nUsage:\npf -s source -o output_file_name [-f filter_string]\n\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="pcap_filter" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=pcap_filter - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "pcap_filter.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "pcap_filter.mak" CFG="pcap_filter - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "pcap_filter - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "pcap_filter - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "pcap_filter - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386 /out:"Release/pf.exe"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "pcap_filter - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/pf.exe" /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "pcap_filter - Win32 Release"
|
||||||
|
# Name "pcap_filter - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\pcap_filter.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "pcap_filter"=.\pcap_filter.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of CACE Technologies nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This sample was contributed by
|
||||||
|
* Marcin Okraszewski (Marcin.OkraszewskiATpl.compuware.com)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <tchar.h>
|
||||||
|
#include <pcap.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/** Prints packet timestaps regardless of format*/
|
||||||
|
int _tmain(int argc, _TCHAR* argv[])
|
||||||
|
{
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
wchar_t cmd[1024];
|
||||||
|
wchar_t tshark_path[MAX_PATH];
|
||||||
|
wchar_t file_path[MAX_PATH];
|
||||||
|
|
||||||
|
if ( argc != 3 ) {
|
||||||
|
wprintf(L"Prints packet timestaps regardless of format.\n");
|
||||||
|
wprintf(L"Usage:\n\t%ls <tshark path> <trace file>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// conversion to short path name in case there are spaces
|
||||||
|
if ( ! GetShortPathNameW(argv[1], tshark_path, MAX_PATH) ||
|
||||||
|
! GetShortPathNameW(argv[2], file_path, MAX_PATH) )
|
||||||
|
{
|
||||||
|
printf("Failed to convert paths to short form.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create tshark command, which will make the trace conversion and print in libpcap format to stdout
|
||||||
|
if ( swprintf_s(cmd, 1024, L"%ls -r %ls -w - -F libpcap", tshark_path, file_path) < 0 ) {
|
||||||
|
wprintf(L"Failed to create command\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// start tshark
|
||||||
|
FILE *tshark_out = _wpopen(cmd, L"rb");
|
||||||
|
if ( tshark_out == NULL ) {
|
||||||
|
strerror_s(errbuf, PCAP_ERRBUF_SIZE, errno);
|
||||||
|
printf("Failed run tshark: %s\n", errbuf);
|
||||||
|
wprintf(L"Command: %ls", cmd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// open stdout from tshark
|
||||||
|
pcap_t *pcap = pcap_fopen_offline(tshark_out, errbuf);
|
||||||
|
if ( pcap == NULL ) {
|
||||||
|
printf("Error opening stream from tshark: %s\n", errbuf);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// print information about every packet int trace
|
||||||
|
struct pcap_pkthdr hdr;
|
||||||
|
while ( pcap_next(pcap, &hdr) ) {
|
||||||
|
printf("packet: ts: %u.%06u, len: %4u, caplen: %4u\n", hdr.ts.tv_sec, hdr.ts.tv_usec, hdr.len, hdr.caplen);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
pcap_close(pcap);
|
||||||
|
_pclose(tshark_out);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
//
|
||||||
|
// NOTE: remember to include WPCAP and HAVE_REMOTE among your
|
||||||
|
// preprocessor definitions.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#define LINE_LEN 16
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs, *d;
|
||||||
|
pcap_t *fp;
|
||||||
|
u_int inum, i=0;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
int res;
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
|
||||||
|
printf("pktdump_ex: prints the packets of the network using WinPcap.\n");
|
||||||
|
printf(" Usage: pktdump_ex [-s source]\n\n"
|
||||||
|
" Examples:\n"
|
||||||
|
" pktdump_ex -s file://c:/temp/file.acp\n"
|
||||||
|
" pktdump_ex -s rpcap://\\Device\\NPF_{C8736017-F3C3-4373-94AC-9A34B7DAD998}\n\n");
|
||||||
|
|
||||||
|
if(argc < 3)
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("\nNo adapter selected: printing the device list:\n");
|
||||||
|
/* The user didn't provide a packet source: Retrieve the local device list */
|
||||||
|
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s\n ", ++i, d->name);
|
||||||
|
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i==0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"No interfaces found! Exiting.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf_s("%d", &inum);
|
||||||
|
|
||||||
|
if (inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for (d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the device */
|
||||||
|
if ( (fp= pcap_open(d->name,
|
||||||
|
100 /*snaplen*/,
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS /*flags*/,
|
||||||
|
20 /*read timeout*/,
|
||||||
|
NULL /* remote authentication */,
|
||||||
|
errbuf)
|
||||||
|
) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError opening adapter\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Do not check for the switch type ('-s')
|
||||||
|
if ( (fp= pcap_open(argv[2],
|
||||||
|
100 /*snaplen*/,
|
||||||
|
PCAP_OPENFLAG_PROMISCUOUS /*flags*/,
|
||||||
|
20 /*read timeout*/,
|
||||||
|
NULL /* remote authentication */,
|
||||||
|
errbuf)
|
||||||
|
) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError opening source: %s\n", errbuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the packets */
|
||||||
|
while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(res == 0)
|
||||||
|
/* Timeout elapsed */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* print pkt timestamp and pkt len */
|
||||||
|
printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);
|
||||||
|
|
||||||
|
/* Print the packet */
|
||||||
|
for (i=1; (i < header->caplen + 1 ) ; i++)
|
||||||
|
{
|
||||||
|
printf("%.2x ", pkt_data[i-1]);
|
||||||
|
if ( (i % LINE_LEN) == 0) printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error reading the packets: %s\n", pcap_geterr(fp));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="pktdump_ex" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=pktdump_ex - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "pktdump_ex.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "pktdump_ex.mak" CFG="pktdump_ex - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "pktdump_ex - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "pktdump_ex - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "pktdump_ex - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "pktdump_ex - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "pktdump_ex - Win32 Release"
|
||||||
|
# Name "pktdump_ex - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\pktdump_ex.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "pktdump_ex"=.\pktdump_ex.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "sendcap"=.\sendcap.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
void usage();
|
||||||
|
|
||||||
|
void main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *indesc,*outdesc;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
char source[PCAP_BUF_SIZE];
|
||||||
|
FILE *capfile;
|
||||||
|
int caplen, sync;
|
||||||
|
u_int res;
|
||||||
|
pcap_send_queue *squeue;
|
||||||
|
struct pcap_pkthdr *pktheader;
|
||||||
|
u_char *pktdata;
|
||||||
|
float cpu_time;
|
||||||
|
u_int npacks = 0;
|
||||||
|
errno_t fopen_error;
|
||||||
|
|
||||||
|
/* Check the validity of the command line */
|
||||||
|
if (argc <= 2 || argc >= 5)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieve the length of the capture file */
|
||||||
|
fopen_error = fopen_s(&capfile, argv[1],"rb");
|
||||||
|
if(fopen_error != 0){
|
||||||
|
printf("Error opening the file, errno %d.\n", fopen_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(capfile , 0, SEEK_END);
|
||||||
|
caplen= ftell(capfile)- sizeof(struct pcap_file_header);
|
||||||
|
fclose(capfile);
|
||||||
|
|
||||||
|
/* Chek if the timestamps must be respected */
|
||||||
|
if(argc == 4 && argv[3][0] == 's')
|
||||||
|
sync = TRUE;
|
||||||
|
else
|
||||||
|
sync = FALSE;
|
||||||
|
|
||||||
|
/* Open the capture */
|
||||||
|
/* Create the source string according to the new WinPcap syntax */
|
||||||
|
if ( pcap_createsrcstr( source, // variable that will keep the source string
|
||||||
|
PCAP_SRC_FILE, // we want to open a file
|
||||||
|
NULL, // remote host
|
||||||
|
NULL, // port on the remote host
|
||||||
|
argv[1], // name of the file we want to open
|
||||||
|
errbuf // error buffer
|
||||||
|
) != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError creating a source string\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the capture file */
|
||||||
|
if ( (indesc= pcap_open(source, 65536, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the file %s.\n", source);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the output adapter */
|
||||||
|
if ( (outdesc= pcap_open(argv[2], 100, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open adapter %s.\n", source);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check the MAC type */
|
||||||
|
if (pcap_datalink(indesc) != pcap_datalink(outdesc))
|
||||||
|
{
|
||||||
|
printf("Warning: the datalink of the capture differs from the one of the selected interface.\n");
|
||||||
|
printf("Press a key to continue, or CTRL+C to stop.\n");
|
||||||
|
getchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate a send queue */
|
||||||
|
squeue = pcap_sendqueue_alloc(caplen);
|
||||||
|
|
||||||
|
/* Fill the queue with the packets from the file */
|
||||||
|
while ((res = pcap_next_ex( indesc, &pktheader, &pktdata)) == 1)
|
||||||
|
{
|
||||||
|
if (pcap_sendqueue_queue(squeue, pktheader, pktdata) == -1)
|
||||||
|
{
|
||||||
|
printf("Warning: packet buffer too small, not all the packets will be sent.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
npacks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res == -1)
|
||||||
|
{
|
||||||
|
printf("Corrupted input file.\n");
|
||||||
|
pcap_sendqueue_destroy(squeue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Transmit the queue */
|
||||||
|
|
||||||
|
cpu_time = (float)clock ();
|
||||||
|
|
||||||
|
if ((res = pcap_sendqueue_transmit(outdesc, squeue, sync)) < squeue->len)
|
||||||
|
{
|
||||||
|
printf("An error occurred sending the packets: %s. Only %d bytes were sent\n", pcap_geterr(outdesc), res);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu_time = (clock() - cpu_time)/CLK_TCK;
|
||||||
|
|
||||||
|
printf ("\n\nElapsed time: %5.3f\n", cpu_time);
|
||||||
|
printf ("\nTotal packets generated = %d", npacks);
|
||||||
|
printf ("\nAverage packets per second = %d", (int)((double)npacks/cpu_time));
|
||||||
|
printf ("\n");
|
||||||
|
|
||||||
|
/* free the send queue */
|
||||||
|
pcap_sendqueue_destroy(squeue);
|
||||||
|
|
||||||
|
/* Close the input file */
|
||||||
|
pcap_close(indesc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* lose the output adapter
|
||||||
|
* IMPORTANT: remember to close the adapter, otherwise there will be no guarantee that all the
|
||||||
|
* packets will be sent!
|
||||||
|
*/
|
||||||
|
pcap_close(outdesc);
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void usage()
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("\nSendcap, sends a libpcap/tcpdump capture file to the net. Copyright (C) 2002 Loris Degioanni.\n");
|
||||||
|
printf("\nUsage:\n");
|
||||||
|
printf("\t sendcap file_name adapter [s]\n");
|
||||||
|
printf("\nParameters:\n");
|
||||||
|
printf("\nfile_name: the name of the dump file that will be sent to the network\n");
|
||||||
|
printf("\nadapter: the device to use. Use \"WinDump -D\" for a list of valid devices\n");
|
||||||
|
printf("\ns: if present, forces the packets to be sent synchronously, i.e. respecting the timestamps in the dump file. This option will work only under Windows NTx.\n\n");
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="sendcap" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=sendcap - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "sendcap.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "sendcap.mak" CFG="sendcap - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "sendcap - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "sendcap - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "sendcap - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "PCAP_DONT_INCLUDE_PCAP_BPF_H" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "sendcap - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "PCAP_DONT_INCLUDE_PCAP_BPF_H" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "sendcap - Win32 Release"
|
||||||
|
# Name "sendcap - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\sendcap.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,134 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <conio.h>
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pcap_if_t *alldevs, *d;
|
||||||
|
pcap_t *fp;
|
||||||
|
u_int inum, i=0;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
int res;
|
||||||
|
struct pcap_pkthdr *header;
|
||||||
|
const u_char *pkt_data;
|
||||||
|
struct pcap_pkthdr old;
|
||||||
|
|
||||||
|
printf("SMP_1\n");
|
||||||
|
printf("\nThis program tests the WinPcap kernel driver on SMP machines.\n");
|
||||||
|
printf("The program tests that timestamps on the captured packets are consistent,\n");
|
||||||
|
printf("and that the caplen is equal to the packet length.\n");
|
||||||
|
printf("If there is an error, it will print out a message saying \"Inconsistent XXX\"\n");
|
||||||
|
|
||||||
|
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the list */
|
||||||
|
for(d=alldevs; d; d=d->next)
|
||||||
|
{
|
||||||
|
printf("%d. %s", ++i, d->name);
|
||||||
|
if (d->description)
|
||||||
|
printf(" (%s)\n", d->description);
|
||||||
|
else
|
||||||
|
printf(" (No description available)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Enter the interface number (1-%d):",i);
|
||||||
|
scanf_s("%d", &inum);
|
||||||
|
|
||||||
|
if(inum < 1 || inum > i)
|
||||||
|
{
|
||||||
|
printf("\nInterface number out of range.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to the selected adapter */
|
||||||
|
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
|
||||||
|
|
||||||
|
/* Open the device */
|
||||||
|
if ( (fp= pcap_open(d->name, 65536, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
|
||||||
|
/* Free the device list */
|
||||||
|
pcap_freealldevs(alldevs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
old.ts.tv_sec=0;
|
||||||
|
old.ts.tv_usec=0;
|
||||||
|
|
||||||
|
|
||||||
|
/* Read the packets */
|
||||||
|
while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0){
|
||||||
|
|
||||||
|
if(res == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//check that caplen is equal to packet length
|
||||||
|
if (header->caplen!=header->len)
|
||||||
|
printf("Inconsistent header: CapLen %d\t Len %d\n",header->caplen,header->len);
|
||||||
|
|
||||||
|
//check that timestamps always grow
|
||||||
|
if ( old.ts.tv_sec > header->ts.tv_sec || (old.ts.tv_sec == header->ts.tv_sec && old.ts.tv_usec > header->ts.tv_usec))
|
||||||
|
printf("Inconsistent Timestamps! Old was %d.%.06d - New is %d.%.06d\n",old.ts.tv_sec,old.ts.tv_usec, header->ts.tv_sec,header->ts.tv_usec);
|
||||||
|
|
||||||
|
old=*header;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res == -1){
|
||||||
|
printf("Error reading the packets: %s\n", pcap_geterr(fp));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_getch();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="smp_1" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=smp_1 - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "smp_1.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "smp_1.mak" CFG="smp_1 - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "smp_1 - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "smp_1 - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "smp_1 - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wpcap.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\lib"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "smp_1 - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wpcap.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\lib"
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "smp_1 - Win32 Release"
|
||||||
|
# Name "smp_1 - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\SMP_1.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "smp_1"=.\smp_1.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,158 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
|
||||||
|
void usage();
|
||||||
|
|
||||||
|
void dispatcher_handler(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||||
|
|
||||||
|
|
||||||
|
void main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pcap_t *fp;
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
struct timeval st_ts;
|
||||||
|
u_int netmask;
|
||||||
|
struct bpf_program fcode;
|
||||||
|
|
||||||
|
/* Check the validity of the command line */
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the output adapter */
|
||||||
|
if ( (fp= pcap_open(argv[1], 100, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf) ) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to open adapter %s.\n", errbuf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't care about netmask, it won't be used for this filter */
|
||||||
|
netmask=0xffffff;
|
||||||
|
|
||||||
|
//compile the filter
|
||||||
|
if (pcap_compile(fp, &fcode, "tcp", 1, netmask) <0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
|
||||||
|
/* Free the device list */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the filter
|
||||||
|
if (pcap_setfilter(fp, &fcode)<0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError setting the filter.\n");
|
||||||
|
pcap_close(fp);
|
||||||
|
/* Free the device list */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Put the interface in statstics mode */
|
||||||
|
if (pcap_setmode(fp, MODE_STAT)<0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"\nError setting the mode.\n");
|
||||||
|
pcap_close(fp);
|
||||||
|
/* Free the device list */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("TCP traffic summary:\n");
|
||||||
|
|
||||||
|
/* Start the main loop */
|
||||||
|
pcap_loop(fp, 0, dispatcher_handler, (PUCHAR)&st_ts);
|
||||||
|
|
||||||
|
pcap_close(fp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispatcher_handler(u_char *state, const struct pcap_pkthdr *header, const u_char *pkt_data)
|
||||||
|
{
|
||||||
|
struct timeval *old_ts = (struct timeval *)state;
|
||||||
|
u_int delay;
|
||||||
|
LARGE_INTEGER Bps,Pps;
|
||||||
|
struct tm ltime;
|
||||||
|
char timestr[16];
|
||||||
|
time_t local_tv_sec;
|
||||||
|
|
||||||
|
/* Calculate the delay in microseconds from the last sample. */
|
||||||
|
/* This value is obtained from the timestamp that the associated with the sample. */
|
||||||
|
delay=(header->ts.tv_sec - old_ts->tv_sec) * 1000000 - old_ts->tv_usec + header->ts.tv_usec;
|
||||||
|
/* Get the number of Bits per second */
|
||||||
|
Bps.QuadPart=(((*(LONGLONG*)(pkt_data + 8)) * 8 * 1000000) / (delay));
|
||||||
|
/* ^ ^
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
converts bytes in bits -- |
|
||||||
|
|
|
||||||
|
delay is expressed in microseconds --
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Get the number of Packets per second */
|
||||||
|
Pps.QuadPart=(((*(LONGLONG*)(pkt_data)) * 1000000) / (delay));
|
||||||
|
|
||||||
|
/* Convert the timestamp to readable format */
|
||||||
|
local_tv_sec = header->ts.tv_sec;
|
||||||
|
localtime_s(<ime, &local_tv_sec);
|
||||||
|
strftime( timestr, sizeof timestr, "%H:%M:%S", <ime);
|
||||||
|
|
||||||
|
/* Print timestamp*/
|
||||||
|
printf("%s ", timestr);
|
||||||
|
|
||||||
|
/* Print the samples */
|
||||||
|
printf("BPS=%I64u ", Bps.QuadPart);
|
||||||
|
printf("PPS=%I64u\n", Pps.QuadPart);
|
||||||
|
|
||||||
|
//store current timestamp
|
||||||
|
old_ts->tv_sec=header->ts.tv_sec;
|
||||||
|
old_ts->tv_usec=header->ts.tv_usec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void usage()
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("\nShows the TCP traffic load, in bits per second and packets per second.\nCopyright (C) 2002 Loris Degioanni.\n");
|
||||||
|
printf("\nUsage:\n");
|
||||||
|
printf("\t tcptop adapter\n");
|
||||||
|
printf("\t You can use \"WinDump -D\" if you don't know the name of your adapters.\n");
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="tcptop" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=tcptop - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "tcptop.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "tcptop.mak" CFG="tcptop - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "tcptop - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "tcptop - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "tcptop - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "tcptop - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../" /I "../bpf/" /I "../lbl/" /I "../../Include/" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_UNICODE" /D "WPCAP" /D "HAVE_REMOTE" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x410 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x410 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "tcptop - Win32 Release"
|
||||||
|
# Name "tcptop - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tcptop.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\include\pcap.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\lib\Wpcap.lib
|
||||||
|
# End Source File
|
||||||
|
# End Target
|
||||||
|
# End Project
|
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "tcptop"=.\tcptop.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
|
@ -0,0 +1,359 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2007 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @ingroup packetapi
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup packet32h Packet.dll definitions and data structures
|
||||||
|
* Packet32.h contains the data structures and the definitions used by packet.dll.
|
||||||
|
* The file is used both by the Win9x and the WinNTx versions of packet.dll, and can be included
|
||||||
|
* by the applications that use the functions of this library
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PACKET32
|
||||||
|
#define __PACKET32
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_AIRPCAP_API
|
||||||
|
#include <airpcap.h>
|
||||||
|
#else
|
||||||
|
#if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
|
||||||
|
#define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
|
||||||
|
typedef struct _AirpcapHandle *PAirpcapHandle;
|
||||||
|
#endif /* AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ */
|
||||||
|
#endif /* HAVE_AIRPCAP_API */
|
||||||
|
|
||||||
|
#ifdef HAVE_DAG_API
|
||||||
|
#include <dagc.h>
|
||||||
|
#endif /* HAVE_DAG_API */
|
||||||
|
|
||||||
|
// Working modes
|
||||||
|
#define PACKET_MODE_CAPT 0x0 ///< Capture mode
|
||||||
|
#define PACKET_MODE_STAT 0x1 ///< Statistical mode
|
||||||
|
#define PACKET_MODE_MON 0x2 ///< Monitoring mode
|
||||||
|
#define PACKET_MODE_DUMP 0x10 ///< Dump mode
|
||||||
|
#define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT ///< Statistical dump Mode
|
||||||
|
|
||||||
|
|
||||||
|
/// Alignment macro. Defines the alignment size.
|
||||||
|
#define Packet_ALIGNMENT sizeof(int)
|
||||||
|
/// Alignment macro. Rounds up to the next even multiple of Packet_ALIGNMENT.
|
||||||
|
#define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
|
||||||
|
|
||||||
|
#define NdisMediumNull -1 ///< Custom linktype: NDIS doesn't provide an equivalent
|
||||||
|
#define NdisMediumCHDLC -2 ///< Custom linktype: NDIS doesn't provide an equivalent
|
||||||
|
#define NdisMediumPPPSerial -3 ///< Custom linktype: NDIS doesn't provide an equivalent
|
||||||
|
#define NdisMediumBare80211 -4 ///< Custom linktype: NDIS doesn't provide an equivalent
|
||||||
|
#define NdisMediumRadio80211 -5 ///< Custom linktype: NDIS doesn't provide an equivalent
|
||||||
|
#define NdisMediumPpi -6 ///< Custom linktype: NDIS doesn't provide an equivalent
|
||||||
|
|
||||||
|
// Loopback behaviour definitions
|
||||||
|
#define NPF_DISABLE_LOOPBACK 1 ///< Drop the packets sent by the NPF driver
|
||||||
|
#define NPF_ENABLE_LOOPBACK 2 ///< Capture the packets sent by the NPF driver
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Network type structure.
|
||||||
|
|
||||||
|
This structure is used by the PacketGetNetType() function to return information on the current adapter's type and speed.
|
||||||
|
*/
|
||||||
|
typedef struct NetType
|
||||||
|
{
|
||||||
|
UINT LinkType; ///< The MAC of the current network adapter (see function PacketGetNetType() for more information)
|
||||||
|
ULONGLONG LinkSpeed; ///< The speed of the network in bits per second
|
||||||
|
}NetType;
|
||||||
|
|
||||||
|
|
||||||
|
//some definitions stolen from libpcap
|
||||||
|
|
||||||
|
#ifndef BPF_MAJOR_VERSION
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief A BPF pseudo-assembly program.
|
||||||
|
|
||||||
|
The program will be injected in the kernel by the PacketSetBPF() function and applied to every incoming packet.
|
||||||
|
*/
|
||||||
|
struct bpf_program
|
||||||
|
{
|
||||||
|
UINT bf_len; ///< Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will follow.
|
||||||
|
struct bpf_insn *bf_insns; ///< A pointer to the first instruction of the program.
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief A single BPF pseudo-instruction.
|
||||||
|
|
||||||
|
bpf_insn contains a single instruction for the BPF register-machine. It is used to send a filter program to the driver.
|
||||||
|
*/
|
||||||
|
struct bpf_insn
|
||||||
|
{
|
||||||
|
USHORT code; ///< Instruction type and addressing mode.
|
||||||
|
UCHAR jt; ///< Jump if true
|
||||||
|
UCHAR jf; ///< Jump if false
|
||||||
|
int k; ///< Generic field used for various purposes.
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Structure that contains a couple of statistics values on the current capture.
|
||||||
|
|
||||||
|
It is used by packet.dll to return statistics about a capture session.
|
||||||
|
*/
|
||||||
|
struct bpf_stat
|
||||||
|
{
|
||||||
|
UINT bs_recv; ///< Number of packets that the driver received from the network adapter
|
||||||
|
///< from the beginning of the current capture. This value includes the packets
|
||||||
|
///< lost by the driver.
|
||||||
|
UINT bs_drop; ///< number of packets that the driver lost from the beginning of a capture.
|
||||||
|
///< Basically, a packet is lost when the the buffer of the driver is full.
|
||||||
|
///< In this situation the packet cannot be stored and the driver rejects it.
|
||||||
|
UINT ps_ifdrop; ///< drops by interface. XXX not yet supported
|
||||||
|
UINT bs_capt; ///< number of packets that pass the filter, find place in the kernel buffer and
|
||||||
|
///< thus reach the application.
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Packet header.
|
||||||
|
|
||||||
|
This structure defines the header associated with every packet delivered to the application.
|
||||||
|
*/
|
||||||
|
struct bpf_hdr
|
||||||
|
{
|
||||||
|
struct timeval bh_tstamp; ///< The timestamp associated with the captured packet.
|
||||||
|
///< It is stored in a TimeVal structure.
|
||||||
|
UINT bh_caplen; ///< Length of captured portion. The captured portion <b>can be different</b>
|
||||||
|
///< from the original packet, because it is possible (with a proper filter)
|
||||||
|
///< to instruct the driver to capture only a portion of the packets.
|
||||||
|
UINT bh_datalen; ///< Original length of packet
|
||||||
|
USHORT bh_hdrlen; ///< Length of bpf header (this struct plus alignment padding). In some cases,
|
||||||
|
///< a padding could be added between the end of this structure and the packet
|
||||||
|
///< data for performance reasons. This filed can be used to retrieve the actual data
|
||||||
|
///< of the packet.
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Dump packet header.
|
||||||
|
|
||||||
|
This structure defines the header associated with the packets in a buffer to be used with PacketSendPackets().
|
||||||
|
It is simpler than the bpf_hdr, because it corresponds to the header associated by WinPcap and libpcap to a
|
||||||
|
packet in a dump file. This makes straightforward sending WinPcap dump files to the network.
|
||||||
|
*/
|
||||||
|
struct dump_bpf_hdr{
|
||||||
|
struct timeval ts; ///< Time stamp of the packet
|
||||||
|
UINT caplen; ///< Length of captured portion. The captured portion can smaller than the
|
||||||
|
///< the original packet, because it is possible (with a proper filter) to
|
||||||
|
///< instruct the driver to capture only a portion of the packets.
|
||||||
|
UINT len; ///< Length of the original packet (off wire).
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct bpf_stat;
|
||||||
|
|
||||||
|
#define DOSNAMEPREFIX TEXT("Packet_") ///< Prefix added to the adapters device names to create the WinPcap devices
|
||||||
|
#define MAX_LINK_NAME_LENGTH 64 //< Maximum length of the devices symbolic links
|
||||||
|
#define NMAX_PACKET 65535
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Addresses of a network adapter.
|
||||||
|
|
||||||
|
This structure is used by the PacketGetNetInfoEx() function to return the IP addresses associated with
|
||||||
|
an adapter.
|
||||||
|
*/
|
||||||
|
typedef struct npf_if_addr {
|
||||||
|
struct sockaddr_storage IPAddress; ///< IP address.
|
||||||
|
struct sockaddr_storage SubnetMask; ///< Netmask for that address.
|
||||||
|
struct sockaddr_storage Broadcast; ///< Broadcast address.
|
||||||
|
}npf_if_addr;
|
||||||
|
|
||||||
|
|
||||||
|
#define ADAPTER_NAME_LENGTH 256 + 12 ///< Maximum length for the name of an adapter. The value is the same used by the IP Helper API.
|
||||||
|
#define ADAPTER_DESC_LENGTH 128 ///< Maximum length for the description of an adapter. The value is the same used by the IP Helper API.
|
||||||
|
#define MAX_MAC_ADDR_LENGTH 8 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
|
||||||
|
#define MAX_NETWORK_ADDRESSES 16 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct WAN_ADAPTER_INT WAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
|
||||||
|
typedef WAN_ADAPTER *PWAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
|
||||||
|
|
||||||
|
#define INFO_FLAG_NDIS_ADAPTER 0 ///< Flag for ADAPTER_INFO: this is a traditional ndis adapter
|
||||||
|
#define INFO_FLAG_NDISWAN_ADAPTER 1 ///< Flag for ADAPTER_INFO: this is a NdisWan adapter, and it's managed by WANPACKET
|
||||||
|
#define INFO_FLAG_DAG_CARD 2 ///< Flag for ADAPTER_INFO: this is a DAG card
|
||||||
|
#define INFO_FLAG_DAG_FILE 6 ///< Flag for ADAPTER_INFO: this is a DAG file
|
||||||
|
#define INFO_FLAG_DONT_EXPORT 8 ///< Flag for ADAPTER_INFO: when this flag is set, the adapter will not be listed or openend by winpcap. This allows to prevent exporting broken network adapters, like for example FireWire ones.
|
||||||
|
#define INFO_FLAG_AIRPCAP_CARD 16 ///< Flag for ADAPTER_INFO: this is an airpcap card
|
||||||
|
#define INFO_FLAG_NPFIM_DEVICE 32
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Describes an opened network adapter.
|
||||||
|
|
||||||
|
This structure is the most important for the functioning of packet.dll, but the great part of its fields
|
||||||
|
should be ignored by the user, since the library offers functions that avoid to cope with low-level parameters
|
||||||
|
*/
|
||||||
|
typedef struct _ADAPTER {
|
||||||
|
HANDLE hFile; ///< \internal Handle to an open instance of the NPF driver.
|
||||||
|
CHAR SymbolicLink[MAX_LINK_NAME_LENGTH]; ///< \internal A string containing the name of the network adapter currently opened.
|
||||||
|
int NumWrites; ///< \internal Number of times a packets written on this adapter will be repeated
|
||||||
|
///< on the wire.
|
||||||
|
HANDLE ReadEvent; ///< A notification event associated with the read calls on the adapter.
|
||||||
|
///< It can be passed to standard Win32 functions (like WaitForSingleObject
|
||||||
|
///< or WaitForMultipleObjects) to wait until the driver's buffer contains some
|
||||||
|
///< data. It is particularly useful in GUI applications that need to wait
|
||||||
|
///< concurrently on several events. In Windows NT/2000 the PacketSetMinToCopy()
|
||||||
|
///< function can be used to define the minimum amount of data in the kernel buffer
|
||||||
|
///< that will cause the event to be signalled.
|
||||||
|
|
||||||
|
UINT ReadTimeOut; ///< \internal The amount of time after which a read on the driver will be released and
|
||||||
|
///< ReadEvent will be signaled, also if no packets were captured
|
||||||
|
CHAR Name[ADAPTER_NAME_LENGTH];
|
||||||
|
PWAN_ADAPTER pWanAdapter;
|
||||||
|
UINT Flags; ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
|
||||||
|
|
||||||
|
#ifdef HAVE_AIRPCAP_API
|
||||||
|
PAirpcapHandle AirpcapAd;
|
||||||
|
#endif // HAVE_AIRPCAP_API
|
||||||
|
|
||||||
|
#ifdef HAVE_NPFIM_API
|
||||||
|
void* NpfImHandle;
|
||||||
|
#endif // HAVE_NPFIM_API
|
||||||
|
|
||||||
|
#ifdef HAVE_DAG_API
|
||||||
|
dagc_t *pDagCard; ///< Pointer to the dagc API adapter descriptor for this adapter
|
||||||
|
PCHAR DagBuffer; ///< Pointer to the buffer with the packets that is received from the DAG card
|
||||||
|
struct timeval DagReadTimeout; ///< Read timeout. The dagc API requires a timeval structure
|
||||||
|
unsigned DagFcsLen; ///< Length of the frame check sequence attached to any packet by the card. Obtained from the registry
|
||||||
|
DWORD DagFastProcess; ///< True if the user requests fast capture processing on this card. Higher level applications can use this value to provide a faster but possibly unprecise capture (for example, libpcap doesn't convert the timestamps).
|
||||||
|
#endif // HAVE_DAG_API
|
||||||
|
} ADAPTER, *LPADAPTER;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Structure that contains a group of packets coming from the driver.
|
||||||
|
|
||||||
|
This structure defines the header associated with every packet delivered to the application.
|
||||||
|
*/
|
||||||
|
typedef struct _PACKET {
|
||||||
|
HANDLE hEvent; ///< \deprecated Still present for compatibility with old applications.
|
||||||
|
OVERLAPPED OverLapped; ///< \deprecated Still present for compatibility with old applications.
|
||||||
|
PVOID Buffer; ///< Buffer with containing the packets. See the PacketReceivePacket() for
|
||||||
|
///< details about the organization of the data in this buffer
|
||||||
|
UINT Length; ///< Length of the buffer
|
||||||
|
DWORD ulBytesReceived; ///< Number of valid bytes present in the buffer, i.e. amount of data
|
||||||
|
///< received by the last call to PacketReceivePacket()
|
||||||
|
BOOLEAN bIoComplete; ///< \deprecated Still present for compatibility with old applications.
|
||||||
|
} PACKET, *LPPACKET;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Structure containing an OID request.
|
||||||
|
|
||||||
|
It is used by the PacketRequest() function to send an OID to the interface card driver.
|
||||||
|
It can be used, for example, to retrieve the status of the error counters on the adapter, its MAC address,
|
||||||
|
the list of the multicast groups defined on it, and so on.
|
||||||
|
*/
|
||||||
|
struct _PACKET_OID_DATA {
|
||||||
|
ULONG Oid; ///< OID code. See the Microsoft DDK documentation or the file ntddndis.h
|
||||||
|
///< for a complete list of valid codes.
|
||||||
|
ULONG Length; ///< Length of the data field
|
||||||
|
UCHAR Data[1]; ///< variable-lenght field that contains the information passed to or received
|
||||||
|
///< from the adapter.
|
||||||
|
};
|
||||||
|
typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
BOOLEAN QueryWinPcapRegistryStringA(CHAR *SubKeyName,
|
||||||
|
CHAR *Value,
|
||||||
|
UINT *pValueLen,
|
||||||
|
CHAR *DefaultVal);
|
||||||
|
|
||||||
|
BOOLEAN QueryWinPcapRegistryStringW(WCHAR *SubKeyName,
|
||||||
|
WCHAR *Value,
|
||||||
|
UINT *pValueLen,
|
||||||
|
WCHAR *DefaultVal);
|
||||||
|
*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
// EXPORTED FUNCTIONS
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
PCHAR PacketGetVersion();
|
||||||
|
PCHAR PacketGetDriverVersion();
|
||||||
|
BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);
|
||||||
|
BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);
|
||||||
|
BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);
|
||||||
|
BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);
|
||||||
|
BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);
|
||||||
|
BOOLEAN PacketSetLoopbackBehavior(LPADAPTER AdapterObject, UINT LoopbackBehavior);
|
||||||
|
INT PacketSetSnapLen(LPADAPTER AdapterObject,int snaplen);
|
||||||
|
BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);
|
||||||
|
BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);
|
||||||
|
BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);
|
||||||
|
BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);
|
||||||
|
LPADAPTER PacketOpenAdapter(PCHAR AdapterName);
|
||||||
|
BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);
|
||||||
|
INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);
|
||||||
|
LPPACKET PacketAllocatePacket(void);
|
||||||
|
VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length);
|
||||||
|
VOID PacketFreePacket(LPPACKET lpPacket);
|
||||||
|
BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);
|
||||||
|
BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);
|
||||||
|
BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
|
||||||
|
BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);
|
||||||
|
BOOLEAN PacketRequest(LPADAPTER AdapterObject,BOOLEAN Set,PPACKET_OID_DATA OidData);
|
||||||
|
HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);
|
||||||
|
BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);
|
||||||
|
BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);
|
||||||
|
BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);
|
||||||
|
BOOL PacketStopDriver();
|
||||||
|
VOID PacketCloseAdapter(LPADAPTER lpAdapter);
|
||||||
|
BOOLEAN PacketStartOem(PCHAR errorString, UINT errorStringLength);
|
||||||
|
BOOLEAN PacketStartOemEx(PCHAR errorString, UINT errorStringLength, ULONG flags);
|
||||||
|
PAirpcapHandle PacketGetAirPcapHandle(LPADAPTER AdapterObject);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Used by PacketStartOemEx
|
||||||
|
//
|
||||||
|
#define PACKET_START_OEM_NO_NETMON 0x00000001
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //__PACKET32
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||||
|
* nor the names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __WIN32_EXTENSIONS_H__
|
||||||
|
#define __WIN32_EXTENSIONS_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Definitions */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit().
|
||||||
|
*/
|
||||||
|
struct pcap_send_queue
|
||||||
|
{
|
||||||
|
u_int maxlen; ///< Maximum size of the the queue, in bytes. This variable contains the size of the buffer field.
|
||||||
|
u_int len; ///< Current size of the queue, in bytes.
|
||||||
|
char *buffer; ///< Buffer containing the packets to be sent.
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct pcap_send_queue pcap_send_queue;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief This typedef is a support for the pcap_get_airpcap_handle() function
|
||||||
|
*/
|
||||||
|
#if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
|
||||||
|
#define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
|
||||||
|
typedef struct _AirpcapHandle *PAirpcapHandle;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BPF_MEM_EX_IMM 0xc0
|
||||||
|
#define BPF_MEM_EX_IND 0xe0
|
||||||
|
|
||||||
|
/*used for ST*/
|
||||||
|
#define BPF_MEM_EX 0xc0
|
||||||
|
#define BPF_TME 0x08
|
||||||
|
|
||||||
|
#define BPF_LOOKUP 0x90
|
||||||
|
#define BPF_EXECUTE 0xa0
|
||||||
|
#define BPF_INIT 0xb0
|
||||||
|
#define BPF_VALIDATE 0xc0
|
||||||
|
#define BPF_SET_ACTIVE 0xd0
|
||||||
|
#define BPF_RESET 0xe0
|
||||||
|
#define BPF_SET_MEMORY 0x80
|
||||||
|
#define BPF_GET_REGISTER_VALUE 0x70
|
||||||
|
#define BPF_SET_REGISTER_VALUE 0x60
|
||||||
|
#define BPF_SET_WORKING 0x50
|
||||||
|
#define BPF_SET_ACTIVE_READ 0x40
|
||||||
|
#define BPF_SET_AUTODELETION 0x30
|
||||||
|
#define BPF_SEPARATION 0xff
|
||||||
|
|
||||||
|
/* Prototypes */
|
||||||
|
pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
|
||||||
|
|
||||||
|
void pcap_sendqueue_destroy(pcap_send_queue* queue);
|
||||||
|
|
||||||
|
int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
|
||||||
|
|
||||||
|
u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
|
||||||
|
|
||||||
|
HANDLE pcap_getevent(pcap_t *p);
|
||||||
|
|
||||||
|
struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
|
||||||
|
|
||||||
|
int pcap_setuserbuffer(pcap_t *p, int size);
|
||||||
|
|
||||||
|
int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks);
|
||||||
|
|
||||||
|
int pcap_live_dump_ended(pcap_t *p, int sync);
|
||||||
|
|
||||||
|
int pcap_offline_filter(struct bpf_program *prog, const struct pcap_pkthdr *header, const u_char *pkt_data);
|
||||||
|
|
||||||
|
int pcap_start_oem(char* err_str, int flags);
|
||||||
|
|
||||||
|
PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //__WIN32_EXTENSIONS_H__
|
|
@ -0,0 +1,137 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 1999 WIDE Project.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the project nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#ifndef _BITTYPES_H
|
||||||
|
#define _BITTYPES_H
|
||||||
|
|
||||||
|
#ifndef HAVE_U_INT8_T
|
||||||
|
|
||||||
|
#if SIZEOF_CHAR == 1
|
||||||
|
typedef unsigned char u_int8_t;
|
||||||
|
typedef signed char int8_t;
|
||||||
|
#elif SIZEOF_INT == 1
|
||||||
|
typedef unsigned int u_int8_t;
|
||||||
|
typedef signed int int8_t;
|
||||||
|
#else /* XXX */
|
||||||
|
#error "there's no appropriate type for u_int8_t"
|
||||||
|
#endif
|
||||||
|
#define HAVE_U_INT8_T 1
|
||||||
|
#define HAVE_INT8_T 1
|
||||||
|
|
||||||
|
#endif /* HAVE_U_INT8_T */
|
||||||
|
|
||||||
|
#ifndef HAVE_U_INT16_T
|
||||||
|
|
||||||
|
#if SIZEOF_SHORT == 2
|
||||||
|
typedef unsigned short u_int16_t;
|
||||||
|
typedef signed short int16_t;
|
||||||
|
#elif SIZEOF_INT == 2
|
||||||
|
typedef unsigned int u_int16_t;
|
||||||
|
typedef signed int int16_t;
|
||||||
|
#elif SIZEOF_CHAR == 2
|
||||||
|
typedef unsigned char u_int16_t;
|
||||||
|
typedef signed char int16_t;
|
||||||
|
#else /* XXX */
|
||||||
|
#error "there's no appropriate type for u_int16_t"
|
||||||
|
#endif
|
||||||
|
#define HAVE_U_INT16_T 1
|
||||||
|
#define HAVE_INT16_T 1
|
||||||
|
|
||||||
|
#endif /* HAVE_U_INT16_T */
|
||||||
|
|
||||||
|
#ifndef HAVE_U_INT32_T
|
||||||
|
|
||||||
|
#if SIZEOF_INT == 4
|
||||||
|
typedef unsigned int u_int32_t;
|
||||||
|
typedef signed int int32_t;
|
||||||
|
#elif SIZEOF_LONG == 4
|
||||||
|
typedef unsigned long u_int32_t;
|
||||||
|
typedef signed long int32_t;
|
||||||
|
#elif SIZEOF_SHORT == 4
|
||||||
|
typedef unsigned short u_int32_t;
|
||||||
|
typedef signed short int32_t;
|
||||||
|
#else /* XXX */
|
||||||
|
#error "there's no appropriate type for u_int32_t"
|
||||||
|
#endif
|
||||||
|
#define HAVE_U_INT32_T 1
|
||||||
|
#define HAVE_INT32_T 1
|
||||||
|
|
||||||
|
#endif /* HAVE_U_INT32_T */
|
||||||
|
|
||||||
|
#ifndef HAVE_U_INT64_T
|
||||||
|
#if SIZEOF_LONG_LONG == 8
|
||||||
|
typedef unsigned long long u_int64_t;
|
||||||
|
typedef long long int64_t;
|
||||||
|
#elif defined(_MSC_EXTENSIONS)
|
||||||
|
typedef unsigned _int64 u_int64_t;
|
||||||
|
typedef _int64 int64_t;
|
||||||
|
#elif SIZEOF_INT == 8
|
||||||
|
typedef unsigned int u_int64_t;
|
||||||
|
#elif SIZEOF_LONG == 8
|
||||||
|
typedef unsigned long u_int64_t;
|
||||||
|
#elif SIZEOF_SHORT == 8
|
||||||
|
typedef unsigned short u_int64_t;
|
||||||
|
#else /* XXX */
|
||||||
|
#error "there's no appropriate type for u_int64_t"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_U_INT64_T */
|
||||||
|
|
||||||
|
#ifndef PRId64
|
||||||
|
#ifdef _MSC_EXTENSIONS
|
||||||
|
#define PRId64 "I64d"
|
||||||
|
#else /* _MSC_EXTENSIONS */
|
||||||
|
#define PRId64 "lld"
|
||||||
|
#endif /* _MSC_EXTENSIONS */
|
||||||
|
#endif /* PRId64 */
|
||||||
|
|
||||||
|
#ifndef PRIo64
|
||||||
|
#ifdef _MSC_EXTENSIONS
|
||||||
|
#define PRIo64 "I64o"
|
||||||
|
#else /* _MSC_EXTENSIONS */
|
||||||
|
#define PRIo64 "llo"
|
||||||
|
#endif /* _MSC_EXTENSIONS */
|
||||||
|
#endif /* PRIo64 */
|
||||||
|
|
||||||
|
#ifndef PRIx64
|
||||||
|
#ifdef _MSC_EXTENSIONS
|
||||||
|
#define PRIx64 "I64x"
|
||||||
|
#else /* _MSC_EXTENSIONS */
|
||||||
|
#define PRIx64 "llx"
|
||||||
|
#endif /* _MSC_EXTENSIONS */
|
||||||
|
#endif /* PRIx64 */
|
||||||
|
|
||||||
|
#ifndef PRIu64
|
||||||
|
#ifdef _MSC_EXTENSIONS
|
||||||
|
#define PRIu64 "I64u"
|
||||||
|
#else /* _MSC_EXTENSIONS */
|
||||||
|
#define PRIu64 "llu"
|
||||||
|
#endif /* _MSC_EXTENSIONS */
|
||||||
|
#endif /* PRIu64 */
|
||||||
|
|
||||||
|
#endif /* _BITTYPES_H */
|
|
@ -0,0 +1,163 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1993, 1994, 1997
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the University of California,
|
||||||
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#) $Header: /tcpdump/master/libpcap/Win32/Include/ip6_misc.h,v 1.5 2006-01-22 18:02:18 gianluca Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file contains a collage of declarations for IPv6 from FreeBSD not present in Windows
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
|
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
#define IN_MULTICAST(a) IN_CLASSD(a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define IN_EXPERIMENTAL(a) ((((u_int32_t) (a)) & 0xf0000000) == 0xf0000000)
|
||||||
|
|
||||||
|
#define IN_LOOPBACKNET 127
|
||||||
|
|
||||||
|
#if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)
|
||||||
|
/* IPv6 address */
|
||||||
|
struct in6_addr
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
u_int8_t u6_addr8[16];
|
||||||
|
u_int16_t u6_addr16[8];
|
||||||
|
u_int32_t u6_addr32[4];
|
||||||
|
} in6_u;
|
||||||
|
#define s6_addr in6_u.u6_addr8
|
||||||
|
#define s6_addr16 in6_u.u6_addr16
|
||||||
|
#define s6_addr32 in6_u.u6_addr32
|
||||||
|
#define s6_addr64 in6_u.u6_addr64
|
||||||
|
};
|
||||||
|
|
||||||
|
#define IN6ADDR_ANY_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||||
|
#define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
|
||||||
|
|
||||||
|
#if (defined _MSC_VER) || (defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF))
|
||||||
|
typedef unsigned short sa_family_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)
|
||||||
|
|
||||||
|
#define __SOCKADDR_COMMON(sa_prefix) \
|
||||||
|
sa_family_t sa_prefix##family
|
||||||
|
|
||||||
|
/* Ditto, for IPv6. */
|
||||||
|
struct sockaddr_in6
|
||||||
|
{
|
||||||
|
__SOCKADDR_COMMON (sin6_);
|
||||||
|
u_int16_t sin6_port; /* Transport layer port # */
|
||||||
|
u_int32_t sin6_flowinfo; /* IPv6 flow information */
|
||||||
|
struct in6_addr sin6_addr; /* IPv6 address */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define IN6_IS_ADDR_V4MAPPED(a) \
|
||||||
|
((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
|
||||||
|
(((u_int32_t *) (a))[2] == htonl (0xffff)))
|
||||||
|
|
||||||
|
#define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff)
|
||||||
|
|
||||||
|
#define IN6_IS_ADDR_LINKLOCAL(a) \
|
||||||
|
((((u_int32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000))
|
||||||
|
|
||||||
|
#define IN6_IS_ADDR_LOOPBACK(a) \
|
||||||
|
(((u_int32_t *) (a))[0] == 0 && ((u_int32_t *) (a))[1] == 0 && \
|
||||||
|
((u_int32_t *) (a))[2] == 0 && ((u_int32_t *) (a))[3] == htonl (1))
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
|
||||||
|
#define ip6_vfc ip6_ctlun.ip6_un2_vfc
|
||||||
|
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
|
||||||
|
#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
|
||||||
|
#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
|
||||||
|
#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
|
||||||
|
#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
|
||||||
|
|
||||||
|
#define nd_rd_type nd_rd_hdr.icmp6_type
|
||||||
|
#define nd_rd_code nd_rd_hdr.icmp6_code
|
||||||
|
#define nd_rd_cksum nd_rd_hdr.icmp6_cksum
|
||||||
|
#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IPV6 extension headers
|
||||||
|
*/
|
||||||
|
#define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */
|
||||||
|
#define IPPROTO_IPV6 41 /* IPv6 header. */
|
||||||
|
#define IPPROTO_ROUTING 43 /* IPv6 routing header */
|
||||||
|
#define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */
|
||||||
|
#define IPPROTO_ESP 50 /* encapsulating security payload */
|
||||||
|
#define IPPROTO_AH 51 /* authentication header */
|
||||||
|
#define IPPROTO_ICMPV6 58 /* ICMPv6 */
|
||||||
|
#define IPPROTO_NONE 59 /* IPv6 no next header */
|
||||||
|
#define IPPROTO_DSTOPTS 60 /* IPv6 destination options */
|
||||||
|
#define IPPROTO_PIM 103 /* Protocol Independent Multicast. */
|
||||||
|
|
||||||
|
#define IPV6_RTHDR_TYPE_0 0
|
||||||
|
|
||||||
|
/* Option types and related macros */
|
||||||
|
#define IP6OPT_PAD1 0x00 /* 00 0 00000 */
|
||||||
|
#define IP6OPT_PADN 0x01 /* 00 0 00001 */
|
||||||
|
#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
|
||||||
|
#define IP6OPT_JUMBO_LEN 6
|
||||||
|
#define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */
|
||||||
|
|
||||||
|
#define IP6OPT_RTALERT_LEN 4
|
||||||
|
#define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
|
||||||
|
#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
|
||||||
|
#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
|
||||||
|
#define IP6OPT_MINLEN 2
|
||||||
|
|
||||||
|
#define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */
|
||||||
|
#define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */
|
||||||
|
#define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */
|
||||||
|
#define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */
|
||||||
|
#define IP6OPT_EID 0x8a /* 10 0 01010 */
|
||||||
|
|
||||||
|
#define IP6OPT_TYPE(o) ((o) & 0xC0)
|
||||||
|
#define IP6OPT_TYPE_SKIP 0x00
|
||||||
|
#define IP6OPT_TYPE_DISCARD 0x40
|
||||||
|
#define IP6OPT_TYPE_FORCEICMP 0x80
|
||||||
|
#define IP6OPT_TYPE_ICMP 0xC0
|
||||||
|
|
||||||
|
#define IP6OPT_MUTABLE 0x20
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)
|
||||||
|
#ifndef EAI_ADDRFAMILY
|
||||||
|
struct addrinfo {
|
||||||
|
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
|
||||||
|
int ai_family; /* PF_xxx */
|
||||||
|
int ai_socktype; /* SOCK_xxx */
|
||||||
|
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
|
||||||
|
size_t ai_addrlen; /* length of ai_addr */
|
||||||
|
char *ai_canonname; /* canonical name for hostname */
|
||||||
|
struct sockaddr *ai_addr; /* binary address */
|
||||||
|
struct addrinfo *ai_next; /* next structure in linked list */
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
#endif /* __MINGW32__ */
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from the Stanford/CMU enet packet filter,
|
||||||
|
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
|
||||||
|
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
|
||||||
|
* Berkeley Laboratory.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.50 2007/04/01 21:43:55 guy Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For backwards compatibility.
|
||||||
|
*
|
||||||
|
* Note to OS vendors: do NOT get rid of this file! Some applications
|
||||||
|
* might expect to be able to include <pcap-bpf.h>.
|
||||||
|
*/
|
||||||
|
#include <pcap/bpf.h>
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1994, 1996
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the Computer Systems
|
||||||
|
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||||
|
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||||
|
* to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.13 2006/10/04 18:13:32 guy Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For backwards compatibility.
|
||||||
|
*
|
||||||
|
* Note to OS vendors: do NOT get rid of this file! Some applications
|
||||||
|
* might expect to be able to include <pcap-namedb.h>.
|
||||||
|
*/
|
||||||
|
#include <pcap/namedb.h>
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||||
|
* Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Politecnico di Torino nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#) $Header: /tcpdump/master/libpcap/pcap-stdinc.h,v 1.10.2.1 2008-10-06 15:38:39 gianluca Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SIZEOF_CHAR 1
|
||||||
|
#define SIZEOF_SHORT 2
|
||||||
|
#define SIZEOF_INT 4
|
||||||
|
#ifndef _MSC_EXTENSIONS
|
||||||
|
#define SIZEOF_LONG_LONG 8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Avoids a compiler warning in case this was already defined
|
||||||
|
* (someone defined _WINSOCKAPI_ when including 'windows.h', in order
|
||||||
|
* to prevent it from including 'winsock.h')
|
||||||
|
*/
|
||||||
|
#ifdef _WINSOCKAPI_
|
||||||
|
#undef _WINSOCKAPI_
|
||||||
|
#endif
|
||||||
|
#include <winsock2.h>
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "bittypes.h"
|
||||||
|
#include <time.h>
|
||||||
|
#include <io.h>
|
||||||
|
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
#include "IP6_misc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define caddr_t char*
|
||||||
|
|
||||||
|
#if _MSC_VER < 1500
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#define vsnprintf _vsnprintf
|
||||||
|
#define strdup _strdup
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define inline __inline
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#include <stdint.h>
|
||||||
|
#else /*__MINGW32__*/
|
||||||
|
/* MSVC compiler */
|
||||||
|
#ifndef _UINTPTR_T_DEFINED
|
||||||
|
#ifdef _WIN64
|
||||||
|
typedef unsigned __int64 uintptr_t;
|
||||||
|
#else
|
||||||
|
typedef _W64 unsigned int uintptr_t;
|
||||||
|
#endif
|
||||||
|
#define _UINTPTR_T_DEFINED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _INTPTR_T_DEFINED
|
||||||
|
#ifdef _WIN64
|
||||||
|
typedef __int64 intptr_t;
|
||||||
|
#else
|
||||||
|
typedef _W64 int intptr_t;
|
||||||
|
#endif
|
||||||
|
#define _INTPTR_T_DEFINED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*__MINGW32__*/
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1993, 1994, 1995, 1996, 1997
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the Computer Systems
|
||||||
|
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||||
|
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||||
|
* to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.59 2006/10/04 18:09:22 guy Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For backwards compatibility.
|
||||||
|
*
|
||||||
|
* Note to OS vendors: do NOT get rid of this file! Many applications
|
||||||
|
* expect to be able to include <pcap.h>, and at least some of them
|
||||||
|
* go through contortions in their configure scripts to try to detect
|
||||||
|
* OSes that have "helpfully" moved pcap.h to <pcap/pcap.h> without
|
||||||
|
* leaving behind a <pcap.h> file.
|
||||||
|
*/
|
||||||
|
#include <pcap/pcap.h>
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006 Paolo Abeni (Italy)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* bluetooth data struct
|
||||||
|
* By Paolo Abeni <paolo.abeni@email.it>
|
||||||
|
*
|
||||||
|
* @(#) $Header: /tcpdump/master/libpcap/pcap/bluetooth.h,v 1.1 2007/09/22 02:10:17 guy Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PCAP_BLUETOOTH_STRUCTS_H__
|
||||||
|
#define _PCAP_BLUETOOTH_STRUCTS_H__
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Header prepended libpcap to each bluetooth h:4 frame.
|
||||||
|
* fields are in network byte order
|
||||||
|
*/
|
||||||
|
typedef struct _pcap_bluetooth_h4_header {
|
||||||
|
u_int32_t direction; /* if first bit is set direction is incoming */
|
||||||
|
} pcap_bluetooth_h4_header;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,934 @@
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from the Stanford/CMU enet packet filter,
|
||||||
|
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
|
||||||
|
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
|
||||||
|
* Berkeley Laboratory.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
|
||||||
|
*
|
||||||
|
* @(#) $Header: /tcpdump/master/libpcap/pcap/bpf.h,v 1.19.2.8 2008-09-22 20:16:01 guy Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is libpcap's cut-down version of bpf.h; it includes only
|
||||||
|
* the stuff needed for the code generator and the userland BPF
|
||||||
|
* interpreter, and the libpcap APIs for setting filters, etc..
|
||||||
|
*
|
||||||
|
* "pcap-bpf.c" will include the native OS version, as it deals with
|
||||||
|
* the OS's BPF implementation.
|
||||||
|
*
|
||||||
|
* XXX - should this all just be moved to "pcap.h"?
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BPF_MAJOR_VERSION
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* BSD style release date */
|
||||||
|
#define BPF_RELEASE 199606
|
||||||
|
|
||||||
|
#ifdef MSDOS /* must be 32-bit */
|
||||||
|
typedef long bpf_int32;
|
||||||
|
typedef unsigned long bpf_u_int32;
|
||||||
|
#else
|
||||||
|
typedef int bpf_int32;
|
||||||
|
typedef u_int bpf_u_int32;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Alignment macros. BPF_WORDALIGN rounds up to the next
|
||||||
|
* even multiple of BPF_ALIGNMENT.
|
||||||
|
*/
|
||||||
|
#ifndef __NetBSD__
|
||||||
|
#define BPF_ALIGNMENT sizeof(bpf_int32)
|
||||||
|
#else
|
||||||
|
#define BPF_ALIGNMENT sizeof(long)
|
||||||
|
#endif
|
||||||
|
#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
|
||||||
|
|
||||||
|
#define BPF_MAXBUFSIZE 0x8000
|
||||||
|
#define BPF_MINBUFSIZE 32
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure for "pcap_compile()", "pcap_setfilter()", etc..
|
||||||
|
*/
|
||||||
|
struct bpf_program {
|
||||||
|
u_int bf_len;
|
||||||
|
struct bpf_insn *bf_insns;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Struct return by BIOCVERSION. This represents the version number of
|
||||||
|
* the filter language described by the instruction encodings below.
|
||||||
|
* bpf understands a program iff kernel_major == filter_major &&
|
||||||
|
* kernel_minor >= filter_minor, that is, if the value returned by the
|
||||||
|
* running kernel has the same major number and a minor number equal
|
||||||
|
* equal to or less than the filter being downloaded. Otherwise, the
|
||||||
|
* results are undefined, meaning an error may be returned or packets
|
||||||
|
* may be accepted haphazardly.
|
||||||
|
* It has nothing to do with the source code version.
|
||||||
|
*/
|
||||||
|
struct bpf_version {
|
||||||
|
u_short bv_major;
|
||||||
|
u_short bv_minor;
|
||||||
|
};
|
||||||
|
/* Current version number of filter architecture. */
|
||||||
|
#define BPF_MAJOR_VERSION 1
|
||||||
|
#define BPF_MINOR_VERSION 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Data-link level type codes.
|
||||||
|
*
|
||||||
|
* Do *NOT* add new values to this list without asking
|
||||||
|
* "tcpdump-workers@lists.tcpdump.org" for a value. Otherwise, you run
|
||||||
|
* the risk of using a value that's already being used for some other
|
||||||
|
* purpose, and of having tools that read libpcap-format captures not
|
||||||
|
* being able to handle captures with your new DLT_ value, with no hope
|
||||||
|
* that they will ever be changed to do so (as that would destroy their
|
||||||
|
* ability to read captures using that value for that other purpose).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These are the types that are the same on all platforms, and that
|
||||||
|
* have been defined by <net/bpf.h> for ages.
|
||||||
|
*/
|
||||||
|
#define DLT_NULL 0 /* BSD loopback encapsulation */
|
||||||
|
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
|
||||||
|
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
|
||||||
|
#define DLT_AX25 3 /* Amateur Radio AX.25 */
|
||||||
|
#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
|
||||||
|
#define DLT_CHAOS 5 /* Chaos */
|
||||||
|
#define DLT_IEEE802 6 /* 802.5 Token Ring */
|
||||||
|
#define DLT_ARCNET 7 /* ARCNET, with BSD-style header */
|
||||||
|
#define DLT_SLIP 8 /* Serial Line IP */
|
||||||
|
#define DLT_PPP 9 /* Point-to-point Protocol */
|
||||||
|
#define DLT_FDDI 10 /* FDDI */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These are types that are different on some platforms, and that
|
||||||
|
* have been defined by <net/bpf.h> for ages. We use #ifdefs to
|
||||||
|
* detect the BSDs that define them differently from the traditional
|
||||||
|
* libpcap <net/bpf.h>
|
||||||
|
*
|
||||||
|
* XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS,
|
||||||
|
* but I don't know what the right #define is for BSD/OS.
|
||||||
|
*/
|
||||||
|
#define DLT_ATM_RFC1483 11 /* LLC-encapsulated ATM */
|
||||||
|
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
#define DLT_RAW 14 /* raw IP */
|
||||||
|
#else
|
||||||
|
#define DLT_RAW 12 /* raw IP */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Given that the only OS that currently generates BSD/OS SLIP or PPP
|
||||||
|
* is, well, BSD/OS, arguably everybody should have chosen its values
|
||||||
|
* for DLT_SLIP_BSDOS and DLT_PPP_BSDOS, which are 15 and 16, but they
|
||||||
|
* didn't. So it goes.
|
||||||
|
*/
|
||||||
|
#if defined(__NetBSD__) || defined(__FreeBSD__)
|
||||||
|
#ifndef DLT_SLIP_BSDOS
|
||||||
|
#define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */
|
||||||
|
#define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
|
||||||
|
#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 17 is used for DLT_OLD_PFLOG in OpenBSD;
|
||||||
|
* OBSOLETE: DLT_PFLOG is 117 in OpenBSD now as well. See below.
|
||||||
|
* 18 is used for DLT_PFSYNC in OpenBSD; don't use it for anything else.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Apparently Redback uses this for its SmartEdge 400/800. I hope
|
||||||
|
* nobody else decided to use it, too.
|
||||||
|
*/
|
||||||
|
#define DLT_REDBACK_SMARTEDGE 32
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These values are defined by NetBSD; other platforms should refrain from
|
||||||
|
* using them for other purposes, so that NetBSD savefiles with link
|
||||||
|
* types of 50 or 51 can be read as this type on all platforms.
|
||||||
|
*/
|
||||||
|
#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
|
||||||
|
#define DLT_PPP_ETHER 51 /* PPP over Ethernet */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The Axent Raptor firewall - now the Symantec Enterprise Firewall - uses
|
||||||
|
* a link-layer type of 99 for the tcpdump it supplies. The link-layer
|
||||||
|
* header has 6 bytes of unknown data, something that appears to be an
|
||||||
|
* Ethernet type, and 36 bytes that appear to be 0 in at least one capture
|
||||||
|
* I've seen.
|
||||||
|
*/
|
||||||
|
#define DLT_SYMANTEC_FIREWALL 99
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Values between 100 and 103 are used in capture file headers as
|
||||||
|
* link-layer types corresponding to DLT_ types that differ
|
||||||
|
* between platforms; don't use those values for new DLT_ new types.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This value was defined by libpcap 0.5; platforms that have defined
|
||||||
|
* it with a different value should define it here with that value -
|
||||||
|
* a link type of 104 in a save file will be mapped to DLT_C_HDLC,
|
||||||
|
* whatever value that happens to be, so programs will correctly
|
||||||
|
* handle files with that link type regardless of the value of
|
||||||
|
* DLT_C_HDLC.
|
||||||
|
*
|
||||||
|
* The name DLT_C_HDLC was used by BSD/OS; we use that name for source
|
||||||
|
* compatibility with programs written for BSD/OS.
|
||||||
|
*
|
||||||
|
* libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
|
||||||
|
* for source compatibility with programs written for libpcap 0.5.
|
||||||
|
*/
|
||||||
|
#define DLT_C_HDLC 104 /* Cisco HDLC */
|
||||||
|
#define DLT_CHDLC DLT_C_HDLC
|
||||||
|
|
||||||
|
#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 106 is reserved for Linux Classical IP over ATM; it's like DLT_RAW,
|
||||||
|
* except when it isn't. (I.e., sometimes it's just raw IP, and
|
||||||
|
* sometimes it isn't.) We currently handle it as DLT_LINUX_SLL,
|
||||||
|
* so that we don't have to worry about the link-layer header.)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides
|
||||||
|
* with other values.
|
||||||
|
* DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header
|
||||||
|
* (DLCI, etc.).
|
||||||
|
*/
|
||||||
|
#define DLT_FRELAY 107
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
|
||||||
|
* that the AF_ type in the link-layer header is in network byte order.
|
||||||
|
*
|
||||||
|
* DLT_LOOP is 12 in OpenBSD, but that's DLT_RAW in other OSes, so
|
||||||
|
* we don't use 12 for it in OSes other than OpenBSD.
|
||||||
|
*/
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
#define DLT_LOOP 12
|
||||||
|
#else
|
||||||
|
#define DLT_LOOP 108
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's
|
||||||
|
* DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other
|
||||||
|
* than OpenBSD.
|
||||||
|
*/
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
#define DLT_ENC 13
|
||||||
|
#else
|
||||||
|
#define DLT_ENC 109
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Values between 110 and 112 are reserved for use in capture file headers
|
||||||
|
* as link-layer types corresponding to DLT_ types that might differ
|
||||||
|
* between platforms; don't use those values for new DLT_ types
|
||||||
|
* other than the corresponding DLT_ types.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is for Linux cooked sockets.
|
||||||
|
*/
|
||||||
|
#define DLT_LINUX_SLL 113
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Apple LocalTalk hardware.
|
||||||
|
*/
|
||||||
|
#define DLT_LTALK 114
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Acorn Econet.
|
||||||
|
*/
|
||||||
|
#define DLT_ECONET 115
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reserved for use with OpenBSD ipfilter.
|
||||||
|
*/
|
||||||
|
#define DLT_IPFILTER 116
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD, but that's DLT_LANE8023
|
||||||
|
* in SuSE 6.3, so we can't use 17 for it in capture-file headers.
|
||||||
|
*
|
||||||
|
* XXX: is there a conflict with DLT_PFSYNC 18 as well?
|
||||||
|
*/
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
#define DLT_OLD_PFLOG 17
|
||||||
|
#define DLT_PFSYNC 18
|
||||||
|
#endif
|
||||||
|
#define DLT_PFLOG 117
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Registered for Cisco-internal use.
|
||||||
|
*/
|
||||||
|
#define DLT_CISCO_IOS 118
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For 802.11 cards using the Prism II chips, with a link-layer
|
||||||
|
* header including Prism monitor mode information plus an 802.11
|
||||||
|
* header.
|
||||||
|
*/
|
||||||
|
#define DLT_PRISM_HEADER 119
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reserved for Aironet 802.11 cards, with an Aironet link-layer header
|
||||||
|
* (see Doug Ambrisko's FreeBSD patches).
|
||||||
|
*/
|
||||||
|
#define DLT_AIRONET_HEADER 120
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reserved for Siemens HiPath HDLC.
|
||||||
|
*/
|
||||||
|
#define DLT_HHDLC 121
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is for RFC 2625 IP-over-Fibre Channel.
|
||||||
|
*
|
||||||
|
* This is not for use with raw Fibre Channel, where the link-layer
|
||||||
|
* header starts with a Fibre Channel frame header; it's for IP-over-FC,
|
||||||
|
* where the link-layer header starts with an RFC 2625 Network_Header
|
||||||
|
* field.
|
||||||
|
*/
|
||||||
|
#define DLT_IP_OVER_FC 122
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is for Full Frontal ATM on Solaris with SunATM, with a
|
||||||
|
* pseudo-header followed by an AALn PDU.
|
||||||
|
*
|
||||||
|
* There may be other forms of Full Frontal ATM on other OSes,
|
||||||
|
* with different pseudo-headers.
|
||||||
|
*
|
||||||
|
* If ATM software returns a pseudo-header with VPI/VCI information
|
||||||
|
* (and, ideally, packet type information, e.g. signalling, ILMI,
|
||||||
|
* LANE, LLC-multiplexed traffic, etc.), it should not use
|
||||||
|
* DLT_ATM_RFC1483, but should get a new DLT_ value, so tcpdump
|
||||||
|
* and the like don't have to infer the presence or absence of a
|
||||||
|
* pseudo-header and the form of the pseudo-header.
|
||||||
|
*/
|
||||||
|
#define DLT_SUNATM 123 /* Solaris+SunATM */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reserved as per request from Kent Dahlgren <kent@praesum.com>
|
||||||
|
* for private use.
|
||||||
|
*/
|
||||||
|
#define DLT_RIO 124 /* RapidIO */
|
||||||
|
#define DLT_PCI_EXP 125 /* PCI Express */
|
||||||
|
#define DLT_AURORA 126 /* Xilinx Aurora link layer */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Header for 802.11 plus a number of bits of link-layer information
|
||||||
|
* including radio information, used by some recent BSD drivers as
|
||||||
|
* well as the madwifi Atheros driver for Linux.
|
||||||
|
*/
|
||||||
|
#define DLT_IEEE802_11_RADIO 127 /* 802.11 plus radiotap radio header */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reserved for the TZSP encapsulation, as per request from
|
||||||
|
* Chris Waters <chris.waters@networkchemistry.com>
|
||||||
|
* TZSP is a generic encapsulation for any other link type,
|
||||||
|
* which includes a means to include meta-information
|
||||||
|
* with the packet, e.g. signal strength and channel
|
||||||
|
* for 802.11 packets.
|
||||||
|
*/
|
||||||
|
#define DLT_TZSP 128 /* Tazmen Sniffer Protocol */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BSD's ARCNET headers have the source host, destination host,
|
||||||
|
* and type at the beginning of the packet; that's what's handed
|
||||||
|
* up to userland via BPF.
|
||||||
|
*
|
||||||
|
* Linux's ARCNET headers, however, have a 2-byte offset field
|
||||||
|
* between the host IDs and the type; that's what's handed up
|
||||||
|
* to userland via PF_PACKET sockets.
|
||||||
|
*
|
||||||
|
* We therefore have to have separate DLT_ values for them.
|
||||||
|
*/
|
||||||
|
#define DLT_ARCNET_LINUX 129 /* ARCNET */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Juniper-private data link types, as per request from
|
||||||
|
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
|
||||||
|
* for passing on chassis-internal metainformation such as
|
||||||
|
* QOS profiles, etc..
|
||||||
|
*/
|
||||||
|
#define DLT_JUNIPER_MLPPP 130
|
||||||
|
#define DLT_JUNIPER_MLFR 131
|
||||||
|
#define DLT_JUNIPER_ES 132
|
||||||
|
#define DLT_JUNIPER_GGSN 133
|
||||||
|
#define DLT_JUNIPER_MFR 134
|
||||||
|
#define DLT_JUNIPER_ATM2 135
|
||||||
|
#define DLT_JUNIPER_SERVICES 136
|
||||||
|
#define DLT_JUNIPER_ATM1 137
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Apple IP-over-IEEE 1394, as per a request from Dieter Siegmund
|
||||||
|
* <dieter@apple.com>. The header that's presented is an Ethernet-like
|
||||||
|
* header:
|
||||||
|
*
|
||||||
|
* #define FIREWIRE_EUI64_LEN 8
|
||||||
|
* struct firewire_header {
|
||||||
|
* u_char firewire_dhost[FIREWIRE_EUI64_LEN];
|
||||||
|
* u_char firewire_shost[FIREWIRE_EUI64_LEN];
|
||||||
|
* u_short firewire_type;
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* with "firewire_type" being an Ethernet type value, rather than,
|
||||||
|
* for example, raw GASP frames being handed up.
|
||||||
|
*/
|
||||||
|
#define DLT_APPLE_IP_OVER_IEEE1394 138
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Various SS7 encapsulations, as per a request from Jeff Morriss
|
||||||
|
* <jeff.morriss[AT]ulticom.com> and subsequent discussions.
|
||||||
|
*/
|
||||||
|
#define DLT_MTP2_WITH_PHDR 139 /* pseudo-header with various info, followed by MTP2 */
|
||||||
|
#define DLT_MTP2 140 /* MTP2, without pseudo-header */
|
||||||
|
#define DLT_MTP3 141 /* MTP3, without pseudo-header or MTP2 */
|
||||||
|
#define DLT_SCCP 142 /* SCCP, without pseudo-header or MTP2 or MTP3 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DOCSIS MAC frames.
|
||||||
|
*/
|
||||||
|
#define DLT_DOCSIS 143
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Linux-IrDA packets. Protocol defined at http://www.irda.org.
|
||||||
|
* Those packets include IrLAP headers and above (IrLMP...), but
|
||||||
|
* don't include Phy framing (SOF/EOF/CRC & byte stuffing), because Phy
|
||||||
|
* framing can be handled by the hardware and depend on the bitrate.
|
||||||
|
* This is exactly the format you would get capturing on a Linux-IrDA
|
||||||
|
* interface (irdaX), but not on a raw serial port.
|
||||||
|
* Note the capture is done in "Linux-cooked" mode, so each packet include
|
||||||
|
* a fake packet header (struct sll_header). This is because IrDA packet
|
||||||
|
* decoding is dependant on the direction of the packet (incomming or
|
||||||
|
* outgoing).
|
||||||
|
* When/if other platform implement IrDA capture, we may revisit the
|
||||||
|
* issue and define a real DLT_IRDA...
|
||||||
|
* Jean II
|
||||||
|
*/
|
||||||
|
#define DLT_LINUX_IRDA 144
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reserved for IBM SP switch and IBM Next Federation switch.
|
||||||
|
*/
|
||||||
|
#define DLT_IBM_SP 145
|
||||||
|
#define DLT_IBM_SN 146
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reserved for private use. If you have some link-layer header type
|
||||||
|
* that you want to use within your organization, with the capture files
|
||||||
|
* using that link-layer header type not ever be sent outside your
|
||||||
|
* organization, you can use these values.
|
||||||
|
*
|
||||||
|
* No libpcap release will use these for any purpose, nor will any
|
||||||
|
* tcpdump release use them, either.
|
||||||
|
*
|
||||||
|
* Do *NOT* use these in capture files that you expect anybody not using
|
||||||
|
* your private versions of capture-file-reading tools to read; in
|
||||||
|
* particular, do *NOT* use them in products, otherwise you may find that
|
||||||
|
* people won't be able to use tcpdump, or snort, or Ethereal, or... to
|
||||||
|
* read capture files from your firewall/intrusion detection/traffic
|
||||||
|
* monitoring/etc. appliance, or whatever product uses that DLT_ value,
|
||||||
|
* and you may also find that the developers of those applications will
|
||||||
|
* not accept patches to let them read those files.
|
||||||
|
*
|
||||||
|
* Also, do not use them if somebody might send you a capture using them
|
||||||
|
* for *their* private type and tools using them for *your* private type
|
||||||
|
* would have to read them.
|
||||||
|
*
|
||||||
|
* Instead, ask "tcpdump-workers@lists.tcpdump.org" for a new DLT_ value,
|
||||||
|
* as per the comment above, and use the type you're given.
|
||||||
|
*/
|
||||||
|
#define DLT_USER0 147
|
||||||
|
#define DLT_USER1 148
|
||||||
|
#define DLT_USER2 149
|
||||||
|
#define DLT_USER3 150
|
||||||
|
#define DLT_USER4 151
|
||||||
|
#define DLT_USER5 152
|
||||||
|
#define DLT_USER6 153
|
||||||
|
#define DLT_USER7 154
|
||||||
|
#define DLT_USER8 155
|
||||||
|
#define DLT_USER9 156
|
||||||
|
#define DLT_USER10 157
|
||||||
|
#define DLT_USER11 158
|
||||||
|
#define DLT_USER12 159
|
||||||
|
#define DLT_USER13 160
|
||||||
|
#define DLT_USER14 161
|
||||||
|
#define DLT_USER15 162
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For future use with 802.11 captures - defined by AbsoluteValue
|
||||||
|
* Systems to store a number of bits of link-layer information
|
||||||
|
* including radio information:
|
||||||
|
*
|
||||||
|
* http://www.shaftnet.org/~pizza/software/capturefrm.txt
|
||||||
|
*
|
||||||
|
* but it might be used by some non-AVS drivers now or in the
|
||||||
|
* future.
|
||||||
|
*/
|
||||||
|
#define DLT_IEEE802_11_RADIO_AVS 163 /* 802.11 plus AVS radio header */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Juniper-private data link type, as per request from
|
||||||
|
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
|
||||||
|
* for passing on chassis-internal metainformation such as
|
||||||
|
* QOS profiles, etc..
|
||||||
|
*/
|
||||||
|
#define DLT_JUNIPER_MONITOR 164
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reserved for BACnet MS/TP.
|
||||||
|
*/
|
||||||
|
#define DLT_BACNET_MS_TP 165
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Another PPP variant as per request from Karsten Keil <kkeil@suse.de>.
|
||||||
|
*
|
||||||
|
* This is used in some OSes to allow a kernel socket filter to distinguish
|
||||||
|
* between incoming and outgoing packets, on a socket intended to
|
||||||
|
* supply pppd with outgoing packets so it can do dial-on-demand and
|
||||||
|
* hangup-on-lack-of-demand; incoming packets are filtered out so they
|
||||||
|
* don't cause pppd to hold the connection up (you don't want random
|
||||||
|
* input packets such as port scans, packets from old lost connections,
|
||||||
|
* etc. to force the connection to stay up).
|
||||||
|
*
|
||||||
|
* The first byte of the PPP header (0xff03) is modified to accomodate
|
||||||
|
* the direction - 0x00 = IN, 0x01 = OUT.
|
||||||
|
*/
|
||||||
|
#define DLT_PPP_PPPD 166
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Names for backwards compatibility with older versions of some PPP
|
||||||
|
* software; new software should use DLT_PPP_PPPD.
|
||||||
|
*/
|
||||||
|
#define DLT_PPP_WITH_DIRECTION DLT_PPP_PPPD
|
||||||
|
#define DLT_LINUX_PPP_WITHDIRECTION DLT_PPP_PPPD
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Juniper-private data link type, as per request from
|
||||||
|
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
|
||||||
|
* for passing on chassis-internal metainformation such as
|
||||||
|
* QOS profiles, cookies, etc..
|
||||||
|
*/
|
||||||
|
#define DLT_JUNIPER_PPPOE 167
|
||||||
|
#define DLT_JUNIPER_PPPOE_ATM 168
|
||||||
|
|
||||||
|
#define DLT_GPRS_LLC 169 /* GPRS LLC */
|
||||||
|
#define DLT_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */
|
||||||
|
#define DLT_GPF_F 171 /* GPF-F (ITU-T G.7041/Y.1303) */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line
|
||||||
|
* monitoring equipment.
|
||||||
|
*/
|
||||||
|
#define DLT_GCOM_T1E1 172
|
||||||
|
#define DLT_GCOM_SERIAL 173
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Juniper-private data link type, as per request from
|
||||||
|
* Hannes Gredler <hannes@juniper.net>. The DLT_ is used
|
||||||
|
* for internal communication to Physical Interface Cards (PIC)
|
||||||
|
*/
|
||||||
|
#define DLT_JUNIPER_PIC_PEER 174
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Link types requested by Gregor Maier <gregor@endace.com> of Endace
|
||||||
|
* Measurement Systems. They add an ERF header (see
|
||||||
|
* http://www.endace.com/support/EndaceRecordFormat.pdf) in front of
|
||||||
|
* the link-layer header.
|
||||||
|
*/
|
||||||
|
#define DLT_ERF_ETH 175 /* Ethernet */
|
||||||
|
#define DLT_ERF_POS 176 /* Packet-over-SONET */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD
|
||||||
|
* for vISDN (http://www.orlandi.com/visdn/). Its link-layer header
|
||||||
|
* includes additional information before the LAPD header, so it's
|
||||||
|
* not necessarily a generic LAPD header.
|
||||||
|
*/
|
||||||
|
#define DLT_LINUX_LAPD 177
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Juniper-private data link type, as per request from
|
||||||
|
* Hannes Gredler <hannes@juniper.net>.
|
||||||
|
* The DLT_ are used for prepending meta-information
|
||||||
|
* like interface index, interface name
|
||||||
|
* before standard Ethernet, PPP, Frelay & C-HDLC Frames
|
||||||
|
*/
|
||||||
|
#define DLT_JUNIPER_ETHER 178
|
||||||
|
#define DLT_JUNIPER_PPP 179
|
||||||
|
#define DLT_JUNIPER_FRELAY 180
|
||||||
|
#define DLT_JUNIPER_CHDLC 181
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Multi Link Frame Relay (FRF.16)
|
||||||
|
*/
|
||||||
|
#define DLT_MFR 182
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Juniper-private data link type, as per request from
|
||||||
|
* Hannes Gredler <hannes@juniper.net>.
|
||||||
|
* The DLT_ is used for internal communication with a
|
||||||
|
* voice Adapter Card (PIC)
|
||||||
|
*/
|
||||||
|
#define DLT_JUNIPER_VP 183
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arinc 429 frames.
|
||||||
|
* DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
|
||||||
|
* Every frame contains a 32bit A429 label.
|
||||||
|
* More documentation on Arinc 429 can be found at
|
||||||
|
* http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf
|
||||||
|
*/
|
||||||
|
#define DLT_A429 184
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arinc 653 Interpartition Communication messages.
|
||||||
|
* DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
|
||||||
|
* Please refer to the A653-1 standard for more information.
|
||||||
|
*/
|
||||||
|
#define DLT_A653_ICM 185
|
||||||
|
|
||||||
|
/*
|
||||||
|
* USB packets, beginning with a USB setup header; requested by
|
||||||
|
* Paolo Abeni <paolo.abeni@email.it>.
|
||||||
|
*/
|
||||||
|
#define DLT_USB 186
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bluetooth HCI UART transport layer (part H:4); requested by
|
||||||
|
* Paolo Abeni.
|
||||||
|
*/
|
||||||
|
#define DLT_BLUETOOTH_HCI_H4 187
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz
|
||||||
|
* <cruz_petagay@bah.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_IEEE802_16_MAC_CPS 188
|
||||||
|
|
||||||
|
/*
|
||||||
|
* USB packets, beginning with a Linux USB header; requested by
|
||||||
|
* Paolo Abeni <paolo.abeni@email.it>.
|
||||||
|
*/
|
||||||
|
#define DLT_USB_LINUX 189
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Controller Area Network (CAN) v. 2.0B packets.
|
||||||
|
* DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
|
||||||
|
* Used to dump CAN packets coming from a CAN Vector board.
|
||||||
|
* More documentation on the CAN v2.0B frames can be found at
|
||||||
|
* http://www.can-cia.org/downloads/?269
|
||||||
|
*/
|
||||||
|
#define DLT_CAN20B 190
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IEEE 802.15.4, with address fields padded, as is done by Linux
|
||||||
|
* drivers; requested by Juergen Schimmer.
|
||||||
|
*/
|
||||||
|
#define DLT_IEEE802_15_4_LINUX 191
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Per Packet Information encapsulated packets.
|
||||||
|
* DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_PPI 192
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header;
|
||||||
|
* requested by Charles Clancy.
|
||||||
|
*/
|
||||||
|
#define DLT_IEEE802_16_MAC_CPS_RADIO 193
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Juniper-private data link type, as per request from
|
||||||
|
* Hannes Gredler <hannes@juniper.net>.
|
||||||
|
* The DLT_ is used for internal communication with a
|
||||||
|
* integrated service module (ISM).
|
||||||
|
*/
|
||||||
|
#define DLT_JUNIPER_ISM 194
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IEEE 802.15.4, exactly as it appears in the spec (no padding, no
|
||||||
|
* nothing); requested by Mikko Saarnivala <mikko.saarnivala@sensinode.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_IEEE802_15_4 195
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Various link-layer types, with a pseudo-header, for SITA
|
||||||
|
* (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com).
|
||||||
|
*/
|
||||||
|
#define DLT_SITA 196
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Various link-layer types, with a pseudo-header, for Endace DAG cards;
|
||||||
|
* encapsulates Endace ERF records. Requested by Stephen Donnelly
|
||||||
|
* <stephen@endace.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_ERF 197
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Special header prepended to Ethernet packets when capturing from a
|
||||||
|
* u10 Networks board. Requested by Phil Mulholland
|
||||||
|
* <phil@u10networks.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_RAIF1 198
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IPMB packet for IPMI, beginning with the I2C slave address, followed
|
||||||
|
* by the netFn and LUN, etc.. Requested by Chanthy Toeung
|
||||||
|
* <chanthy.toeung@ca.kontron.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_IPMB 199
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Juniper-private data link type, as per request from
|
||||||
|
* Hannes Gredler <hannes@juniper.net>.
|
||||||
|
* The DLT_ is used for capturing data on a secure tunnel interface.
|
||||||
|
*/
|
||||||
|
#define DLT_JUNIPER_ST 200
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bluetooth HCI UART transport layer (part H:4), with pseudo-header
|
||||||
|
* that includes direction information; requested by Paolo Abeni.
|
||||||
|
*/
|
||||||
|
#define DLT_BLUETOOTH_HCI_H4_WITH_PHDR 201
|
||||||
|
|
||||||
|
/*
|
||||||
|
* AX.25 packet with a 1-byte KISS header; see
|
||||||
|
*
|
||||||
|
* http://www.ax25.net/kiss.htm
|
||||||
|
*
|
||||||
|
* as per Richard Stearn <richard@rns-stearn.demon.co.uk>.
|
||||||
|
*/
|
||||||
|
#define DLT_AX25_KISS 202
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LAPD packets from an ISDN channel, starting with the address field,
|
||||||
|
* with no pseudo-header.
|
||||||
|
* Requested by Varuna De Silva <varunax@gmail.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_LAPD 203
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Variants of various link-layer headers, with a one-byte direction
|
||||||
|
* pseudo-header prepended - zero means "received by this host",
|
||||||
|
* non-zero (any non-zero value) means "sent by this host" - as per
|
||||||
|
* Will Barker <w.barker@zen.co.uk>.
|
||||||
|
*/
|
||||||
|
#define DLT_PPP_WITH_DIR 204 /* PPP - don't confuse with DLT_PPP_WITH_DIRECTION */
|
||||||
|
#define DLT_C_HDLC_WITH_DIR 205 /* Cisco HDLC */
|
||||||
|
#define DLT_FRELAY_WITH_DIR 206 /* Frame Relay */
|
||||||
|
#define DLT_LAPB_WITH_DIR 207 /* LAPB */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 208 is reserved for an as-yet-unspecified proprietary link-layer
|
||||||
|
* type, as requested by Will Barker.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman
|
||||||
|
* <avn@pigeonpoint.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_IPMB_LINUX 209
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FlexRay automotive bus - http://www.flexray.com/ - as requested
|
||||||
|
* by Hannes Kaelber <hannes.kaelber@x2e.de>.
|
||||||
|
*/
|
||||||
|
#define DLT_FLEXRAY 210
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Media Oriented Systems Transport (MOST) bus for multimedia
|
||||||
|
* transport - http://www.mostcooperation.com/ - as requested
|
||||||
|
* by Hannes Kaelber <hannes.kaelber@x2e.de>.
|
||||||
|
*/
|
||||||
|
#define DLT_MOST 211
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local Interconnect Network (LIN) bus for vehicle networks -
|
||||||
|
* http://www.lin-subbus.org/ - as requested by Hannes Kaelber
|
||||||
|
* <hannes.kaelber@x2e.de>.
|
||||||
|
*/
|
||||||
|
#define DLT_LIN 212
|
||||||
|
|
||||||
|
/*
|
||||||
|
* X2E-private data link type used for serial line capture,
|
||||||
|
* as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
|
||||||
|
*/
|
||||||
|
#define DLT_X2E_SERIAL 213
|
||||||
|
|
||||||
|
/*
|
||||||
|
* X2E-private data link type used for the Xoraya data logger
|
||||||
|
* family, as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
|
||||||
|
*/
|
||||||
|
#define DLT_X2E_XORAYA 214
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IEEE 802.15.4, exactly as it appears in the spec (no padding, no
|
||||||
|
* nothing), but with the PHY-level data for non-ASK PHYs (4 octets
|
||||||
|
* of 0 as preamble, one octet of SFD, one octet of frame length+
|
||||||
|
* reserved bit, and then the MAC-layer data, starting with the
|
||||||
|
* frame control field).
|
||||||
|
*
|
||||||
|
* Requested by Max Filippov <jcmvbkbc@gmail.com>.
|
||||||
|
*/
|
||||||
|
#define DLT_IEEE802_15_4_NONASK_PHY 215
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DLT and savefile link type values are split into a class and
|
||||||
|
* a member of that class. A class value of 0 indicates a regular
|
||||||
|
* DLT_/LINKTYPE_ value.
|
||||||
|
*/
|
||||||
|
#define DLT_CLASS(x) ((x) & 0x03ff0000)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NetBSD-specific generic "raw" link type. The class value indicates
|
||||||
|
* that this is the generic raw type, and the lower 16 bits are the
|
||||||
|
* address family we're dealing with. Those values are NetBSD-specific;
|
||||||
|
* do not assume that they correspond to AF_ values for your operating
|
||||||
|
* system.
|
||||||
|
*/
|
||||||
|
#define DLT_CLASS_NETBSD_RAWAF 0x02240000
|
||||||
|
#define DLT_NETBSD_RAWAF(af) (DLT_CLASS_NETBSD_RAWAF | (af))
|
||||||
|
#define DLT_NETBSD_RAWAF_AF(x) ((x) & 0x0000ffff)
|
||||||
|
#define DLT_IS_NETBSD_RAWAF(x) (DLT_CLASS(x) == DLT_CLASS_NETBSD_RAWAF)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The instruction encodings.
|
||||||
|
*/
|
||||||
|
/* instruction classes */
|
||||||
|
#define BPF_CLASS(code) ((code) & 0x07)
|
||||||
|
#define BPF_LD 0x00
|
||||||
|
#define BPF_LDX 0x01
|
||||||
|
#define BPF_ST 0x02
|
||||||
|
#define BPF_STX 0x03
|
||||||
|
#define BPF_ALU 0x04
|
||||||
|
#define BPF_JMP 0x05
|
||||||
|
#define BPF_RET 0x06
|
||||||
|
#define BPF_MISC 0x07
|
||||||
|
|
||||||
|
/* ld/ldx fields */
|
||||||
|
#define BPF_SIZE(code) ((code) & 0x18)
|
||||||
|
#define BPF_W 0x00
|
||||||
|
#define BPF_H 0x08
|
||||||
|
#define BPF_B 0x10
|
||||||
|
#define BPF_MODE(code) ((code) & 0xe0)
|
||||||
|
#define BPF_IMM 0x00
|
||||||
|
#define BPF_ABS 0x20
|
||||||
|
#define BPF_IND 0x40
|
||||||
|
#define BPF_MEM 0x60
|
||||||
|
#define BPF_LEN 0x80
|
||||||
|
#define BPF_MSH 0xa0
|
||||||
|
|
||||||
|
/* alu/jmp fields */
|
||||||
|
#define BPF_OP(code) ((code) & 0xf0)
|
||||||
|
#define BPF_ADD 0x00
|
||||||
|
#define BPF_SUB 0x10
|
||||||
|
#define BPF_MUL 0x20
|
||||||
|
#define BPF_DIV 0x30
|
||||||
|
#define BPF_OR 0x40
|
||||||
|
#define BPF_AND 0x50
|
||||||
|
#define BPF_LSH 0x60
|
||||||
|
#define BPF_RSH 0x70
|
||||||
|
#define BPF_NEG 0x80
|
||||||
|
#define BPF_JA 0x00
|
||||||
|
#define BPF_JEQ 0x10
|
||||||
|
#define BPF_JGT 0x20
|
||||||
|
#define BPF_JGE 0x30
|
||||||
|
#define BPF_JSET 0x40
|
||||||
|
#define BPF_SRC(code) ((code) & 0x08)
|
||||||
|
#define BPF_K 0x00
|
||||||
|
#define BPF_X 0x08
|
||||||
|
|
||||||
|
/* ret - BPF_K and BPF_X also apply */
|
||||||
|
#define BPF_RVAL(code) ((code) & 0x18)
|
||||||
|
#define BPF_A 0x10
|
||||||
|
|
||||||
|
/* misc */
|
||||||
|
#define BPF_MISCOP(code) ((code) & 0xf8)
|
||||||
|
#define BPF_TAX 0x00
|
||||||
|
#define BPF_TXA 0x80
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The instruction data structure.
|
||||||
|
*/
|
||||||
|
struct bpf_insn {
|
||||||
|
u_short code;
|
||||||
|
u_char jt;
|
||||||
|
u_char jf;
|
||||||
|
bpf_u_int32 k;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macros for insn array initializers.
|
||||||
|
*/
|
||||||
|
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
|
||||||
|
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
|
||||||
|
|
||||||
|
#if __STDC__ || defined(__cplusplus)
|
||||||
|
extern int bpf_validate(const struct bpf_insn *, int);
|
||||||
|
extern u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
|
||||||
|
#else
|
||||||
|
extern int bpf_validate();
|
||||||
|
extern u_int bpf_filter();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
|
||||||
|
*/
|
||||||
|
#define BPF_MEMWORDS 16
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user