static int ConfigureNetworkInterfaceWithCustomDns()

in CodeSnippets/Networking/CustomDns/custom_dns.c [28:61]


static int ConfigureNetworkInterfaceWithCustomDns(void)
{
    Networking_IpConfig ipConfig;

    // Convert the addresses from the numbers-and-dots notation into integers.
    struct in_addr dnsServers[numOfDnsServerAddressSpecified];
    for (int i = 0; i < numOfDnsServerAddressSpecified; i++) {
        if (inet_pton(AF_INET, dnsServerIpAddress[i], &dnsServers[i]) != 1) {
            Log_Debug("ERROR: Invalid DNS server address or address family specified.\n");
            return -1;
        }
    }

    Networking_IpConfig_Init(&ipConfig);

    int result =
        Networking_IpConfig_EnableCustomDns(&ipConfig, dnsServers, numOfDnsServerAddressSpecified);

    if (result != 0) {
        Log_Debug("ERROR: Networking_IpConfig_EnableCustomDns: %d (%s)\n", errno, strerror(errno));
        Networking_IpConfig_Destroy(&ipConfig);
        return -1;
    }

    result = Networking_IpConfig_Apply(networkInterfaceToConfigure, &ipConfig);
    Networking_IpConfig_Destroy(&ipConfig);

    if (result != 0) {
        Log_Debug("ERROR: Networking_IpConfig_Apply: %d (%s)\n", errno, strerror(errno));
        return -1;
    }

    return 0;
}