Java Networking: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 34: Line 34:


{{External|https://docs.oracle.com/javase/8/docs/api/java/net/NetworkInterface.html}}
{{External|https://docs.oracle.com/javase/8/docs/api/java/net/NetworkInterface.html}}
The JVM representation of a network interface available on the host. It is identified by a name, the same name returned by [[ifconfig -a]] or [[ip add]], if the host runs a Unix system.
Comparison between the information visible from JVM and directly from the system with <tt>ip addr</tt>:
<pre>
</pre>
<pre>
[eap@dc1 ~]$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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
      valid_lft forever preferred_lft forever
    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 08:00:27:2c:e2:de brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
      valid_lft 86249sec preferred_lft 86249sec
    inet6 fe80::a00:27ff:fe2c:e2de/64 scope link
      valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:95:52:f2 brd ff:ff:ff:ff:ff:ff
    inet 172.20.1.11/16 brd 172.20.255.255 scope global eth1
      valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe95:52f2/64 scope link
      valid_lft forever preferred_lft forever
</pre>




The representation of a network interface available on the host. It is identified by a name, the same name returned by [[ifconfig -a]], if the host runs a Unix system.


The instance can be used to get the list of addresses associated with the interface.  
The instance can be used to get the list of addresses associated with the interface.  


NetworkInterface code in GitHub: https://github.com/NovaOrdis/playground/tree/master/java/network/NetworkInterface
NetworkInterface code in GitHub: https://github.com/NovaOrdis/playground/tree/master/java/network/NetworkInterface

Revision as of 20:38, 15 March 2017

Internal

Concepts

InetAddress

https://docs.oracle.com/javase/8/docs/api/java/net/InetAddress.html

This class represents an Internet Protocol (IP) address. Its subclasses represent either 32 bit IPv4 addresses (Inet4Address) or an 128 bit IPv6 addresses (Inet6Address)

Inet4Address

https://docs.oracle.com/javase/8/docs/api/java/net/Inet4Address.html

Inet6Address

https://docs.oracle.com/javase/8/docs/api/java/net/Inet6Address.html

SocketAddress

https://docs.oracle.com/javase/8/docs/api/java/net/SocketAddress.html

Is an immutable representation of a socket address. It does not have any association with any protocol. The values are used by sockets for binding, connecting or as returned values.

InetSocketAddress

https://docs.oracle.com/javase/8/docs/api/java/net/InetSocketAddress.html

Represents an IP socket address (IP address + port or hostname + port).

NetworkInterface

https://docs.oracle.com/javase/8/docs/api/java/net/NetworkInterface.html

The JVM representation of a network interface available on the host. It is identified by a name, the same name returned by ifconfig -a or ip add, if the host runs a Unix system.

Comparison between the information visible from JVM and directly from the system with ip addr:


[eap@dc1 ~]$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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
       valid_lft forever preferred_lft forever
    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 08:00:27:2c:e2:de brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
       valid_lft 86249sec preferred_lft 86249sec
    inet6 fe80::a00:27ff:fe2c:e2de/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:95:52:f2 brd ff:ff:ff:ff:ff:ff
    inet 172.20.1.11/16 brd 172.20.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe95:52f2/64 scope link
       valid_lft forever preferred_lft forever


The instance can be used to get the list of addresses associated with the interface.

NetworkInterface code in GitHub: https://github.com/NovaOrdis/playground/tree/master/java/network/NetworkInterface