Brian Silverman | 66f079a | 2013-08-26 16:24:30 -0700 | [diff] [blame] | 1 | #include "aos/crio/ip.h" |
| 2 | |
| 3 | #include <ifLib.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | namespace aos { |
| 7 | namespace util { |
| 8 | |
| 9 | // 4-slot cRIO: motfec0 |
| 10 | // 8-slot cRIO port 1: fec0 |
| 11 | // `ifShow` will show you all of the ones on a given cRIO |
| 12 | const char *const kCrioNetInterfaces[] = {"fec0", "motfec0"}; |
| 13 | in_addr GetOwnIPAddress() { |
| 14 | char buffer[INET_ADDR_LEN]; |
| 15 | in_addr r; |
| 16 | while (true) { |
| 17 | for (size_t i = 0; |
| 18 | i < sizeof(kCrioNetInterfaces) / sizeof(kCrioNetInterfaces[0]); ++i) { |
| 19 | if (ifAddrGet(const_cast<char *>(kCrioNetInterfaces[i]), buffer) == OK) { |
| 20 | if (inet_aton(buffer, &r) == OK) { |
| 21 | return r; |
| 22 | } else { |
| 23 | buffer[sizeof(buffer) - 1] = '\0'; |
| 24 | printf("inet_aton('%s', %p) failed\n", buffer, &r); |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | } // namespace util |
| 32 | } // namespace aos |