4.2 net wizardry

cak at Purdue.ARPA cak at Purdue.ARPA
Fri Jan 6 03:20:00 AEST 1984


From:  Christopher A Kent <cak at Purdue.ARPA>

Ok all you 4.2 net hackers, here's one for you. I have a server process
that I want to set up so it accepts connections only from a specific
host. As far as I can tell, there is no clean way to do this. My
initial attempt looked something like:

	s = socket()
	bind(s, <desired foreign host>)
	listen(s, 1)
	fd = accept(s)

but that doesn't work; the bind always fails. Digging a bit deeper, I
realized that bind lets you specify the *local* address; as far as I
can tell, this is pretty useless unless you want to isolate a
particular interface.

The best hack I can come up with is to use the 'from' information
provided by accept and check to see if the connection came from the
right host, and close things down if not.

Also, this solution has the side effect of leaving a pending receiver
after the first connection is made. This connection will NEVER be
accepted; I want a single virtual circuit between two particular
machines. Is listen(s, 0) valid? If I do that after the accept, will it
take away the pending receiver? Can I do an accept without a listen?

In some respects, the BBN interface was nicer, since it let you specify
both sides of the connection information, including foreign address and
port. It can be useful at times.

Cheers,
chris

----------



More information about the Comp.unix.wizards mailing list