lua-bitstring


bitstring parsing and creation library for lua

Lua bitstring parsing and creation library based on Erlang bit syntax. Bitstring is useful for network protocol programming and for manipulation of bit based file formats. It provides conversion of strings to binary and hexadecimal formats

Example

Parsing and creation of EAP-TLS message

EAP-TLS protocol defined in RFC 2716

``` code, identifier, length, eap_type, L_bit, M_bit, S_bit, R_bits = bitstring.unpack( "8:int, 8:int, 16:int:big, 8:int, 1:int, 1:int, 1:int, 5:int", eap_tls_message);

composed_eap_tls_message = bitstring.pack( "8:int, 8:int, 16:int:big, 8:int, 1:int, 1:int, 1:int, 5:int", code, identifier, length, eap_type, L_bit, M_bit, S_bit, R_bits) ```

Parsing IP packet

IP header format is defined in RFC 791 paragraph 3.1

``` local version, ihl, type_of_service, total_length, identification, reserved, df, mf, fragment_offset, ttl, protocol, header_checksum, src, dst = bitstring.unpack( [[ 4:int, 4:int, 8:int, 16:int, 16:int, 1:int, 1:int, 1:int, 13:int, 8:int, 8:int, 16:int, 32:int, 32:int]], ip_packet)

local data = string.sub(ip_packet, ihl * 4 + 1)

```

Project Information

Labels:
lua bitstring hexstream binstream