-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ bindings #48
base: master
Are you sure you want to change the base?
C++ bindings #48
Conversation
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
Signed-off-by: Marek Küthe <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the time I thought it worthwhile to differenciate Tun and Tap strongly. Even with the C API being close to identical, the processing of the data isn't. With an unique tuntap class it becomes easier to dynamically do Tun or Tap, but it also becomes harder to statically make sure what kind of frames we are getting from the device.
If nothing speaks against it, perhaps the PR can be merged? |
When I was developing a program, I asked on Stackoverflow. In the example, I used this libtuntap library, among others. Someone there kindly noted that if there is an error in the constuctor, the destructor is never called and a memory leak occurs. I have now adapted the bindings as suggested on Stackoverflow so that a unique_ptr is used. |
Hello,
when I was working with the libtuntap in C++, I noticed a few things about the wrapper:
There are two different classes for tun devices and for tap devices. This is very inconvenient with memory allocation, since C/C++ has static typing. However, if you want to decide at runtime (e.g. based on configuration files) whether to use Tun or Tap, this is unfavorable.
One way to solve this would be to use a common parent class. However, since only the call to tuntap_start changes, a variable in the constructor makes more sense in my understanding.
Furthermore, there was no way to specify the tunnel ID.
Furthermore, there was faulty error handling. In my tests (it was my fault) I had the case that the interface name could not be set. This was not reported back. Instead, the function simply logged an output and pretended that everything was OK.
This is my attempt to improve these points. I also made a few beauty corrections. I also added an argument validation, which recognizes very simple errors and then throws an exception.