KDK_NC_GET_IPV6(3)

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

💖 KDK_NC_GET_IPV6(3) 💖

okay so bestie, welcome to the KDK_NC_GET_IPV6(3) page from the Library Functions Manual ✨ this is where we learn how to grab every single IPv6 address off a network card, and honestly? it's giving main character energy 👑


🌸 NAME 🌸

kdk_nc_get_ipv6 — 获取指定网卡的所有IPv6地址 (aka: go get ALL the IPv6 addys for the NIC you point at) 🦋


✨ SYNOPSIS ✨

#include <libkync.h>

extern char** kdk_nc_get_ipv6(const char* nc);

Link with -lkyhw. don't forget it, fr fr 💅


🎀 Detailed Description 🎀

The main function of the interface is to obtain all IPv6 addresses of the specified NIC nc 🫶

The argument nc is the name of the NIC, such as "eno1". like, that's the whole vibe. you hand it a card name, it hands you back the addresses 💖


🌈 RETURN VALUE 🌈

  • On success, returns a list of IPv6 addresses, ending with NULL, generated by alloc and required to be recycled by kdk_nc_freeall ♻️ (yes bestie, YOU have to free it. it's not gonna clean up after itself 😭)
  • On error, return NULL. that's it. that's the whole warning 🚨

💀 EXAMPLES 💀

here's the full serve, no cap:

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

like, look at her go 😭 she loops through every card, prints the whole little profile, then pulls AllIpV4 and AllIpV6 lists and walks them with an index counter until NULL. iconic behavior. and then — the important part — every single pointer gets free'd and both card lists get kdk_nc_freeall'd 🧚 memory hygiene is self care, bestie 💜


👑 CONFORMING TO 👑

These functions are as per the withdrawn POSIX.1e draft specification. 🕰️ (withdrawn, babe. retro. vintage.)

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_ipv4(), kdk_nc_is_wireless(), kdk_nc_get_vendor_and_product(), kdk_nc_get_driver(), and kdk_nc_freeall(). 🐧 so if you're not on Linux, vibe check accordingly 💅


🦋 SEE ALSO 🦋

go read the whole friend group, they're all slaying in their own lanes 🌈


and that's a wrap!! this lil masterpiece comes to you from the Linux Programmer's Manual, dated Fri Aug 25 2023 📅 periodt. now go free your pointers before you leak something, ily, bye 💖✨🎀

📦 where this page comes from