You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ryan Bloom <rb...@raleigh.ibm.com> on 1999/09/02 17:08:50 UTC

bind-connect in rfc1413.c

Okay, I must be missing something.  I am trying to put some of the APR
stuff into Apache 2.0, and I came across a case I wasn't prepared for when
I wrote APR.

In rfc1413.c, line 130:

bind (sock, &our_query_sin, sizeof(struct sockaddr_in));

On line 141:

connect(sock, &rmt_query_sin, sizeof(struct sockaddr_in));

It's the same socket in both calls, and it's a SOCK_STREAM socket.  Why
are we binding and then connecting?  There are comments about trying to
bind both local and remote ends to the same IP addr.  But this doesn't
make any sense to me.  Dean seems to have a comment at the beginning of
the function saying something is broken, but he isn't specific about what
it is.

In all of the TCP/IP network programming I have done, bind is done on the
server side, and connect is done on the client side.  In fact, most of my
books say the bind is really unnecessary.

So, what am I missing?

Ryan

_______________________________________________________________________
Ryan Bloom		rbb@raleigh.ibm.com
4205 S Miami Blvd	
RTP, NC 27709		It's a beautiful sight to see good dancers 
			doing simple steps.  It's a painful sight to
			see beginners doing complicated patterns.	


Re: bind-connect in rfc1413.c

Posted by Dirk-Willem van Gulik <di...@webweaving.org>.

On Thu, 2 Sep 1999, Ryan Bloom wrote:

> Okay, I must be missing something.  I am trying to put some of the APR
> stuff into Apache 2.0, and I came across a case I wasn't prepared for when
> I wrote APR.

> bind (sock, &our_query_sin, sizeof(struct sockaddr_in));
> connect(sock, &rmt_query_sin, sizeof(struct sockaddr_in));
 
> In all of the TCP/IP network programming I have done, bind is done on the
> server side, and connect is done on the client side.  In fact, most of my
> books say the bind is really unnecessary.

If I recall correctly, the gist of this is: that this way a TCP client can
control its IP source address that will be used for anything going out of
this socket. And this in turn is nessesary to accomodate for restriction
'3' in the rfc:

   Queries are permitted only for fully specified connections.  The
   query contains the local/foreign port pair -- the local/foreign
   address pair used to fully specify the connection is taken from the
   local and foreign address of query connection.  This means a user on
   address A may only query the server on address B about connections
   between A and B.

See ftp://ftp.ripe.net/rfc/rfc1413.txt or any other source for the full
story. The bit about bind() controlling the IP source address in a socket
is described as a note in Stevens and on the BSD man pages.

Dw.
















St. Johns                                                       [Page 8]