RockSaw Raw Socket Library for Java

Software icon

RockSaw is a simple API for performing network I/O with IPv4 and IPv6 raw sockets in Java. It has been deployed on tens of thousands of computing nodes as part of custom enterprise applications. Also, RockSaw contains a Ping.java example program that demonstrates how to send ICMPv4 and ICMPv6 ECHO_REQUEST packets and how to receive ICMPv4 and ICMPv6 ECHO_REPLY packets.

The current version of RockSaw compiles on Linux, Win32 with Cygwin/MinGW/Winsock or Visual C++, Solaris 8/9/10, FreeBSD, and Darwin/Mac OS X. It should compile on other POSIX systems using the GNU tool chain.

The Ping.java example program requires VServ TCP/IP to compile because it uses the ICMPEchoPacket class.

Some of the companies using RockSaw in their products are Cisco, Nortel, ByteSphere Technologies, and others.

On most operating systems, you must have root access or administrative privileges to use raw sockets.

The API is minimalist, but functional. If you have special needs, do not hesitate to inquire about custom support.

ByteSphere Technologies graciously funded IPv6 support. Please check out their network management and fault management products.

RockSaw Frequently Asked Questions

  1. Why do I get an invalid argument error when I try to write to a TCP raw socket?
  2. Why can't I send TCP packets on Windows XP?
  3. Why can't I establish a TCP connection?
  4. Why can I get replies to ICMPv6 echo requests on POSIX systems but not on Microsoft Windows?
  5. Where's the name come from?
  1. Why do I get an invalid argument error when I try to write to a TCP raw socket?

    java.io.IOException: An invalid argument was supplied. at org.savarese.rocksaw.net.RawSocket.__throwIOException(RawSocket.java:) at org.savarese.rocksaw.net.RawSocket.write(RawSocket.java:)

    This problem occurs only under the Windows family of operating systems. It occurs when you open a raw socket in the TCP protocol family (IPPROTO_TCP) and then try to write to it. Windows does not support writing to IPPROTO_TCP raw sockets even though it allows you to create one. It does, however, support IPPROTO_UDP.

    In order to write TCP packets via a raw socket on Windows, you have to open the socket with either IPPROTO_IP or IPPROTO_RAW. Then you have to set the IP_HDRINCL socket option and populate both the IP and TCP headers of each packet. What this means in terms of RockSaw is that on Windows you have to use RawSocket.getProtocolByName("ip") and setIPHeaderInclude(true).

  2. Why can't I send TCP packets on Windows XP?

    New restrictions on raw socket functionality were imposed in Windows XP SP2. If you're running Windows XP SP2, you cannot send TCP packets (but you can still receive them), nor can you spoof the source address of IP packets. The source address must exist on a local network interface.

  3. Why can't I establish a TCP connection?

    Even though you can send TCP packets with a raw socket, the operating system's TCP/IP stack will process incoming TCP and UDP packets. When you send a TCP SYN packet with a raw socket, the destination's response will be rejected by the operating system because it is unaware of the SYN you sent. Therefore, you cannot complete a three-way handshake.

  4. Why can I get replies to ICMPv6 echo requests on POSIX systems but not on Microsoft Windows?

    The Microsoft Windows family of operating systems does not calculate the ICMPv6 checksum for outgoing ICMPv6 packets. Therefore, you have to calculate the checksum yourself. This can be tricky because you have to determine the address of the outgoing network interface, which can vary on multi-interface systems depending on the available routes. See the example.Ping source code to see how to compute the required checksum and send an ICMPv6 echo request on Windows.
  5. Where's the name come from?

    ($rocksaw="SOCK_RAW\n")=~s/(.)([^_]+)_(.)(.+)/$3\L$2\E$1\L$4\E/&&print$rocksaw