Skip to content
Snippets Groups Projects
Select Git revision
  • 9dad7c69fd343f30e44218b5754f1357d110355e
  • master default
  • windows_ci_static
  • c_link
  • cpack
  • windows_ci
  • cert_pk_id
  • proxy_push_result
  • cnode_put_id
  • update-windows-build
  • proxy
  • resubscribe_on_token_change
  • actions
  • client_mode
  • llhttp
  • search_node_add
  • crypto_aes_gcm_argon2
  • ios_notifications
  • log_fmt
  • v2asio
  • fix-msvc
  • v3.4.0
  • v3.3.1
  • v3.3.1rc1
  • v3.3.1rc2
  • v3.3.0
  • v3.2.0
  • v3.1.11
  • v3.1.10
  • v3.1.9
  • v3.1.8.2
  • v3.1.8.1
  • v3.1.8
  • v3.1.7
  • v3.1.6
  • v3.1.5
  • v3.1.4
  • v3.1.3
  • v3.1.2
  • v3.1
  • v3.0.1
41 results

getif_workaround_android.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    getif_workaround_android.h 1.09 KiB
    //Code from getifaddrs.3 man
    #include <arpa/inet.h>
    #include <sys/socket.h>
    #include <ifaddrs.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <net/if.h>
    #include <asio.hpp>
    #include <stdexcept>
    namespace dht{
    namespace workaround{
    
    asio::ip::address_v4
    get_interface(){
        struct ifaddrs *ifaddr;
        if(getifaddrs(&ifaddr) == -1){
            throw std::runtime_error("Can't getifaddrs");
        }
        for (struct ifaddrs *if1 = ifaddr; if1 != NULL; if1 = if1->ifa_next){
            if (if1->ifa_addr == NULL)
                continue;
            if (if1->ifa_addr->sa_family != AF_INET)
                continue;
            if((if1->ifa_flags & IFF_MULTICAST) == IFF_MULTICAST){
                char* sa_data = if1->ifa_addr->sa_data;
                uint32_t value = sa_data[2] << 24
                    | sa_data[3] << 16
                    | sa_data[4] << 8
                    | sa_data[5];
                freeifaddrs(ifaddr);
                return asio::ip::address_v4(value);
            }
        }
        freeifaddrs(ifaddr);
        throw std::runtime_error("Can't find a interface which supports multicast");
    }
    
    } /* namespace workaround */
    } /* namespace dht */