I need to upgrade a Windows Kernel Mode Driver from IPV4 to IPV4/IPV6 but the existing kernel mode socket library which uses TDI does not support IPV6.
So I would like to change the socket library to "Winsock Kernel" http://msdn.microsoft.com/en-us/library/windows/hardware/ff571084(v=vs.85).aspx
Note: This is not winsock2.
I started making the necessary modifications to use WSK instead of Kernsock from Storagecraft but there is a lot to consider given that this driver code runs on both windows and linux.
I am wondering if there is a kernel mode socket wrapper around WSK available, preferably with BSD or winsock2 function API signatures. My searches do not yield anything.
Thanks.
I found one UDP code project which seems to provide most of what I need.
I thought I would post it here for anyone else who needs a WSK wrapper.
Project:
https://code.google.com/p/wskudp/
UDP Source:
https://code.google.com/p/wskudp/source/browse/#svn%2Ftrunk%2Fwskudp
TCP Source:
https://code.google.com/p/wskudp/source/browse/#svn%2Ftrunk%2Fwsktcp
Thanks to https://code.google.com/u/x86ddk/ for creating the project.
NOTE: I haven't tested this yet.
Related
I have a TCP server (which I can not change/modify) running which sends data and I want it to connect to Unity WebGL build.So first of all I know it is natively not supported to connect to a TCP server in WebGL. I searched for workarounds and tried the following : Use Websockify to enable connection from the TCP server to a WebSocket. I used the NativeWebsocket Library but it would not connect to the server unfortunately. I also read about these blogs :
How to let a Unity WebGL build connect to a local python server?
https://forum.unity.com/threads/webgl-tcp-client.738419/
But they didn't really help either. Has anyone tried this or knows how to make it work (if it is even possible :) )?
Thanks in advance
Unity3D uses the .NET C# libraries, so even though Unity doesn't explicitly provide a TCP library, you can still use .NET's TCP APIs. It's worth noting that not all platforms will support this, for example, WebGL doesn't support TCP communication.
See the example in .NET documentation for help on implementation: System.Net.Sockets TcpClient
For WebGL, it is impossible to use TCP communication, so you'll have to wrap the server in some kind of HTTP/Websockets transport - you cannot leave the server as is, it will not work because the protocol cannot be communicated with for security reasons.
If you have any question as to the specifics of implementation, feel free to ask in the comments - I don't have enough information to elaborate further on your specific application
I create an UDP socket with the Socket module and version: 6. I want it to listen only to IPv6 (by default, version: 6 listens on both v4 and v6). Erlang's inet module has a ipv6_v6only option but I don't know how to use it when using Elixir's Socket module. Calling :inet.setopts/2 after the call to Socket.UDP.open/2 always produce a {:error, :einval}. Any code example?
(I know I can do it by tuning the net.ipv6.bindv6only sysctl on Linux but I would prefer a solution that does not require to be root.)
Socket.UDP.open/2 is effectively routed to :gen_udp.open/2 which accepts a keyword of type open_option() as a second argument, which is in turn an extended type option().
Somewhat alongside the following would do
Socket.UDP.socket(port, version: 6)
This could have been easily seen from the arguments/1 implementation I’ve linked above.
I want to route my tcp packet from A to B through C.
I am new to network programming and some code samples will be very helpful.
Is there a way to do it through boost library?
how can I implement IP in IP protocol
Read the C++11 standard n3337. IP is not even mentioned there.
So you cannot implement IP in IP in standard hosted C++ code.
However, your device or computer might run some Linux kernel (e.g. on RaspBerryPi). Then you should read Advanced Linux Programming and syscalls(2), proc(5) and ip(7) and iptables(8) and several Linux HowTO-s
Is there a way to do it through boost library?
Did you read the documentation of boost? Did you consider using POCO or Qt libraries ?
Summary:
I am guessing that the issue here is something to do with how Windows and Linux handle TCP connections, or sockets, but I have no idea what it is. I'm initiating a TCP connection to a piece of custom hardware that someone else has developed and I am trying to understand its behaviour. In doing so, I've created a .Net core 2.2 application; run on a Windows system, I can initiate the connection successfully, but on Linux (latest Raspbian), I cannot.
It appears that it may be because Linux systems do not try to retry/retransmit a SYN after a RST, whereas Windows ones do - and this behaviour seems key to how this peculiar piece of hardware works..
Background:
We have a black box piece of hardware that can be controlled and queried over a network, by using a manufacturer-supplied Windows application. Data is unencrypted and requires no authentication to connect to it and the application has some other issues. Ultimately, we want to be able to relay data from it to another system, so we decided to make our own application.
I've spent quite a long time trying to understand the packet format and have created a library, which targets .net core 2.2, that can be used to successfully communicate with this kit. In doing so, I discovered that the device seems to require a kind of "request to connect" command to be sent, via UDP. Straight afterwards, I am able to initiate a TCP connection on port 16000, although the first TCP attempt always results in a RST,ACK being returned - so a second attempt needs to be made.
What I've developed works absolutely fine on both Windows (x86) and Linux (Raspberry Pi/ARM) systems and I can send and receive data. However, when run on the Raspbian system, there seems to be problems when initiating the TCP connection. I could have sworn that we had it working absolutely fine on a previous build, but none of the previous commits seem to work - so it may well be a system/kernel update that has changed something.
The issue:
When initiating a TCP connection to this device, it will - straight away - reset the connection. It does this even with the manufacturer-supplied software, which itself then immediately re-attempts the connection again and it succeeds; so this kind of reset-once-then-it-works-the-second-time behaviour in itself isn't a "problem" that I have any control over.
What I am trying to understand is why a Windows system immediately re-attempts the connection through a retransmission...
..but the Linux system just gives up after one attempt (this is the end of the packet capture..)
To prove it is not an application-specific issue, I've tried using ncat/netcat on both the Windows system and the Raspbian system, as well as a Kali system on a separate laptop to prove it isn't an ARM/Raspberry issue. Since the UDP "request" hasn't been sent, the connection will never succeed anyway, but this simply demonstrates different behaviour between the OSes.
Linux versions look pretty much the same as above, whereby they send a single packet that gets reset - whereas the Windows attempt demonstrates the multiple retransmissions..
So, does anyone have any answer for this behaviour difference? I am guessing it isn't a .net core specific issue, but is there any way I can set socket options to attempt a retransmission? Or can it be set at the OS level with systemctl commands or something? I did try and see if there are any SocketOptionNames, in .net, that look like they'd control attempts/retries, as this answer had me wonder, but no luck so far.
If anyone has any suggestions as to how to better align this behaviour across platforms, or can explain the reason for this difference is at all, I would very much appreciate it!
Nice find! According to this, Windows´ TCP will retry a connection if it receives a RST/ACK from the remote host after sending a SYN:
... Upon receiving the ACK/RST client from the target host, the client determines that there is indeed no service listening there. In the Microsoft Winsock implementation of TCP, a pending connection will keep attempting to issue SYN packets until a maximum retry value is reached (set in the registry, this value defaults to 3 extra times)...
The value used to limit those retries is set in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpMaxConnectRetransmissions according to the same article. At least in Win10 Pro it doesn´t seem to be present by default.
Although this is a conveniece for Windows machines, an application still should determine its own criteria for handling a failed connect attempt IMO (i. e number of attempts, timeouts etc).
Anyhow, as I said, surprising fact! Living and learning I guess ...
Cristian.
I am working with the BlueZ libraries for managing the bluetooth stack under linux. I am trying to open a socket that should connect with a specific service whose UUID is known. I have successfully tried to open sockets between a server and a client following the examples here:
http://people.csail.mit.edu/albert/bluez-intro/c404.html
where it is also described how to explore services in a remote host; however, what I cannot figure out is how to specify the UUID while connecting the socket. This is something quite straightforward on other contexts, as it happens when using Android libraries; however, with BlueZ I haven't found examples on the web.
Thanks for the help!
Stefano
-- added some details in a reply... don't know if it's right or not; if not, sorry
thanks for your help!
In my post I said I wanted to connect a socket with a specified UUID since I had in mind a function like createRfcommSocketToServiceRecord as can be found in:
http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createRfcommSocketToServiceRecord%28java.util.UUID%29
which returns a socket given a certain UUID. I am developing two softwares, one being the client and the other the server, therefore it's a service I am creating, not a standard one. I publish such service on the server with a specified UUID, and I would like to connect to it from the client. The server is running fine, since with an android platform, exploiting the mentioned createRfcommSocketToServiceRecord method, I am able to connect to the server with the right service.
The example you posted is very clear as well, but unfortunately it is in Python, while (I forgot to point out) I am using Bluez as a C library. I am able to exploit the SDP and inspect services on a remote server; however, when it is the time of setting up the socket, I don't see how to specify the port. I thought about the rc_channel, but as far as I understood it is the bluetooth channel (ranging from 1 to 11 or something similar). Could you please point out Where I should be able to specify the port while creating the socket in the client? And where am I able to find the right port in the complex structure the sdp is dealing with? -- referred to:
http://people.csail.mit.edu/albert/bluez-intro/x604.html
Thanks again for the help!
You don't connect sockets by UUID. You use a socket to connect to remote device and browse its SDP to discover the UUIDs it offers, and map that to a socket port. Here's an example of this process using PyBluez, python wrappers above BlueZ
http://people.csail.mit.edu/albert/bluez-intro/x290.html