Both server and socket reporting ECONNRESET. Whats going on? [closed] - c++

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 5 years ago.
Improve this question
I have a C++ server and client.
I am using the poll() system call to monitor sockets on the server for read-ready, write-ready and errors.
For some of the connections, I see the poll() detects an ECONNRESET after sending out a bunch of data and fails midway. On the client side too, I see a ECONNRESET being reported.
So essentially both sides are reporting that the remote side closed the connection.
How can this happen?
How do I debug this? Is there any tcp layer logging that I can enable?

Is there any tcp layer logging that I can enable?
The most common tool to enable you seeing what's going on at your low level IP transport channels is Wireshark.
You can inspect any packets send and received over your NIC in detail with that tool.
Another one is tcpdump for linux systems.

Related

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.

Connection Management in UDP with 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 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".

Firebase C++ realtime database connection lost on Windows [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 3 years ago.
Improve this question
I have been using Firebase C++ SDK's Auth and Realtime Database (for Windows) in a simple test application. After a succesful authentication every new message (node) is being arrived from the cloud within just a few millisecs until the following happens:
I leave my computer untouched in idle state.
Due to the energy settings it goes to sleep after 10-15 minutes. (don't want to change the settings!)
After I wake it up again the network connection is re-established for all other background applications (like Skype, Outlook etc)
It seems Firebase's connection is NOT re-established.
Is there any built-in function to get notification from Firebase when it's lost the connection and try to re-login, re-connect to the database either automatically or manually?
I guess it has a background keep-alive connection to check network status but I couldn't get any useful information about it. The documentation says it can keep everything synced even in offline mode.
any built-in function to get notification from Firebase when it's lost the connection[?]
For that you'd attach a listener to the virtual .info/connected node, as shown here: https://firebase.google.com/docs/database/android/offline-capabilities#section-connection-state. Somehow this section is missing from the C++ documentation, which is why I linked you to the Android version.

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 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.