MLton.Socket improvement

Henry Cejtin henry@sourcelight.com
Sun, 16 Dec 2001 23:16:32 -0600


In  the  MLton.Socket structure, we should have a routine which lets you bind
the IP address of a socket to.  This isn't used super  frequently,  but  does
get used.

The main use is to bind it to 127.0.0.1 (localhost) so that only processes on
the same machine can connect to it.  As an example, the modern sendmail binds
to port 127.0.0.1, so this way you can use it from fetchmail (to send mail to
your local mailbox) without having it accept connections from other machines,
and hence without making your machine vulnerable.

Another  rarer  use  is  to  on machines with more than one NIC address.  (Of
course this covers all machines in reality because one address is 127.0.0.1.)
Then  you  can  have  more than one socket listening on the same port number.
Also you can set which IP address a connection came from.

Note,  this  all really argues for making the MLton interface closer to the C
interface: make the bind call explicit with two options:

    An int option whch is the port number (or NONE for pick one).

    A word option which is the IP address (or NONE meaning any  or  default).
        On accept() type things, it will accept connections to any address on
        the machine.  On connect() type  things  it  probably  grabs  the  IP
        address  of  the  interface  that  is  `closest'  to  the place being
        connected to in the machines routing table.

I  think  that  the  same  might  be  an  argument  for  separating  out  the
name->address translation and the connect.

If you tell me what interface sounds good to you, I'm glad to do it.