use of org.eclipse.kura.net.IP4Address in project kura by eclipse.
the class ConnectionInfoImpl method getIpAddress.
@Override
public IP4Address getIpAddress() {
IP4Address ipAddress = null;
String sIpAddress = this.m_props.getProperty("IPADDR");
if (sIpAddress != null) {
try {
ipAddress = (IP4Address) IPAddress.parseHostAddress(sIpAddress);
} catch (Exception e) {
s_logger.error("Error parsing IP address!", e);
}
}
return ipAddress;
}
use of org.eclipse.kura.net.IP4Address in project kura by eclipse.
the class RouteFile method findRoute.
private RouteConfig findRoute(Properties props, int index) {
RouteConfig route = null;
IPAddress dest = null;
IPAddress gw = null;
IPAddress mask = null;
if (!props.containsKey("ADDRESS" + index)) {
return null;
}
try {
dest = IPAddress.parseHostAddress((String) props.get("ADDRESS" + index));
gw = IPAddress.parseHostAddress((String) props.get("GATEWAY" + index));
mask = IPAddress.parseHostAddress((String) props.get("NETMASK" + index));
} catch (UnknownHostException e) {
e.printStackTrace();
}
if (dest != null && gw != null && mask != null) {
if (dest instanceof IP4Address) {
route = new RouteConfigIP4((IP4Address) dest, (IP4Address) gw, (IP4Address) mask, this.interfaceName, -1);
} else if (dest instanceof IP6Address) {
route = new RouteConfigIP6((IP6Address) dest, (IP6Address) gw, (IP6Address) mask, this.interfaceName, -1);
}
}
return route;
}
use of org.eclipse.kura.net.IP4Address in project kura by eclipse.
the class RouteFile method removeRoute.
public boolean removeRoute(IPAddress destination, IPAddress gateway, IPAddress netmask, String iface) {
RouteConfig route = null;
if (destination instanceof IP4Address) {
route = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, this.interfaceName, -1);
} else if (destination instanceof IP6Address) {
route = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, this.interfaceName, -1);
}
int index = routeIndex(route);
if (index != -1) {
this.routes.remove(index);
storeFile();
return true;
}
return false;
}
use of org.eclipse.kura.net.IP4Address in project kura by eclipse.
the class RouteFile method addRoute.
public boolean addRoute(IPAddress destination, IPAddress gateway, IPAddress netmask, String ifaceName) {
RouteConfig route = null;
if (destination instanceof IP4Address) {
route = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, ifaceName, -1);
} else if (destination instanceof IP6Address) {
route = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, ifaceName, -1);
}
if (routeIndex(route) != -1) {
return false;
}
this.routes.add(route);
storeFile();
return true;
}
use of org.eclipse.kura.net.IP4Address in project kura by eclipse.
the class RouteServiceImpl method entryToRoute.
private RouteConfig entryToRoute(String entry) {
RouteConfig route;
IPAddress destination;
IPAddress gateway;
IPAddress netmask;
int metric;
String iface;
String tmp;
try {
route = null;
StringTokenizer tok = new StringTokenizer(entry, " ");
tmp = tok.nextToken();
destination = IPAddress.parseHostAddress(tmp);
gateway = IPAddress.parseHostAddress(tok.nextToken());
netmask = IPAddress.parseHostAddress(tok.nextToken());
tok.nextToken();
metric = Integer.parseInt(tok.nextToken());
tok.nextToken();
tok.nextToken();
iface = tok.nextToken();
} catch (Exception e) {
s_logger.error("Error parsing route table entry: " + e.getMessage());
e.printStackTrace();
return null;
}
if (destination instanceof IP4Address) {
route = new RouteConfigIP4((IP4Address) destination, (IP4Address) gateway, (IP4Address) netmask, iface, metric);
} else if (destination instanceof IP6Address) {
route = new RouteConfigIP6((IP6Address) destination, (IP6Address) gateway, (IP6Address) netmask, iface, metric);
}
s_logger.trace("Route successfully read from route table entry");
return route;
}
Aggregations