本文整理匯總了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();
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}