sockets

John Sloan,8292,X1243,ML44E jsloan at ncar.ucar.edu
Thu Jun 7 05:01:35 AEST 1990


>From article <4529 at castle.ed.ac.uk>, by elev26 at castle.ed.ac.uk (Gerard A. Allan):
> In article <4421 at infmx.UUCP> kevinf at infmx.UUCP (Kevin Franden) writes:
	:
>>Doesn't there exist a function to determin a preexisiting (I've 
>>heard some call this a "wellknown") service's socket number?
	:
> sounds like you want, 
>                     struct servent *getservbyname(name, proto)
>                     char *name, *proto;

This is probably what he _needs_, although I'll probably be the
Nth among M to point out that it's not what he asked for.

getservbyname() returns the _port_ number for a "well known" service
(i.e. defined in /etc/services, or if you have Yellow Pages, in the YP
services file). A service's "socket" has no meaning outside the context
of a particular process since a socket is merely a file descriptor
(integer) that is specific to a paticular process. You must create your
own socket (via socket()).  Once you have the host address (e.g. via
gethostbyname()) and port number (e.g. via getservbyname()) you can
bind or connect your socket to that address and port.

--
John Sloan              +1 303 497 1243                   ...!ncar!jsloan
NCAR/SCD, POB 3000      AMA#515306, DoD#0011         jsloan at ncar.ucar.edu
Boulder CO 80307        1990 BMW K75S Pilot     jsloan%ncar at ncario.BITNET
Logical Disclaimer:  belong(opinions,jsloan). belong(opinions,_):-!,fail.



More information about the Comp.unix.wizards mailing list