summaryrefslogtreecommitdiff
path: root/src/Network/ifaddrs.c
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-11-17 20:28:44 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2023-11-18 20:03:24 +0100
commit88a7bb50033baab3c2d0eed7e4be868e8966300a (patch)
tree861631a1e5e7434b92a8f19ef8f7b783790e1d1f /src/Network/ifaddrs.c
parent5b908c86320ee73f2722c85f8a47fa03ec093c6c (diff)
Split to library and executable parts
Diffstat (limited to 'src/Network/ifaddrs.c')
-rw-r--r--src/Network/ifaddrs.c41
1 files changed, 0 insertions, 41 deletions
diff --git a/src/Network/ifaddrs.c b/src/Network/ifaddrs.c
deleted file mode 100644
index 37c3e00..0000000
--- a/src/Network/ifaddrs.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "ifaddrs.h"
-
-#include <arpa/inet.h>
-#include <ifaddrs.h>
-#include <net/if.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <endian.h>
-
-uint32_t * broadcast_addresses(void)
-{
- struct ifaddrs * addrs;
- if (getifaddrs(&addrs) < 0)
- return 0;
-
- size_t capacity = 16, count = 0;
- uint32_t * ret = malloc(sizeof(uint32_t) * capacity);
-
- for (struct ifaddrs * ifa = addrs; ifa; ifa = ifa->ifa_next) {
- if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET &&
- ifa->ifa_flags & IFF_BROADCAST) {
- if (count + 2 >= capacity) {
- capacity *= 2;
- uint32_t * nret = realloc(ret, sizeof(uint32_t) * capacity);
- if (nret) {
- ret = nret;
- } else {
- free(ret);
- return 0;
- }
- }
-
- ret[count] = ((struct sockaddr_in*)ifa->ifa_broadaddr)->sin_addr.s_addr;
- count++;
- }
- }
-
- freeifaddrs(addrs);
- ret[count] = 0;
- return ret;
-}