[Winpcap-users] pcap_sendpacket sends only 4 bytes...!
Boaz Brickner
boaz.brickner at gmail.com
Thu Feb 25 03:46:36 PST 2010
Hi,
It seems that your bug is "sizeof(pkt_data_iface1_2) is the buffer size."
sizeof is an operator that returns the size of the type and not the length
of the buffer.
http://msdn.microsoft.com/en-us/library/4s7x1k91%28VS.71%29.aspx
You should use the length of the buffer you want to send.
When you receive a packet, you also receive a packet header (pcap_pkthdr),
which contains the length of the packet buffer (caplen).
You should use this length and you should not use the sizeof operator.
By the way, the sizeof operator returns 4 when you use it on an int type or
a pointer type, so this is why you got only 4 bytes.
I hope this helps,
Boaz.
Try Pcap.Net in http://pcapdotnet.codeplex.com
On Thu, Feb 25, 2010 at 12:39, Valpondi Hereza, Fabio <
fabio.valpondi_hereza at siemens.com> wrote:
> Hi,
>
> I am programming a kind of bridge device, reading from one interface, and
> forwarding the frame through another interface. Also in the inverse way.
> The frame capture using "pcap_loop" happens without problems (I print the
> frame contents as well as length for debugging purposes).
>
> The problem is when I try to send the interface via the other interface. I
> use the following call for the pcap_sendpacket function:
> *pcap_sendpacket(iface2, pkt_data_iface1_2,sizeof(pkt_data_iface1_2));*
>
> *iface2* is the outgoing interface
> *pkt_data_iface1_2* is the frame received on Interface 1 and being sent
> over Interface 2
> *sizeof(pkt_data_iface1_2)* is the buffer size.
>
> Only the first four bytes of the frame are sent. The device that uses
> wireshark to analyze the frames sent by my program, shows them as malformed.
> I also tried for the size parameter *sizeof(hear_iface1_2->caplen)* or the
> *pcap_inject* function: *The result was the same.*
>
> My question is: does anybody know, why only the first four bytes are sent?
>
>
> Thanks a lot for your help!
>
> Best regards,
> Fabio Valpondi
>
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20100225/ec2a1f9a/attachment.htm
More information about the Winpcap-users
mailing list