Permalink
Commits on Jul 4, 2015
  1. Fix packet range access

    vmx committed Jul 4, 2015
    When getting a slice via a range, the end of the range is not the relative
    offset from the start of the range, but the absolute position counted from
    the start of the original array.
Commits on Jun 19, 2015
  1. Get variable size directly from the vector

    vmx committed Jun 18, 2015
    Use the vector length of variable-length field of the struct to
    calculate its total byte size.
Commits on Jun 18, 2015
  1. Revert "Add function to determine the packet_size from a struct"

    vmx committed Jun 18, 2015
    Don't use the length expression to calculate the size of a struct, but
    use the vector length directly (which will be added in the next commit).
    
    This reverts commit 853eb81.
Commits on Jun 13, 2015
  1. Add function to determine the packet_size from a struct

    vmx committed Jun 13, 2015
    There's a new `packet_size` function that is implemented for the
    packets in case the size of a packet can be determined from the
    struct. This is the case when the sizes of all variable sized fields
    are defined by a length expression (as opposed to a length function).
    
    This makes it possible to create a new packet from a struct without
    knowing its size up front. Example:
    
        #[packet]
        pub struct Simple {
            sz: u8,
            #[length = "sz"]
            #[payload]
            payload: Vec<u8>
        }
    
        let payload = vec![1, 2, 3, 4];
        let simple = Simple {
            sz: payload.len() as u8,
            payload: payload
        };
    
        let mut packet = vec![0; SimplePacket::packet_size(&simple)];
        MutableDcpOpenPacket::new(&mut packet[..]).unwrap().populate(simple);
Commits on May 28, 2015
  1. Add support for constants in length expressions

    vmx committed May 23, 2015
    Constants in length expressions must be all uppercase in order to be
    recognized as constants.
  2. Allow existing field names only

    vmx committed May 23, 2015
    There's an error if a field name is specified in a length expression that
    isn't part of the struct. It also errors if the field name where the current
    length expression is used on is part of the expression.
Commits on May 26, 2015
  1. Add new "length" attribute

    vmx committed May 21, 2015
    It's now possible to describe the length of a variable sized field with
    an arithmetic expression that may also include other field names.
    
    An example would be the options field in an IPv4 packet
    
        #[packet]
        pub struct Ipv4 {
            ...
            header_length: u4,
            ...
            #[length = "header_length - 4"]
            options: Vec<Ipv4Option>,
            ...
        }
    
    Within such a length expression only field names, integers and basic
    arithmetic operators like + - * / % are allowed.
Commits on May 25, 2015
  1. Concatenate the length function call early

    vmx committed May 20, 2015
    Pass on the concatenated string that call the length function of a variable
    size field.
  2. Use compiletest_rs for the tests

    vmx committed May 25, 2015
    The compiletest_rs crate is a standalone version of rustc's compiletest utility.
    It makes it possible to test for compile time failures. With this crate it's possible
    to run the libpnet_macros tests with a simple `cargo test`.
  3. Add main function to tests

    vmx committed May 25, 2015
    Without a main function the tests won't pass.
  4. Move tests into `run-pass` directory

    vmx committed May 25, 2015
    compiletest_rs normally has tests that compile without failures in a directory
    called `run-pass`. This commit makes libpnet_macros follow this convention.
  5. Ignore `variable_length_fields2` test

    vmx committed May 25, 2015
    The error message for wrong length function parameter types is not
    implemented yet, hence ignore this test.
  6. Make struct in tests public

    vmx committed May 25, 2015
    Some tests haven't had the struct definition made public, hence were failing
    early and not due to the reason they should've failed.
  7. Error when struct/enum isn't public

    vmx committed May 24, 2015
    The should be an error when a struct that has an `#[packet]` attribute isn't
    public. This is an implementation for the "must_be_pub" test.
Commits on May 14, 2015
  1. Add function to get the minimum packet size

    vmx committed May 13, 2015
    The `minimum_packet_size()` returns the total number of bytes the
    fixed-size elements have.
    
    With this function it's possble to determine the size of the packet buffer
    that is needed to be populated by a struct. Only the variable sized fields
    need to be added to the size.