source: trunk/athena/etc/xdm/xdm/streams.c @ 6052

Revision 6052, 3.2 KB checked in by lwvanels, 33 years ago (diff)
Initial revision
Line 
1/*
2 * xdm - display manager daemon
3 *
4 * $XConsortium: streams.c,v 1.2 91/08/25 10:50:29 keith Exp $
5 *
6 * Copyright 1988 Massachusetts Institute of Technology
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation for any purpose and without fee is hereby granted, provided
10 * that the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of M.I.T. not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission.  M.I.T. makes no representations about the
15 * suitability of this software for any purpose.  It is provided "as is"
16 * without express or implied warranty.
17 *
18 * Author:  Keith Packard, MIT X Consortium
19 */
20
21/*
22 * streams.c - Support for STREAMS
23 */
24
25#include "dm.h"
26
27#ifdef XDMCP
28#ifdef STREAMSCONN
29
30#include <fcntl.h>
31#include <tiuser.h>
32#include <netconfig.h>
33#include <netdir.h>
34
35extern int      xdmcpFd;
36extern int      chooserFd;
37
38extern FD_TYPE  WellKnownSocketsMask;
39extern int      WellKnownSocketsMax;
40
41CreateWellKnownSockets ()
42{
43    struct t_bind bind_addr;
44    struct netconfig *nconf;
45    struct nd_hostserv service;
46    struct nd_addrlist *servaddrs;
47    char *name, *localHostname();
48    char bindbuf[15];
49    int it;
50
51    if (request_port == 0)
52        return;
53    Debug ("creating UDP stream %d\n", request_port);
54
55    nconf = getnetconfigent("udp");
56    if (!nconf) {
57        t_error("getnetconfigent udp");
58        return;
59    }
60
61    xdmcpFd = t_open(nconf->nc_device, O_RDWR, NULL);
62    if (xdmcpFd == -1) {
63        LogError ("XDMCP stream creation failed\n");
64        t_error ("t_open");
65        return;
66    }
67    name = localHostname ();
68    registerHostname (name, strlen (name));
69    RegisterCloseOnFork (xdmcpFd);
70
71    service.h_host = HOST_SELF;
72    sprintf(bindbuf, "%d", request_port);
73    service.h_serv = bindbuf;
74    netdir_getbyname(nconf, &service, &servaddrs);
75    freenetconfigent(nconf);
76
77    bind_addr.qlen = 5;
78    bind_addr.addr.buf = servaddrs->n_addrs[0].buf;
79    bind_addr.addr.len = servaddrs->n_addrs[0].len;
80    it = t_bind(xdmcpFd, &bind_addr, &bind_addr);
81    netdir_free(servaddrs, ND_ADDRLIST);
82    if (it < 0)
83    {
84        LogError ("error binding STREAMS address %d\n", request_port);
85        t_error("t_bind");      /* also goes to log file */
86        t_close (xdmcpFd);
87        xdmcpFd = -1;
88        return;
89    }
90    WellKnownSocketsMax = xdmcpFd;
91    FD_SET (xdmcpFd, &WellKnownSocketsMask);
92
93    chooserFd = t_open ("/dev/tcp", O_RDWR, NULL);
94    Debug ("Created chooser fd %d\n", chooserFd);
95    if (chooserFd == -1)
96    {
97        LogError ("chooser stream creation failed\n");
98        t_error("t_open chooser");
99        return;
100    }
101    if (chooserFd > WellKnownSocketsMax)
102        WellKnownSocketsMax = chooserFd;
103    FD_SET (chooserFd, &WellKnownSocketsMask);
104}
105
106GetChooserAddr (addr, lenp)
107    char        *addr;          /* return */
108    int         *lenp;          /* size of addr, returned as amt used */
109{
110    struct netbuf nbuf;
111    int retval;
112
113    nbuf.buf = addr;
114    nbuf.maxlen = *lenp;
115    retval = t_getname (chooserFd, nbuf, LOCALNAME);
116    if (retval < 0) {
117        if (debugLevel > 0)
118            t_error("t_getname on chooser fd");
119    }
120    *lenp = nbuf.len;
121    return retval;
122}
123
124#endif /* STREAMSCONN */
125#endif /* XDMCP */
Note: See TracBrowser for help on using the repository browser.