Main Page Modules Data Structures File List Data Fields Globals Related Pages

# Packet32.h

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 1999 - 2003
    00003  * NetGroup, Politecnico di Torino (Italy)
    00004  * All rights reserved.
    00005  *
    00006  * Redistribution and use in source and binary forms, with or without
    00007  * modification, are permitted provided that the following conditions
    00008  * are met:
    00009  *
    00010  * 1. Redistributions of source code must retain the above copyright
    00011  * notice, this list of conditions and the following disclaimer.
    00012  * 2. Redistributions in binary form must reproduce the above copyright
    00013  * notice, this list of conditions and the following disclaimer in the
    00014  * documentation and/or other materials provided with the distribution.
    00015  * 3. Neither the name of the Politecnico di Torino nor the names of its
    00016  * contributors may be used to endorse or promote products derived from
    00017  * this software without specific prior written permission.
    00018  *
    00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    00022  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    00023  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00030  *
    00031  */
    00032
    00044 #ifndef __PACKET32
    00045 #define __PACKET32
    00046
    00047 #include <winsock2.h>
    00048 #include "devioctl.h"
    00049
    00050 // Working modes
    00051 #define PACKET_MODE_CAPT 0x0
    00052 #define PACKET_MODE_STAT 0x1
    00053 #define PACKET_MODE_DUMP 0x10
    00054 #define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT
    00055
    00056 // ioctls
    00057 #define FILE_DEVICE_PROTOCOL        0x8000
    00058
    00059 #define IOCTL_PROTOCOL_STATISTICS   CTL_CODE(FILE_DEVICE_PROTOCOL, 2 , METHOD_BUFFERED, FILE_ANY_ACCESS)
    00060 #define IOCTL_PROTOCOL_RESET        CTL_CODE(FILE_DEVICE_PROTOCOL, 3 , METHOD_BUFFERED, FILE_ANY_ACCESS)
    00061 #define IOCTL_PROTOCOL_READ         CTL_CODE(FILE_DEVICE_PROTOCOL, 4 , METHOD_BUFFERED, FILE_ANY_ACCESS)
    00062 #define IOCTL_PROTOCOL_WRITE        CTL_CODE(FILE_DEVICE_PROTOCOL, 5 , METHOD_BUFFERED, FILE_ANY_ACCESS)
    00063 #define IOCTL_PROTOCOL_MACNAME      CTL_CODE(FILE_DEVICE_PROTOCOL, 6 , METHOD_BUFFERED, FILE_ANY_ACCESS)
    00064 #define IOCTL_OPEN                  CTL_CODE(FILE_DEVICE_PROTOCOL, 7 , METHOD_BUFFERED, FILE_ANY_ACCESS)
    00065 #define IOCTL_CLOSE                 CTL_CODE(FILE_DEVICE_PROTOCOL, 8 , METHOD_BUFFERED, FILE_ANY_ACCESS)
    00066
    00067 #define  pBIOCSETBUFFERSIZE 9592
    00068 #define  pBIOCSETF 9030
    00069 #define  pBIOCGSTATS 9031
    00070 #define  pBIOCSRTIMEOUT 7416
    00071 #define  pBIOCSMODE 7412
    00072 #define  pBIOCSWRITEREP 7413
    00073 #define  pBIOCSMINTOCOPY 7414
    00074 #define  pBIOCSETOID 2147483648
    00075 #define  pBIOCQUERYOID 2147483652
    00076 #define  pATTACHPROCESS 7117
    00077 #define  pDETACHPROCESS 7118
    00078 #define  pBIOCSETDUMPFILENAME 9029
    00079 #define  pBIOCEVNAME 7415
    00080 #define  pBIOCSENDPACKETSNOSYNC 9032
    00081 #define  pBIOCSENDPACKETSSYNC 9033
    00082 #define  pBIOCSETDUMPLIMITS 9034
    00083 #define  pBIOCISDUMPENDED 7411
    00084
    00085 #define  pBIOCSTIMEZONE 7471
    00086
    00087
    00089 #define Packet_ALIGNMENT sizeof(int)
    00090
    00091 #define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
    00092
    00098 typedef struct NetType
    00099 {
    00100     UINT LinkType;
    00101     UINT LinkSpeed;
    00102 }NetType;
    00103
    00104
    00105 //some definitions stolen from libpcap
    00106
    00107 #ifndef BPF_MAJOR_VERSION
    00108
    00114 struct bpf_program {
    00115     UINT bf_len;
    00116     struct bpf_insn *bf_insns;
    00117 };
    00118
    00124 struct bpf_insn {
    00125     USHORT  code;
    00126     UCHAR   jt;
    00127     UCHAR   jf;
    00128     int k;
    00129 };
    00130
    00136 struct bpf_stat {
    00137     UINT bs_recv;
    00138
    00139
    00140     UINT bs_drop;
    00141
    00142
    00143     UINT ps_ifdrop;
    00144     UINT bs_capt;
    00145
    00146 };
    00147
    00153 struct bpf_hdr {
    00154     struct timeval  bh_tstamp;
    00155
    00156     UINT    bh_caplen;
    00157
    00158
    00159     UINT    bh_datalen;
    00160     USHORT      bh_hdrlen;
    00161
    00162
    00163
    00164 };
    00165
    00173 struct dump_bpf_hdr{
    00174     struct timeval  ts;
    00175     UINT            caplen;
    00176
    00177
    00178     UINT            len;
    00179 };
    00180
    00181
    00182 #endif
    00183
    00184 #define        DOSNAMEPREFIX   TEXT("Packet_")
    00185 #define        MAX_LINK_NAME_LENGTH 64          //< Maximum length of the devices symbolic links
    00186 #define        NMAX_PACKET 65535
    00187
    00194 typedef struct _ADAPTER  {
    00195     HANDLE hFile;
    00196     CHAR  SymbolicLink[MAX_LINK_NAME_LENGTH];
    00197     int NumWrites;
    00198
    00199     HANDLE ReadEvent;
    00200
    00201
    00202
    00203
    00204
    00205
    00206
    00207     UINT ReadTimeOut;
    00208
    00209 }  ADAPTER, *LPADAPTER;
    00210
    00216 typedef struct _PACKET {
    00217     HANDLE       hEvent;
    00218     OVERLAPPED   OverLapped;
    00219     PVOID        Buffer;
    00220
    00221     UINT         Length;
    00222     DWORD        ulBytesReceived;
    00223
    00224     BOOLEAN      bIoComplete;
    00225 }  PACKET, *LPPACKET;
    00226
    00234 struct _PACKET_OID_DATA {
    00235     ULONG Oid;
    00236
    00237     ULONG Length;
    00238     UCHAR Data[1];
    00239
    00240 };
    00241 typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
    00242
    00249 typedef struct npf_if_addr {
    00250     struct sockaddr IPAddress;
    00251     struct sockaddr SubnetMask;
    00252     struct sockaddr Broadcast;
    00253 }npf_if_addr;
    00254
    00255 #ifdef __cplusplus
    00256 extern "C" {
    00257 #endif
    00258
    00263 //---------------------------------------------------------------------------
    00264 // FUNCTIONS
    00265 //---------------------------------------------------------------------------
    00266
    00267 PCHAR PacketGetVersion();
    00268 BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);
    00269 BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);
    00270 BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);
    00271 BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);
    00272 BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);
    00273 BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);
    00274 BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);
    00275 BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);
    00276 BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);
    00277 LPADAPTER PacketOpenAdapter(LPTSTR AdapterName);
    00278 BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);
    00279 INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);
    00280 LPPACKET PacketAllocatePacket(void);
    00281 VOID PacketInitPacket(LPPACKET lpPacket,PVOID  Buffer,UINT  Length);
    00282 VOID PacketFreePacket(LPPACKET lpPacket);
    00283 BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);
    00284 BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);
    00285 BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG  BufferSize);
    00286 BOOLEAN PacketGetNetInfo(LPTSTR AdapterName, PULONG netp, PULONG maskp);
    00287 BOOLEAN PacketGetNetInfoEx(LPTSTR AdapterName, npf_if_addr* buffer, PLONG NEntries);
    00288 BOOLEAN PacketRequest(LPADAPTER  AdapterObject,BOOLEAN Set,PPACKET_OID_DATA  OidData);
    00289 HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);
    00290 BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);
    00291 BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);
    00292 BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);
    00293 BOOL PacketStopDriver();
    00294 VOID PacketCloseAdapter(LPADAPTER lpAdapter);
    00295
    00296 #ifdef __cplusplus
    00297 }
    00298 #endif
    00299
    00300 #endif //__PACKET32

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.