-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
Install the Hammer parser combinator library and verify your setup. Once done, you can dive into any of the protocol examples.
| Tool | Why |
|---|---|
| GCC (or any C compiler) | Compiles parsers written with Hammer |
| pkg-config | Locates an installed Hammer library when not using the checkout-local build |
| make | Most examples use Makefiles |
| SCons | Required to build Hammer from source |
Hammer must be built from source. It is not in most system package managers (yet).
sudo apt install gcc sconsgit clone https://github.com/riversideresearch/hammer.git
cd hammer
scons examplesThis builds Hammer plus the SCons-managed examples under build/opt/. The standalone protocol examples in examples/dns, examples/ntp, and examples/tftp can link against this checkout-local build directly.
Install Hammer only if you want to compile code outside the checkout with pkg-config libhammer:
sudo scons install
sudo ldconfig # refresh the dynamic linker cache (Linux only)Hammer installs a pkg-config file. Check that it's found:
pkg-config --cflags --libs libhammerYou should see output like:
-I/usr/local/include -L/usr/local/lib -lhammer
If this fails, make sure scons install completed without errors and that /usr/local/lib/pkgconfig is in your PKG_CONFIG_PATH.
Note: Hammer supports RTEMS 5 on SPARC targets, including a static (no-heap) memory mode for embedded systems. If you're building for RTEMS, see Using RTEMS instead of the instructions above.
Every C file that uses Hammer needs these headers:
#include <hammer/hammer.h> // Core API: h_parse, h_uint8, h_sequence, etc.
#include <hammer/glue.h> // Convenience macros: H_RULE, H_ARULE, H_MAKE_UINT, etc.For code outside the Hammer checkout, use pkg-config to get the right compiler and linker flags:
gcc -g $(pkg-config --cflags libhammer) -o my_parser my_parser.c $(pkg-config --libs libhammer)Or in a Makefile:
CC = gcc
CFLAGS = -g $(shell pkg-config --cflags libhammer)
LDFLAGS = $(shell pkg-config --libs libhammer)
my_parser: my_parser.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)- Hammer Fundamentals - Understand the core concepts.
- Protocol Examples - Pick a protocol and build a parser.
Learn Hammer
Protocol Examples
NTP
- NTP Overview
- Parsing the Header
- Parsing Data Fields
- Extension Fields and MAC
- Assembling the Parser
- Hex Input Preprocessing
- Running and Testing
DNS
TFTP
- TFTP Overview
- RRQ/WRQ Packets
- DATA Packets
- ACK Packets
- ERROR Packets
- Assembling the Parser
- Running and Testing
References
- Hammer Quick Reference
- Parsing Backends
- Unit Testing
- Using RTEMS
- Extending Hammer
- Adding a New Example
- Adding a New Binding
Further Reading