KDK_NC_GET_IPV4(3)
👑 KDK_NC_GET_IPV4 👑 — the kdk_nc_get_ipv4(3) page, bestie edition 💅
okay so you're here for kdk_nc_get_ipv4, and honestly? good taste. this is a section 3 library functions manual page from the Linux Programmer's Manual, and it's about yoinking every single IPv4 address off one specific network card. let's get into it 🦋
✨ NAME ✨
kdk_nc_get_ipv4 — 获取指定网卡的所有IPv4地址
fr fr that's "get all IPv4 addresses of the specified NIC" in Chinese, and it's giving exactly what it says on the tin 💖
🌸 SYNOPSIS 🌸
#include <libkync.h>
extern char** kdk_nc_get_ipv4(const char* nc);
and listen, bestie, you gotta link with -lkyhw or none of this works. no cap. 🔥
💜 Detailed Description 💜
So the whole main character job of this function is to obtain all IPv4 addresses of the NIC you point it at — that's the nc argument.
The argument nc is the name of the NIC, like "eno1" for example. that's it. that's the whole vibe check. 🎀
🫶 RETURN VALUE 🫶
- On success — you get back a list of IPv4 addresses, and it's terminated with
NULL. it was generated byalloc, so you have to recycle it withkdk_nc_freeall. do NOT forget this. memory leaks are not the vibe 😭 - On error — it just returns
NULL. no drama, just nothing. 💀
🌈 EXAMPLES 🌈
here's the full demo, bestie, copy it exactly, every character, i'm literally watching 👀
#include "libkync.h"
#include <stdio.h>
#include <stdlib.h>
int main()
{
char **cards = kdk_nc_get_cardlist();
size_t index = 0;
printf("所有网卡:\n");
while (cards[index])
{
char *mac = kdk_nc_get_phymac(cards[index]);
char *ipv4 = kdk_nc_get_private_ipv4(cards[index]);
char *ipv6 = kdk_nc_get_private_ipv6(cards[index]);
char *driver = kdk_nc_get_driver(cards[index]);
char vendor[256] = " ", product[256] = " ";
kdk_nc_get_vendor_and_product(cards[index], vendor, product);
printf("Card %zd: %sStatus: %sMac: %sIPv4: %sIPv6: %s Vendor: %s Product: %s Type: %s driver: %s\n",
index + 1, cards[index], kdk_nc_is_up(cards[index]) == 1 ? "Up" : "Down",
mac, ipv4, ipv6, vendor, product,
kdk_nc_is_wireless(cards[index]) ? "wireless" : "ethernet", driver);
char **list4 = kdk_nc_get_ipv4(cards[index]);
int i = 0;
printf("AllIpV4: ");
while (list4 && list4[i])
{
printf("%s", list4[i++]);
}
printf("\n");
char **list6 = kdk_nc_get_ipv6(cards[index]);
printf("AllIpV6: ");
i = 0;
while (list6 && list6[i])
{
printf("%s", list6[i++]);
}
printf("\n");
free(mac);
free(ipv4);
free(ipv6);
free(list4);
free(list6);
free(driver);
index++;
}
kdk_nc_freeall(cards);
char **upcards = kdk_nc_get_upcards();
index = 0;
printf("工作网卡:\n");
while (upcards[index])
{
printf("Card %zd: %s\n", index + 1, upcards[index]);
index++;
}
kdk_nc_freeall(upcards);
return 0;
}
see how it walks every card, grabs the kdk_nc_get_ipv4 list, prints each one in a while (list4 && list4[i]) loop, then frees everything? that's the energy. ate. 🍓
🧚 CONFORMING TO 🧚
These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn!! we still love her tho 💜)
The following functions are Linux extensions:
kdk_nc_is_up()kdk_nc_get_cardlist()kdk_nc_get_phymac()kdk_nc_get_private_ipv4()kdk_nc_get_upcards()kdk_nc_get_private_ipv6()kdk_nc_get_ipv6()kdk_nc_is_wireless()kdk_nc_get_vendor_and_product()kdk_nc_get_driver()kdk_nc_freeall()
💖 SEE ALSO 💖
go read these next, i'm obsessed with all of them:
kdk_nc_is_up(3)kdk_nc_get_cardlist(3)kdk_nc_get_phymac(3)kdk_nc_get_private_ipv4(3)kdk_nc_get_upcards(3)kdk_nc_get_private_ipv6(3)kdk_nc_get_ipv6(3)kdk_nc_is_wireless(3)kdk_nc_get_vendor_and_product(3)kdk_nc_get_driver(3)kdk_nc_freeall(3)
🎀 quick reminder before you go: that list fromkdk_nc_get_ipv4is yours to free withkdk_nc_freeall. free your pointers, protect your peace. 🫶
and that's the whole page, bestie!! this one lives in the Linux Programmer's Manual, dated Fri Aug 25 2023 — so it's vintage, it's iconic, it's lowkey a classic. go forth and enumerate those IPv4 addresses. 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