kent@sas.UUCP (Paul Kent) (08/15/89)
hello,
this is a first posting, so please be gentle if i screw up.
I have written a client/server pair of programs modelled on the
whois_client/whois_server pair in "Internetworking with TCP/IP"
by Douglas Comer. (a very useful book, thanks!)
For those who might help, but do not have the book, the server
does this (and a bit of error checking too :-)
hp = gethostbyname(host);
s = socket(hp->h_addrtype, SOCK_STREAM, 0);
bind(s, &sa, sizeof(sa) );
listen(s, 5);
for(;;)
{
t = accept(s, ..
read(t, ...)
process(...)
write(t, ...)
close(t)
}
while the client does this:
hp = gethostbyname(host);
s = socket(hp->h_addrtype, SOCK_STREAM, 0);
connect(s, &sa, sizeof(sa) );
write(s, ...)
read(s, ...)
exit(0)
Under Apollo bsd4.2 (SR9.7 and SR10) , as well as Ultrix (RISC),
they work nicely if i start the server in one shell, and then run the
client in another.
I am interested in having inetd start my tcp server process, as soon
as it hears a request from a client. This is where the wheels fall off.
My pair of programs use the "well known" (to the pair at least)
service "pmka", whose entry in /etc/services is:
pmka 601/tcp # See Paul Kent
The entry in inetd.conf is: (the executable is not owned by root)
pmka stream tcp nowait /udr/saspmk/tcp/com/pmkad pmkad
now, the inetd man page says that it starts the client with a socket
descriptor of 0 for the service requested.
Question 1: do i accept connections on descriptor 0,
-or- do i read/write it hoping that inetd accepted
the connection for me?
-or am i supposed to bind it in some fashion?
example fragments most welcome... i have no unix source access or i
would snoop around ftpd and telnetd
ditto for things your mother should have told you
about inetd spawned servers, but forgot to.
Question 2: any tips on how to debug a process launched by inetd?
Question 3: i ultimately want to write client/server code to support
communications between two SAS sessions via the internet.
(SAS/Share and micro-to-host link if you know our products)
how do i request that a well know number be assigned to
my/SAS's application?
Thank You
Paul
R&D -- applications
--
---- nothing ventured, nothing disclaimed ----
paul kent, SAS Institute, box 8000, cary nc 27512-8000 -- 919 467 8000
.... {seismo|mcnc}!rti!sas!kent or kent@sas.UUCP
dls@mentor.cc.purdue.edu (David L Stevens) (08/15/89)
inetd(8) does the accept(2) for you; descriptor 0 is an ESTABLISHED state (as opposed to LISTEN state) TCP socket. Re: debugging. I found it useful to write some inetd-like functions that do the accept(2) and dup2(2) it onto descriptor 0. I then used "#ifdef DEBUG"'s to include or exclude the function that does the setup. The remaining code (the server proper) works the same with or without inetd. Further, you can do dbx-debugging easily if the accept is done in the same process (ie, no fork(2) after the accept(2)). When it works, just recompile without "DEBUG" defined and you're done. The code I have is for a particular server I'm working on, so it's not really worth posting, but it is easily adapted and I'll send it on request to anyone who asks (via mail). Actually, reproducing it yourself isn't a bad exercise in using sockets, either... -- +-DLS (dls@mentor.cc.purdue.edu)
hwajin@wrs.wrs.com (Hwajin Bae) (08/16/89)
In article <1149@sas.UUCP> kent@sas.UUCP (Paul Kent) writes: >now, the inetd man page says that it starts the client with a socket >descriptor of 0 for the service requested. >Question 1: do i accept connections on descriptor 0, > -or- do i read/write it hoping that inetd accepted > the connection for me? Inetd will automaticallly dup descriptor 0 to be the new socket connection established. You can safely assume that the descriptor 0 will be the socket descriptor for the connection you desire on the server side. To be able to find out the address of the remote peer who just made a connect() call to the server (invoked by the inetd), you can use getpeername() call. -- Hwajin Bae Wind River Systems 1350 Ocean Ave Emeryville, CA 94608
ron@ron.rutgers.edu (Ron Natalie) (08/16/89)
Question 1: do i accept connections on descriptor 0,
-or- do i read/write it hoping that inetd accepted
the connection for me?
-or am i supposed to bind it in some fashion?
Answer 1: Number 2 is correct. Inetd accepts the connection for you and
forces it to be file descriptor zero.
Question 2: any tips on how to debug a process launched by inetd?
Answer 2: Most of the inetd started servers have a -d option that allows
you to start up the job with the old socket/bind/accept sequence
so you can test it without having to change the inetd configuration.
Actually, since all that grungy bind stuff is taken care of it's
easier to write inetd applications.
Question 3: i ultimately want to write client/server code to support
communications between two SAS sessions via the internet.
(SAS/Share and micro-to-host link if you know our products)
how do i request that a well know number be assigned to
my/SAS's application?
Answer 3: The numbers are enumerated in a document known as assigned
numbers. My guess is that Postel is still responsible for
dealing them out.
> paul kent, SAS Institute, box 8000, cary nc 27512-8000 -- 919 467 8000
Gee, that address sounds familiar. Seems to be on a few zillion output runs
here.