Re: Accept

From: Shawn Bayern (shawn.bayern@yale.edu)
Date: Mon Apr 03 2000 - 02:39:42 EDT


On Mon, 3 Apr 2000, Sasha Oblak wrote:

> Is there anyway to tell to tell accept() which port the new TCP socket
> should be on? Normally, accept creates a new socket on a random port,
> but is there anyway to control this feature?

Nope, don't think so. Jeez, you're really asking for trouble with all
this stuff, aren't you? :)

General advice: bump this up to a higher level. Implement whatever
functionality you're tring to implement -- e.g., authentication or some
other sort of mapping, or whatever it might be that's making you want to
choose the port for the new socket -- by a new CLIENT connection from the
server back to the originating machine. That is,

        Conceptual "client" Conceptual "server"
        ------------------- -------------------
        socket(); socket();
                                bind();
                                listen();
        connect(); --> accept();

        socket(); socket();
        bind(); bind();
        listen();
        accept(); <-- connect();

The bind() for the second ("client") socket on the server's end lets you
choose the server-side port, if that's really what you need to do.

In general, let the stack do all of the work for you that it wants to do.
Tricks with port numbers aren't, as far as I'm concerned, the way to go;
stuff like rsh/rlogin, which rely on connections from privileged ports,
are generally considered to be based on BAD ideas, not clever ones.

Shawn



This archive was generated by hypermail 2b29 : Wed Apr 27 2005 - 03:30:03 EDT