]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_ipv6_addr.c
colorful ipv6 status message
[i3/i3status] / src / print_ipv6_addr.c
index be64ba3ae6acfe8dba02a7d02a22397409327894..abf45081b3ea6b1daaa67c9fde714f57e1cb4032 100644 (file)
@@ -1,13 +1,15 @@
 // vim:ts=8:expandtab
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
 #include <stdio.h>
 #include <stdbool.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
 #include <netdb.h>
 #include <string.h>
-#include <arpa/inet.h>
 #include <yajl/yajl_gen.h>
 #include <yajl/yajl_version.h>
 
@@ -49,7 +51,7 @@ static char *get_sockname(struct addrinfo *addr) {
         if ((ret = getnameinfo((struct sockaddr*)&local, local_len,
                                buf, sizeof(buf), NULL, 0,
                                NI_NUMERICHOST)) != 0) {
-                fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret));
+                fprintf(stderr, "i3status: getnameinfo(): %s\n", gai_strerror(ret));
                 (void)close(fd);
                 return NULL;
         }
@@ -62,7 +64,7 @@ static char *get_sockname(struct addrinfo *addr) {
  * Returns the IPv6 address with which you have connectivity at the moment.
  * The char * is statically allocated and mustn't be freed
  */
-static char *get_ipv6_addr() {
+static char *get_ipv6_addr(void) {
         struct addrinfo hints;
         struct addrinfo *result, *resp;
         static struct addrinfo *cached = NULL;
@@ -117,7 +119,9 @@ void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, con
         char *outwalk = buffer;
 
         if (addr_string == NULL) {
+                START_COLOR("color_bad");
                 OUTPUT_FULL_TEXT(format_down);
+                END_COLOR;
                 return;
         }
 
@@ -132,6 +136,7 @@ void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, con
                         walk += strlen("ip");
                 }
         }
-
+        START_COLOR("color_good");
         OUTPUT_FULL_TEXT(buffer);
+        END_COLOR;
 }