refactored the IP address handling code
It is now split up much more cleanly, has less stuff running on the
cRIO, and doesn't do as much of the stuff with string manipulation.
Before, it was kind of ridicilous how many times the code converted IP
addresses back and forth between 32-bit ints and strings to do various
manipulations and pass them around. Also, there was various junk that
the cRIO code did that it did not need to be doing.
diff --git a/aos/crio/ip.cc b/aos/crio/ip.cc
new file mode 100644
index 0000000..9230365
--- /dev/null
+++ b/aos/crio/ip.cc
@@ -0,0 +1,32 @@
+#include "aos/crio/ip.h"
+
+#include <ifLib.h>
+#include <stdio.h>
+
+namespace aos {
+namespace util {
+
+// 4-slot cRIO: motfec0
+// 8-slot cRIO port 1: fec0
+// `ifShow` will show you all of the ones on a given cRIO
+const char *const kCrioNetInterfaces[] = {"fec0", "motfec0"};
+in_addr GetOwnIPAddress() {
+ char buffer[INET_ADDR_LEN];
+ in_addr r;
+ while (true) {
+ for (size_t i = 0;
+ i < sizeof(kCrioNetInterfaces) / sizeof(kCrioNetInterfaces[0]); ++i) {
+ if (ifAddrGet(const_cast<char *>(kCrioNetInterfaces[i]), buffer) == OK) {
+ if (inet_aton(buffer, &r) == OK) {
+ return r;
+ } else {
+ buffer[sizeof(buffer) - 1] = '\0';
+ printf("inet_aton('%s', %p) failed\n", buffer, &r);
+ }
+ }
+ }
+ }
+}
+
+} // namespace util
+} // namespace aos