Tuesday, September 2, 2014

IPv6 - InetAddress and scope_id

Ever wondered whats the scope_id which comes after IPv6 address prefixed with "%" in Java InetAddress.getAllByName() or InetAddress.getByName() method.

The Javadoc is as below

The IPv6-address is a literal IPv6 address as described above. The scope_id refers to an interface on the local system, and it can be specified in two ways.
  1. As a numeric identifier. This must be a positive integer that identifies the particular interface and scope as understood by the system. Usually, the numeric values can be determined through administration tools on the system. Each interface may have multiple values, one for each scope. If the scope is unspecified, then the default value used is zero.

  2. As a string. This must be the exact string that is returned by NetworkInterface.getName() for the particular interface in question. When an Inet6Address is created in this way, the numeric scope-id is determined at the time the object is created by querying the relevant NetworkInterface.
Note also, that the numeric scope_id can be retrieved from Inet6Address instances returned from the NetworkInterface class. This can be used to find out the current scope ids configured on the system. 

But to me the above explanation is not very clear.

After digging up little bit, I have found out how this scope_id is fetched. This is the integer id assigned to the network interfaces available in the system. This interface id can be found using "ip addr" or "ip link" command.



I have written the following program for analysis purpose.

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class networkinterfacetest1 {
  public static void main(String...args) {
    Enumeration<NetworkInterface> networkInterfaces;
    try {
      networkInterfaces = NetworkInterface.getNetworkInterfaces();
      Integer notIncludedMatch = null;
      Integer match = null;
      while (networkInterfaces.hasMoreElements()) {
        Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses();
        while (inetAddresses.hasMoreElements()) {
        InetAddress addr = inetAddresses.nextElement();
        System.out.println("ip all:" + addr);
        }
      }
    } catch (SocketException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}


I have a system where the ip addr output is as below.

[user@BGL-351L tch]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  inet 127.0.0.1/8 scope host lo
   inet6 ::1/128 scope host
   valid_lft forever preferred_lft forever
2: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
  link/ether 08:11:96:09:04:04 brd ff:ff:ff:ff:ff:ff
3: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  link/ether 5c:26:0a:77:e4:fd brd ff:ff:ff:ff:ff:ff
  inet 10.10.64.86/22 brd 10.10.67.255 scope global em1
  inet6 fcff:3:10:64:5e26:aff:fe77:e4fd/64 scope global dynamic
   valid_lft 2591601sec preferred_lft 604401sec
  inet6 fe80::5e26:aff:fe77:e4fd/64 scope link
   valid_lft forever preferred_lft forever


In the same machine If I runthe above program, I have got the output as

ip all:BGL-351L/10.10.64.86
ip all:BGL-351L/fe80:0:0:0:5e26:aff:fe77:e4fd%3
ip all:BGL-351L/fcff:3:10:64:5e26:aff:fe77:e4fd%3


And in another machine the "ip addr" and program output are as below as

[user@BGL-341L]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  inet 127.0.0.1/8 scope host lo
  inet6 ::1/128 scope host
   valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  link/ether 00:0c:29:64:61:4a brd ff:ff:ff:ff:ff:ff
  inet 10.10.68.24/22 brd 10.10.71.255 scope global eth0
  inet6 3002::20c:29ff:fe64:614a/64 scope global dynamic
   valid_lft 2591981sec preferred_lft 604781sec
  inet6 fe80::20c:29ff:fe64:614a/64 scope link
   valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
  link/ether 9a:ee:72:78:fc:cc brd ff:ff:ff:ff:ff:ff
  inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0


Program output:

ip all:BGL-341L/fe80:0:0:0:20c:29ff:fe64:614a%2
ip all:BGL-341L/3002:0:0:0:20c:29ff:fe64:614a%2
ip all:BGL-341L/10.10.68.24


So, In both the above cases, the id assigned to em1 or eth0 came as scope_id along with ipv6 address in java program output.
 

Monday, August 18, 2014

vnc server unable connect to socket: Connection refused (111)

In order to avoid this problem, go to the file vim /etc/sysconfig/vncservers.
Remove the localhost in the following line

VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

it should be as below

VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp".

Also you can additionally change the screen resolution so that screen size will be better.
I use the following values.

 VNCSERVERARGS[2]="-geometry 1920x1080 -nolisten tcp"

Thursday, July 31, 2014

Run eclipse from windows mount patition in linux

Windows partition is using the NTFS filesystem and it was mounted with an fmask that does not permit setting execute permissions on files.

 To resolve this problem, follow the steps below.
  1. Determine the drive's corresponding device by opening a terminal and typing: df
  2. The column on the far left is the device, and the column on the far right is the path for the drive. Find the device for the Vista partition.
  3. Unmount the Windows partition. (Click the eject button alt text that's next to it in Nautilus)
  4. Open a terminal
  5. Type the following:
    sudo mkdir /media/vista
    sudo mount -t ntfs -o fmask=0022,dmask=0000,uid=1000,gid=1000 \
        <DRIVE> /media/vista
    
    Replace <DRIVE> with your drive's device.

Saturday, July 19, 2014

How to start eclipse with different java home

To point eclipse to a different installed java, edit the the eclipse.ini file as below.


Note: Sample taken from eclipse luna package.
A sample eclipse.ini file will look like below

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140603-1326
-product
org.eclipse.epp.package.standard.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.7
-XX:MaxPermSize=256m
-Xms40m
-Xmx512m


Here before the -vmargs, add the path of your installed java with "-vm" option. Please not the path should be in the next line after "-vm". If you give continuously on the same line, then it will not work. An example eclipse.ini with custom java location is below.

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140603-1326
-product
org.eclipse.epp.package.standard.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
/usr/java/jdk1.7.0_65/bin/java
-vmargs
-Dosgi.requiredJavaVersion=1.7
-XX:MaxPermSize=256m
-Xms40m
-Xmx512m

How to find JDK is 32 bit or 64 bit

There is no direct way to find the installed java is 32 bit or 64 bit. So, to check run the following command.

if you get the out put as below, then your java is 32 bit.

[root@Vijay install]# /usr/java/jdk1.7.0_60/bin/java -d64 -version
Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.


If you have 64 bit java then you will get the out put as below

[root@Vijay install]# /usr/java/jdk1.7.0_65/bin/java -d64 -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mo
de)