Network programming and Packets interactions - c#

Greeting,
This month I will start working on my master thesis. My thesis's subject is about network security.
I need to deal with network interfaces and packets.
I've used shappcap before to interact with packets but I'm not sure if C# is the most powerful language to deal with network programing and packets.
I worked a bit with wireshark and I saw how powerful it is and as you know winsharp is open source developed using C++.
I'm not sure if I should use C# or C++ for network security programming and I want your through about the best language might be for network programming and packets interaction.
should I use C#, C++, or java or some thing else?
please give me your advice.
Thank you,
UPDATE
..........................
I'm going to do different packet mining by taking each packet and read each field on it then use these values and in same stages I would modify some of the packets value then resend them back.
I want to control the packet since it received by the network interface until it passes to the application layer.
also

You'd be able to do network programming using almost any language you want to. If you are equally comfortable in all of the languages you've mentioned, you should determine what system libraries or APIs will you be interfacing with. For example, if you will be doing packet-level network programming on a Unix system, C would probably be your best best. If you want to integrate with Wireshark, go with C++. If you want to use an Apache Commons component, use Java. I suggest you come up with a more specific set of requirements for your actual program before trying to decide which language to use.

WireShark uses WinPCap so you could go that route as well.
For security application, is that a intrution detection system or do you actually want to drop offending packets? WinPCap, SharpPCap etc. do not allow you you drop packets, for this you will need to look at some kind of intermediate driver or look at Windows Filtering Platform (WFP)
http://www.microsoft.com/whdc/device/network/WFP.mspx
IMHO, if you can find a callback driver that calls back to user mode and allows you to filter the packets from C# or C++, this would probably be fine for experimental purposes etc. but for a production solution, I think you would need to stick to the kernel level to ensure that you can keep-up with the peek volume.

Use C++, Boost and Poco and you can do what you want. Boost asio is: Portable networking, including sockets, timers, hostname resolution and socket iostreams. Poco library also provides solutions for network, cryprography NetSSL ... and more. For more information you can visit www.boost.org and www.pocoproject.org

You can use java if you like - jpcap works well.

I would suggest using C#, since there is a very strong library called Pcap.Net that wraps WinPcap with .NET code. This should make it easy for you to receive, send and interpret packets different packets of different protocols.

Related

Which technology to choose for PubSub between java service and C# client

Which technology would you suggest for PubSub between Java Service and C# desktop client.
What do you think about CometD? Is there any nice .net API for it?
Server and client will run within the same organization so can use different protocols
Is CometD a right choice at all or would it be better to use TCP instead of HTTP?
Since your apps run within the same organization, you will likely be able to use more efficient transport than HTTP, or even TCP, depending on your situation and requirements.
The Data Distribution Service (DDS) is a standard by the OMG based on Pub/Sub. Standardized language bindings are C, C++, Java and Ada, but C# and others are available as well. Different languages as well as operating systems can be mixed in your system. Structured datatypes to be distributed are specified in a language-neutral format (by the standard a subset of OMG IDL), which is then translated into language-specific interfaces and datatypes to be used by your applications.
It can use different transport layers, like UDP or also TCP. Although I can not determine from your brief description whether DDS would be your best choice, I think it is worth investigating. See this Wikipedia entry for a very brief introduction and list of references.
Warning: I have only used cometd (no atmosphere or even none-java solutions)
I like cometd as it was very fast to get started and the documentation was good. Also the javascript API worked without any issues.
and then the bayeux specification could be implemented on c# too: https://github.com/Oyatel/CometD.NET
http://bugs.cometd.org/browse/COMETD-23
You might want to look at some messaging protocols such as AMQP and STOMP. There's decent support for both protocols in both Java and .NET and you can choose your choice of message brokers such as RabbitMQ or ActiveMQ and others.

VOIP in C#, asp.net or Java

Could you people please give some good resource / ideas of implementing VOIP in c#.net, Asp.net or Java.
Why I am specifying 2 different language platforms is we are yet to take up a call.
Basically we don't have the idea henceforth the concept is more important to us.
We are going to make a White board application and one of the client requirement is
White board should have VOIP
conferencing, chat image sharing and
ability to upload .pdf files
I reckon your looking into developing software like orange business webex or something similar. The software is not too difficult to develop. First, are you planning to write the entire application yourself or just purchase the components and integrate ? I would recommend you shop around for components and just integrate because VOIP is rather complex.
Here is a link for SIP communicator in java which supports VOIP
Doing simple point-to-point VOIP isn't too difficult. Basically, you need a codec on each end, and then typically use UDP to send encoded packets from one end to the other.
There can also be network connectivity issues, particularly related to NAT.
If you want to interoperate with existing VOIP-based systems, then you will need to support one of the underlying connection protocols, such as H.323, and you may also need monitoring and control over RTP. Those protocols are notoriously complex.
There are a bunch of tricks to play when doing this kind of thing with a managed language like C# or Java, particularly related to avoiding hiccups due to GC.
A link to a few more Java VOIP projects/components:
http://voip.dev.java.net/
One "gotcha" to beware of, in terms of future functionality, is that Java's (as opposed to JavaFX's) video support is something of an open question at the moment.

What is the best way for C# app to communicate unix c++ app

the ways I can think of
Web service or soap
Socket
Database table
shared file
Any concise example you know of for webservice?
Web services or soap would be fairly easy, however, if the C++ application isn't a web server naturally (or the C# application), it may be easier to just use socket programming directly.
Sockets are fairly easy to use from both C# and C++. They give you complete control over the type of date transmitted, at the cost of potentially a little more work in the handling.
The biggest issues to watch for are probably endianness of binary data, and encoding of text data, if you use sockets directly. Otherwise, it's very easy.
Since you are already aware of the Web service and socket approach, I'll mention some other options. If you like simplicity, check out XML-RPC. This is what SOAP was before large standards committees and corporate interests began to control the specification. You can find implementations of XML-RPC for just about every major programming language out there. Hessian is an interesting binary protocol that has many fans and supports just about every major language as well. Protocol Buffers is popular within Google. The official version from Google does not support C#. However, the two highest rep users of SO do provide ports of protobuf for the .Net space.
I will probably be ridiculed for this, but also take a look at CORBA. It's not in vogue these days, but has many substantial technical creds, especially if one end of the communication is C++. IMHO, it's WS-* with OO support and no angle brackets required. For interop, I think it still should have a seat at the table. When engaged in C++ development, I found OmniOrb to be quite effective and efficient. Take a look at this SO Question for some pointers concerning using CORBA in .Net.
Sockets are easiest; and I would always go for that first. If database is an option, that's also trivial, but that would really depend. If it's queued events, that would make sense, but if it's request/response, it's probably not so great.
you can use gsoap to have a C/C++ program use a webservice.
You can also call a cgi program that is written in C++.
I have written a server in C that communicated with a C# client, and the endianess can be a pain to deal with, webservices is so much simpler.
Do you want it to communicate with each other (for instance, through tcp (like many others have pointed)) or do you want to be able to translate objects from C# to C++? If so, check out Apache Thrift (http://incubator.apache.org/thrift/).

File transfer between 2 remote systems using internal modem

My requirement is to write an application to send a file from a remote machine to another machine using internal modem. Both system are connected thru VPN or a internet.
Basically we have two systems both having internal dial up modems. The two systems are connected through either VPN or Internet.
One system should send a file (XML) to another.
I was given the freedom to do it in either C++ or C#. Or is there any other language we can do this easily?
How can I go about this task? Do we need an client/server type application or do we need an app only at the receiving end?
Is there any built in technology available for this type of file transfers using modems?
Since I don't have the programming point of view, my question may not be clear! I tried to put max information on my requirements, but if I am not clear, please ask me.
If you are connected via a VPN, then there are many existing programs available to transfer files between each other. The most well known is FTP. There are many freely available FTP or SFTP packages.
The fact that you are using a modem does not matter. Only that they are in the same network or visible on the internet.
It's been a while, so my memory is fuzzy:
There are modem libraries out there. Find one and use it. No need to reinvent the low level software. I seem to remember using a product from Dialogic (At least I think that was the company). It worked well. I did a quick search and there are 50 companies with that name, but I did see some that mention C, C++ and C# librariers. If you do a little research you'll find what you need.
You will need to learn how to initiate communications between the modems. Almost all modems use the Hayes Modem AT Command Set.
Modems are slow: So pick a compression algorithm before sending data. zlib is an industry favorite.
Your modem library of choice should provide several mechanisms for doing the pure data transfer that you are asking about. Choose the one that fits your data best.

Java and C# interoperability

I have two programs. One is in C# and another one in Java.
Those programs will, most probably, always run on the same machine.
What would be the best way to let them talk to each other?
So, to clarify the problem:
This is a personal project (so professional/costly libraries are a no go).
The message volume is low, there will be about 1 to 2 messages per second.
The messages are small, a few primitive types should do the trick.
I would like to keep the complexity low.
The java application is deployed as a single jar as a plugin for another application. So the less external libraries I have to merge, the better.
I have total control over the C# application.
As said earlier, both application have to run on the same computer.
Right now, my solution would be to use sockets with some sort of csv-like format.
I am author of jni4net, open source interprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
Kyle has the right approach in asking about the interaction. There is no "correct" answer without knowing what the usage patterns are likely to be.
Any architectural decision -- especially at this level -- is a trade-off.
You must ask yourself:
What kind of messages need to be passed between the systems?
What types of data need to be shared?
Is there an important requirement to support complex model objects or will primitives + arrays do?
what is the volume of the data?
How frequently will the interactions occur?
What is the acceptable communication latency?
Until you have an understanding of the answers, or potential answers, to those questions, it will be difficult to choose an implementation architecture. Once we know which factors are important, it will be far easier to choose the more suitable implementation candidates that reflect the requirements of the running system.
I've heard good things about IKVM, the JVM that's made with .NET.
Ice from ZeroC is a really high performance "enterprisey" interop layer that supports Java and .net amongst others. I think of it as an updated Corba - it even has its own object oriented interface definition language called Slice (like Corba's IDL, but actually quite readable).
The feature set is extensive, with far more on offer than web services, but clearly it isn't an open standard, so not a decision to make lightly. The generated code it spits out is somewhat ugly too...
I realize you're talking about programs on the same machine, but I've always liked the idea of passing messages in XML over HTTP.
Your server could be a web server that's ready to accept an XML payload. Your client can send HTTP messages with XML in the body, and receive an HTTP response with XML in it.
One reason I like this is that HTTP is such a widely used protocol that it's easy to accept or create HTTP POST or GET requests in any language (in the event that you decide to change either the client or server language in the future). HTTP and XML have been around for a while, so I think they're here to stay.
Another reason I like it is that your server could be used by other clients, too, as long as they know HTTP and XML.
I used JNBridge (http://www.jnbridge.com/jnbpro.htm) on a relatively simple project where we had a .NET client app using a relatively significant jar file full of business object logic that we didn't want to port. It worked quite nicely, but I wouldn't say we fully exercised the capabilities of JNBridge.
I am a big fan of Thrift an interoperability stack from Facebook. You said they code will probably run on the same machine so it could be overkill but you can still use it.
If they are separate programs and running as independent applications,you may use sockets. I know it's bit complex to define communication protocol but it'll be quite straight-forward.
However if you have just two separate programs but want to run them as single application, then I guess IKVM is a better approach as suggested by marxidad.
It appears a very similar question has been asked before here on stack overflow (I was searching Google for java windows shared memory):
Efficient data transfer from Java to C++ on windows
From the answer I would suggest you to investigate:
"Your fastest solution will be memory
mapping a shared segment of memory,
and them implementing a ring-buffer or
other message passing mechanism. In
C++ this is straight forward, and in
Java you have the FileChannel.map
method which makes it possible."

Categories

Resources