[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Dave Mason <dmason@s...> |
| Subject: | Re: multi-threaded udp resolver |
>>>>> 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