[quote="vbextreme"][/quote]
Ho visto che sei molto bravo!!
Secondo te "seguendo te": è scritto bene questo codice per l'informazione net
File info_net.h:
#ifndef INFO_NET_H_INCLUDED
#define INFO_NET_H_INCLUDED
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "def_cond.h"
#define SIZE 50
#define SIZE_ST 256 /* length standard buffer linux */
#define FILE_ARP "/proc/net/arp"
#define FILE_DEV "/proc/net/dev"
#define kb 1024.000
#define mb 1048576.000
#define gb 1073741824.000
#define tb 1099511627776.000
typedef struct NetArp {
char arp_ipaddres[SIZE];
char arp_hwtype[SIZE];
char arp_flags[SIZE];
char arp_hwaddres[SIZE];
char arp_mask[SIZE];
char arp_device[SIZE];
}NETARP;
typedef struct _NETDEV
{
char face[SIZE];
unsigned int dow_byte;
unsigned int dow_pck;
unsigned int dow_err;
unsigned int dow_drop;
unsigned int dow_fifo;
unsigned int dow_frame;
unsigned int dow_compressed;
unsigned int dow_multicast;
unsigned int up_byte;
unsigned int up_pck;
unsigned int up_err;
unsigned int up_drop;
unsigned int up_fifo;
unsigned int up_colls;
unsigned int up_carrier;
unsigned int up_compressed;
}NETDEV;
typedef struct Unit_down_up {
char dow[SIZE];
char up[SIZE];
}UNIT;
int info_system_net(NETDEV *, NETARP *, double);
int info_net_ip_dev(NETARP *);
int info_net_down_up(NETDEV *, char *);
void unit_dow_up_byte(UNIT *, unsigned int *, unsigned int *);
#endif
File info_net.c
#include "info_net.h"
int info_system_net(NETDEV *dev, NETARP *arp, double sec)
{
UNIT unit;
unsigned int x, y;
unsigned int s_d, s_u;
switch(info_net_ip_dev(arp)) {
case 1:
info_net_down_up(dev, arp->arp_device);
s_d = dev->dow_byte;
s_u = dev->up_byte;
break;
case 2:
return 2;
break;
case 0:
return 0;
break;
}
printf("IP_Gateway: %s\n", arp->arp_ipaddres);
printf("Device: %s\n", arp->arp_device);
con_getrc(&y,&x);
do {
if(info_net_down_up(dev, arp->arp_device)) {
unit_dow_up_byte(&unit, &dev->dow_byte, &dev->up_byte);
con_gotorc(y,x);
printf("Dow: %10s Up: %10s ", unit.dow, unit.up);
s_d = ((1.0 / sec) * (dev->dow_byte - s_d));
s_u = ((1.0 / sec) * (dev->up_byte - s_u));
unit_dow_up_byte(&unit, &s_d, &s_u);
printf("speed Dow: %10s/s speed Up: %10s/s", unit.dow, unit.up);
con_flush();
s_d = dev->dow_byte;
s_u = dev->up_byte;
}
else {
con_gotorc(y,x);
printf("Erropr! file\n");
con_flush();
}
thr_sleep(sec);
}while(sec != 0.0);
printf("\n");
return 1;
}
void unit_dow_up_byte(UNIT *unit, unsigned int *down, unsigned int *uplo)
{
float d, u;
if(*down < kb) {
sprintf(unit->dow, "%dB", *down);
}
else if(*down < mb) {
d = *down / kb;
sprintf(unit->dow, "%.3fKb", d);
}
else if(*down < gb) {
d = *down / mb;
sprintf(unit->dow, "%.3fMB", d);
}
else if(*down < tb) {
d = *down / tb;
sprintf(unit->dow, "%.3fGb", d);
}
if(*uplo < kb) {
sprintf(unit->up, "%dB", *uplo);
}
else if(*uplo < mb) {
u = *uplo / kb;
sprintf(unit->up, "%.3fKb", u);
}
else if(*uplo < gb) {
u = *uplo / mb;
sprintf(unit->up, "%.3fMB", u);
}
else if(*down < tb) {
u = *uplo / tb;
sprintf(unit->up, "%.3fGb", u);
}
}
int info_net_ip_dev(NETARP *arp)
{
FILE *farp;
char bufarp[SIZE_ST];
char *arp_tmp;
if(!(farp = fopen(FILE_ARP, "r"))) {
return 0;
}
if(!fgets(bufarp,SIZE_ST,farp)){
fclose(farp);
return 0;
}
if(fgets(bufarp,SIZE_ST,farp)){
arp_tmp = str_skipspace(bufarp);
arp_tmp = str_copytoc(arp->arp_ipaddres,arp_tmp,' ');
arp_tmp = str_skipspace(arp_tmp);
arp_tmp = str_copytoc(arp->arp_hwtype,arp_tmp,' ');
arp_tmp = str_skipspace(arp_tmp);
arp_tmp = str_copytoc(arp->arp_flags,arp_tmp,' ');
arp_tmp = str_skipspace(arp_tmp);
arp_tmp = str_copytoc(arp->arp_hwaddres,arp_tmp,' ');
arp_tmp = str_skipspace(arp_tmp);
arp_tmp = str_copytoc(arp->arp_mask,arp_tmp,' ');
arp_tmp = str_skipspace(arp_tmp);
arp_tmp = str_copytoc(arp->arp_device,arp_tmp,' ');
arp->arp_device[((strlen(arp->arp_device))-1)] = '\0';
}
else {
fclose(farp);
return 2;
}
fclose(farp);
return 1;
}
int info_net_down_up(NETDEV *dev, char *devis)
{
FILE *fdu;
char bufdu[SIZE_ST];
char *du_tmp;
char *du_etmp;
if(!(fdu = fopen(FILE_DEV, "r"))) {
return 0;
}
while(fgets(bufdu,SIZE_ST,fdu)) {
if(!strncmp(bufdu, devis, 3)) {
du_tmp = str_skipspace(bufdu);
du_tmp = str_copytoc(dev->face,du_tmp,':');
++du_tmp;
du_tmp = str_skipspace(du_tmp);
dev->dow_byte = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->dow_pck = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->dow_err = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->dow_drop = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->dow_fifo = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->dow_frame = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->dow_compressed = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->dow_multicast = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->up_byte = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->up_pck = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->up_err = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->up_drop = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->up_fifo = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->up_colls = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->up_carrier = strtoul(du_tmp,&du_etmp,10);
du_tmp = du_etmp + 1;
du_tmp = str_skipspace(du_tmp);
dev->up_compressed = strtoul(du_tmp,&du_etmp,10);
}
}
fclose(fdu);
return 1;
}