/* * getters.c * This file is part of Network-inador * * Copyright (C) 2025 - Félix Arreola Rodríguez * * Network-inador is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Network-inador is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Network-inador; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include #include #include "network-inador-private.h" #include "interfaces.h" #include "ip-address.h" uint32_t *network_inador_list_ifaces (NetworkInadorHandle *handle) { uint32_t *memory; FList *g; Interface *iface; int c; memory = (uint32_t *) malloc ((handle->interfaces_counter + 1) * sizeof (uint32_t)); if (memory == NULL) return NULL; c = 0; for (g = handle->interfaces; g != NULL; g = g->next) { iface = (Interface *) g->data; memory[c] = iface->index; c++; } memory[c] = 0; return memory; } Interface *network_inador_get_iface (NetworkInadorHandle *handle, uint32_t index) { _interfaces_locate_by_index (handle->interfaces, index); } const unsigned char *network_inador_iface_get_name (Interface *iface) { return iface->name; } uint32_t network_inador_iface_get_index (Interface *iface) { return iface->index; } uint32_t network_inador_iface_get_link_type (Interface *iface) { return iface->link_type; } uint32_t network_inador_iface_get_master_index (Interface *iface) { return iface->master_index; } uint32_t network_inador_iface_get_mtu (Interface *iface) { return iface->mtu; } uint16_t network_inador_iface_get_flags (Interface *iface) { return iface->flags; } uint8_t network_inador_iface_get_is_wireless (Interface *iface) { return iface->is_wireless; } uint8_t network_inador_iface_get_num_ips (Interface *iface) { return iface->address_counter; } IPAddr *network_inador_iface_get_ipaddr_by_index (Interface *iface, int index) { return (IPAddr *) f_list_nth_data (f_list_first (iface->address), index); } Interface *network_inador_ipaddr_get_iface (IPAddr *ip_addr) { return ip_addr->iface; } uint8_t network_inador_ipaddr_get_family (IPAddr *ip_addr) { return ip_addr->family; } uint8_t network_inador_ipaddr_get_prefix (IPAddr *ip_addr) { return ip_addr->prefix; } uint8_t network_inador_ipaddr_has_local (IPAddr *ip_addr) { return ip_addr->has_local; } uint8_t network_inador_ipaddr_has_brd (IPAddr *ip_addr) { return ip_addr->has_brd; } uint8_t network_inador_ipaddr_get_scope (IPAddr *ip_addr) { return ip_addr->scope; } uint32_t network_inador_ipaddr_get_flags (IPAddr *ip_addr) { return ip_addr->flags; } void network_inador_ipaddr_get_cacheinfo (IPAddr *ip_addr, struct ifa_cacheinfo *cacheinfo) { memcpy (cacheinfo, &ip_addr->cacheinfo, sizeof (struct ifa_cacheinfo)); } void network_inador_ipaddr_get_addr (IPAddr *ip_addr, void *addr, int *addr_size) { int family_size = 0; if (ip_addr->family == AF_INET) { family_size = sizeof (struct in_addr); } else if (ip_addr->family == AF_INET6) { family_size = sizeof (struct in6_addr); } if (addr_size != NULL) { /* Verificar que no supere el máximo de la dirección */ if (*addr_size < family_size) { family_size = *addr_size; } } memcpy (addr, &ip_addr->addr, family_size); if (addr_size != NULL) { *addr_size = family_size; } } void network_inador_ipaddr_get_local_addr (IPAddr *ip_addr, void *addr, int *addr_size) { int family_size = 0; if (ip_addr->family == AF_INET) { family_size = sizeof (struct in_addr); } else if (ip_addr->family == AF_INET6) { family_size = sizeof (struct in6_addr); } if (addr_size != NULL) { /* Verificar que no supere el máximo de la dirección */ if (*addr_size < family_size) { family_size = *addr_size; } } memcpy (addr, &ip_addr->local_addr, family_size); if (addr_size != NULL) { *addr_size = family_size; } } void network_inador_ipaddr_get_brd_addr (IPAddr *ip_addr, void *addr, int *addr_size) { int family_size = 0; if (ip_addr->family == AF_INET) { family_size = sizeof (struct in_addr); } else if (ip_addr->family == AF_INET6) { family_size = sizeof (struct in6_addr); } if (addr_size != NULL) { /* Verificar que no supere el máximo de la dirección */ if (*addr_size < family_size) { family_size = *addr_size; } } memcpy (addr, &ip_addr->brd_addr, family_size); if (addr_size != NULL) { *addr_size = family_size; } } const unsigned char *network_inador_ipaddr_get_label (IPAddr *ip_addr) { return ip_addr->label; }