1. If I have a doubt if I use the same buffer because
    I alter the packets and the rewrite to the opposite
    interface, that�s why I use 4 open adapters.


2. The parameters are the same, memory size are the same
for both interfaces


3. pheader:=@buffer_in;      <<<< here my error

      Is a pointer to a structure

    ! this is my error !!!!!!!!!

   I have to something like this

  pheader:=@buffer_in[offset_in];


because this is the real position of the packet when I capture multiple
packets  in one time.


tv_seg          :=pheader^.tv_sec;
tv_microseg     :=pheader^.tv_microsec;

tlen1_in        :=pheader^.bh_datalen;
tlen_in         :=pheader^.bh_caplen;

offset_in:=offset_in+pheader^.cabecera;

// here offset_in is the begin of the packet to be read

offset_in:=Packet_WORDALING(offset_in+tlen1_in);


// now offset_in : is the position of the next header of the packet


4. The program works fine when the traffic is no burstly, when the traffic
is not burstly
it worls fine because I only read one packets per time

the packets in the application are rebuilt fine, I calculate tcp and ip
checksum after modifiy
the packets. The problem is the point 3.

Thanks a lot. You found the problem.



----- Original Message -----
From: "Jesper Munkholm Jensen (JMJ)" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 30, 2002 10:19 AM
Subject: RE: [WinPcap-users] Loosing Packets or truncated packets


> Hi again,
>
> I can see a few things, but i'm not sure if they can cause the problem. It
> depends on your values.
>
> First;
> I don't think that you need to open 4 adapters. I'm working on a project
> similar to yours, and i'm just working with 2 adapters. I think the
> Read/write functions for the can work on the same adapter. I don't even
> think that you need a semaphore for each adapter (Although you need one if
> you have multiple threads writing the same adapter).
>
> Second;
> In your code i can see that the lines
>
> l:=NetworkSetup_in.memoriesize;
>
> PacketInitPacket(Packet_R_out,@buffer_out,l);
>
> from the snipet where you set up your output adapters, you use the in
> parameters for the output section.
>
> Third;
> I don't know Delphi at all, but i'm having trouble understanden the
>
> pheader:=@buffer_in;
>
> in the start of you "while" loop. When do you advance this value? Doesn't
> this mean that you use the bpf_header from the first packet each time??
>
> These are the only things I could find. But i'm no expert maybe someone
else
> knows??
>
> Otherwise i would look at the part you took out. You describe it as
>
> // Here my code that modifies the packet for a H323 application
>
> and i presume that you do some kind of editing of the packet fore some
kind
> of VoIP application.. Are you sure you don't mess up the packet?
>
> I can recommend using ethereal on the receiving computer, to see if the
> packet alteration are good enough. By doing this, i've been able to
> distinquish between WinpCap initialization errors, and my own packet
editing
> errors..
>
> Hope this help,
>
> - Jesper
>
> -----Original Message-----
> From: David Rodriguez [mailto:[EMAIL PROTECTED]]
> Sent: 8. august 2002 16:55
> To: [EMAIL PROTECTED]
> Subject: Re: [WinPcap-users] Loosing Packets or truncated packets
>
>
> Hello,
>
>
> My program is written in Delphi 6.0
>
>
> I use 2 interfaces
>
> in    : card 0
> out   : card 1
>
>
> I use 4 handlers:
>
>
> Adapter_R_in   : Reading data in the interface 0
> Adapter_W_in   : Writing data in the interface 0
>
> Adapter_R_out  : Reading data in the interface 1
> Adapter_W_out  : Writing data in the interface 1
>
>
>
> NetworkSetup_in          : Registre for set parameters in interface 0
> NetworkSetup_out        : Registre for set parameters in interface 1
> (these parameters are similar for both interfaces)
>
>
> I use 2 process
>
> demo_in.    : read data from the interface 0 and then write to the
interface
> 1
>
> demo_out   : read data from the interface 1 and then write to the
interface
> 0
>
>
>
>
>
> Part of my code is here:
>
>
> Procedure Setup
> begin
>
>       Adapter_R_in:=nil;
>       Adapter_R_in:=  PacketOpenAdapter(@s_in);
>        asm     add esp,4  end;
>
>       Adapter_W_in:=nil;
>       Adapter_W_in:=  PacketOpenAdapter(@s_in);
>        asm     add esp,4  end;
>
>
>   if (Adapter_R_in^.hFile=INVALID_HANDLE_VALUE)  then
>   begin halt; end;
>
>   if (Adapter_W_in^.hFile=INVALID_HANDLE_VALUE)  then
>   begin halt; end;
>
>
>
> // mode promiscous
> if not(PacketSetHwFilter(Adapter_R_in,NetworkSetup_in.mode)) then halt;
>   asm
>      add esp,8
>   end;
>
>
>
> if not(PacketSetBuff(Adapter_R_in,NetworkSetup_in.memoriesize)) then halt;
>   asm
>      add esp,8
>   end;
>
> l:=NetworkSetup_in.memoriesize;
>
>
>   PacketSetReadTimeout(Adapter_R_in,0);
>   asm
>      add esp,8
>   end;
>
>
> Packet_R_in :=NIL;
> Packet_R_in := PacketAllocatePacket();
> if Packet_R_in=NIL then halt;
>
> Packet_w_in :=NIL;
> Packet_w_in := PacketAllocatePacket();
> if Packet_w_in=NIL then halt;
>
>
>
> l:=NetworkSetup_in.memoriesize;
>
> PacketInitPacket(Packet_R_in,@buffer_in,l);
> asm
>      add esp,12
> end;
>
>
>
> /// end of the interface in
>
>
>
>       Adapter_R_out:=nil;
>       Adapter_R_out:=  PacketOpenAdapter(@s_out);
>        asm     add esp,4  end;
>
>       Adapter_W_out:=nil;
>       Adapter_W_out:=  PacketOpenAdapter(@s_out);
>        asm     add esp,4  end;
>
>
>   if (Adapter_R_out^.hFile=INVALID_HANDLE_VALUE)  then
>   begin halt; end;
>
>   if (Adapter_W_out^.hFile=INVALID_HANDLE_VALUE)  then
>   begin halt; end;
>
>
> // mode promiscous
>
> if not(PacketSetHwFilter(Adapter_R_out,NetworkSetup_out.mode)) then halt;
>   asm
>      add esp,8
>   end;
>
>
> if not(PacketSetBuff(Adapter_R_out,NetworkSetup_out.memoriesize)) then
halt;
>   asm
>      add esp,8
>   end;
>
>
>
>   PacketSetReadTimeout(Adapter_R_out,0);
>   asm
>      add esp,8
>   end;
>
>
> Packet_R_out :=NIL;
> Packet_R_out := PacketAllocatePacket();
> if Packet_R_out=NIL then halt;
>
> Packet_w_out :=NIL;
> Packet_w_out := PacketAllocatePacket();
> if Packet_w_out=NIL then halt;
>
>
>
> l:=NetworkSetup_in.memoriesize;
>
> PacketInitPacket(Packet_R_out,@buffer_out,l);
> asm
>      add esp,12
> end;
>
>
>
>
>
> /// end of the interface out
>
>
> finalizo:=false;
>
> lin_mac   :=0;
> lout_mac  :=0;
>
>
> vdemo:=demo.create;
> vdemo.Priority:=tplowest;
>
> vdemo_out:=demo_out.create;
> vdemo_out.Priority:=tpTimeCritical;
>
>
> vdemo_in:=demo_in.create;
> vdemo_in.Priority:=tpTimeCritical;
>
>
> //  vdemo_in : process 0
> //  vdemo_out   : process 1
> //
> //  by the moment I dont use events
>
>
>
> end;
>
>
> /// Begin of the process demo_in
>
> Procedure demo_in.execute;
>
> {$A-}
> type header=record
>
>      tv_sec      :integer;
>      tv_microsec :integer;
>      bh_caplen   :integer;
>      bh_datalen  :integer;
>      cabecera    :byte;
>      end;
> {$A+}
> var ps:pointer;
>
>     pheader :^header;
>     i,j     :Integer;
>     s       :string[255];
>     P,P1       :pointer;
>     ports_in,portd_in :word;
>
>
>     IP_D_in :Cardinal;
>     IP_S_in :Cardinal;
>
>     MAC_D:tmac;
>     MAC_S:tmac;
>
>
>
>
>
>     TAMANO_IP : WORD;
>
>     SeqNumber     :Cardinal;
>     Acknolegment  :Cardinal;
>
>     LL      :Integer;
>
>
>     chk_IP        :Cardinal;
>     chk_IP_Word   :Word;
>     ii,jj:integer;
>
>     length_user  :integer;
>     length_number:integer;
>     index_number :integer;
>
>
>     // new variables
>
>     existe_usuario    :boolean;
>     existe_usuario_i  :integer;
>
>
> begin
>
>
>
> repeat
>
>  if(PacketReceivePacket(Adapter_R_in,Packet_R_in,TRUE)=FALSE) then
> begin
>  halt;
> end; asm     add esp,12;  end;
>
> offset_in:=0;
>
>   if packet_R_in^.ulBytesReceived<>0 then
>
> repeat
>
> pheader:=@buffer_in;
>
> tv_seg          :=pheader^.tv_sec;
> tv_microseg     :=pheader^.tv_microsec;
>
> tlen1_in        :=pheader^.bh_datalen; // the real size of the packet
> tlen_in         :=pheader^.bh_caplen;
>
> offset_in:=offset_in+pheader^.cabecera;
>
>
> real_time:=pheader^.tv_sec;
>
>
>
>
> // Here my code that modifies the packet for a H323 application
> //
>
>
>
>
>
>
> // writing data to the interface out
>
>   Move((@buffer_in[offset_in])^,buffer_w_out,tlen1_in);
>   ll:=tlen1_in;
>
>   PacketInitPacket(Packet_W_out,@buffer_W_out,ll);asm add esp,12  end;
>   ll:=1;
>   PacketSetNumWrites(Adapter_W_out,ll);asm add esp,8;end;
>   PacketSendPacket(Adapter_W_out,Packet_W_out,TRUE);asm add esp,12  end;
>
>
>
>
>
> offset_in:=Packet_WORDALING(offset_in+tlen1_in);
>
>
>
> until(offset_in>=packet_R_in^.ulBytesReceived) or (finalizo);
>
> // finalizo is a variable to finish the process
>
> until(finalizo);
> finalizo:=false;
> end;
>
>
>
> // the same procedure for demo_out process
>
> // Note:   the function integer is 4 bytes length
>
>
> Function Packet_WORDALING(L:integer):integer;
> begin
>         Result:=(L+3) and (not (integer(3)));
> end;
>
>
>
>
> ----- Original Message -----
> From: "Jesper Munkholm Jensen (JMJ)" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, July 30, 2002 9:02 AM
> Subject: RE: [WinPcap-users] Loosing Packets or truncated packets
>
>
> > You could try publishing the relevant code parts, and see what the
> response
> > is. I'll be glad to browse through it and se if I can see something
you've
> > missed. I've been through most aspects of the library about know...
> >
> > - Jesper
> >
> > -----Original Message-----
> > From: David Rodriguez [mailto:[EMAIL PROTECTED]]
> > Sent: 8. august 2002 16:03
> > To: [EMAIL PROTECTED]
> > Subject: Re: [WinPcap-users] Loosing Packets or truncated packets
> >
> >
> > I use packet.ddl lybrary, I dont use pcaplib
> >
> > The strange thing is that when I use more memory more problems.
> > When I used 256k of buffer user and system I got rarely errors.
> >
> > I dont set any kind of filter the one is promiscous mode.
> >
> > David
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Jesper Munkholm Jensen (JMJ)" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, July 30, 2002 8:11 AM
> > Subject: RE: [WinPcap-users] Loosing Packets or truncated packets
> >
> >
> > > Do you use the Packet.dll or the Winpcap?
> > >
> > > A thing to remember is that WinPcap library function pcap_next(),
> returns
> > a
> > > pointer to the packet in its own buffer, so if you hang on to the
packet
> > to
> > > long you may risk it being overwritten. In bursts maybe this could
cause
> > the
> > > error, but the depends on your code. Can't see how using a greater
> buffer
> > > would enhance this error, so maybe i'm of track. Just a thought...
> > >
> > > - Jesper
> > >
> > > -----Original Message-----
> > > From: David Rodriguez [mailto:[EMAIL PROTECTED]]
> > > Sent: 8. august 2002 15:06
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: [WinPcap-users] Loosing Packets or truncated packets
> > >
> > >
> > > I dont use any filter
> > >
> > > I use the following:
> > >
> > >  NdisSetPacketFlags(pPacket, NDIS_FLAGS_SKIP_LOOPBACK);  //
> > >    for avoid reading packets writing in one interface were read it
> again.
> > >
> > > I use also win 2000
> > >
> > > David
> > >
> > >
> > > ----- Original Message -----
> > > From: "Loris Degioanni" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Tuesday, July 30, 2002 3:53 AM
> > > Subject: Re: [WinPcap-users] Loosing Packets or truncated packets
> > >
> > >
> > > > Do you set a filter? If yes, what is its snaplen?
> > > >
> > > > Loris
> > > >
> > > > > Hello
> > > > >
> > > > > I am doing an application using 2 nic cards, I read information
from
> > one
> > > > interface
> > > > >
> > > > > and then send for the other interface.
> > > > >
> > > > > The problem is when I do ping from a router (the router send the
> ping
> > > > >
> > > > > every 1  ms ) the packet is truncated to 64 bytes. The size of the
> > ping
> > > > >
> > > > > is 74 bytes.
> > > > >
> > > > > The strange thing is tha if I use 256K of buffer for 2 interfaces
I
> > > rarely
> > > > get the
> > > > >
> > > > > error. But when I increase the buffer to 2M I get a lot of error
> > > specially
> > > > when the
> > > > >
> > > > > traffic is burstly.
> > > > >
> > > > > What the increase of the buffer produce this error, does the
driver
> > copy
> > > > all
> > > > >
> > > > > the content of the kernel memory to the user memory even the
memory
> > has
> > > > >
> > > > > little information ?
> > > > >
> > > > > Note: My timeout in PacketSetReadTimeout is Zero
> > > > >
> > > > >
> > > > >
> > > > > Thaks in advanced
> > > > >
> > > > >
> > > > >
> > > > > David
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > David Rodriguez
> > > > > davidgrs
> > > > >
> > > > >
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > > ------
> > > > > Join the world's largest e-mail service with MSN Hotmail. Click
Here
> > > > >
> > > > >
> > > >
> > >
> >
>

Reply via email to