summaryrefslogtreecommitdiff
path: root/src/netinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/netinfo.c')
-rw-r--r--src/netinfo.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/netinfo.c b/src/netinfo.c
new file mode 100644
index 0000000..f159df1
--- /dev/null
+++ b/src/netinfo.c
@@ -0,0 +1,39 @@
+/**
+ * Cmon (c'mon) is a simple system resource monitor
+ * Copyright (C) 2022 Aaron Ball <nullspoon@oper.io>
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#include "netinfo.h"
+
+// direction: r (receive) or t (transmit)
+unsigned long long net_x_bytes(char* dev, char direction) {
+ char procpath[1024] = {'\0'};
+ int status = 0;
+ unsigned long long bytes;
+
+ // Assemble the path
+ sprintf(procpath, "/sys/class/net/%s/statistics/%cx_bytes", dev, direction);
+
+ // Read value
+ FILE* fd = fopen(procpath, "r");
+ status = fscanf(fd, "%lld", &bytes);
+ fclose(fd);
+
+ // Ensure read worked
+ if(status == 0)
+ return -1;
+
+ return bytes;
+}

Generated by cgit