KDK_NET_FREEALL(3)

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

✨ KDK_NET_FREEALL(3) ✨

okay bestie, sit down, we're learning a man page 💖 this one lives in the Library Functions Manual, and honestly? it's short, it's sweet, it's a little cleanup crew in function form.


🌸 NAME 🌸

kdk_net_freeall — 用于回收字符串列表 (bestie that's "for recycling a list of strings", no cap 🫶)


🌈 SYNOPSIS 🌈

#include <libkync.h>

extern inline void kdk_net_freeall(char **ptr);

Link with -lkyhw.
💅 heads up: you gotta link with -lkyhw, that's not optional, that's the vibe.

🦋 Detailed Description 🦋

So like, the whole main character job of this interface? It recycles a list of strings of type char **. That's it. That's the assignment. ✨

The argument ptr is a list of strings of type char **. Literally that's what it is. Lowkey the most self-explanatory parameter of all time and we're obsessed with the honesty 💀


💜 RETURN VALUE 💜

No return value. It's giving void energy. It frees and it leaves. No receipts, no follow-up questions. 🌸


🎀 EXAMPLES 🎀

okay this is the whole demo, and it's a LOT — it's showing kdk_net_freeall working alongside its whole friend group. Copy it exactly, don't get creative, bestie:

#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_freeall shows up three whole times in there? main character energy, fr fr 👑 note that kdk_net_get_hosts() and kdk_net_get_hosts_domain() get plain old free() instead, because they're single strings, not lists. iykyk 🧚


⭐ CONFORMING TO ⭐

These functions are as per the withdrawn POSIX.1e draft specification. 👀 (withdrawn! gone! iconic but gone!)

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_get_netmask()
  • kdk_net_free_chain()
  • kdk_net_get_up_port()
  • kdk_net_get_hosts()
  • kdk_net_get_hosts_domain()
  • kdk_net_get_proc_port()
  • kdk_net_get_resolv_conf()

🔥 SEE ALSO 🔥

go read the whole squad, they're all linked here and they all ate:


okay that's the whole page, you're officially educated 💖 this one came from the Linux Programmer's Manual, dated Thu Sep 14 2023 — shoutout to the author of this little string-recycler, whoever you are, you understood the assignment 🫶 go free some strings, bestie, and don't leak memory, periodt. ✨🎀

📦 where this page comes from