Here you can find the source of ipv4ToStr(int ipv4)
Parameter | Description |
---|---|
ipv4 | the IPv4 address to be converted (must be in big endian byte-order) |
static public String ipv4ToStr(int ipv4)
//package com.java2s; /**// ww w.java2 s .c o m * NetUtil * Copyright (c) 2014 Frank Duerr * * NetUtil is part of SDN-MQ. This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Converts an IPv4 address from integer representation to dotted decimal notation (e.g., "192.168.1.1"). * @param ipv4 the IPv4 address to be converted (must be in big endian byte-order) * @return dotted decimal notation */ static public String ipv4ToStr(int ipv4) { short[] decimals = new short[4]; for (int i = 0; i < 4; i++) { decimals[i] = (short) (ipv4 & 0xff); ipv4 >>= 8; } String dottedStr = Short.toString(decimals[3]) + "." + Short.toString(decimals[2]) + "." + Short.toString(decimals[1]) + "." + Short.toString(decimals[0]); return dottedStr; } }