int netstat_snap(int snaptype) { FILE *f; char buffer[1024], hdr[1024]; char *interface; if ((f = fopen(NETSTAT_DEV, "r")) == NULL) { printf("Cannot open %s\n", NETSTAT_DEV); return (UPERF_FAILURE); } /* ignore headers */ if (fgets(buffer, 1024, f) == NULL) { fclose(f); return (UPERF_FAILURE); } if (fgets(buffer, 1024, f) == NULL) { fclose(f); return (UPERF_FAILURE); } while (fgets(buffer, 1024, f) > 0) { strncpy(hdr, buffer, 1024); interface = strtok(hdr, NETSTAT_SEP); if (snaptype == SNAP_BEGIN) { strncpy(nics[no_nics].interface, interface, INTERFACE_LEN); netstat_parse(buffer, &nics[no_nics++].s[0]); } else { int ind = find_nic(interface); if (ind < 0) { printf("Nic %s came online", interface); continue; } else { netstat_parse(buffer, &nics[ind].s[1]); } } } fclose(f); return (UPERF_SUCCESS); }
/** * __init module function */ static int __init init_lvwnet(void) { printk(KERN_INFO "lvwnet_node: Starting module %s now.\n", LVWNET_VERSION); if (!__params_verify()) return -EINVAL; //invalid params ethernic = find_nic(ethernic_name); if (ethernic == NULL){ printk(KERN_ALERT "lvwnet_node: ethernet interface [%s] not found.\n", ethernic_name); return -EINVAL; } spin_lock_init(&lvwnet_lock); spin_lock_init(&lvwnet_recv_lock); spin_lock_init(&lvwnet_send_reg_lock); //Setting pointers to get hw from modified mac80211 __init_sysfs(); //extern function from modified mac80211 /** convert from char to hex */ __set_ptrs_hw(); __set_ptr_skb(); printk(KERN_INFO "lvwnet_node: set as loaded (node before)\n"); lvwnet_set_loaded(); printk(KERN_INFO "lvwnet_node: set as loaded (node after)\n"); mac_strtoh(ctrl_host_addr_h, ctrl_host_addr); printk(KERN_INFO "lvwnet_node: host set as node, and controller is: [%pM]\n", ctrl_host_addr_h); printk(KERN_INFO "lvwnet_node: Registering ethertype 0x0808[lvwnet].\n"); dev_add_pack(&pkt_type_lvwnet); //dev_add_pack(&pkt_type_lvwnet_data); printk(KERN_INFO "lvwnet_node: Initializing netlink interface. (not ready yet... sorry...)\n"); send_reg_to_controller(); reg_timer_init(); return 0; }
int netstat_snap(int snaptype) { FILE *f; char buffer[1024], hdr[1024]; char *interface, *tmp; struct packet_stats ps; if ((f = popen(NETSTAT_DEV, "r")) == NULL) { printf("Cannot open %s\n", NETSTAT_DEV); return (UPERF_FAILURE); } while (fgets(buffer, 1024, f) > 0) { memset(buffer + o_address, ' ', NETSTAT_ADDRLEN); strncpy(hdr, buffer, 1024); interface = strtok(hdr, NETSTAT_SEP); if (snaptype == SNAP_BEGIN) { strncpy(nics[no_nics].interface, interface, INTERFACE_LEN); netstat_parse(buffer, &nics[no_nics++].s[0]); } else { int ind = find_nic(interface); if (ind < 0) { printf("Nic %s came online", interface); continue; } else { netstat_parse(buffer, &nics[ind].s[1]); } } } pclose(f); return (UPERF_SUCCESS); }