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


Java Inet4Address.getByAddress方法代码示例

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


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

示例1: localAddress

import java.net.Inet4Address; //导入方法依赖的package包/类
@Override
protected SocketAddress localAddress(DatagramChannel handle) throws Exception {
    InetSocketAddress inetSocketAddress = (InetSocketAddress) handle.socket().getLocalSocketAddress();
    InetAddress inetAddress = inetSocketAddress.getAddress();

    if ((inetAddress instanceof Inet6Address) && (((Inet6Address) inetAddress).isIPv4CompatibleAddress())) {
        // Ugly hack to workaround a problem on linux : the ANY address is always converted to IPV6
        // even if the original address was an IPV4 address. We do store the two IPV4 and IPV6
        // ANY address in the map.
        byte[] ipV6Address = ((Inet6Address) inetAddress).getAddress();
        byte[] ipV4Address = new byte[4];

        for (int i = 0; i < 4; i++) {
            ipV4Address[i] = ipV6Address[12 + i];
        }

        InetAddress inet4Adress = Inet4Address.getByAddress(ipV4Address);
        return new InetSocketAddress(inet4Adress, inetSocketAddress.getPort());
    } else {
        return inetSocketAddress;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:NioDatagramAcceptor.java

示例2: ipIntToInet4Address

import java.net.Inet4Address; //导入方法依赖的package包/类
public static InetAddress ipIntToInet4Address(int ip){
	byte[] ipAddress=new byte[4];
	writeInt(ipAddress, 0, ip);
       try {
		return  Inet4Address.getByAddress(ipAddress);
	} catch (UnknownHostException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:w22ee,项目名称:onekey-proxy-android,代码行数:12,代码来源:CommonMethods.java

示例3: fromIpv4String

import java.net.Inet4Address; //导入方法依赖的package包/类
/**
 * 从IPv4String转换为InetAddress.
 * 
 * IpString如果确定ipv4, 使用本方法减少字符分析消耗 .
 * 
 * 先字符串传换为byte[]再调getByAddress(byte[]),避免了调用getByName(ip)可能引起的DNS访问.
 */
public static Inet4Address fromIpv4String(String address) {
	byte[] bytes = ip4StringToBytes(address);
	if (bytes == null) {
		return null;
	} else {
		try {
			return (Inet4Address) Inet4Address.getByAddress(bytes);
		} catch (UnknownHostException e) {
			throw new AssertionError(e);
		}
	}
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:20,代码来源:IPUtil.java

示例4: ipIntToInet4Address

import java.net.Inet4Address; //导入方法依赖的package包/类
public static InetAddress ipIntToInet4Address(int ip) {
    byte[] ipAddress = new byte[4];
    writeInt(ipAddress, 0, ip);
    try {
        return Inet4Address.getByAddress(ipAddress);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:IronMan001,项目名称:ss-android,代码行数:12,代码来源:CommonMethods.java


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