diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/first_network_device.c | 43 | ||||
| -rw-r--r-- | src/print_cpu_temperature.c | 6 | ||||
| -rw-r--r-- | src/print_ip_addr.c | 5 | ||||
| -rw-r--r-- | src/print_wireless_info.c | 1 | 
4 files changed, 29 insertions, 26 deletions
| diff --git a/src/first_network_device.c b/src/first_network_device.c index 3f34cf2..b930f53 100644 --- a/src/first_network_device.c +++ b/src/first_network_device.c @@ -14,10 +14,10 @@  #include "i3status.h" -#ifdef __linux__ -#define LOOPBACK_DEV "lo" -#else +#ifdef __OpenBSD__  #define LOOPBACK_DEV "lo0" +#else +#define LOOPBACK_DEV "lo"  #endif  static bool sysfs_devtype(char *dest, size_t n, const char *ifnam) { @@ -67,24 +67,7 @@ static bool is_virtual(const char *ifname) {  }  static net_type_t iface_type(const char *ifname) { -#ifdef __linux__ -    char devtype[32]; - -    if (!sysfs_devtype(devtype, sizeof(devtype), ifname)) -        return NET_TYPE_OTHER; - -    /* Default to Ethernet when no devtype is available */ -    if (!devtype[0]) -        return NET_TYPE_ETHERNET; - -    if (strcmp(devtype, "wlan") == 0) -        return NET_TYPE_WIRELESS; - -    if (strcmp(devtype, "wwan") == 0) -        return NET_TYPE_OTHER; - -    return NET_TYPE_OTHER; -#elif __OpenBSD__ +#ifdef __OpenBSD__      /*       *First determine if the device is a wireless device by trying two ioctl(2)       * commands against it. If either succeeds we can be sure it's a wireless @@ -127,8 +110,24 @@ static net_type_t iface_type(const char *ifname) {          return NET_TYPE_ETHERNET;      }  #else -#error Missing implementation to determine interface type. +    char devtype[32]; + +    if (!sysfs_devtype(devtype, sizeof(devtype), ifname)) +        return NET_TYPE_OTHER; + +    /* Default to Ethernet when no devtype is available */ +    if (!devtype[0]) +        return NET_TYPE_ETHERNET; + +    if (strcmp(devtype, "wlan") == 0) +        return NET_TYPE_WIRELESS; + +    if (strcmp(devtype, "wwan") == 0) +        return NET_TYPE_OTHER; + +    return NET_TYPE_OTHER;  #endif +    return NET_TYPE_OTHER;  }  const char *first_eth_interface(const net_type_t type) { diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c index 56ab62a..431664e 100644 --- a/src/print_cpu_temperature.c +++ b/src/print_cpu_temperature.c @@ -112,7 +112,7 @@ static int read_temperature(char *thermal_zone, temperature_t *temperature) {          /* 'path' is the node within the full path (defaults to acpitz0). */          if (BEGINS_WITH(sensordev.xname, thermal_zone)) {              mib[3] = SENSOR_TEMP; -            /* Limit to temo0, but should retrieve from a full path... */ +            /* Limit to temp0, but should retrieve from a full path... */              for (numt = 0; numt < 1 /*sensordev.maxnumt[SENSOR_TEMP]*/; numt++) {                  mib[4] = numt;                  if (sysctl(mib, 5, &sensor, &slen, NULL, 0) == -1) { @@ -205,7 +205,7 @@ error_netbsd1:  /*   * Reads the CPU temperature from /sys/class/thermal/thermal_zone%d/temp (or - * the user provided path) and returns the temperature in degree celcius. + * the user provided path) and returns the temperature in degree celsius.   *   */  void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, const char *format_above_threshold, int max_threshold) { @@ -216,6 +216,8 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const      bool colorful_output = false;      char *thermal_zone;      temperature_t temperature; +    temperature.raw_value = 0; +    sprintf(temperature.formatted_value, "%.2f", 0.0);      if (path == NULL)          asprintf(&thermal_zone, THERMAL_ZONE, zone); diff --git a/src/print_ip_addr.c b/src/print_ip_addr.c index f9cd1f4..c955c1c 100644 --- a/src/print_ip_addr.c +++ b/src/print_ip_addr.c @@ -29,6 +29,7 @@ const char *get_ip_addr(const char *interface, int family) {      struct ifaddrs *ifaddr, *addrp;      bool found = false; +    int interface_len = strlen(interface);      getifaddrs(&ifaddr); @@ -39,13 +40,13 @@ const char *get_ip_addr(const char *interface, int family) {      for (addrp = ifaddr;           (addrp != NULL && -          (strcmp(addrp->ifa_name, interface) != 0 || +          (strncmp(addrp->ifa_name, interface, interface_len) != 0 ||             addrp->ifa_addr == NULL ||             addrp->ifa_addr->sa_family != family));           addrp = addrp->ifa_next) {          /* Check if the interface is down */ -        if (strcmp(addrp->ifa_name, interface) != 0) +        if (strncmp(addrp->ifa_name, interface, interface_len) != 0)              continue;          found = true;          if ((addrp->ifa_flags & IFF_RUNNING) == 0) { diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c index c3b5270..efdd59b 100644 --- a/src/print_wireless_info.c +++ b/src/print_wireless_info.c @@ -16,6 +16,7 @@  #endif  #ifdef __APPLE__ +#include <sys/socket.h>  #define IW_ESSID_MAX_SIZE 32  #endif | 
