snat like example for c#

Home Forums Discussions Support Portal snat like example for c#

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #12210
    nekron
    Participant

    Hi …

    is there any example working like the legacy example snat ?

    thanks for your help

    #12211
    Vadim Smirnov
    Keymaster

    Unfortunately, no. Personally, I prefer C/C++ for protocol header manipulation, and when I had a need for NAT in a C# project, I implemented it as a C++/CLI class library.

    #12212
    nekron
    Participant

    Thanks for your fast response !

    I tried to generate a dll out of the sample – but my c++ knowledge is basically zero …

    maybe you have an sample like snat in a dll ?

    • This reply was modified 5 months, 2 weeks ago by nekron.
    #12214
    Vadim Smirnov
    Keymaster

    As I mentioned above, I once re-implemented NAT as a C++/CLI class library having the interface below. However, it’s a little complicated for the sample and I also need to preserve some sugar cubes for the customers.

    
    
    // natcl.h
    
    #pragma once
    
    using namespace System;
    using namespace Collections::Generic;
    using namespace Threading;
    using namespace msclr::interop;
    
    namespace nat_managed_lib
    {
    public ref class managed_network_adapter_info sealed
    {
    String^ adapter_name_;
    String^ friendly_name_;
    List<String^>^ ip_addresses_;
    
    public:
    property String^ AdapterName
    {
    String^ get() { return adapter_name_; }
    void set(String^ value) { adapter_name_ = value; }
    }
    
    property String^ FriendlyName
    {
    String^ get() { return friendly_name_; }
    void set(String^ value) { friendly_name_ = value; }
    }
    
    property List<String^>^ IpAddresses
    {
    List<String^>^ get() { return ip_addresses_; }
    void set(List<String^>^ value) { ip_addresses_ = value; }
    }
    };
    
    public ref class nat_wrapper sealed
    {
    public:
    event EventHandler^ AdaptersListChangeEvent;
    
    private:
    ManualResetEvent^ adapters_list_change_notify_event_;
    Thread^ adapter_list_change_notify_thread_;
    volatile bool is_adapter_list_change_thread_active_ = true;
    
    bool set_adapter_list_change_event();
    void adapter_list_change_thread();
    
    native::nat_unmanaged* native_nat_provider_;
    
    public:
    explicit nat_wrapper(String^ device_name);
    !nat_wrapper();
    ~nat_wrapper();
    
    List<managed_network_adapter_info^>^ get_network_adapters();
    
    Boolean set_nat_parameters(
    // provider interface name
    String^ provider,
    // client interface name
    String^ client,
    // provider IP address to be used for NAT (adapter may have multiply IP addresses)
    String^ nat_ip,
    // DNS IP address for DNS forwarding
    String^ dns_ip,
    // Enable DNS forwarding (redirect DNS requests to the IP above). Otherwise client provided IP is used for DNS.
    Boolean dns_forwarding
    );
    
    Boolean start_nat();
    Boolean stop_nat();
    Boolean is_started();
    
    Boolean is_ip_routing_dynamic_success();
    
    void re_initialize();
    
    Boolean block_client_ip_address(String^ ip_address);
    Boolean block_client_mac_address(String^ mac_address);
    };
    }
    
    
    • This reply was modified 5 months, 2 weeks ago by Vadim Smirnov.
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.