use of org.eclipse.kura.core.net.modem.ModemInterfaceAddressImpl in project kura by eclipse.
the class NetworkServiceImpl method getModemInterfaceAddresses.
private List<ModemInterfaceAddress> getModemInterfaceAddresses(String interfaceName, boolean isUp) throws KuraException {
List<ModemInterfaceAddress> modemInterfaceAddresses = new ArrayList<ModemInterfaceAddress>();
if (isUp) {
ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
ModemInterfaceAddressImpl modemInterfaceAddress = new ModemInterfaceAddressImpl();
modemInterfaceAddresses.add(modemInterfaceAddress);
try {
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
String currentNetmask = ifconfig.getInetMask();
if (currentNetmask != null) {
modemInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
modemInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
modemInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
modemInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
modemInterfaceAddress.setGateway(conInfo.getGateway());
modemInterfaceAddress.setDnsServers(conInfo.getDnsServers());
ModemConnectionStatus connectionStatus = isUp ? ModemConnectionStatus.CONNECTED : ModemConnectionStatus.DISCONNECTED;
modemInterfaceAddress.setConnectionStatus(connectionStatus);
// TODO - other attributes
} else {
return null;
}
} else {
return null;
}
} catch (UnknownHostException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
return modemInterfaceAddresses;
}
Aggregations