2 * The Dynix/PTX TLI implementation is not quite compatible with System V
3 * Release 4. Some important functions are not present so we are limited to
6 * Diagnostics are reported through syslog(3).
8 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
12 static char sccsid[] = "@(#) ptx.c 1.3 94/12/28 17:42:38";
17 /* System libraries. */
19 #include <sys/types.h>
20 #include <sys/tiuser.h>
21 #include <sys/socket.h>
23 #include <netinet/in.h>
32 /* Forward declarations. */
34 static void ptx_sink();
36 /* tli_host - determine TLI endpoint info, PTX version */
38 void tli_host(struct request_info *request)
40 static struct sockaddr_in client;
41 static struct sockaddr_in server;
44 * getpeerinaddr() was suggested by someone at Sequent. It seems to work
45 * with connection-oriented (TCP) services such as rlogind and telnetd,
46 * but it returns 0.0.0.0 with datagram (UDP) services. No problem: UDP
47 * needs special treatment anyway, in case we must refuse service.
50 if (getpeerinaddr(request->fd, &client, sizeof(client)) == 0
51 && client.sin_addr.s_addr != 0) {
52 request->client->sin = &client;
53 if (getmyinaddr(request->fd, &server, sizeof(server)) == 0) {
54 request->server->sin = &server;
56 tcpd_warn("warning: getmyinaddr: %m");
58 sock_methods(request);
63 * Another suggestion was to temporarily switch to the socket
64 * interface, identify the endpoint addresses with socket calls, then
65 * to switch back to TLI. This seems to works OK with UDP services,
66 * which is exactly what we should be looking at right now.
69 #define SWAP_MODULE(f, old, new) (ioctl(f, I_POP, old), ioctl(f, I_PUSH, new))
71 if (SWAP_MODULE(request->fd, "timod", "sockmod") != 0)
72 tcpd_warn("replace timod by sockmod: %m");
74 if (SWAP_MODULE(request->fd, "sockmod", "timod") != 0)
75 tcpd_warn("replace sockmod by timod: %m");
76 if (request->sink != 0)
77 request->sink = ptx_sink;
81 /* ptx_sink - absorb unreceived IP datagram */
83 static void ptx_sink(int fd)
87 int size = sizeof(sa);
90 * Eat up the not-yet received datagram. Where needed, switch to the
91 * socket programming interface.
94 if (ioctl(fd, I_FIND, "timod") != 0)
95 ioctl(fd, I_POP, "timod");
96 if (ioctl(fd, I_FIND, "sockmod") == 0)
97 ioctl(fd, I_PUSH, "sockmod");
98 (void) recvfrom(fd, buf, sizeof(buf), 0, &sa, &size);