KDK_NET_GET_NETMASK(3)

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

💖 KDK_NET_GET_NETMASK(3) — kdk_net_get_netmask 🦋

okay bestie, sit down, hydrate, because we're learning a libkynetinfo function and it's lowkey adorable. this is section 3 of the Library Functions Manual, so it's a C library call, not a command you type at a shell. no cap. 💅


✨ NAME ✨

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

(fr fr, that's the line as written in the page — i'm not touching it. the prose further down says the actual main job is grabbing subnet mask info, so read both, ok? 🫶)


🌸 SYNOPSIS 🌸

#include <libkynetinfo.h>

extern void kdk_net_get_netmask(IN const char *nc, OUT char *mask);

Link with -lkynetinfo.

bestie note: that IN and OUT? they're just annotations telling you which arg goes in and which one gets written to. the function returns void so the only way you get anything back is through mask. 👑

💜 Detailed Description 💜

The main function of the interface is to obtain subnet mask information. that's the whole assignment. the main character task. 🎀

The argument nc is the name of the NIC, such as "eno1".

The argument mask is the subnet mask information.

so: you hand it a network interface name, it fills in your mask buffer. two args, no drama. ✨


🫶 RETURN VALUE 🫶

No return value.

like, literally none. it's void. don't go assigning the result to anything, there's nothing to catch. 🙈


🔥 EXAMPLES 🔥

here's the full example program from the page, copied exactly so you can paste it and vibe:

#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 the mask moment? that's our girl working her shift:

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

char mask[32] gets a buffer, the NIC name "enaftgm1i0" goes in, and the mask lands in mask. iconic behavior. 🌈


⭐ CONFORMING TO ⭐

These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn!! say it with me: withdrawn. it's giving vintage, not current. 🕰️)

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_proc_port()
  • kdk_net_get_up_port()
  • kdk_net_get_hosts()
  • kdk_net_get_hosts_domain()
  • kdk_net_get_resolv_conf()
  • kdk_net_freeall()

🦋 SEE ALSO 🦋


okay that's the whole page, you ate it, i'm so proud. 💖

mwah 💋 — this one's from the Linux Programmer's Manual, dated Thu Sep 14 2023, and it lives under KDK_NET_GET_NETMASK(3). go get that mask bestie, ily. ✨👑🌸

📦 where this page comes from