caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Vincent B." <vb@luminar.eu.org>
To: "Raphaël Proust" <raphlalou@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] IPv6 zone-id
Date: Fri, 11 Jul 2014 16:13:36 +0200	[thread overview]
Message-ID: <53BFF110.8080900@luminar.eu.org> (raw)
In-Reply-To: <CAAmHUA=Xu741uhzuxL4YgvC3OPxOFFqvOW4K=UVv=sLi0UNkUQ@mail.gmail.com>

On 11/07/2014 10:03, Raphaël Proust wrote:
> On Wed, Jul 9, 2014 at 6:35 PM, Vincent B. <vb@luminar.eu.org> wrote:
>> > The Unix module does not make possible to use IPv6 link-local
>> > addresses.
>> >
>> > This is due to the fact that the "sockaddr" type in Unix is not as
>> > complete as its C counterpart, especially it lacks zone-id information
>> > that is required to use such addresses.
>> >
>> > Since I needed such features, I started writing a library
>> > (http://github.com/vbmithr/ocaml-sockopt), unfortunately, given that
>> > every networking piece of code written in OCaml use the primitives of
>> > the Unix module, I would have to patch all networking code I want to
>> > use which is not very convenient.
> Is it possible to make a new networking module using Cstruct to manage
> sockaddr and such?

Not sure what you mean by "using Cstruct to manage sockaddr…" but
yeah, it is just a matter of binding the relevant C primitives. The Unix module is
far from exhaustive, yet it is the normal entry point for doing networking in OCaml.
The issue here is to be able to use existing networking OCaml code.

>> >
>> > So I'm in the process of writing a patch for OCaml and I'm taking the
>> > approach of extending the sockaddr type like this:
>> >
>> > type sockaddr_raw (* a real struct sockaddr *)
>> >
>> > type sockaddr =
>> >   ADDR_UNIX of string
>> > | ADDR_INET of inet_addr * int
>> > | ADDR_RAW of sockaddr_raw
>> >
>> > And then upgrading all the Unix code that uses type sockaddr.
>> >
>> > This approach seems to me the most conservative towards existing
>> > code. Should I continue in this direction or this design is not the
>> > optimal one ?
> Although very conservative towards the existing codebases, I don't
> like this approach for the following reasons.
> 
> The same sockaddr can be represented in different ways (which means
> that equality becomes non-trivial, and the choice of representation is
> non-obvious for programmers).

That is indeed an issue. 

> The Unix module is build as abstractions from the underlying system,
> adding a sockaddr_raw defeats that. It becomes abstractionless.

This is an issue as well.

> Additionally, is sockaddr_raw completely opaque? what
> constructors/destructors are available?

Unix.getifaddrs would return a RAW sockaddr for example.

You raise valid points. The best approach IMO would be to extend the abstraction
to accomodate for the other features. The root issue is that type sockaddr in OCaml is
not abstracting enough of the C interface: A struct sockaddr is more than what is
abstracted from it. Changing the type sockaddr in OCaml would break all existing networking
code.

That's why I was looking for advice basically. I'm gonna look for alternative OCaml
stdlib to see if there is anything better for networking.

Thanks for you answer :)

Vincent

  reply	other threads:[~2014-07-11 14:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-09 17:35 Vincent B.
2014-07-11  8:03 ` Raphaël Proust
2014-07-11 14:13   ` Vincent B. [this message]
2014-07-11 19:25     ` Vincent B.
2014-07-16 16:04       ` Francis Dupont
2014-07-17  9:48         ` Vincent B.
2014-07-17 10:51           ` David Allsopp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53BFF110.8080900@luminar.eu.org \
    --to=vb@luminar.eu.org \
    --cc=caml-list@inria.fr \
    --cc=raphlalou@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).