-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IPv4/6 conversions from/to Cstructs #36
Conversation
Should these functions go in a module |
Cstruct.set_uint8 cs (2 + off) ((|~) (i >! 8)); | ||
Cstruct.set_uint8 cs (3 + off) ((|~) (i >! 0)) | ||
|
||
let to_cstruct i = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would encourage not allocating cstructs in these functions, but passing in a cstruct to write into. This is because they must be allocated via Io_page
in Mirage (so that the underlying page is aligned to a 4K block).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then shall I remove the function to_cstruct
altogether ? The function to_cstruct_raw
works on passed-in cstruct
. The only difference is that to_cstruct_raw
can raise an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, removing the allocator is fine, or having an alloc
optional argument that can override it. So you could have
val set_cstruct : ?off:int -> t -> Cstruct.t -> unit
val to_cstruct : ?(alloc:unit -> Cstruct.t) -> i -> Cstruct.t
The latter would let you pass in Io_page.(to_cstruct (make 1))
as the allocator function, and use Cstruct.create
by default if not specified.
Looks pretty good. The I'm a bit hesitant to put I support the inclusion of bigarray/bigstring functions in the primary signature but I think perhaps an Out of curiosity, is your application packet parsing? @avsm, how do your packet parsers use cstruct+ipaddr, today (or do they)? |
Oh, also, if you could add cstruct to https://github.com/mirage/ocaml-ipaddr/blob/master/.travis-ci.sh that would placate Travis. |
On 2 Oct 2014, at 18:51, David Sheets [email protected] wrote:
-anil |
Thanks @dsheets and @avsm for the comments. I have split the
One slight downside of putting the cstruct stuff in its own module is that doing open Ipaddr
open Ipaddr_cstruct results in Yes, @dsheets, application is packet parsing. Which is why I did not have much use for converting between ASCII and cstructs. |
It looks like @avsm is in the process of removing/optionalizing unnecessary I've been thinking about your agree with your suggestion to use Finally, could Sorry for the vacillation and thanks very much for your contribution. :-) |
On 3 October 2014 09:49, David Sheets [email protected] wrote:
Richard Mortier |
I agree. I think my complete interface proposal for a 3.0 would be as follows:
This is a significant breaking change but I think something like this would fix the string/bytes/bigstring/cstruct representation confusion. I'd like to fix this problem once, correctly so we never have to think about this again. |
Oh, I forgot a fifth case for exceptional functions on ASCII reps into a specific buffer position. Perhaps this is |
The prefixes for these suffixes will some of: |
gah. why doesn't github format as markdown when things come in from mail. now out of order... ok-- generally agree. (and now seeing your followup.) just to be sure i'm clear, the prefix for all these is and then we have the following suffixes:
?
could go with |
right. responding to @dsheets last comment: not prefer proposal for |
I put the |
I think we should release the |
Another comment on this: the available conversion functions in I wanted to add the |
i guess follow the convention just discussed for ipaddr.3.0? (or do i misunderstand the question?) On 3 October 2014 17:06, Nicolas Ojeda Bar [email protected] wrote:
Richard Mortier |
Sorry for the confusing comment. I just wanted to point out that even in the current state, the interfaces of |
ah right. i just meant, i guess it would make sense at some point to make On 3 October 2014 21:14, Nicolas Ojeda Bar [email protected] wrote:
Richard Mortier |
The Macaddr.t is now passed in the first position, just like in Ipaddr.V{4,6}.to_cstruct_raw.
This way it is consistent with the `of_bytes_exn' function.
No. We want to clean up the variations first with some more modules/pre-applied functors. Do you need this feature imminently? |
I'm merging mirage/mirage-tcpip#70 which could use this (But has temporary overrides in place to work without it) |
Any chance this will go in anytime soon? I'm working on something which will need either this or some overrides like those required for @nojb 's ipv6 patch (which are still in place). |
I seem to remember that a little refactoring was necessary to make all the possible conversions fit more seamlesssly, with less code duplication and with an uniform interface (maybe in the style of ocplib-endian). Until this is done you may be better off including the necessary functions in your code I guess :( |
@dsheets any (more) opinion on that PR? |
This needs refactoring/renaming work that will likely break backward compat of the interface. Analysis/suggestions/PRs very welcome for that. |
It only took 2.5 years, but mirage/ocaml-cstruct#133 has significantly reduced the dependency cone of the cstruct library. So depending on it directly from ipaddr is now feasible |
for conversion to/from cstructs based on mirage#36 Co-authored-by: Nicolás Ojeda Bär <[email protected]>
It took half a decade, but fixed in #90 based on this PR |
…exp and macaddr-cstruct (4.0.0) CHANGES: * Rename the `to/from_bytes` functions to refer to `octets` instead. This distinguishes the meaning of human-readable addresses (`string`s in this library) and byte-packed representations(`octet`s in this library) from the OCaml `bytes` type that represents mutable strings. Porting code should just be a matter of renaming functions such as: - `Ipaddr.of_bytes` becomes `Ipaddr.of_octets` - `Macaddr.to_bytes` becomes `Macaddr.to_octets` * Introduce new `write_octets` functions that can write octet representations of IPv4/v6 into an existing bytestring. * Use the `domain-name` library to produce domain names from IP addresses. * Remove the `ipaddr.sexp` and `macaddr.sexp` ocamlfind subpackages and instead have `ipaddr-sexp` and `macaddr-sexp` to match the opam package names. * Add new `Ipaddr_cstruct` and `Macaddr_cstruct` libraries for conversion to/from cstructs (mirage/ocaml-ipaddr#36 @nojb @avsm)
Re #12