Click here to Skip to main content
12,448,720 members (54,480 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hello,

how can I send TcpPacket, after that I want to detect this TcpPacket ??

I work with sharppcap and packetDotNet dll

I tried this code but I can't detect tcpPacket :

byte[] bytes = new byte[54];
PacketDotNet.Utils.ByteArraySegment by = new                      
 
PacketDotNet.Utils.ByteArraySegment(bytes);
TcpPacket tcppacket = new TcpPacket(by);
 

var devices = CaptureDeviceList.Instance;
ICaptureDevice device = devices[2];
device.Open(DeviceMode.Normal, 1000);
 
tcppacket.Syn = true;
tcppacket.DestinationPort = 8080;
tcppacket.WindowSize = 555;
tcppacket.AcknowledgmentNumber = 1000;
tcppacket.SequenceNumber = 1000;
 
device.SendPacket(tcppacket);            
RawCapture raw;
 
while ((raw=device.GetNextPacket()) != null)
{
 
    Packet packet = Packet.ParsePacket(raw.LinkLayerType, raw.Data);
 
    TcpPacket tcp = TcpPacket.GetEncapsulated(packet);
    
    if (tcp != null)
    {
        DateTime time = raw.Timeval.Date;
        int len = raw.Data.Length;
 
        string srcIp = tcp.SourcePort.ToString();
        string dstIp = tcp.DestinationPort.ToString();
 
        Console.WriteLine("{0}:::{1}:::{2},{3} ::: Len={4}", time.Hour, time.Minute, time.Second, time.Millisecond, len);
        Console.WriteLine("{0} ***** {1}", srcIp, dstIp);
    }
    else
    {
        Console.WriteLine("Nooooo Tcp Packet");
    }
}
Posted 16-Mar-12 6:09am
Updated 16-Mar-12 7:45am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 16 Mar 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100