RockSaw Raw Socket Library for Java
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.
| Version | Source | Binaries | License | Changes | Documentation |
| 1.0.1 | rocksaw-1.0.1-src.tar.gz | rocksaw-1.0.1-bin.tar.gz | LICENSE | CHANGES | 1.0.1 API |
| 1.0.0 | rocksaw-1.0.0-src.tar.gz | rocksaw-1.0.0-bin.tar.gz | LICENSE |
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
- Why do I get an invalid argument error when I try to write to a TCP raw socket?
- Why can't I send TCP packets on Windows XP?
- Why can't I establish a TCP connection?
- Why can I get replies to ICMPv6 echo requests on POSIX systems but not on Microsoft Windows?
- Where's the name come from?
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 toIPPROTO_TCPraw sockets even though it allows you to create one. It does, however, supportIPPROTO_UDP.In order to write TCP packets via a raw socket on Windows, you have to open the socket with either
IPPROTO_IPorIPPROTO_RAW. Then you have to set theIP_HDRINCLsocket 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 useRawSocket.getProtocolByName("ip")andsetIPHeaderInclude(true).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.
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.
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.Where's the name come from?
($rocksaw="SOCK_RAW\n")=~s/(.)([^_]+)_(.)(.+)/$3\L$2\E$1\L$4\E/&&print$rocksaw