KDK_NET_GET_ROUTE(3)

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

💖 KDK_NET_GET_ROUTE — ok bestie, let's talk gateways 💖

It's the kdk_net_get_route page from the KDK_NET_GET_ROUTE(3) library functions manual, and no cap, it's a lil baby page but it's important. It's 获取网关信息 — aka, it grabs your gateway info. Slay.


✨ NAME ✨

kdk_net_get_route — 获取网关信息 (get gateway information, bestie, that's the whole vibe) 🛣️


🌸 SYNOPSIS 🌸

#include <libkynetinfo.h>

extern prouteMapList kdk_net_get_route();

Link with -lkynetinfo.

So you include the header, you call the function, and you link against -lkynetinfo. Periodt. 💅


🦋 Detailed Description 🦋

The main character job of this interface? Obtain gateway information. That's it. That's the whole personality. It goes and gets the gateway info and hands it to you. Iconic behaviour honestly. 🫶


💀 RETURN VALUE 💀

On success, you get back a pointer to a prouteMapList structure stuffed with gateway information. A whole linked list of routes, just for you. 😭💖

The route structure is defined in <libkynetinfo.h> as follows:

typedef struct route
{
    char name[32]; //网卡名
    char addr[16]; //网关地址
    struct route *next;
} routeMapList, *prouteMapList;

So like: name is the 网卡名 (the NIC name), addr is the 网关地址 (the gateway address), and next is the pointer to the next one because we're doing linked-list things, iykyk. 🔗

On error, return NULL. That's it. That's the sad path. Not slay but it's honest. 🙈


⭐ EXAMPLES ⭐

Okay here's the full demo, bestie. Copy it, run it, live your truth. 🧚

#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;
}

And yes bestie, notice it calls kdk_net_free_route(list) when it's done with the route list, because we free our memory in this house. Also it does kdk_net_free_chain(chain), kdk_net_freeall(port), kdk_net_freeall(resolv), free(hosts), free(domain). Cleaning up is the ultimate main character move. 🧼✨


👑 CONFORMING TO 👑

These functions are as per the withdrawn POSIX.1e draft specification. (Withdrawn, bestie. RIP to that draft, it's giving history lesson.) 📜

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_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 🌈

Go read your sisters, they're all icons:


Ok that's the whole page, mwah 💋 This one came straight out of the Linux Programmer's Manual, dated Thu Sep 14 2023. Go get your gateway, bestie, you got this. 🎀🦋💜

📦 where this page comes from