KDK_NET_GET_UP_PORT(3)
okay so you pulled up kdk_net_get_up_port(3) — yes bestie, it's from the Library Functions Manual, and it's lowkey one of the cutest little helpers hanging out in libkynetinfo. Grab a snack, hydrate, we're doing this. 💖
🌸 NAME 🌸
kdk_net_get_up_port — 获取所有UP状态的端口号 — which is just "gimme every port number that's currently in UP state". That's the whole gig. She's focused, she's iconic, she does one thing. 🫶
🦋 SYNOPSIS 🦋
#include <libkynetinfo.h>
extern char **kdk_net_get_up_port();
Link with -lkynetinfo. Do not skip that part, or the linker will act like it's never met her. 💅
🎀 Detailed Description 🎀
The main function of the interface is to obtain the port number for all UP statuses. That's literally the mission statement. Every port that's up and living its truth gets collected. No notes. ✨
✨ RETURN VALUE ✨
- On success — returns the port number for all UP statuses of type
char **, and the list ends with aNULLcharacter. It was generated byalloc, so you HAVE to recycle it withkdk_net_freeall. Leaving it there is a memory leak and leaks are not the vibe. 🚫🧚 - On error — returns
NULL.
🔥 EXAMPLES 🔥
Bestie, this example is a whole tour of the entire library, not just one function. It's giving "main character demo file". Every line is verbatim, don't you dare retype it from memory. 👑
#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_up_port(), walks the char ** until she hits that NULL, prints each one, and then hands the whole thing back with kdk_net_freeall(port)? That's the pattern, memorise it, it's a whole lifestyle. 💅
👑 CONFORMING TO 👑
These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn, so, y'know, it's giving vintage. Not our problem.) 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_netmask()kdk_net_get_proc_port()kdk_net_get_hosts()kdk_net_get_hosts_domain()kdk_net_get_resolv_conf()kdk_net_freeall()
💜 SEE ALSO 💜
Go read her friends, they're all slaying in their own lanes:
kdk_net_get_multiple_port_stat(3)kdk_net_get_port_stat(3)kdk_net_get_route(3)kdk_net_get_iptable_rules(3)kdk_net_free_route(3)kdk_net_free_chain(3)kdk_net_get_netmask()kdk_net_get_proc_port(3)kdk_net_get_hosts(3)kdk_net_get_hosts_domain(3)kdk_net_get_resolv_conf(3)kdk_net_freeall(3)
and that's the page!! 🎀✨ This one came to you courtesy of the Linux Programmer's Manual, dated Thu Sep 14 2023, filed forever under KDK_NET_GET_UP_PORT(3). Free your char **, text your friends, and go get that UP state. Periodt. 💖🦋
📦 where this page comes from
- arch rolling: libkysdk-system 3.0.1.4-1 · LGPL-3.0-or-later AND LGPL-2.1-only OR LGPL-3.0-only AND LGPL-2.1-only WITH Qt-LGPL-exception-1.1 OR LGPL-3.0-only WITH Qt-LGPL-exception-1.1 AND MIT
- ubuntu resolute: libkysdk-system-dev 3.0.1.2-0ubuntu1 · LGPL-3.0-only
- ubuntu stonking: libkysdk-system-dev 3.0.1.3-0ubuntu1 · LGPL-3.0-or-later
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms