Connection Management in UDP with C++ [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a client/Server systems implemented by Boost asio in C++ that a client sends a request to server. Then the server registers this client to the list of alive clients and keeps sending data to it over UDP protocol. But, the server should keep track of alive clients and stop sending data to a disconnected or dead client.
I wonder how I can implement the UDP session/socket management here since UDP is a connectionless protocol and cannot provide us any information about alive clients. Should I use another library for UDP session management in C++? Or I should use another protocol in the application layer for UDP session management.
I know there is a library in Java called Verax IPMI https://en.wikipedia.org/wiki/Verax_IPMI which provides this ability. But, how about in C++?
Thanks for reading my question.

Just keep a list of endpoints that you've seen recently (meaning they sent you a datagram). Usually, you allow for a grace time (e.g. 30s) before removing a client from the list.
That way, if some datagrams were dropped you don't immediately forget the "connection".

Related

What exactly network implementation has been used in Blockchains? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I'm already working on a blockchain project, However I have a problem on implementing a peer to peer network between nodes. I found a Udemy course and in that course Redis pub/sub was used for peet to peer network but is it only available in a local network right ? or in another article it says that there are some main nodes that run 24/7 so others first make connection with them. but is it not sort of server-side network ??
my question is how can I actually implement a peer to peer network that many nodes around the world can communicate with each other without any main server ?
Usual implementation of P2P connection is to have one predefined port (for example in case of Bitcoin Core it's 8333) and the applications periodically broadcast their messages on this particular port.
It's also usual to have in your app a preset list of nodes that are likely to be online 24/7, so that the app can listen to their messages right from the startup and doesn't have to wait for other nodes to broadcast their presence.
The app can keep a list of currently active nodes (for example the ping period is 60 seconds, so any node that has pinged within the last 60 seconds is considered active) in case it needs to communicate with the other nodes directly.
But most communication is usually done via broadcasting and listening to messages on the predefined port.

TCP connection breaks after 1 message [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a project which i communicate with DNS servers. For example I used googles DNS server. After connecting to the server and sending a message, everything works well and the server returns an answer. But by the time i send the second query, the server already closed the connection by himself(sends FIN) and now I send a message to an invalid fd. Is there a known solution to this problem?
From the DNS over TCP RFC:
The server should assume that the client will initiate connection
closing, and should delay closing its end of the connection until
all outstanding client requests have been satisfied.
This means that if you send multiple requests simultaneously, the connection will stay open until all the requests have been replied to. But once there are no more pending requests, the connection can be closed.
If you want to make multiple requests, then you either need to send them all at once, or create new connections for each single request.

MITM with winpcap and/or sockets? - C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i am developing an MITM for windows. I am using winpcap. I did correctly the arp spoofing and the ip fordwarding to the victims of my network. The problem of winpcap is that you cant control the packets, you need sockets to do this.
With winpcap you read incoming packets, you filter them, change them and send to router ok, easy. The problem comes when you need to act as a server. For example, if we want to supplant an executable we need to serve our own exe. And we cant use sockets to serve our file to the victims because we are using winpcap, we must create all the packet and send it with pcap_sendpacket(), we must hear the victim responses, how?, the only way is waiting all incoming packets from all victims and from different protocols and to filter all searching our ACK, for all packets tcp in the download.
Is this way viable? Or shall i create a server in each sniffer port and to do this with sockets?. Mmmm ideas pls. What is better, and what would you do?
Thanks and sorry for my English :)
Regards!.
Yes, this is possible. Here are the steps that you need to take to do this successfully.
Identify an unused IP address on the subnet. If you try to use the address that is already bound you will be racing against and fighting the IP stack in the host OS. Since it knows nothing of the connections that you're managing/spoofing, it will send RST packets in reaction to almost every response packet that you receive (Note, I'm assuming that you're using TCP)
Select a MAC that you will use. You actually can use the same MAC as the host OS network stack, which will allow you to operate without actually putting the interface into promiscuous mode. The host OS will not interfere since the Layer 2 addresses will not match the host OS's knowledge of the Layer 2 address, but you will still have to supply ARP replies for your Layer 2 address when other host look for you.
Effectively, write your own IP stack. Yes, you will be responsible for calculating checksums, tracking session state and everything else.
A far easier approach that you seem to be resistant to is to use Scapy. Scapy abstracts much of this for you, allowing you to focus on the logic of what it is you're actually trying to do. For example, Scapy will take care of the checksums for you if you'd like it to.

How to handle a single connection from multiple clients on a single ip using TCP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to develop a server for an application of mine in C++. I'm not really familiar with networking concepts. This server is going be a simple one and I'll use one of the networking libraries out there. I just couldn't figure out the necessary keywords to research the following issue:
Let's say that there are 100 users on 100 different computers, all sharing the same internet connection, behind the same router. They all decide to open my client to connect to my server. How do you deal with this issue if you want to keep the connections open and on the same port.
For the purposes of your server, it doesn't make any difference whether those 100 connections are all coming from the same computer, from the same router, or from totally separate networks.
While the server side of the connection will use the same port for all of these, each connection will have a different combination of client side IP address and port. In the case you describe, where all 100 are behind the same router using the same IP address, the router will take care of making sure they all have different client side port numbers. You can read about network address translation (NAT) if you want to learn the details about one common way that is done.
This kind of server programming is not easy and requires network skills. You can have a look at this tutorial. It's C and unix, but it shows the function you'll need to use:
socket interface for network access
listening/accepting new connextion
forking new processes to handle the different clients (although in C++ you'd probebly look for multithreading which is more efficient for this kind of task).

How Should I Implement Security On UDP Socket [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm working on a peer to peer networking application but I cannot solve how I'm going to provide security on UDP sockets.
I don't want to reinvent the wheel, but I don't which method I should choose to implement security.
My idea is to generate RSA keys between every peer and share these keys over an insecure socket at first and keep the connection secure with those keys. But I'm not sure about how to implement RSA and if this is the most secure way to go.
I'm using C++ for this project by the way
Thank you very much
You are looking for DTLS, the Datagram TLS.
It is like the TLS protocol that you know from HTTPS and various other secure point-to-point communication links, but it is implemented over UDP. You will find it already implemented in various libraries including GnuTLS and OpenSSL.
From the security point-of-view, one major difference between TLS and DTLS is that TLS defines an ill-formed message as an unrecoverable error, whereas DTLS specifically allows the connection to continue in this case. This makes the protocol more sensitive to even slight coding errors (think Lucky Thirteen), so you had better not try to implement it yourself.