当前位置: 首页>>代码示例>>Java>>正文


Java Inet6Address.getByAddress方法代码示例

本文整理汇总了Java中java.net.Inet6Address.getByAddress方法的典型用法代码示例。如果您正苦于以下问题:Java Inet6Address.getByAddress方法的具体用法?Java Inet6Address.getByAddress怎么用?Java Inet6Address.getByAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.Inet6Address的用法示例。


在下文中一共展示了Inet6Address.getByAddress方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readFrom

import java.net.Inet6Address; //导入方法依赖的package包/类
@Override
public void readFrom(DataInput in) throws Exception {
  int len = in.readByte();
  if (len > 0 && (len != Global.IPV4_SIZE && len != Global.IPV6_SIZE))
    throw new IOException("length has to be " + Global.IPV4_SIZE + " or " + Global.IPV6_SIZE
        + " bytes (was " + len + " bytes)");
  byte[] a = new byte[len]; // 4 bytes (IPv4) or 16 bytes (IPv6)
  in.readFully(a);
  if (len == Global.IPV6_SIZE) {
    int scope_id = in.readInt();
    this.ip_addr = Inet6Address.getByAddress(null, a, scope_id);
  } else {
    this.ip_addr = InetAddress.getByAddress(a);
  }

  // changed from readShort(): we need the full 65535, with a short we'd only get up to 32K !
  port = in.readUnsignedShort();
  vmViewId = in.readInt();
  mostSigBits = in.readLong();
  leastSigBits = in.readLong();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:22,代码来源:JGAddress.java

示例2: addDnsServer

import java.net.Inet6Address; //导入方法依赖的package包/类
private InetAddress addDnsServer(Builder builder, String format, byte[] ipv6Template, InetAddress address) throws UnknownHostException {
    int size = dnsServers.size();
    size++;
    if (address instanceof Inet6Address && ipv6Template == null) {
        Log.i(TAG, "addDnsServer: Ignoring DNS server " + address);
    } else if (address instanceof Inet4Address) {
        String alias = String.format(format, size + 1);
        dnsServers.put(alias, address.getHostAddress());
        builder.addRoute(alias, 32);
        return InetAddress.getByName(alias);
    } else if (address instanceof Inet6Address) {
        ipv6Template[ipv6Template.length - 1] = (byte) (size + 1);
        InetAddress i6addr = Inet6Address.getByAddress(ipv6Template);
        dnsServers.put(i6addr.getHostAddress(), address.getHostAddress());
        return i6addr;
    }
    return null;
}
 
开发者ID:iTXTech,项目名称:Daedalus,代码行数:19,代码来源:DaedalusVpnService.java

示例3: _getBroadcastIPAddress4IPv6

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * The broadcast ip for a icmp v6 request is replaced all bytes except the last three bytes with _IPv6_BROADCAST_IPADDRESS_PREFIX
 *
 * @param inet6Address
 * @return
 */
private Inet6Address _getBroadcastIPAddress4IPv6(Inet6Address inet6Address) throws UnknownHostException {
    //"fe80:0:0:0:250:56ff:febc:2688" -> "FF02::1:FFbc:2688"
    byte[] ipInBytes = inet6Address.getAddress();
    byte[] broadcastIpAddress = new byte[ipInBytes.length];
    System.arraycopy(_IPv6_BROADCAST_IPADDRESS_PREFIX, 0, broadcastIpAddress, 0, _IPv6_BROADCAST_IPADDRESS_PREFIX.length);
    int reservedBytes = 3;
    System.arraycopy(ipInBytes, ipInBytes.length - reservedBytes, broadcastIpAddress, _IPv6_BROADCAST_IPADDRESS_PREFIX.length -
            reservedBytes, reservedBytes);
    return (Inet6Address) Inet6Address.getByAddress(broadcastIpAddress);
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:17,代码来源:MacAddressHelper.java

示例4: forgeScoped

import java.net.Inet6Address; //导入方法依赖的package包/类
/** creates scoped ipv6 address without any lookups. hostname can be null, for missing */
private InetAddress forgeScoped(String hostname, String address, int scopeid) throws IOException {
    byte bytes[] = InetAddress.getByName(address).getAddress();
    return Inet6Address.getByAddress(hostname, bytes, scopeid);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:NetworkAddressTests.java

示例5: startNewSession

import java.net.Inet6Address; //导入方法依赖的package包/类
private boolean startNewSession(SECCDiscoveryRes seccDiscoveryRes) {
	/*
	 * Establish a new V2GCommunicationSessionEVCC if SECCDiscoveryRes was successful and initiate
	 * the respective TCP client connection
	 */
	if (seccDiscoveryRes != null) {
		// Reset SECCDiscoveryReq retry counter
		setSeccDiscoveryRequestCounter(0);
		
		Inet6Address seccAddress;
		
		try {
			// TODO seems to work, but is the needed scope ID really the one of the UDP client?
			seccAddress = Inet6Address.getByAddress(
									InetAddress.getByAddress(seccDiscoveryRes.getSeccIPAddress()).getHostAddress(),
									seccDiscoveryRes.getSeccIPAddress(), 
									UDPClient.getInstance().getUdpClientAddress().getScopeId()
								);
		} catch (UnknownHostException e) {
			getLogger().fatal("SECC address could not be resolved", e);
			return false;
		}
		
		getLogger().info("UDP server responded: SECC reachable at address " + 
						 seccAddress.getHostAddress() + " and port " + 
						 ByteUtils.toIntFromByteArray(seccDiscoveryRes.getSeccPort())); 
		
		if (!startTransportLayerClient(seccDiscoveryRes, seccAddress)) return false;
		
		setV2gCommunicationSessionEVCC(new V2GCommunicationSessionEVCC(getTransportLayerClient()));
		
		/*
		 * Tell the TCP- or TLSClient to notify if 
		 * - a new V2GTPMessage has arrived
		 * - a timeout has occurred while waiting for the respective response message
		 */
		getTransportLayerClient().addObserver(getV2gCommunicationSessionEVCC());
		
		getV2gCommunicationSessionEVCC().addObserver(this);
		
		// Set TLS security flag for communication session
		boolean secureConn = (((Byte) getSecurity()).compareTo((Byte) GlobalValues.V2G_SECURITY_WITH_TLS.getByteValue()) == 0) ? true : false;
		getV2gCommunicationSessionEVCC().setTlsConnection(secureConn);
		
		sendSupportedAppProtocolReq();
	} else {
		getLogger().fatal("Maximum number of SECCDiscoveryReq messages reached");
		return false;
	}
	
	return true;
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:53,代码来源:V2GCommunicationSessionHandlerEVCC.java

示例6: getByAddressForInterface

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * @param network Network interface index
 * @throws UnknownHostException
 */
private Inet6Address getByAddressForInterface(final NetworkInterface network, final InetAddress address) throws UnknownHostException {
    // Append network interface. Workaround for issue #8802
    return Inet6Address.getByAddress(address.getHostAddress(),
            IPAddressUtil.textToNumericFormatV6(address.getHostAddress()), network.getIndex());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:10,代码来源:NetworkInterfaceAwareSocketFactory.java


注:本文中的java.net.Inet6Address.getByAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。