Click here to Skip to main content
Rate this: bad
good
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
Edited 16-Mar-12 7:45am
387.2K
v2

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

  Print Answers RSS
0 CPallini 405
1 Sergey Alexandrovich Kryukov 262
2 OriginalGriff 165
3 George Jonsson 134
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,890
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 16 Mar 2012
Copyright © CodeProject, 1999-2014
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