ohmu
·
2026-10-15
1#pragma once
2
3#include "fastfetch.h"
4#include "modules/localip/option.h"
5
6#ifndef IN6_IS_ADDR_GLOBAL
7 /* Global Unicast: 2000::/3 (001...) */
8 #define IN6_IS_ADDR_GLOBAL(a) (((a)->s6_addr[0] & 0xE0) == 0x20)
9#endif
10#ifndef IN6_IS_ADDR_UNIQUE_LOCAL
11 /* Unique Local: fc00::/7 (1111 110...) */
12 #define IN6_IS_ADDR_UNIQUE_LOCAL(a) (((a)->s6_addr[0] & 0xFE) == 0xFC)
13#endif
14#ifndef IN6_IS_ADDR_LINKLOCAL
15 /* Link-Local: fe80::/10 (1111 1110 10...) */
16 #define IN6_IS_ADDR_LINKLOCAL(a) (((a)->s6_addr[0] == 0xFE) && (((a)->s6_addr[1] & 0xC0) == 0x80))
17#endif
18
19typedef struct FFLocalIpResult {
20 FFstrbuf name;
21 FFstrbuf ipv4;
22 FFstrbuf ipv6;
23 FFstrbuf mac;
24 FFstrbuf flags;
25 int32_t mtu;
26 int32_t speed; // in Mbps
27 FFLocalIpType defaultRoute;
28} FFLocalIpResult;
29
30typedef struct FFLocalIpNIFlag {
31 uint32_t flag;
32 const char* name;
33} FFLocalIpNIFlag;
34
35static inline void ffLocalIpFillNIFlags(FFstrbuf* buf, uint64_t flag, const FFLocalIpNIFlag names[]) {
36 for (const FFLocalIpNIFlag* nf = names; flag && nf->name; ++nf) {
37 if (flag & nf->flag) {
38 if (buf->length > 0) {
39 ffStrbufAppendC(buf, ',');
40 }
41 ffStrbufAppendS(buf, nf->name);
42 flag &= ~nf->flag;
43 }
44 }
45}
46
47const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results);