summaryrefslogtreecommitdiff
path: root/hscript/network.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-24 01:34:51 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-24 01:34:51 -0500
commit30b63f19fedde7b60bf99f3a68c0437a0c93b64e (patch)
treeb47af6071422452d35f864c089f9c08a0a72fac2 /hscript/network.cc
parent725e3f9f0c401aa34bb0d3d01bb8119797d038f7 (diff)
downloadhorizon-30b63f19fedde7b60bf99f3a68c0437a0c93b64e.tar.gz
horizon-30b63f19fedde7b60bf99f3a68c0437a0c93b64e.tar.bz2
horizon-30b63f19fedde7b60bf99f3a68c0437a0c93b64e.tar.xz
horizon-30b63f19fedde7b60bf99f3a68c0437a0c93b64e.zip
hscript: Finally implement R.V.network.netaddress.Interface
Diffstat (limited to 'hscript/network.cc')
-rw-r--r--hscript/network.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/hscript/network.cc b/hscript/network.cc
index e8f27b9..14e33b4 100644
--- a/hscript/network.cc
+++ b/hscript/network.cc
@@ -231,8 +231,35 @@ Key *NetAddress::parseFromData(const std::string &data, int lineno, int *errors,
}
}
-bool NetAddress::validate(ScriptOptions) const {
- /* possible to validate an address in the Installation Environment? */
+bool NetAddress::validate(ScriptOptions opts) const {
+ if(!opts.test(InstallEnvironment)) {
+ return true;
+ }
+
+#ifdef HAS_INSTALL_ENV
+ /* Retrieving the index is always valid, and is not even privileged. */
+ struct ifreq request;
+ int my_sock = ::socket(AF_INET, SOCK_STREAM, 0);
+ if(my_sock == -1) {
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "netaddress: can't open socket", ::strerror(errno));
+ return false;
+ }
+ memset(&request, 0, sizeof(request));
+ memcpy(&request.ifr_name, _iface.c_str(), _iface.size());
+ errno = 0;
+ if(ioctl(my_sock, SIOCGIFFLAGS, &request) == -1) {
+ if(errno == ENODEV) {
+ output_warning("installfile:" + std::to_string(this->lineno()),
+ "netaddress: specified interface does not exist");
+ return true;
+ }
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "netaddress: trouble communicating with interface",
+ ::strerror(errno));
+ return false;
+ }
+#endif
return true;
}