In writing networking code, one is often faced with the task of interpretin
g a raw buffer according to a standardized packet format. This is needed, f
or example, when monitoring network traffic for specific kinds of packets,
or when unmarshaling an incoming packet for protocol processing. In such ca
ses, a programmer typically writes C code that understands the grammar of a
packet and that also performs any necessary byte-order and alignment adjus
tments. Because of the complexity of certain protocol formats, and because
of the low-level of programming involved, writing such code is usually a cu
mbersome and error-prone process. Furthermore, code written in this style l
oses the domain-specific information, viz, the packet format? in its detail
s, making it difficult to maintain.
We propose to use the idea of types to eliminate the need for writing such
low-level code manually. Unfortunately, types in programming languages, suc
h as C, are not well-suited for the purpose of describing packet formats. T
herefore, we have designed PACKETTYPES, a small packet specification langua
ge that serves as a type system for packet formats. PACKETTYPES convenientl
y expresses features commonly found in protocol formats, including layering
of protocols by encapsulation, variable-sized fields, and optional fields.
A compiler for this language generates efficient code for type checking a
packet, i.e., matching a packet against a type. In this paper, we describe
the design, implementation, and some uses of this language.