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 is the de facto standard API for
multi-platform raw socket programming in Java, having been deployed on
hundreds of thousands of computing nodes as part of commercial products
and custom enterprise applications. To help you get started, RockSaw
Ping.java example program that demonstrates how to send
ICMPv4 and ICMPv6
ECHO_REQUEST packets and how to receive
ICMPv4 and ICMPv6
The current version of RockSaw compiles on the following 32-bit and 64-bit platforms: Linux, Windows 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.
Ping.java example program requires
to compile because it uses the
Some of the companies using RockSaw in their products are Cisco, Brocade, 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
- How do I compile for 64-bit Windows?
- 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 receive UDP or TCP packets?
- 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?
How do I compile for 64-bit Windows?
Follow the instructions in the README for Win32, but run vcvars64.bat instead of vcvars32.bat to use the 64-bit Visual C++ compiler.
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_TCPraw sockets even though it allows you to create one. It does, however, support
In order to write TCP packets via a raw socket on Windows, you have to open the socket with either
IPPROTO_RAW. Then you have to set the
IP_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 use
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, nor can you spoof the source address of IP packets. The source address must exist on a local network interface.
Why can't I receive UDP or TCP packets?
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 without forwarding them to a raw socket. The Linux kernel, whose TCP/IP stack is not derived from BSD or System V Unix, is an exception.
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?perl -e '($rocksaw="SOCK_RAW\n")=~s/(.)([^_]+)_(.)(.+)/$3\L$2\E$1\L$4\E/&&print$rocksaw'