rockdrilla

dump addresses from btmp via stdin

Jul 18th, 2017
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #define _GNU_SOURCE
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <stddef.h>
  8. #include <utmp.h>
  9. #include <arpa/inet.h>
  10.  
  11. const int utmp_len = sizeof(struct utmp);
  12.  
  13. int main(int argc, const char * argv[]) {
  14.   struct utmp z;
  15.   const int32_t * x = z.ut_addr_v6;
  16.   char buf[INET6_ADDRSTRLEN];
  17.   const char *text;
  18.  
  19.   while(read(STDIN_FILENO, &z, utmp_len) == utmp_len) {
  20.     text = inet_ntop(
  21.       (x[1] || x[2] || x[3]) ? (AF_INET6) : (AF_INET),
  22.       x,
  23.       buf, sizeof(buf));
  24.     printf("%s\n", text);
  25.   }
  26.   return 0;
  27. }
Add Comment
Please, Sign In to add comment