Computes the 64 bit 6to4 prefix from a given IPv4 base address. - Android Network

Android examples for Network:IP Address

Description

Computes the 64 bit 6to4 prefix from a given IPv4 base address.

Demo Code

/*****************************************************************************
 *  Project: Android IPv6Config/*w ww  . j  a  v a2 s. c o  m*/
 *  Description: Android application to change IPv6 kernel configuration
 *  Author: Ren? Mayrhofer
 *  Copyright: Ren? Mayrhofer, 2011-2014
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 
 * as published by the Free Software Foundation.
 *****************************************************************************/
//package com.java2s;

import java.net.Inet4Address;

public class Main {
    /** Computes the 64 bit 6to4 prefix from a given IPv4 base address. The 
     * format is 2002:%02x%02x:%02x%02x with the 4 bytes of ipv4Base filled in.
     */
    public static String compute6to4Prefix(Inet4Address ipv4Base) {
        if (ipv4Base == null)
            return null;

        byte[] addrBytes = ipv4Base.getAddress();
        String prefix = String.format("2002:%02x%02x:%02x%02x",
                addrBytes[0], addrBytes[1], addrBytes[2], addrBytes[3]);
        return prefix;
    }
}

Related Tutorials