Re: multi-threaded udp resolver

From: Dave Mason (dmason@sarg.Ryerson.CA)
Date: Sat Mar 18 2000 - 20:17:11 MET

  • Next message: Frank Atanassow: "Re: Syntax for label, NEW PROPOSAL"

    >>>>> On 10 Mar 2000 09:34:47 +1100, Julian Assange <proff@iq.org> said:

    > While ocaml provides appropriate udp send/receive functions, the
    > best mechanism for understanding the structure of dns packets is
    > unknown to me. DNS packets are `loosely' structured. That is, there
    >[...]
    > Vixie's named/bind daemon doesn't even attempt to describe the
    > structure in any sort of data form, but rather uses the code flow
    > itself to describe the structure (e.g pulling 16 bits, assigning it
    > to a variable, advancing the interpretation pointer by 16 bits,
    > testing the variable, pulling 32 bits etc).

    I would unpack the packet into a char list and then process it with something like:

    let dispatch cont = function
            | t1::t2::rest -> (match (ord t1)*256+(ord t2) with
                    | 1 -> type1 cont rest
                    | 2 -> type2 cont rest
                    | _ -> error...
                    )
            | _ -> error...
    and type1 cont = function
            | f1::f2::f3::...::rest] -> cont (...f1...f2...f3...) rest
            | _ -> error...
    and type1 cont = function
            | f1::f2::rest] -> dispatch (fun v rest' -> cont (...f1...f2...v...) rest') rest
            | _ -> error...
    ;;

    note that cont is a continuation, that will be used to process the
    rest of the string after the current value is parsed.

    You could also use an ocaml parser.

    > This method is incredibly error-prone, and it's hard to see a good
    > way of fitting it in with ocaml's type system. Any ideas on the best
    > way to approach this problem?

    Getting the types right can be a little tricky, but is doable.

    ../Dave



    This archive was generated by hypermail 2b29 : Tue Mar 21 2000 - 15:19:33 MET