[comp.unix.i386] Creating a socket with ISC's libinet.a

mark@zok.UUCP (Mark W. Snitily) (01/14/90)

Has anyone tried to create a socket using the libinet.a that comes
with ISC's X11 development package?

The code in it's simplest form would be:

      #include <sys/types.h>
      #include <sys/socket.h>
      main()
      {
         int s;
         s = socket(AF_INET, SOCK_STREAM, 0);
      }

And then linked via "cc -o sock sock.c -linet" (assuming the file
is named sock.c).

I've tried every combination of format (e.g. AF_INET) and type (e.g.
SOCK_STREAM) and the socket() call always returns -1 (meaning error).

ISC's X11 server appears to open a Unix domain socket (AF_UNIX with
/tmp/.X11-unix/X0).

I don't have ISC's TCP/IP package, only the libinet.a library that comes
with the X11 libraries.

Does anyone know how to create and use a socket with this library?

Thanks...

-- Mark

Mark W. Snitily                 Consulting Services:
894 Brookgrove Lane             Graphics, Operating Systems, Compilers
Cupertino, CA 95014             (408) 252-0456
mark@zok.uucp

eric@mks.com (Eric Gisin) (01/16/90)

In article <403@zok.UUCP>, mark@zok.UUCP (Mark W. Snitily) writes:
> Has anyone tried to create a socket using the libinet.a that comes
> with ISC's X11 development package?
> 
> ... [deleted]
> I've tried every combination of format (e.g. AF_INET) and type (e.g.
> SOCK_STREAM) and the socket() call always returns -1 (meaning error).
> 
> ISC's X11 server appears to open a Unix domain socket (AF_UNIX with
> /tmp/.X11-unix/X0).
> 
> I don't have ISC's TCP/IP package, only the libinet.a library that comes
> with the X11 libraries.
> 
> Does anyone know how to create and use a socket with this library?
> 

The -linet routines emulate BSD sockets by using the native stream
devices and system calls in System V.
socket(AF_INET, SOCK_STREAM) looks up it parameters in /etc/socket.conf,
which tells socket to open /dev/tcp and push the "socket" module.
So if you don't have the tcp/ip package,
you won't have /dev/tcp and can't use socket().

Your basic misconception is that /dev/.X11-unix/0 is a UNIX domain socket.
The socket emulation does NOT implemement AF_UNIX.
/dev/.X11-unix/0 is one end of a Stream pipe.
This allows X11 to work without the tcp/ip package,
it uses just the basic streams package.

I figured all this out while trying to decide what it would
take to build X11.4 on 386/IX.  It looks like you could
easily build it with either socket emulation or native streams.
But you would only get tcp based connections, not local connections.
Has anyone reverse engineered the local connection code
that Interactive uses? It is different that the scheme
ATT uses in lib/X/XStream.c.  Interactive uses /dev/spx,
while ATT uses /dev/ptmx. Are either of these devices documented?

pcg@aber-cs.UUCP (Piercarlo Grandi) (01/18/90)

In article <1990Jan16.011859.5080@mks.com> eric@mks.com (Eric Gisin) writes:
    
    I figured all this out while trying to decide what it would
    take to build X11.4 on 386/IX.  It looks like you could
    easily build it with either socket emulation or native streams.

Use native streams! A lot of us out here don't have ethernet,
and want to run X. Once you have done streams, sockets is
trivial.

    But you would only get tcp based connections, not local connections.

The reverse, if you use streams. Or maybe you mean TLI...

    Has anyone reverse engineered the local connection code
    that Interactive uses? It is different that the scheme
    ATT uses in lib/X/XStream.c.  Interactive uses /dev/spx,
    while ATT uses /dev/ptmx. Are either of these devices documented?

/dev/spx is a clone device for stream pipes. It is not really
documented, but in the AT&T stream manuals they give as an
example the source for a driver for stream pipes; methinks that
/dev/spx is exactly that driver, without even too many bells
and whistles. Actually I think that in normal use you just want
to clone /dev/spx, and then the returned filedescriptor can be
used as a pipe.

I actually reckon that if all pipes in the system were done
with streams, they would be faster (as are the socket/mbuf
based pipes of BSD). Just wait until SysV.4...

"/dev/ptmx" is the clone device of the stream ptys. What they
do is fairly easy to understand if you look at
"/usr/include/sys/pt*.h"... Actually it is not really different
from a stream pipe; you open the clone device, and you get in
the minor of the returned filedescriptor the number fo the
couple of /dev/pt[sm] devices that you have been allocated; a
stream pipe exists between the two sides, master and slave.
Then you push "ldterm" on the slave part, and that's it. I
think that for X11 one should not push "ldterm", unless the X11
protocol has been changed to require processing through a line
discipline (:-> :-> :->), and just use /dev/spmx as a generator
of named pipes.

In the GNU emacs for SysV.3.2 patches that I posted a while ago
there is a section on using stream ptys instead of BSD
compatible ptys, and the code is very generic.
-- 
Piercarlo "Peter" Grandi           | ARPA: pcg%cs.aber.ac.uk@nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth        | UUCP: ...!mcvax!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk