* limitations under the License.
*/
+#define _BSD_SOURCE
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
+#include <endian.h>
#include <sys/stat.h>
#include <sys/mman.h>
#define DB_LD_FILE DB_PATH "/load"
#define IF_SCAN_PATTERN \
- " %[^ :]:%u %u" \
- " %*d %*d %*d %*d %*d %*d" \
- " %u %u"
+ " %[^ :]:%" SCNu64 " %" SCNu64 \
+ " %*u %*u %*u %*u %*u %*u" \
+ " %" SCNu64 " %" SCNu64
#define LD_SCAN_PATTERN \
"%f %f %f"
struct traffic_entry {
uint32_t time;
- uint32_t rxb;
- uint32_t rxp;
- uint32_t txb;
- uint32_t txp;
+ uint64_t rxb;
+ uint64_t rxp;
+ uint64_t txb;
+ uint64_t txp;
};
struct conn_entry {
static inline uint32_t timeof(void *entry)
{
- return ntohl(((struct traffic_entry *)entry)->time);
+ return be32toh(((struct traffic_entry *)entry)->time);
}
static int update_file(const char *path, void *entry, int esize)
static int update_ifstat(
- const char *ifname, uint32_t rxb, uint32_t rxp, uint32_t txb, uint32_t txp
+ const char *ifname, uint64_t rxb, uint64_t rxp, uint64_t txb, uint64_t txp
) {
char path[1024];
}
}
- e.time = htonl(time(NULL));
- e.rxb = htonl(rxb);
- e.rxp = htonl(rxp);
- e.txb = htonl(txb);
- e.txp = htonl(txp);
+ e.time = htobe32(time(NULL));
+ e.rxb = htobe64(rxb);
+ e.rxp = htobe64(rxp);
+ e.txb = htobe64(txb);
+ e.txp = htobe64(txp);
return update_file(path, &e, sizeof(struct traffic_entry));
}
}
}
- e.time = htonl(time(NULL));
- e.rate = htons(rate);
+ e.time = htobe32(time(NULL));
+ e.rate = htobe16(rate);
e.rssi = rssi;
e.noise = noise;
}
}
- e.time = htonl(time(NULL));
- e.udp = htonl(udp);
- e.tcp = htonl(tcp);
- e.other = htonl(other);
+ e.time = htobe32(time(NULL));
+ e.udp = htobe32(udp);
+ e.tcp = htobe32(tcp);
+ e.other = htobe32(other);
return update_file(path, &e, sizeof(struct conn_entry));
}
}
}
- e.time = htonl(time(NULL));
- e.load1 = htons(load1);
- e.load5 = htons(load5);
- e.load15 = htons(load15);
+ e.time = htobe32(time(NULL));
+ e.load1 = htobe16(load1);
+ e.load5 = htobe16(load5);
+ e.load15 = htobe16(load15);
return update_file(path, &e, sizeof(struct load_entry));
}
static int run_daemon(void)
{
FILE *info;
- uint32_t rxb, txb, rxp, txp;
+ uint64_t rxb, txb, rxp, txp;
uint32_t udp, tcp, other;
uint16_t rate;
uint8_t rssi, noise;
if (strstr(line, "TIME_WAIT"))
continue;
- if ((strstr(line, "src=127.0.0.1 ") && strstr(line, "dst=127.0.0.1 "))
+ if ((strstr(line, "src=127.0.0.1 ") && strstr(line, "dst=127.0.0.1 "))
|| (strstr(line, "src=::1 ") && strstr(line, "dst=::1 ")))
continue;
if (!e->time)
continue;
- printf("[ %u, %u, %" PRIu32
- ", %u, %u ]%s\n",
- ntohl(e->time),
- ntohl(e->rxb), ntohl(e->rxp),
- ntohl(e->txb), ntohl(e->txp),
+ printf("[ %" PRIu32 ", %" PRIu64 ", %" PRIu64
+ ", %" PRIu64 ", %" PRIu64 " ]%s\n",
+ be32toh(e->time),
+ be64toh(e->rxb), be64toh(e->rxp),
+ be64toh(e->txb), be64toh(e->txp),
((i + sizeof(struct traffic_entry)) < m.size) ? "," : "");
}
if (!e->time)
continue;
- printf("[ %u, %d, %d, %d ]%s\n",
- ntohl(e->time),
- e->rate, e->rssi, e->noise,
+ printf("[ %" PRIu32 ", %" PRIu16 ", %" PRIu8 ", %" PRIu8 " ]%s\n",
+ be32toh(e->time),
+ be16toh(e->rate), e->rssi, e->noise,
((i + sizeof(struct radio_entry)) < m.size) ? "," : "");
}
if (!e->time)
continue;
- printf("[ %u, %u, %u, %u ]%s\n",
- ntohl(e->time), ntohl(e->udp),
- ntohl(e->tcp), ntohl(e->other),
+ printf("[ %" PRIu32 ", %" PRIu32 ", %" PRIu32 ", %" PRIu32 " ]%s\n",
+ be32toh(e->time), be32toh(e->udp),
+ be32toh(e->tcp), be32toh(e->other),
((i + sizeof(struct conn_entry)) < m.size) ? "," : "");
}
if (!e->time)
continue;
- printf("[ %u, %u, %u, %u ]%s\n",
- ntohl(e->time),
- ntohs(e->load1), ntohs(e->load5), ntohs(e->load15),
+ printf("[ %" PRIu32 ", %" PRIu16 ", %" PRIu16 ", %" PRIu16 " ]%s\n",
+ be32toh(e->time),
+ be16toh(e->load1), be16toh(e->load5), be16toh(e->load15),
((i + sizeof(struct load_entry)) < m.size) ? "," : "");
}