Click here to Skip to main content
15,908,254 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to use DataBinding/DataSets to INSERT both a row in a parent table, and its CHILD table rows (matched by key) at the same time (or right after) Pin
Draekz8-Jun-10 4:12
Draekz8-Jun-10 4:12 
QuestionMouseLeave event triggered on the wrong window Pin
martingeorgiev7-Jun-10 8:43
martingeorgiev7-Jun-10 8:43 
AnswerRe: MouseLeave event triggered on the wrong window Pin
Andrew Rissing7-Jun-10 8:53
Andrew Rissing7-Jun-10 8:53 
GeneralRe: MouseLeave event triggered on the wrong window Pin
martingeorgiev7-Jun-10 8:57
martingeorgiev7-Jun-10 8:57 
GeneralRe: MouseLeave event triggered on the wrong window Pin
Andrew Rissing7-Jun-10 9:06
Andrew Rissing7-Jun-10 9:06 
GeneralRe: MouseLeave event triggered on the wrong window Pin
Andrew Rissing7-Jun-10 9:17
Andrew Rissing7-Jun-10 9:17 
GeneralRe: MouseLeave event triggered on the wrong window Pin
martingeorgiev7-Jun-10 9:20
martingeorgiev7-Jun-10 9:20 
QuestionRIP BASED SOFTWARE ROUTER FOR WINDOWS using C# Pin
Member 32734627-Jun-10 7:29
Member 32734627-Jun-10 7:29 
Good day everyone,

I am working on a project and I am having a few issues.

Project detail

1. Am trying to simulate a RIP based router in Windows
2. I am developing this in C#
3. Am using Winpcap and SharpCap
4. So far I have figured out what my routing table would look like

My issues are as follows

1. Initially when RIP starts it sends a request packet out all RIP enabled interfaces
on IP address 255.255.255.255
I have tried to simulate this directly but decided to let .NET manage the packet
header creation, so what i have done is simply to send "Type 1 message" as
the payload and when the receiving router sees this it knows it should send its routes.

This is not how it should be done, but i guess i can work with this for now, as I can't
seem to be able to create my own packet header in C# easily.

Any suggestions on how best I can create a packet without doing low level stuffs would be
appreciated or any library i can simply reference that just accepts port number, ip addresses,
payload and returns a packet as response?

2. After sending I should wait for response from other Routers.
These received packets are called Response Packets and contain the responding routers'
routes.

To do this i have decided that after the Request is sent out all interfaces, I would wait for about
25sec for responses.

Issue: I do not know how best to implement this, I have tried editting the Sample Codes in sharpCap
and also tried socket.listen method
but I can't tell if anything is coming in or not.

3. I installed WireShark to help me detect if I am even sending anything out the interfaces in the first place
and it appears am not, as wireshark does not report anything. And yes I selected the right interface.

So any help please.

Below is a cut out of my code so far

...
ArrayList ripIntefaces;
public void start(int[] deviceIndex)
{
//get list of intefaces again
var devices = LivePcapDeviceList.Instance;

//send request out all RIP enabled interfaces
for (int k = 0; k < deviceIndex.Length; k++)
sendRequestsInitial(devices[deviceIndex[k]]);

//wait 4 response
while (true)
{
//1st time around dont run infinitively, just capture n close
for (int k = 0; k < deviceIndex.Length; k++)
receiveResponse(ripIntefaces, deviceIndex); //this should be threaded 4 listening on each interface
}
}

....
private void sendRequestsInitial(LivePcapDevice enabledIntf)
{
string nxtHop = enabledIntf.Addresses[1].Addr.ipAddress.ToString(); //should be but I cant bind ip add "255.255.255.255";
int portNo = 520;

Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);

IPAddress sendTo = IPAddress.Parse(nxtHop);
IPEndPoint sEndPoint = new IPEndPoint(sendTo, portNo);
EndPoint sendEndPoint = (EndPoint)sEndPoint;
sock.Bind(sendEndPoint);

//create packet to send
byte[] pktContent = packetProcessor.makeRequestPacket();

sock.SendTo(pktContent,sendEndPoint);
}

....

private void receiveResponse(ArrayList ripNetworks, int[] deviceIndex)
{
//monitor all ripInterfaces
//start new thread 4 each - WORK ON
var devices = LivePcapDeviceList.Instance;
LivePcapDevice device = devices[deviceIndex[0]]; //testing 4 1 device 1st, others with thread

device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);

int readTimeoutMilliseconds = 25000;
device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

device.StartCapture();

//device.Close();


}

...

private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
{
// myPacket tempPacket = new myPacket();

var packet = PacketDotNet.Packet.ParsePacket(e.Packet);
var ip = PacketDotNet.IpPacket.GetEncapsulated(packet);
var udp = PacketDotNet.UdpPacket.GetEncapsulated(packet);
string result = string.Empty;

if(ip != null)
{

if (udp != null)
{
result = Encoding.UTF8.GetString(udp.PayloadData);

}
}
Console.WriteLine(result);
}


....................

class packetProcessor
{
static byte[] packet;
public static byte[] makeRequestPacket()
{
string content = "Type 1 Message, Request";
packet = Encoding.ASCII.GetBytes(content);
return packet;
}
}

So any inputs??
Questionusing and close Pin
imbiz7-Jun-10 7:16
imbiz7-Jun-10 7:16 
AnswerRe: using and close Pin
Keith Barrow7-Jun-10 7:23
professionalKeith Barrow7-Jun-10 7:23 
GeneralRe: using and close Pin
imbiz7-Jun-10 9:20
imbiz7-Jun-10 9:20 
GeneralRe: using and close Pin
Chris Trelawny-Ross7-Jun-10 14:01
Chris Trelawny-Ross7-Jun-10 14:01 
GeneralRe: using and close Pin
imbiz7-Jun-10 14:46
imbiz7-Jun-10 14:46 
GeneralRe: using and close Pin
harold aptroot7-Jun-10 9:51
harold aptroot7-Jun-10 9:51 
AnswerRe: using and close Pin
harold aptroot7-Jun-10 7:25
harold aptroot7-Jun-10 7:25 
GeneralRe: using and close Pin
imbiz7-Jun-10 8:37
imbiz7-Jun-10 8:37 
AnswerRe: using and close Pin
PIEBALDconsult7-Jun-10 13:49
mvePIEBALDconsult7-Jun-10 13:49 
GeneralRe: using and close Pin
imbiz7-Jun-10 14:47
imbiz7-Jun-10 14:47 
AnswerRe: using and close Pin
prasadbuddhika7-Jun-10 18:35
prasadbuddhika7-Jun-10 18:35 
GeneralRe: using and close Pin
imbiz8-Jun-10 1:09
imbiz8-Jun-10 1:09 
Questiontext to speech problem Pin
maryamtooty7-Jun-10 6:08
maryamtooty7-Jun-10 6:08 
AnswerRe: text to speech problem Pin
Anshul R8-Jun-10 20:30
Anshul R8-Jun-10 20:30 
GeneralRe: text to speech problem Pin
maryamtooty11-Jun-10 5:20
maryamtooty11-Jun-10 5:20 
GeneralRe: text to speech problem Pin
Anshul R11-Jun-10 6:16
Anshul R11-Jun-10 6:16 
Questionhtml into cs Pin
genieabdo7-Jun-10 6:02
genieabdo7-Jun-10 6:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.