KDK_NET_FREE_CHAIN(3)

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

💖 KDK_NET_FREE_CHAIN 💖

okay bestie, welcome to KDK_NET_FREE_CHAIN(3) from the Library Functions Manual — yes she's a section 3 girlie and she's here to clean up your mess 💅 this one is the designated cleanup crew for your firewall info structs, and honestly? iconic behaviour.


✨ NAME ✨

kdk_net_free_chain — 释放由kdk_net_get_iptable_rules返回的防火墙信息结构体

(fr fr, it frees the firewall info struct that kdk_net_get_iptable_rules handed you 🧚 no leaks in this house.)


🌸 SYNOPSIS 🌸

#include <libkynetinfo.h>

extern void kdk_net_free_chain(pChain list);

Link with -lkynetinfo.


🦋 DETAILED DESCRIPTION 🦋

so the whole main character job of this interface is to release the firewall information structure that came back from kdk_net_get_iptable_rules. that's it. that's the gig. she takes the thing you got, and she lets it go 🕊️

the argument list is literally just the return value of kdk_net_get_iptable_rules. you got it from there, you hand it right back here. matching set, no cap. 🔥


🎀 RETURN VALUE 🎀

No return value. she gives you nothing back and that's the point, she's done her job and she's leaving 🫶


👑 EXAMPLES 👑

here's the full example, bestie — copied with love, every line, exactly as it lives:

#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_chain(chain) shows up right after that while(tmpchain) loop walks the whole chain? that's the moment. you walked the list, you printed everything, and now you free it. main character energy: look at it, love it, release it ✨


🌈 CONFORMING TO 🌈

These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn, bestie — she's vintage, she's archival, she's still serving 💜)

The following functions are Linux extensions: 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_route(), kdk_net_get_proc_port(), kdk_net_get_up_port(), kdk_net_get_hosts(), kdk_net_get_hosts_domain(), kdk_net_get_resolv_conf() and kdk_net_freeall().


⭐ SEE ALSO ⭐

the whole friend group, go say hi:


ok one last thing: kdk_net_free_chain is the twin of kdk_net_get_iptable_rules — you take from one, you give back to the other. don't skip the giving back. memory leaks are not the vibe 😭

and that's a wrap, bestie! this page comes to you from the Linux Programmer's Manual, dated Thu Sep 14 2023, filed under KDK_NET_FREE_CHAIN(3). go free your chains, you absolute legend 🎀💖✨

📦 where this page comes from