KDK_NET_GET_RESOLV_CONF(3)

📦 version 3.0.1.4, in arch rolling, ubuntu resolute, ubuntu stonking

💖 KDK_NET_GET_RESOLV_CONF(3) 💖

okay bestie, welcome to the Library Functions Manual ✨ we're talking about kdk_net_get_resolv_conf from the libkynetinfo girlies, and honestly? she's serving exactly one job and she does it. let's get into it 🎀


🌸 NAME 🌸

kdk_net_get_resolv_conf — 获取DNS配置文件 (yes bestie, she grabs your DNS config file, that's the whole vibe 🦋)


✨ SYNOPSIS ✨

#include <libkynetinfo.h>

extern char** kdk_net_get_resolv_conf();

Link with -lkynetinfo.

like literally just link her in and you're set 💅


💜 Detailed Description 💜

The main character energy of this interface is: obtain the DNS configuration file. that's it. that's the function. no cap, that is literally the entire purpose 🙈


🫶 RETURN VALUE 🫶

On success? she returns the DNS configuration file, typed as char **, and it's ending with a NULL character so you know where the party stops 🎉

⚠️ bestie listen. this thing is Generated by alloc and it needs to be recycled by kdk_net_freeall. you do NOT just let it sit there. free your girl or it's a leak, and we don't do leaks in this house 💀

On error, return NULL. that's it, that's the fail state 😭


🌈 EXAMPLES 🌈

here's the whole demo, copied exactly, no edits, she is what she is 💖

#include "libkynetinfo.h"
#include "stdio.h"
#include "stdlib.h"

int main(int argc, char *argv[])
{
    prouteMapList list = kdk_net_get_route(), tmp = list;
    while (tmp)
    {
        printf("%s default route %s0, tmp->name, tmp->addr);
        tmp = tmp->next;
    }
    kdk_net_free_route(list);
    if (argc < 2)
        printf("please input test port num0);
    else
        printf("port:%s's state %d0, argv[1], kdk_net_get_port_stat(atoi(argv[1])));

    pChain chain = kdk_net_get_iptable_rules();
    pChain tmpchain = chain;
    while(tmpchain)
    {
        printf("Chain: %spolice: %s0,tmpchain->total,tmpchain->policy);
        pChainData tmpData = tmpchain->data;
        if(tmpData)
            printf("target: %sprot: %sopt: %ssource: %sdestination: %soption: %s0,tmpData->target,tmpData->prot,tmpData->opt,
                                tmpData->source,tmpData->destination,tmpData->option);
        printf("0);
        tmpchain = tmpchain->next;
    }
    kdk_net_free_chain(chain);

    int result[65536];
    int net = kdk_net_get_multiple_port_stat(0, 1000, result);
    if(net == 0)
    {
        size_t count = 0;
        for(;count < 1000 ;count++)
        {
            printf("%d", result[count]);
        }
    }
    else
        printf("Failed With %d", net);
     printf("0);

    char mask[32] = " ";
    kdk_net_get_netmask("enaftgm1i0", mask);
    printf("mask = %s0, mask);

    char **port = kdk_net_get_proc_port();
    size_t index = 0;
    while(port[index])
    {
        printf("No.%ld, port = %s0, index+1, port[index]);
        index++;
    }
    kdk_net_freeall(port);

    port = kdk_net_get_up_port();
    index = 0;
    while(port[index])
    {
        printf("No.%ld, port = %s0, index+1, port[index]);
        index++;
    }
    kdk_net_freeall(port);

    char *hosts = kdk_net_get_hosts();
    if (hosts != NULL)
    {
        printf("hosts = %s0, hosts);
        free(hosts);
    }

    char *domain = kdk_net_get_hosts_domain();
    if (domain != NULL)
    {
        printf("domain = %s0, domain);
        free(domain);
    }

    char **resolv = kdk_net_get_resolv_conf();
    index = 0;
    while(resolv[index])
    {
        printf("No.%ld, resolv = %s0, index+1, resolv[index]);
        index++;
    }
    kdk_net_freeall(resolv);
    return 0;
}

see how at the end she calls kdk_net_get_resolv_conf(), loops while resolv[index] is truthy, prints each one, and then — the moment we've all been waiting for — kdk_net_freeall(resolv) 🧚 iconic. responsible. we love to see it 👑


👑 CONFORMING TO 👑

These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn, bestie. it's giving vintage. it's giving deprecated-by-history 📜)

The following functions are Linux extensions:

  • kdk_net_get_multiple_port_stat()
  • kdk_net_get_port_stat()
  • kdk_net_get_route()
  • kdk_net_get_iptable_rules()
  • kdk_net_free_route()
  • kdk_net_free_chain()
  • kdk_net_get_netmask()
  • kdk_net_get_proc_port()
  • kdk_net_get_hosts()
  • kdk_net_get_hosts_domain()
  • kdk_net_get_up_port()
  • kdk_net_freeall()

🔥 SEE ALSO 🔥

go read her friends, they're all so valid 💅


aaaand that's the whole page bestie 🎀 she lives in the Linux Programmer's Manual, dated Thu Sep 14 2023, and this one is officially wrapped. go free your char ** and hydrate 💖✨🦋🌸🫶

📦 where this page comes from