/**************************************************************************** load the list of network interfaces ****************************************************************************/ void load_interfaces(void) { const char **ptr; int i; struct iface_struct ifaces[MAX_INTERFACES]; ptr = lp_interfaces(); allones_ip = *interpret_addr2("255.255.255.255"); loopback_ip = *interpret_addr2("127.0.0.1"); SAFE_FREE(probed_ifaces); /* dump the current interfaces if any */ while (local_interfaces) { struct interface *iface = local_interfaces; DLIST_REMOVE(local_interfaces, local_interfaces); ZERO_STRUCTPN(iface); SAFE_FREE(iface); } /* probe the kernel for interfaces */ total_probed = get_interfaces(ifaces, MAX_INTERFACES); if (total_probed > 0) { probed_ifaces = memdup(ifaces, sizeof(ifaces[0])*total_probed); } /* if we don't have a interfaces line then use all broadcast capable interfaces except loopback */ if (!ptr || !*ptr || !**ptr) { if (total_probed <= 0) { DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n")); exit(1); } for (i=0;i<total_probed;i++) { if (probed_ifaces[i].netmask.s_addr != allones_ip.s_addr && probed_ifaces[i].ip.s_addr != loopback_ip.s_addr) { add_interface(probed_ifaces[i].ip, probed_ifaces[i].netmask); } } return; } if (ptr) { while (*ptr) { char *ptr_cpy = strdup(*ptr); if (ptr_cpy) { interpret_interface(ptr_cpy); free(ptr_cpy); } ptr++; } } if (!local_interfaces) { DEBUG(0,("WARNING: no network interfaces found\n")); } }
bool check_cast(const DexType* type, const DexType* base_type) { if (type == base_type) return true; const auto cls = type_class(type); if (cls == nullptr) return false; if (check_cast(cls->get_super_class(), base_type)) return true; auto intfs = cls->get_interfaces(); for (auto intf : intfs->get_type_list()) { if (check_cast(intf, base_type)) return true; } return false; }
int main(int argc, char *argv[]) { int skt; int size, rt; unsigned char buf[4096]; struct sockaddr sa; int asize; /* Check our huge range of flags */ if (argc > 1) { if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "-h") ==0) { printf("axdigi version %s. Copyright (C) 1995 Craig Small VK2XLZ\n\n", VERSION); printf("axdigi comes with ABSOLUTELY NO WARRANTY.\n"); printf("This is free software, and you are welcome to redistribute it\n"); printf("under the terms of GNU General Public Licence as published\n"); printf("by Free Software Foundation; either version 2 of the License, or\n"); printf("(at your option) any later version.\n"); return 0; } } if ((skt = socket(AF_INET, SOCK_PACKET, htons(ETH_P_AX25))) == -1) { perror("socket"); return(1); } get_interfaces(skt); while(1) { asize = sizeof(sa); if ((size = recvfrom(skt, buf, sizeof(buf), 0, &sa, &asize)) == -1) { perror("recv"); exit(1); } if ((rt = recv_packet(buf, size, sa.sa_data)) >= 0) { if (rt < port_count) { asize = sizeof(sa); strcpy(sa.sa_data, portname[rt]); if (sendto(skt, buf, size, 0, &sa, asize) == -1) perror("sendto"); continue; } /* printf("Unknown port %s\n", sa.sa_data);*/ } /* recv_packet true */ } /* while(1) */ close(skt); }
bool is_assignable_to_interface(const DexType* type, const DexType* iface) { if (type == iface) return true; auto cls = type_class(type); if (cls) { for (auto extends : cls->get_interfaces()->get_type_list()) { if (is_assignable_to_interface(extends, iface)) { return true; } } } return false; }
/* * Returns zero or more local interfaces to the requestor */ DWORD request_net_config_get_interfaces(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); DWORD result = ERROR_SUCCESS; result = get_interfaces(remote, response); // Transmit the response if valid packet_transmit_response(result, remote, response); return result; }
void load_interfaces(void) { struct iface_struct *ifaces = NULL; const char **ptr = lp_interfaces(); int i; gfree_interfaces(); /* Probe the kernel for interfaces */ total_probed = get_interfaces(talloc_tos(), &ifaces); if (total_probed > 0) { probed_ifaces = (struct iface_struct *)smb_memdup(ifaces, sizeof(ifaces[0])*total_probed); if (!probed_ifaces) { DEBUG(0,("ERROR: smb_memdup failed\n")); exit(1); } } TALLOC_FREE(ifaces); /* if we don't have a interfaces line then use all broadcast capable interfaces except loopback */ if (!ptr || !*ptr || !**ptr) { if (total_probed <= 0) { DEBUG(0,("ERROR: Could not determine network " "interfaces, you must use a interfaces config line\n")); exit(1); } for (i=0;i<total_probed;i++) { if (probed_ifaces[i].flags & IFF_BROADCAST) { add_interface(&probed_ifaces[i]); } } return; } if (ptr) { while (*ptr) { char *ptr_cpy = SMB_STRDUP(*ptr); if (ptr_cpy) { interpret_interface(ptr_cpy); free(ptr_cpy); } ptr++; } } if (!local_interfaces) { DEBUG(0,("WARNING: no network interfaces found\n")); } }
int main(int argc, char **argv) { int sockfd = 0; int iftype = 0; struct if_nameindex *pInterfaces; struct if_nameindex *pFreeInterfacesMem; ur::WiredInterface *ifWiredHead = NULL; std::string ssidname; std::string wirelessaddress("notset"); pInterfaces = pFreeInterfacesMem = if_nameindex(); while ((pInterfaces != NULL) && (pInterfaces->if_name != NULL)) { // (DEBUG) std::cout << "Interface[" << pInterfaces->if_index << "]: " << pInterfaces->if_name << std::endl; if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) continue; /* For now we only need to find wireless interfaces. Eventually * we will enumerate both wired and wireless, so I will just loop through all * interfaces for now and call a 'no_op()' function for the wired interface */ get_interfaces(sockfd, pInterfaces->if_name, &iftype, &ssidname); if(iftype == IFT_WIRED) { get_wired_interface(sockfd, pInterfaces->if_name, ifWiredHead); } if(iftype == IFT_WIRELESS) { get_wireless_interface(sockfd, pInterfaces->if_name, &wirelessaddress); } close(sockfd); ++pInterfaces; } // (DEBUG) See if it worked std::cout << "SSID: " << ssidname << std::endl; std::cout << "ADDR: " << wirelessaddress << std::endl; /* Open the serial comm port for the LCD display */ /* Print the SSID and the IPv4 Address */ /* cleanup and go away */ if (pFreeInterfacesMem != NULL) if_freenameindex(pFreeInterfacesMem); while (ifWiredHead != NULL) { ur::WiredInterface *pWiredInterface; pWiredInterface = ifWiredHead->GetNext(); delete ifWiredHead; ifWiredHead = pWiredInterface; } return EXEC_SUCCESS; }
/**************************************************************************** return True if the list of probed interfaces has changed ****************************************************************************/ BOOL interfaces_changed(void) { int n; struct iface_struct ifaces[MAX_INTERFACES]; n = get_interfaces(ifaces, MAX_INTERFACES); if ((n > 0 )&& (n != total_probed || memcmp(ifaces, probed_ifaces, sizeof(ifaces[0])*n))) { return True; } return False; }
static bool addr_matches_if(const char *n) { union sudo_in_addr_un addr; struct interface *ifp; #ifdef HAVE_STRUCT_IN6_ADDR unsigned int j; #endif unsigned int family; debug_decl(addr_matches_if, SUDO_DEBUG_MATCH) #ifdef HAVE_STRUCT_IN6_ADDR if (inet_pton(AF_INET6, n, &addr.ip6) == 1) { family = AF_INET6; } else #endif /* HAVE_STRUCT_IN6_ADDR */ if (inet_pton(AF_INET, n, &addr.ip4) == 1) { family = AF_INET; } else { debug_return_bool(false); } SLIST_FOREACH(ifp, get_interfaces(), entries) { if (ifp->family != family) continue; switch (family) { case AF_INET: if (ifp->addr.ip4.s_addr == addr.ip4.s_addr || (ifp->addr.ip4.s_addr & ifp->netmask.ip4.s_addr) == addr.ip4.s_addr) debug_return_bool(true); break; #ifdef HAVE_STRUCT_IN6_ADDR case AF_INET6: if (memcmp(ifp->addr.ip6.s6_addr, addr.ip6.s6_addr, sizeof(addr.ip6.s6_addr)) == 0) debug_return_bool(true); for (j = 0; j < sizeof(addr.ip6.s6_addr); j++) { if ((ifp->addr.ip6.s6_addr[j] & ifp->netmask.ip6.s6_addr[j]) != addr.ip6.s6_addr[j]) break; } if (j == sizeof(addr.ip6.s6_addr)) debug_return_bool(true); break; #endif /* HAVE_STRUCT_IN6_ADDR */ } } debug_return_bool(false); }
char * prt_interfaces(int i) { static char buffer[1024]; struct numera_data datafinal = get_interfaces(); //for(i = 0; i < datafinal.nInterfaces; i++) //{ struct ifreq *item = &datafinal.ifr[i]; strcpy(buffer,inet_ntoa(((struct sockaddr_in *)&item->ifr_addr)->sin_addr)); //buffer = inet_ntoa(((struct sockaddr_in *)&item->ifr_addr)->sin_addr); //} return (buffer == 0) ? NULL : buffer; }
bool interfaces_changed(void) { bool ret = false; int n; struct iface_struct *ifaces = NULL; n = get_interfaces(talloc_tos(), &ifaces); if ((n > 0 )&& (n != total_probed || memcmp(ifaces, probed_ifaces, sizeof(ifaces[0])*n))) { ret = true; } TALLOC_FREE(ifaces); return ret; }
static NetData* init_data() { NetData* data = g_new(NetData, 1); data->current = g_new(double, DATA_FIELDS); data->last = g_new(double, DATA_FIELDS); data->rate = g_new(double, DATA_FIELDS); get_interfaces(data); //do a first run so that we have some meaningful numbers for the next //time around collect_data(data); return data; }
int main() { struct interface** ifs; int i; ifs = get_interfaces(); i = 0; for(;;) { if(ifs[i] == NULL) { return 0; } print_interface_info(ifs[i]); i++; } return 0; }
/** load the list of network interfaces **/ void load_interfaces(TALLOC_CTX *mem_ctx, const char **interfaces, struct interface **local_interfaces) { const char **ptr = interfaces; int i; struct iface_struct ifaces[MAX_INTERFACES]; struct in_addr loopback_ip; int total_probed; *local_interfaces = NULL; loopback_ip = interpret_addr2("127.0.0.1"); /* probe the kernel for interfaces */ total_probed = get_interfaces(ifaces, MAX_INTERFACES); /* if we don't have a interfaces line then use all interfaces except loopback */ if (!ptr || !*ptr || !**ptr) { if (total_probed <= 0) { DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n")); } for (i=0;i<total_probed;i++) { if (ifaces[i].ip.s_addr != loopback_ip.s_addr) { add_interface(mem_ctx, ifaces[i].ip, ifaces[i].netmask, local_interfaces); } } } while (ptr && *ptr) { interpret_interface(mem_ctx, *ptr, ifaces, total_probed, local_interfaces); ptr++; } if (!*local_interfaces) { DEBUG(0,("WARNING: no network interfaces found\n")); } }
/** load the list of network interfaces **/ void load_interface_list(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, struct interface **local_interfaces) { const char **ptr = lpcfg_interfaces(lp_ctx); int i; struct iface_struct *ifaces; int total_probed; bool enable_ipv6 = lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", true); *local_interfaces = NULL; /* probe the kernel for interfaces */ total_probed = get_interfaces(mem_ctx, &ifaces); /* if we don't have a interfaces line then use all interfaces except loopback */ if (!ptr || !*ptr || !**ptr) { if (total_probed <= 0) { DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n")); } for (i=0; i<total_probed; i++) { if (!is_loopback_addr((struct sockaddr *)&ifaces[i].ip)) { add_interface(mem_ctx, &ifaces[i], local_interfaces, enable_ipv6); } } } while (ptr && *ptr) { interpret_interface(mem_ctx, *ptr, ifaces, total_probed, local_interfaces, enable_ipv6); ptr++; } if (!*local_interfaces) { DEBUG(0,("WARNING: no network interfaces found\n")); } talloc_free(ifaces); }