hammer - Adjust hammer to new breadnx / cluster_readx API
[dragonfly.git] / contrib / tcp_wrappers / update.c
blob142820b948ba4ee348797eba52bcbb3b0aa9611f
1 /*
2 * Routines for controlled update/initialization of request structures.
3 *
4 * request_init() initializes its argument. Pointers and string-valued members
5 * are initialized to zero, to indicate that no lookup has been attempted.
6 *
7 * request_set() adds information to an already initialized request structure.
8 *
9 * Both functions take a variable-length name-value list.
11 * Diagnostics are reported through syslog(3).
13 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
15 * $FreeBSD: src/contrib/tcp_wrappers/update.c,v 1.2 2000/02/03 10:27:00 shin Exp $
18 /* System libraries */
20 #include <stdio.h>
21 #include <syslog.h>
22 #include <string.h>
23 #include <unistd.h>
25 /* Local stuff. */
27 #include "mystdarg.h"
28 #include "tcpd.h"
30 /* request_fill - request update engine */
32 static struct request_info *request_fill(request, ap)
33 struct request_info *request;
34 va_list ap;
36 int key;
37 char *ptr;
39 while ((key = va_arg(ap, int)) > 0) {
40 switch (key) {
41 default:
42 tcpd_warn("request_fill: invalid key: %d", key);
43 return (request);
44 case RQ_FILE:
45 request->fd = va_arg(ap, int);
46 continue;
47 case RQ_CLIENT_SIN:
48 #ifdef INET6
49 request->client->sin = va_arg(ap, struct sockaddr *);
50 #else
51 request->client->sin = va_arg(ap, struct sockaddr_in *);
52 #endif
53 continue;
54 case RQ_SERVER_SIN:
55 #ifdef INET6
56 request->server->sin = va_arg(ap, struct sockaddr *);
57 #else
58 request->server->sin = va_arg(ap, struct sockaddr_in *);
59 #endif
60 continue;
63 * All other fields are strings with the same maximal length.
66 case RQ_DAEMON:
67 ptr = request->daemon;
68 break;
69 case RQ_USER:
70 ptr = request->user;
71 break;
72 case RQ_CLIENT_NAME:
73 ptr = request->client->name;
74 break;
75 case RQ_CLIENT_ADDR:
76 ptr = request->client->addr;
77 break;
78 case RQ_SERVER_NAME:
79 ptr = request->server->name;
80 break;
81 case RQ_SERVER_ADDR:
82 ptr = request->server->addr;
83 break;
85 STRN_CPY(ptr, va_arg(ap, char *), STRING_LENGTH);
87 return (request);
90 /* request_init - initialize request structure */
92 struct request_info *VARARGS(request_init, struct request_info *, request)
94 static struct request_info default_info;
95 struct request_info *r;
96 va_list ap;
99 * Initialize data members. We do not assign default function pointer
100 * members, to avoid pulling in the whole socket module when it is not
101 * really needed.
103 VASTART(ap, struct request_info *, request);
104 *request = default_info;
105 request->fd = -1;
106 strcpy(request->daemon, unknown);
107 sprintf(request->pid, "%d", getpid());
108 request->client->request = request;
109 request->server->request = request;
110 r = request_fill(request, ap);
111 VAEND(ap);
112 return (r);
115 /* request_set - update request structure */
117 struct request_info *VARARGS(request_set, struct request_info *, request)
119 struct request_info *r;
120 va_list ap;
122 VASTART(ap, struct request_info *, request);
123 r = request_fill(request, ap);
124 VAEND(ap);
125 return (r);