drm/linux: Add kasprintf and kvasprintf()
[dragonfly.git] / contrib / tcp_wrappers / ptx.c
blobb9c312b82cdc06c6bebffc69c362179a911c4ce1
1 /*
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
4 * IP-based services.
5 *
6 * Diagnostics are reported through syslog(3).
7 *
8 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
9 */
11 #ifndef lint
12 static char sccsid[] = "@(#) ptx.c 1.3 94/12/28 17:42:38";
13 #endif
15 #ifdef PTX
17 /* System libraries. */
19 #include <sys/types.h>
20 #include <sys/tiuser.h>
21 #include <sys/socket.h>
22 #include <stropts.h>
23 #include <netinet/in.h>
24 #include <netdb.h>
25 #include <stdio.h>
26 #include <syslog.h>
28 /* Local stuff. */
30 #include "tcpd.h"
32 /* Forward declarations. */
34 static void ptx_sink();
36 /* tli_host - determine TLI endpoint info, PTX version */
38 void tli_host(request)
39 struct request_info *request;
41 static struct sockaddr_in client;
42 static struct sockaddr_in server;
45 * getpeerinaddr() was suggested by someone at Sequent. It seems to work
46 * with connection-oriented (TCP) services such as rlogind and telnetd,
47 * but it returns 0.0.0.0 with datagram (UDP) services. No problem: UDP
48 * needs special treatment anyway, in case we must refuse service.
51 if (getpeerinaddr(request->fd, &client, sizeof(client)) == 0
52 && client.sin_addr.s_addr != 0) {
53 request->client->sin = &client;
54 if (getmyinaddr(request->fd, &server, sizeof(server)) == 0) {
55 request->server->sin = &server;
56 } else {
57 tcpd_warn("warning: getmyinaddr: %m");
59 sock_methods(request);
61 } else {
64 * Another suggestion was to temporarily switch to the socket
65 * interface, identify the endpoint addresses with socket calls, then
66 * to switch back to TLI. This seems to works OK with UDP services,
67 * which is exactly what we should be looking at right now.
70 #define SWAP_MODULE(f, old, new) (ioctl(f, I_POP, old), ioctl(f, I_PUSH, new))
72 if (SWAP_MODULE(request->fd, "timod", "sockmod") != 0)
73 tcpd_warn("replace timod by sockmod: %m");
74 sock_host(request);
75 if (SWAP_MODULE(request->fd, "sockmod", "timod") != 0)
76 tcpd_warn("replace sockmod by timod: %m");
77 if (request->sink != 0)
78 request->sink = ptx_sink;
82 /* ptx_sink - absorb unreceived IP datagram */
84 static void ptx_sink(fd)
85 int fd;
87 char buf[BUFSIZ];
88 struct sockaddr sa;
89 int size = sizeof(sa);
92 * Eat up the not-yet received datagram. Where needed, switch to the
93 * socket programming interface.
96 if (ioctl(fd, I_FIND, "timod") != 0)
97 ioctl(fd, I_POP, "timod");
98 if (ioctl(fd, I_FIND, "sockmod") == 0)
99 ioctl(fd, I_PUSH, "sockmod");
100 (void) recvfrom(fd, buf, sizeof(buf), 0, &sa, &size);
103 #endif /* PTX */