KDK_NET_GET_IPTABLE_RULES(3)

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

✨ KDK_NET_GET_IPTABLE_RULES(3) ✨

okay bestie sit DOWN because we're doing a Library Functions Manual page today 💅 this is kdk_net_get_iptable_rules from the libkynetinfo girlies and she is literally the firewall info getter. no cap.


🎀 NAME 🎀

kdk_net_get_iptable_rules — 获取防火墙信息 (aka: go get me the firewall info, bestie 🔥)


🌸 SYNOPSIS 🌸

#include <libkynetinfo.h>

extern pChain kdk_net_get_iptable_rules();

Link with -lkynetinfo.
link with -lkynetinfo or she will NOT link. fr fr. that's not a vibe, that's a requirement 💀

🦋 Detailed Description 🦋

so the whole main character job of this interface is to obtain firewall information. that's it. that's the gig. she pulls the firewall tea and hands it to you ✨


👑 RETURN VALUE 👑

On success, she returns a pointer to a pChain structure containing firewall information. slay.

the pChain structure is defined in <libkynetinfo.h> as follows (copying this EXACTLY because structs are not a vibe to paraphrase, periodt):

typedef struct chain
{
    char total[16]; //链名
    char policy[32]; //链的规则
    pChainData data;
    struct chain *next;
} Chain, *pChain;

typedef struct chain_data
{
    char target[8];
    char prot[4 + 1];
    char opt[4 + 1];
    char source[32];
    char destination[64];
    char option[128];
    struct chain_data *next;
} chainData, *pChainData;

On error, return NULL. that's it, that's the whole failure mode, and honestly? iconic. when you see NULL just know she said "no 💅".


🌈 EXAMPLES 🌈

here's the full demo, verbatim, typos and all (we do NOT touch the code, we only stan it):

#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 she calls kdk_net_get_iptable_rules(), walks the chain with tmpchain = tmpchain->next, prints tmpchain->total and tmpchain->policy, dips into tmpchain->data for target, prot, opt, source, destination and option, and then cleans up with kdk_net_free_chain(chain)? that's the whole loop. main character energy only 💖


💜 CONFORMING TO 💜

these functions are as per the withdrawn POSIX.1e draft specification. yes, withdrawn. we're serving vintage, bestie 🎀

the following functions are Linux extensions: kdk_net_get_netmask(), kdk_net_get_port_stat(), kdk_net_get_multiple_port_stat(), kdk_net_get_route(), kdk_net_free_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() and kdk_net_freeall().


💅 SEE ALSO 💅


that's the whole page bestie, go read the friends, they're all in the same friend group 🫶

okay bye pookie, this was the Linux Programmer's Manual edition of KDK_NET_GE...TABLE_RULES(3), dated Thu Sep 14 2023 — literally so 2023 of her, and yes the name in the corner is truncated like that, she's mysterious like that 💀✨ love that for her. mwah 🍓

📦 where this page comes from