Commits

William Giokas committed c6aa6f2

Added network back

Figured out some of the errors. Hopefully this is somewhat stable.
Numbered release soon-ish.

Signed-off-by: William Giokas <1007380@gmail.com>

Comments (0)

Files changed (3)

 than show 3 differently formatted timezones and a 5-10-15 minute system load. I
 added some patches from the site to make it show network speed, temperature and
 a heavily edited battery meter (with time remaining and status) that I threw
-together. Somewhere in the history there's an ip address check, but I'm still
-working on making what I've got up stable. 
+together. I also took some stuff from i3status and put it in here, notably the
+ip address check.
 
 If this thing is of use to you, then I guess I'm doing something right.
 
 #LDFLAGS = ${LIBS}
 
 # compiler and linker
-#CC = cc
+#CC = clang
 
 #include <X11/Xlib.h>
 
+#include <ifaddrs.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <net/if.h>
+
 #include "config.h"
 
+#define NI_NUMERICHOST 1
+
 static Display *dpy;
 
 char *
 	return retstr;
 }
 
+char *
+get_ip_addr(const char *interface)
+{
+    static char part[512];
+    socklen_t len = sizeof(struct sockaddr_in);
+    memset(part, 0, sizeof(part));
+    struct ifaddrs *ifaddr, *addrp;
+    bool found = false;
+
+    getifaddrs(&ifaddr);
+
+    if(ifaddr == NULL)
+        return NULL;
+
+    for (addrp = ifaddr;
+            (addrp != NULL &&
+             (strcmp(addrp->ifa_name, interface) != 0 ||
+              addrp->ifa_addr == NULL ||
+              addrp->ifa_addr->sa_family != AF_INET));
+            addrp = addrp->ifa_next) {
+            /* check if interface is down/up */
+                if (strcmp(addrp->ifa_name, interface) != 0)
+                    continue;
+            found = true;
+            if (strcmp(addrp->ifa_name, interface) != 0) {
+                    freeifaddrs(ifaddr);
+                    return NULL;
+                }
+        }
+
+        if (addrp == NULL) {
+                freeifaddrs(ifaddr);
+                return (found ? "no IP" : NULL);
+            }
+
+        int ret;
+    if ((ret = getnameinfo(addrp->ifa_addr, len, part, sizeof(part), NULL, 0, NI_NUMERICHOST)) != 0) {
+            fprintf(stderr, "dwmstatus: getnameinfo(): %d\n", gai_strerror(ret));
+            freeifaddrs(ifaddr);
+            return "no IP";
+        }
+    freeifaddrs(ifaddr);
+    return part;
+}
+
 /* END NETWORK STUFF
  *
  * TEMPERATURE STUFF
     char *batt = NULL;
     char *net = NULL;
     char *temp = NULL;
+    char *ipaddr = NULL;
     time_t count60 = 0;
     time_t count10 = 0;
 
             free(avgs);
             free(batt);
             free(temp);
+            free(ipaddr);
 
 		    avgs   = loadavg();
             batt   = getbattery(BATT_PATH);
             temp   = gettemperature(TEMP_SENSOR_PATH, TEMP_SENSOR_UNIT);
+            ipaddr = get_ip_addr(NET_DEVICE);
         }
         /* Update every second */
         net    = get_netusage(NET_DEVICE);
 
         /* Format of display */
-		status = smprintf("%s | %s | [%s] | T: %s | %s",
-				net, batt, avgs, temp, time);
+		status = smprintf("%s (%s) | %s | [%s] | T: %s | %s",
+				net, ipaddr, batt, avgs, temp, time);
         free(net);
 		setstatus(status);
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.