From 8864d3e009749317d0512410af5f9c83c330bef7 Mon Sep 17 00:00:00 2001 From: coast Date: Thu, 29 May 2025 22:51:56 +0200 Subject: [PATCH] Upload files to ".suckless/slstatus/components" --- .suckless/slstatus/components/entropy.c | 29 ++++++++ .suckless/slstatus/components/entropy.o | Bin 0 -> 1800 bytes .suckless/slstatus/components/hostname.c | 17 +++++ .suckless/slstatus/components/hostname.o | Bin 0 -> 1656 bytes .suckless/slstatus/components/ip.c | 87 +++++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 .suckless/slstatus/components/entropy.c create mode 100644 .suckless/slstatus/components/entropy.o create mode 100644 .suckless/slstatus/components/hostname.c create mode 100644 .suckless/slstatus/components/hostname.o create mode 100644 .suckless/slstatus/components/ip.c diff --git a/.suckless/slstatus/components/entropy.c b/.suckless/slstatus/components/entropy.c new file mode 100644 index 0000000..65010b0 --- /dev/null +++ b/.suckless/slstatus/components/entropy.c @@ -0,0 +1,29 @@ +/* See LICENSE file for copyright and license details. */ +#include "../slstatus.h" +#if defined(__linux__) + #include + #include + + #include "../util.h" + + #define ENTROPY_AVAIL "/proc/sys/kernel/random/entropy_avail" + + const char * + entropy(const char *unused) + { + uintmax_t num; + + if (pscanf(ENTROPY_AVAIL, "%ju", &num) != 1) + return NULL; + + return bprintf("%ju", num); + } +#elif defined(__OpenBSD__) | defined(__FreeBSD__) + const char * + entropy(const char *unused) + { + // https://www.unicode.org/charts/PDF/U2200.pdf + /* Unicode Character 'INFINITY' (U+221E) */ + return "\u221E"; + } +#endif diff --git a/.suckless/slstatus/components/entropy.o b/.suckless/slstatus/components/entropy.o new file mode 100644 index 0000000000000000000000000000000000000000..53d9b826a654b98a1b893261bafd83408dcde303 GIT binary patch literal 1800 zcmbtUO=}Zj5S~pF8?lBe6#`Y*Ln`&_%?Hh;Pz|Ko6^aL`pa+SY&BoLuo4C7?Mh_l( zv4leZfd9i|K|z0lXT9{`LGMDG*~}!{ZHk}+Z)fJ2d1l_cGu^j$H}AzX4Ma4!4HHjL zfOj(!yA+ruNWpn9c7LRe{URa8{u-&8F^DfMlfSo~N#+lYy>CZ^55IgM)tfg4D;drW z0>)q~ldKsx76O)^7=gQ=(jS*z^dQ@HJ66`~d)cP#I(94Tnoh0L&f1RecDntF`O4gG z0c@1ZtNQZBgGbl&d{O09UN7Vd#oS6ExEeqlTkCidcrXiMpdAt>zg3I)3m7BOUOxnF zXI@*Jn@t{IGU1nl2*6X)>nT0-)lA<6RrNejZigI7$87^;b=qxwD^O0yw-v6~t>7`( zf9~`YE^^m){XSBupxvm{U9)YEZ}4A+j%?aBdb6;U*pa=EnC!jyi)hfBmjqz_j34QM zecDgr%EG4^r@0Xx`b-3o_Z*L^Xn)#2s`;<{JaVaK0Z&+@|Mf74w)7WWVk{TQ`^>)l z&r4W%qVF?b;-bHc5z)dE_z4=czsGhG{Uc6@-b>z}!|)Ofsu|^{xzXSF_z9gl|DRk? z=1lWHi%0qkKCL&Vfx-R1l7ljbhrVu6KGlrQ9wE@V{~9?V;j&}o0$S7fNe17HGe<_0 F{|A)uwEh49 literal 0 HcmV?d00001 diff --git a/.suckless/slstatus/components/hostname.c b/.suckless/slstatus/components/hostname.c new file mode 100644 index 0000000..dab8b63 --- /dev/null +++ b/.suckless/slstatus/components/hostname.c @@ -0,0 +1,17 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include + +#include "../slstatus.h" +#include "../util.h" + +const char * +hostname(const char *unused) +{ + if (gethostname(buf, sizeof(buf)) < 0) { + warn("gethostbyname:"); + return NULL; + } + + return buf; +} diff --git a/.suckless/slstatus/components/hostname.o b/.suckless/slstatus/components/hostname.o new file mode 100644 index 0000000000000000000000000000000000000000..e678e250ff6529f528eae90f3cf2e086aa8f44d0 GIT binary patch literal 1656 zcmb_cL2DCH5S~q|skFwlSP<%Ay@;YdvcX&mmX)BbPy_`JdeKeXHqd6b?!IDT4|?gb z;1BTNFOdcRfIp+)$y*OXop19ddA>#jap2|6eDlrBd-G=V{=w$MiszAtM{6{(1SLAD zO!Tl+L#ok5dh&&4i8hYz0XxReVKH0^3L6QE@70Z?b8x=+x*h9Yn(NLmiTd#>(R#bR z>fcy@{OqP5v{ax1zu9QE8h4v5@R6K+UWjHARmdxV$r(MzzRW&|_wFfqgSxk}P@Vh8 zWZ+jz4^e>qeyyI?<_vOnL;hL%aeCH6G&8O~@h+5VdB+LJ+7(_)7Qd{`*dnhwFIScs zn1)~b15RirTB*9EHroyA>~E3jF<^QdWeLY#Fop1pIOWgNk<<*1o}Rbx6@!C6W8uER z!LM5QErYxHeG9inh)CtbzK%M)>uj|5M9bpcNa=W>NxhDAM5>eLq_PwS=sYB(x@o^3 zCrn9F9V;GzXSRgKkardzxVE6b z=wWDstREZVz~J+|1CmL_JVCDW0*<$_<&AAvx?BG?`;hZr<8eRaZ1S>2>R+-!)}_Ae zp}`ss?}M@BTNSs&$^M8Pq6-K6C)==em;0Q3nBU)KlI_pDAnv)O|06FE?undk{5M1R zTl_BbroI0wlTh9n?~iX+>I*)tc3Ik7v?vWC{4b%78;_js+ashf@t7}L3_OMwS(_F= NFy}uQGe?RW{|ibfj{^Vz literal 0 HcmV?d00001 diff --git a/.suckless/slstatus/components/ip.c b/.suckless/slstatus/components/ip.c new file mode 100644 index 0000000..2cdad46 --- /dev/null +++ b/.suckless/slstatus/components/ip.c @@ -0,0 +1,87 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include +#if defined(__OpenBSD__) + #include + #include +#elif defined(__FreeBSD__) + #include + #include +#endif + +#include "../slstatus.h" +#include "../util.h" + +static const char * +ip(const char *interface, unsigned short sa_family) +{ + struct ifaddrs *ifaddr, *ifa; + int s; + char host[NI_MAXHOST]; + + if (getifaddrs(&ifaddr) < 0) { + warn("getifaddrs:"); + return NULL; + } + + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) + continue; + + s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), + host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); + if (!strcmp(ifa->ifa_name, interface) && + (ifa->ifa_addr->sa_family == sa_family)) { + freeifaddrs(ifaddr); + if (s != 0) { + warn("getnameinfo: %s", gai_strerror(s)); + return NULL; + } + return bprintf("%s", host); + } + } + + freeifaddrs(ifaddr); + + return NULL; +} + +const char * +ipv4(const char *interface) +{ + return ip(interface, AF_INET); +} + +const char * +ipv6(const char *interface) +{ + return ip(interface, AF_INET6); +} + +const char * +up(const char *interface) +{ + struct ifaddrs *ifaddr, *ifa; + + if (getifaddrs(&ifaddr) < 0) { + warn("getifaddrs:"); + return NULL; + } + + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) + continue; + + if (!strcmp(ifa->ifa_name, interface)) { + freeifaddrs(ifaddr); + return ifa->ifa_flags & IFF_UP ? "up" : "down"; + } + } + + freeifaddrs(ifaddr); + + return NULL; +}