1 #include <u.h> 2 #include <libc.h> 3 #include "ip.h" 4 5 int 6 myipaddr(uchar *to, char *dev) 7 { 8 char buf[256]; 9 int n, fd, clone; 10 char *ptr; 11 12 /* Opening clone ensures the 0 connection exists */ 13 sprint(buf, "%s/clone", dev); 14 clone = open(buf, OREAD); 15 if(clone < 0) 16 return -1; 17 18 sprint(buf, "%s/0/local", dev); 19 fd = open(buf, OREAD); 20 close(clone); 21 if(fd < 0) 22 return -1; 23 n = read(fd, buf, sizeof(buf)-1); 24 close(fd); 25 if(n <= 0) 26 return -1; 27 buf[n] = 0; 28 29 ptr = strchr(buf, ' '); 30 if(ptr) 31 *ptr = 0; 32 33 parseip(to, buf); 34 return 0; 35 } 36