List of usage examples for java.net InetAddress getByAddress
public static InetAddress getByAddress(byte[] addr) throws UnknownHostException
From source file:org.bgp4j.rib.RoutingInformationBaseTest.java
@Test public void testAddSinglePrefixNextHop() throws Exception { InetAddressNextHop<InetAddress> nextHop = new InetAddressNextHop<InetAddress>( InetAddress.getByAddress(new byte[] { (byte) 0xc0, (byte) 0xa8, (byte) 0x01, (byte) 0x01 })); rib.addRoutes(Arrays.asList(LESS_NLRI), attrs, nextHop); Assert.assertEquals(1, catcher.getRouteAddedEvents().size()); Assert.assertEquals(0, catcher.getRouteWithdrawnEvents().size()); Assert.assertTrue(catcher.getRouteAddedEvents().contains( new RouteAdded(RIB_NAME, RIB_SIDE, new Route(rib.getRibID(), RIB_AFK, LESS_NLRI, attrs, nextHop)))); Assert.assertTrue(listener.getRouteAddedEvents().contains( new RouteAdded(RIB_NAME, RIB_SIDE, new Route(rib.getRibID(), RIB_AFK, LESS_NLRI, attrs, nextHop)))); }
From source file:com.shonshampain.streamrecorder.util.StreamProxy.java
private void init() { try {/*from w w w. ja v a 2 s.c om*/ socket = new ServerSocket(port, 0, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); socket.setSoTimeout(5000); port = socket.getLocalPort(); Logger.d(DBG, TAG, "port " + port + " obtained"); } catch (IOException e) { Logger.e(TAG, "Error initializing server", e); } }
From source file:org.opendaylight.controller.web.DaylightWebAdmin.java
/** * Return nodes connected to controller {controller} * * @param controller//w w w.jav a 2 s. co m * - byte[] of the address of the controller * @return List<NodeBean> */ @RequestMapping("/cluster/controller/{controller}") @ResponseBody public String getNodesConnectedToController(@PathVariable("controller") String controller) { IClusterGlobalServices clusterServices = (IClusterGlobalServices) ServiceHelper .getGlobalInstance(IClusterGlobalServices.class, this); if (clusterServices == null) { return null; } IConnectionManager connectionManager = (IConnectionManager) ServiceHelper .getGlobalInstance(IConnectionManager.class, this); if (connectionManager == null) { return null; } ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, GlobalConstants.DEFAULT.toString(), this); if (switchManager == null) { return null; } byte[] address = gson.fromJson(controller, byte[].class); InetAddress controllerAddress = null; try { controllerAddress = InetAddress.getByAddress(address); } catch (UnknownHostException e) { return null; } List<NodeBean> result = new ArrayList<NodeBean>(); Set<Node> nodes = connectionManager.getNodes(controllerAddress); if (nodes == null) { return gson.toJson(result); } for (Node node : nodes) { Description description = (Description) switchManager.getNodeProp(node, Description.propertyName); NodeBean nodeBean; if (description == null || description.getValue().equals("None")) { nodeBean = new NodeBean(node); } else { nodeBean = new NodeBean(node, description.getValue()); } result.add(nodeBean); } return gson.toJson(result); }
From source file:org.rm3l.ddwrt.utils.Utils.java
@Nullable public static InetAddress getBroadcastAddress(@Nullable final WifiManager wifiManager) throws IOException { if (wifiManager == null) { return null; }/*from ww w. java2s. c o m*/ final DhcpInfo dhcpInfo = wifiManager.getDhcpInfo(); if (dhcpInfo == null) { return null; } final int broadcast = (dhcpInfo.ipAddress & dhcpInfo.netmask) | ~dhcpInfo.netmask; final byte[] quads = new byte[4]; for (int k = 0; k < 4; k++) { quads[k] = (byte) ((broadcast >> k * 8) & 0xFF); } return InetAddress.getByAddress(quads); }
From source file:org.opennms.protocols.dhcp.detector.DhcpDetectorTest.java
@Test(timeout = 90000) @Ignore/*ww w . j av a 2 s . c o m*/ public void testJdhcp() throws IOException { DHCPSocket mySocket = new DHCPSocket(68); try { DHCPMessage messageOut = new DHCPMessage(InetAddressUtils.addr(DHCP_SERVER_IP)); // fill DHCPMessage object messageOut.setOp((byte) 1); messageOut.setHtype((byte) 1); messageOut.setHlen((byte) 6); messageOut.setHops((byte) 0); messageOut.setXid(191991743); // should be a random int messageOut.setSecs((short) 0); messageOut.setFlags((short) 0); byte[] hw = new byte[16]; hw[0] = (byte) 0x00; hw[1] = (byte) 0x60; hw[2] = (byte) 0x97; hw[3] = (byte) 0xC6; hw[4] = (byte) 0x76; hw[5] = (byte) 0x64; messageOut.setChaddr(hw); // set message type option to DHCPDISCOVER byte[] opt = new byte[1]; opt[0] = (byte) DHCPMessage.DISCOVER; messageOut.setOption(53, opt); mySocket.send(messageOut); DHCPMessage messageIn = new DHCPMessage(); mySocket.receive(messageIn); messageIn.printMessage(); System.out.println("Destination Address: " + messageIn.getDestinationAddress()); System.out.println("Ch Address: " + Arrays.toString(messageIn.getChaddr())); System.out.println("Siaddr: " + Arrays.toString(messageIn.getSiaddr())); System.out.println("Ciaddr: " + Arrays.toString(messageIn.getCiaddr())); System.out.println("Option54: " + Arrays.toString(messageIn.getOption(54))); System.out.println(InetAddress.getByAddress(messageIn.getOption(54))); } finally { IOUtils.closeQuietly(mySocket); } }
From source file:com.offbynull.portmapper.pcp.MapPcpResponse.java
/** * Constructs a {@link MapPcpResponse} object by parsing a buffer. * @param buffer buffer containing PCP response data * @throws NullPointerException if any argument is {@code null} * @throws BufferUnderflowException if not enough data is available in {@code buffer} * @throws IllegalArgumentException if there's not enough or too much data remaining in the buffer, or if the version doesn't match the * expected version (must always be {@code 2}), or if the r-flag isn't set, or if there's an unsuccessful/unrecognized result code, * or if the op code doesn't match the MAP opcode, or if the response has a {@code 0} for its {@code internalPort} or * {@code assignedExternalPort} field, or if there were problems parsing options *///from w ww . ja va 2s .co m public MapPcpResponse(ByteBuffer buffer) { super(buffer); Validate.isTrue(super.getOp() == 1); mappingNonce = ByteBuffer.allocate(12); buffer.get(mappingNonce.array()); mappingNonce = mappingNonce.asReadOnlyBuffer(); this.protocol = buffer.get() & 0xFF; for (int i = 0; i < 3; i++) { // reserved block buffer.get(); } this.internalPort = buffer.getShort() & 0xFFFF; this.assignedExternalPort = buffer.getShort() & 0xFFFF; byte[] addrArr = new byte[16]; buffer.get(addrArr); try { this.assignedExternalIpAddress = InetAddress.getByAddress(addrArr); // should automatically shift down to ipv4 if ipv4-to-ipv6 // mapped address } catch (UnknownHostException uhe) { throw new IllegalArgumentException(uhe); // should never happen, will always be 16 bytes } Validate.inclusiveBetween(0, 255, protocol); // should never happen Validate.inclusiveBetween(0, 65535, internalPort); // can be 0 if referencing all Validate.inclusiveBetween(0, 65535, assignedExternalPort); // can be 0 if removing parseOptions(buffer); }
From source file:org.opendaylight.lispflowmapping.lisp.util.MaskUtil.java
private static InetAddress normalizeIP(InetAddress address, int maskLength) throws UnknownHostException { ByteBuffer byteRepresentation = ByteBuffer.wrap(address.getAddress()); byte b = (byte) 0xff; int mask = maskLength; for (int i = 0; i < byteRepresentation.array().length; i++) { if (mask >= 8) { byteRepresentation.put(i, (byte) (b & byteRepresentation.get(i))); } else if (mask > 0) { byteRepresentation.put(i, (byte) ((byte) (b << (8 - mask)) & byteRepresentation.get(i))); } else {//w ww .ja va2 s. c o m byteRepresentation.put(i, (byte) (0 & byteRepresentation.get(i))); } mask -= 8; } return InetAddress.getByAddress(byteRepresentation.array()); }
From source file:org.opentides.util.UrlUtil.java
/** * Helper function that converts string of IP Address * into an InetAddress// w w w .j a v a 2 s .c om * * @param IPString * @return InetAddress */ public static InetAddress convertIPString(String IPString) { try { // convert IP String to bytes String[] IPAddress = IPString.split("\\."); byte[] IPBytes = { (byte) Integer.parseInt(IPAddress[0]), (byte) Integer.parseInt(IPAddress[1]), (byte) Integer.parseInt(IPAddress[2]), (byte) Integer.parseInt(IPAddress[3]) }; return InetAddress.getByAddress(IPBytes); } catch (UnknownHostException uhe) { _log.error("FAILED to convert IP address [" + IPString + "]", uhe); return null; } }
From source file:it.infn.ct.jsaga.adaptor.rocci.job.rOCCIJobControlAdaptor.java
public boolean testIpAddress(byte[] testAddress) { Inet4Address inet4Address;// ww w .ja v a2 s . c o m boolean result = false; try { inet4Address = (Inet4Address) InetAddress.getByAddress(testAddress); result = inet4Address.isSiteLocalAddress(); } catch (UnknownHostException ex) { log.error(ex); } return result; }
From source file:com.vuze.plugin.azVPN_Air.Checker.java
public Checker(PluginInterface pi) { this.pi = pi; this.config = pi.getPluginconfig(); this.texts = pi.getUtilities().getLocaleUtilities(); try {/*w ww. j ava 2 s .c o m*/ testSocketAddress = InetAddress.getByAddress(new byte[] { 1, 1, 1, 1 }); } catch (UnknownHostException e) { } }