blob: 9230365601ec39e662d9957abc3ecee899717c64 [file] [log] [blame]
Brian Silverman66f079a2013-08-26 16:24:30 -07001#include "aos/crio/ip.h"
2
3#include <ifLib.h>
4#include <stdio.h>
5
6namespace aos {
7namespace 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
12const char *const kCrioNetInterfaces[] = {"fec0", "motfec0"};
13in_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