Subject: [clisp-list] binding sockets?

From: [email-masked] (Don Cohen)
Date: Tue Oct 28 09:34:29 2003

Is there a way to create a socket stream bound to a particular IP
address?  I recall that I thought it was a big improvement when it
became possible to create one that was not, but now I'd like to be
able to use multiple addresses on the same machine for different
servers.

Also I notice in impnotes:

 (SOCKET:SOCKET-SERVER-HOST socket-server)
 (SOCKET:SOCKET-SERVER-PORT socket-server)

      Returns the host mask indicating which hosts can connect to this
 server and the port which was bound using SOCKET:SOCKET-SERVER. 

Is that correct?  I thought this was the local ip address, not remote.

I've not looked up the underlying c mechanisms, but perhaps one
solution would be to make these functions setf-able ?

---

From: "John K. Hinsdale" <[email-masked]>
Date: Tue Oct 28 10:13:19 2003

> address?

Doesn't appear to be.  I checked the source (socket.d) and it looks
like the creation of a socket by default listens on all configured
addresses on the server (i.e., uses the mask "0.0.0.0").

 > I recall that I thought it was a big improvement when it became
 > possible to create one that was not, but now I'd like to be able to
 > use multiple addresses on the same machine for different servers.

To do that it would be necessary to extend the CLISP socket interface
to allow the specification of the listen address expcitly as part of
the creation of the server socket.  This is part of the info that gets
passed to the bind() system call.  This "address" is not a host
address but rather a "mask" with 0 as a wildcard, e.g.  0.0.0.0
matches everything, while 10.100.123.143 will match that exact IP and
have the effect of listening only on that IP.

The source in socket.d seems to treat the listen mask as a "hostname"
that can be resolved but that is not who things work w/ the IP address
on the server side; it is more the "mask" that gets matched vs. the
destination address someing from the connecting client.

 > server and the port which was bound using SOCKET:SOCKET-SERVER. 

Seems like for a server-side socket it should return the "mask"
above.  To call this "which hosts can connect" is inaccurate;
rather it should be described as "which local IP addresse(s)
can be connected to."

 > Is that correct?  I thought this was the local ip address, not

It is a mask that matches one or more local IP addresses.

 > I've not looked up the underlying c mechanisms,

The listen-mask and listen port are tightly coupled info and should be
specified together.  They are part of the "C" structure "struct
sockaddr" which contains members for the address and port.  This
struct serves both the client and server cases, but the address part
means different things in each case: for client it means the host/IP
and port to connect to; for the server it means the "listen-mask" and
port to listen on.

This structure is associated w/ the "C" socket for a server by the
system call bind().

Generally to make a TCP connection the calls are:

Server:  socket() ... bind(address-mask/port) ... listen() ... accept()
Client:  socket() ... connect(hostname-or-address/port)

 > perhaps one solution would be to make these functions setf-able ?

Probably not appropriate given that you cannot generally change the
listen-addresses and port once a socket is created and listening.  It
should just be set at creation time and not changed thereafter (but
should be allowed to be examined).

Hope this helps.  It's been a while since I did TCP programming but I
think this is mostly accurate.

---
John Hinsdale, Alma Mater Software, Inc., Tarrytown, NY 10591-3710 USA
[email-masked] | http://www.alma.com/staff/hin | +1 914 631 4690

---

From: Sam Steingold <[email-masked]>
Date: Tue Oct 28 10:24:49 2003

> * Don Cohen <[email-masked]> [2003-10-28 09:36:26 -0800]:
>

it's a mask for remote hosts.
see stream.d:SOCKET-SERVER and socket.d:create_server_socket.

> solution would be to make these functions setf-able ?

too much trouble. it will amount to closing an existing socket server
and creating a new one.  all it will save is a lisp object allocation
which is cheap (you aren't creating zillions of those, right?)

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Growing Old is Inevitable; Growing Up is Optional.

---

From: [email-masked] (Don Cohen)
Date: Tue Oct 28 10:33:40 2003

> have the effect of listening only on that IP.
That leaves me wondering about what's in between.
I suppose 10.100.123.0 means any last byte, but one might hope for
more control.  Like address/30 or even separate 32 bit address and mask.
Still, even the two extremes would be very useful.

 > It is a mask that matches one or more local IP addresses.
ok, so request #1 is a fix to documentation
Of course, it won't make much difference if there's no way to
control the value.

So request #2 is that socket-server should accept this as an argument.
(I see the reply coming: "great idea, please submit the patch".
 I'm only hoping as usual that someone else gets there before me.)

 > specified together.  
I don't see how they're tightly coupled.  I gather you can't change
either of them after creation?  Is there a way to listen on multiple
ports?

---

From: Sam Steingold <[email-masked]>
Date: Tue Oct 28 11:13:23 2003

> * John K. Hinsdale <[email-masked]> [2003-10-28 13:12:44 -0500]:
>
> the creation of the server socket.

the argument to SOCKET-SERVER can be an existing SOCKET-STREAM, in
which case the peer address of that SOCKET-STREAM will be the only
address from which this SOCKET-SERVER can accept connections.

I am not sure about the reasons for this dichotomy (either port or mask
but not both; either mask 0.0.0.0 or a single IP).

I think it would be a good idea to add a second optional argument to
act as a mask (I am not sure what type that should be - a dotted quad
string? a bit vector? a byte array? a uint32?  what about ipv6?), i.e.:

      (socket-server port mask)

backwards compatibolity requires supporting

      (socket-server socket-stream)

maybe we also need

      (socket-server port socket-stream)

what about

      (socket-server socket-stream mask)

this would apply mask to the socket-stream-peer-host.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
As a computer, I find your faith in technology amusing.

---

From: "John K. Hinsdale" <[email-masked]>
Date: Thu Oct 30 04:24:02 2003

> From: Sam Steingold <[email-masked]>
 > Date: Tue, 28 Oct 2003 14:11:18 -0500
 >

There probably isn't a good reason.  SOCKET-SERVER should simply allow
you to specify explicitly the address (or 0.0.0.0) on which the listen
is done.

 > I think it would be a good idea to add a second optional argument
 > to act as a mask

Yes

 > (I am not sure what type that should be - a dotted quad
 > string? a bit vector? a byte array? a uint32?  what about ipv6?)

Dotted quad string probably easiest for most users.

 >       (socket-server socket-stream mask)

I'm having trouble imagining a user for either of these.  Usually. you
just want to say listen on this port, on these address(es) and that's
that.

---

---

From: Sam Steingold <[email-masked]>
Date: Thu Oct 30 05:52:03 2003

> * John K. Hinsdale <[email-masked]> [2003-10-30 07:23:10 -0500]:
>
>  > maybe we also need

means listen on port for connections from the peer of socket-stream.
is this a reasonable request?
(I think FTP does something like this)

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Apathy Club meeting this Friday.  If you want to come, you're not invited.

---

From: "John K. Hinsdale" <[email-masked]>
Date: Thu Oct 30 06:21:15 2003

> [Sam Steingold

The peer of socket-stream is a remote host; I don't know that it's
possible to listen for connections from a particular remote host.
When you listen you specify the port and the LOCAL addresses,
connections to can be accepted.

So I don't know that this usage makes sense.

---

---

From: Sam Steingold <[email-masked]>
Date: Thu Oct 30 06:59:02 2003

> * John K. Hinsdale <[email-masked]> [2003-10-30 09:20:27 -0500]:
>
>  > [Sam Steingold
>  > 

you must be right.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Even Windows doesn't suck, when you use Common Lisp