KDK_NET_FREE_ROUTE(3)

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

💖 KDK_NET_FREE_ROUTE — the libkynetinfo cleanup bestie 💖

okay so this is kdk_net_free_route(3), a library function from the Library Functions Manual, and honestly? she's the responsible friend who makes sure nobody leaves their gateway info just lying around. 🌸

✨ NAME ✨

kdk_net_free_route — 释放由 kdk_net_get_route 返回的网关信息结构体

(translation for the girlies who don't read Chinese: she frees the gateway info struct that kdk_net_get_route handed you. you borrow it, you give it back. periodt. 💅)

✨ SYNOPSIS ✨

#include <libkynetinfo.h>

extern void kdk_net_free_route(prouteMapList list);

Link with -lkynetinfo.

lowkey the most important line here is the last one. if you forget -lkynetinfo the linker will simply Not Know Her. 😭

✨ Detailed Description ✨

so the main character job of this interface? it's to release the gateway information structure that came back from kdk_net_get_route. that's it. that's the whole vibe. 🦋

and the argument, list, is literally the return value of kdk_net_get_route. you don't construct it, you don't guess at it, you just hand back exactly what you were given. no cap. 💖


✨ RETURN VALUE ✨

No return value.

she gives you nothing back and that's correct. her job is to take things away. iconic behaviour honestly. 👑

✨ EXAMPLES ✨

here's the whole example, copied exactly because we do not mess with code in this house 🫶

#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 kdk_net_free_route(list) shows up right after the while loop walks the list? yeah. you read the routes, then you let her go. clean. ✨


✨ CONFORMING TO ✨

These functions are as per the withdrawn POSIX.1e draft specification. 📜

and then, the plot twist — these following functions are Linux extensions, meaning they're the special extra ones, not the standard ones:

  • kdk_net_get_netmask()
  • kdk_net_get_port_stat()
  • kdk_net_get_multiple_port_stat()
  • kdk_net_get_iptable_rules()
  • kdk_net_get_route()
  • kdk_net_free_chain()
  • kdk_net_get_proc_port()
  • kdk_net_get_up_port()
  • kdk_net_get_hosts()
  • kdk_net_get_hosts_domain()
  • kdk_net_get_resolv_conf()
  • kdk_net_freeall()
note that kdk_net_free_route herself is not on that extension list — she's the POSIX.1e draft-spec girlie. the withdrawn one. vintage. 💜

✨ SEE ALSO ✨

go read these next bestie, they're all in the same friend group 🎀


okay that's the whole page!! 🥳 this little angel lives in the Linux Programmer's Manual, dated Thu Sep 14 2023, and she'll be right here whenever you need to free your route. remember: you got the pointer, you give it back, and everyone goes home happy. mwah 💋✨

📦 where this page comes from