../m4/mpd.m4 \
../m4/the_rest_funcs.m4 \
../m4/typez.m4 \
- ../m4/x11.m4
+ ../m4/x11.m4 \
+ ../m4/net.m4
')
--- /dev/null
+dnl Copyright 08/10/2015
+dnl Aaron Caffrey https://github.com/wifiextender
+
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+dnl MA 02110-1301, USA.
+
+
+dnl TEST_NET() function in configure.ac
+dnl
+dnl Allow the user to compile the program
+dnl without net related functions, thus
+dnl decreasing the required dependencies.
+dnl
+dnl Did not included tests for some of the Net
+dnl headers as they fail to compile just by including
+dnl them in gcc, but pass the tests in clang. Is there
+dnl are any _POSIX_SOURCE m4 alternative to compile a
+dnl test case on the fly ?
+AC_DEFUN([TEST_NET],[
+ WITH_NET=1
+ dnl WITH_PCI=1
+ dnl PCI_LIBS=""
+
+ AC_ARG_WITH([net],
+ AS_HELP_STRING([--with-net],
+ [Net funcs]),
+ [],
+ [with_net=yes]
+ )
+
+ AS_IF([test "x$with_net" = "xno"], [
+ WITH_NET=0
+ ])
+
+ AS_IF([test "x$with_net" = "xyes"], [
+
+ AC_CHECK_HEADERS([ \
+ linux/if_link.h \
+ ifaddrs.h \
+ arpa/inet.h \
+ netpacket/packet.h \
+ sys/socket.h \
+ net/if.h \
+ sys/ioctl.h \
+ linux/sockios.h \
+ linux/ethtool.h \
+ netdb.h \
+ ],[],[
+ ERR([Missing core header files.])
+ ])
+
+ AC_CHECK_FUNCS([ \
+ getifaddrs \
+ freeifaddrs \
+ getaddrinfo \
+ freeaddrinfo \
+ socket \
+ ioctl \
+ inet_ntop \
+ ],[],[
+ ERR([Missing core library functions.])
+ ])
+
+ NOTIFY([getifaddrs])
+ AC_COMPILE_IFELSE([
+ AC_LANG_SOURCE([[
+ #include <ifaddrs.h>
+ int main(void) {
+ struct ifaddrs *ifaddr;
+ if (-1 == getifaddrs(&ifaddr)) {
+ return 0;
+ }
+ freeifaddrs(ifaddr);
+ return 0;
+ }
+ ]])
+ ],[],[
+ COMPILE_FAILED([getifaddrs])
+ ]
+ )
+
+ ])
+
+ dnl AC_ARG_WITH([pci],
+ dnl AS_HELP_STRING([--with-pci],
+ dnl [PCI funcs]),
+ dnl [],
+ dnl [with_pci=yes]
+ dnl )
+
+ dnl AS_IF([test "x$with_pci" = "xno"], [
+ dnl WITH_PCI=0
+ dnl AC_SUBST(PCI_LIBS)
+ dnl ])
+
+ dnl AS_IF([test "x$with_pci" = "xyes"], [
+ dnl PCI_LIBS="-lpci"
+
+ dnl AC_CHECK_HEADERS([ \
+ dnl pci/pci.h \
+ dnl ],[],[
+ dnl ERR([Missing core header files.])
+ dnl ])
+
+ dnl ])
+
+ dnl AC_SUBST(PCI_LIBS)
+ AC_DEFINE_UNQUOTED([WITH_NET],[$WITH_NET],[Net funcs])
+ dnl AC_DEFINE_UNQUOTED([WITH_PCI],[$WITH_PCI],[PCI funcs])
+
+])
])
-dnl TEST_NET() function in configure.ac
-dnl
-dnl Allow the user to compile the program
-dnl without net related functions, thus
-dnl decreasing the required dependencies.
-dnl
-dnl Did not included tests for some of the Net
-dnl headers as they fail to compile just by including
-dnl them in gcc, but pass the tests in clang. Is there
-dnl are any _POSIX_SOURCE m4 alternative to compile a
-dnl test case on the fly ?
-AC_DEFUN([TEST_NET],[
- WITH_NET=1
- AC_ARG_WITH([net],
- AS_HELP_STRING([--with-net],
- [Net funcs]),
- [],
- [with_net=yes]
- )
-
- AS_IF([test "x$with_net" = "xno"], [
- WITH_NET=0
- ])
-
- AS_IF([test "x$with_net" = "xyes"], [
-
- AC_CHECK_HEADERS([ \
- linux/if_link.h \
- ifaddrs.h \
- arpa/inet.h \
- netpacket/packet.h \
- sys/socket.h \
- net/if.h \
- sys/ioctl.h \
- linux/sockios.h \
- linux/ethtool.h \
- netdb.h \
- ],[],[
- ERR([Missing core header files.])
- ])
-
- AC_CHECK_FUNCS([ \
- getifaddrs \
- freeifaddrs \
- getaddrinfo \
- freeaddrinfo \
- socket \
- ioctl \
- inet_ntop \
- ],[],[
- ERR([Missing core library functions.])
- ])
-
- NOTIFY([getifaddrs])
- AC_COMPILE_IFELSE([
- AC_LANG_SOURCE([[
- #include <ifaddrs.h>
- int main(void) {
- struct ifaddrs *ifaddr;
- if (-1 == getifaddrs(&ifaddr)) {
- return 0;
- }
- freeifaddrs(ifaddr);
- return 0;
- }
- ]])
- ],[],[
- COMPILE_FAILED([getifaddrs])
- ]
- )
-
- ])
- AC_DEFINE_UNQUOTED([WITH_NET],[$WITH_NET],[Net funcs])
-
-])
-
-
dnl TEST_SOME_FUNCS() function in configure.ac
dnl
dnl The tests are simple enough, just to
#define BYTES_TO_MB(x) (x/2/1024) /* block bytes */
#define FMT_UINT "%"PRIuMAX
+#define FMT_UINTX "%"PRIxMAX
#define UFINT "%"PRIuFAST16
/* stay away from va_list */
#define BATTERY_USED(x, z) (BATTERY_NUM(x, z, "now"))
#define BATTERY_TOTAL(x, z) (BATTERY_NUM(x, z, "full"))
+/* NIC model and vendor */
+#define NIC_NUM(x, y, z) (FILL_ARR(x, "%s%s%s%s", \
+ "/sys/class/net/", y, "/device/", z))
+#define NIC_VEND(x, z) (NIC_NUM(x, z, "vendor"))
+#define NIC_MODEL(x, z) (NIC_NUM(x, z, "device"))
+
/* exit with error */
#define CANNOT_OPEN "Could not open"
#define ERR "Error:"
#if WITH_NET == 1
-#include <arpa/inet.h>
#include <netdb.h>
/* #include <sys/types.h> */
#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
#include <ifaddrs.h>
#include <linux/if_link.h>
#include <netpacket/packet.h>
#include <net/if.h>
-#include <sys/ioctl.h>
#include <linux/sockios.h>
#include <linux/ethtool.h>
#include <linux/if.h>
+/* #if WITH_PCI == 1 */
+/* #include <pci/pci.h> */
+/* #endif /1* WITH_PCI *1/ */
+
#endif /* WITH_NET */
#include "include/headers.h"
if (-1 == getifaddrs(&ifaddr)) {
FUNC_FAILED("getifaddrs()");
}
+ FILL_STR_ARR(1, str1, "Null");
for (ifa = ifaddr; NULL != ifa; ifa = ifa->ifa_next) {
if (NULL == ifa->ifa_addr) {
20 == infiniband
*/
if (6 != mac->sll_halen) {
- FILL_STR_ARR(1, str1, "Null");
break;
}
FILL_ARR(str1, "%02x:%02x:%02x:%02x:%02x:%02x",
} else if (7 == num) { /* link speed */
get_link_speed(str1, str2);
- if ('\0' == str1[0]) {
- FILL_STR_ARR(1, str1, "Null");
- }
}
break;
}
RECOMPILE_WITH("net");
#endif /* WITH_NET */
}
+
+
+/* void */
+/* get_nic_info(char *str1, char *str2) { */
+/* #if WITH_PCI == 1 */
+
+/* uintmax_t vendor = 0, model = 0; */
+/* char temp[VLA]; */
+/* struct pci_access *pacc = NULL; */
+/* struct pci_dev *dev; */
+
+/* NIC_VEND(temp, str2); */
+/* FILE *fp = fopen(temp, "r"); */
+/* if (NULL == fp) { */
+/* exit_with_err(CANNOT_OPEN, temp); */
+/* } */
+
+/* #pragma GCC diagnostic push */
+/* #pragma GCC diagnostic ignored "-Wunused-result" */
+/* fscanf(fp, FMT_UINTX, &vendor); /1* hex *1/ */
+/* #pragma GCC diagnostic pop */
+/* fclose(fp); */
+
+/* NIC_MODEL(temp, str2); */
+/* if (NULL == (fp = fopen(temp, "r"))) { */
+/* exit_with_err(CANNOT_OPEN, temp); */
+/* } */
+
+/* #pragma GCC diagnostic push */
+/* #pragma GCC diagnostic ignored "-Wunused-result" */
+/* fscanf(fp, FMT_UINTX, &model); /1* hex *1/ */
+/* #pragma GCC diagnostic pop */
+/* fclose(fp); */
+
+/* pacc = pci_alloc(); */
+/* if (NULL == pacc) { */
+/* goto error; */
+/* } */
+
+/* pci_init(pacc); */
+/* if (NULL == pacc) { */
+/* goto error; */
+/* } */
+/* pci_scan_bus(pacc); */
+
+/* for (dev = pacc->devices; NULL != dev; dev = dev->next) { */
+/* pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS); */
+
+/* if ((uintmax_t)vendor == (uintmax_t)dev->vendor_id && */
+/* (uintmax_t)model == (uintmax_t)dev->device_id) { */
+
+/* pci_lookup_name(pacc, temp, VLA, */
+/* PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, */
+/* (uintmax_t)vendor, (uintmax_t)model); */
+
+/* FILL_STR_ARR(1, str1, temp); */
+/* break; */
+/* } */
+/* } */
+
+/* error: */
+/* if (NULL != pacc) { */
+/* pci_cleanup(pacc); */
+/* } */
+/* return; */
+
+/* #else */
+/* RECOMPILE_WITH("pci"); */
+/* #endif /1* WITH_PCI *1/ */
+/* } */
void get_net(char *, char *, unsigned char num);
void get_link_speed(char *, char *);
void get_ip_lookup(char *, char *);
+/* void get_nic_info(char *, char *); */
#endif /* NET_H_ */
{ .name = "ipcast", .key = 'D', .arg = "eth0", .doc = "The NIC broadcast address." },
{ .name = "iplink", .key = 'e', .arg = "eth0", .doc = "The NIC link speed (useful for wireless/wifi)." },
{ .name = "iplookup", .key = 'E', .arg = "site", .doc = "Mini website IP lookup." },
+ /* { .name = "nicinfo", .key = 'G', .arg = "eth0", .doc = "The NIC vendor and model." }, */
{ .name = "statio", .key = 'S', .arg = "sda", .doc = "Read and written MBs to the drive so far." },
{ .doc = NULL }
};
}
break;
+ /* case 'G': */
+ /* { */
+ /* char nic_info[VLA]; */
+ /* get_nic_info(nic_info, arg); */
+ /* GLUE(arguments->all, FMT_KERN, nic_info); */
+ /* } */
+ /* break; */
+
case 'E':
{
char ip_lookup[VLA];