3 * $Id: bres.h,v 1.1 1999/10/04 21:40:42 mdw Exp $
5 * Background reverse name resolution
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the mLib utilities library.
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 1999/10/04 21:40:42 mdw
34 * Added background resolver from `fw'.
45 /*----- Header files ------------------------------------------------------*/
47 #include <sys/types.h>
49 #include <sys/socket.h>
50 #include <netinet/in.h>
51 #include <arpa/inet.h>
55 #include <mLib/selbuf.h>
57 /*----- Data structures ---------------------------------------------------*/
59 /* --- Client allocated request block --- */
61 typedef struct bres_client {
62 struct bres_client *next, *prev; /* Queue of waiting resolve jobs */
63 struct bres_server *rs; /* Pointer to attached server */
64 int q; /* Query type (name or address) */
66 struct in_addr addr; /* Address to resolve */
67 char *name; /* Name to resolve */
69 void (*func)(struct hostent */*h*/, void */*p*/); /* Handler function */
70 void *p; /* Argument for handler function */
73 /* --- Server maintained resolver blocks --- */
75 typedef struct bres_server {
76 struct bres_server *next, *prev; /* Doubly-linked list of servers */
77 pid_t kid; /* Process id of server process */
78 int fd; /* File descriptors */
79 struct bres_client *rc; /* Pointer to attached client */
80 sel_timer t; /* Timeout for idle servers */
81 sel_file f; /* Read selector for server */
84 /*----- Functions provided ------------------------------------------------*/
86 /* --- @bres_abort@ --- *
88 * Arguments: @bres_client *rc@ = pointer to client block
92 * Use: Removes a queued job.
95 extern void bres_abort(bres_client */*rc*/);
97 /* --- @bres_byaddr@ --- *
99 * Arguments: @bres_client *rc@ = pointer to client block
100 * @struct in_addr addr@ = address to resolve
101 * @void (*func)(struct hostent *h, void *p)@ = handler function
102 * @void *p@ = argument for handler function
106 * Use: Adds an address lookup job to the queue. The job will be
107 * processed when there's a spare resolver process to deal with
111 extern void bres_byaddr(bres_client */*rc*/, struct in_addr /*addr*/,
112 void (*/*func*/)(struct hostent */*h*/, void */*p*/),
115 /* --- @bres_byname@ --- *
117 * Arguments: @bres_client *rc@ = pointer to client block
118 * @const char *name@ = name to resolve
119 * @void (*func)(struct hostent *h, void *p)@ = handler function
120 * @void *p@ = argument for handler function
124 * Use: Adds a name lookup job to the queue. The job will be
125 * processed when there's a spare resolver process to deal with
129 extern void bres_byname(bres_client */*rc*/, const char */*name*/,
130 void (*/*func*/)(struct hostent */*h*/, void */*p*/),
133 /* --- @bres_exec@ --- *
135 * Arguments: @const char *file@ = file containing server code or null
139 * Use: Makes `bres' use a standalone server rather than copies of
140 * the current process. This can reduce memory consumption for
141 * large processes, at the expense of startup time (which
142 * shouldn't be too bad anyway, because of the resolver design).
143 * If the filename is null, a default set up at install time is
144 * used. It's probably a good idea to leave it alone.
147 extern void bres_exec(const char */*file*/);
149 /* --- @bres_init@ --- *
151 * Arguments: @sel_state *s@ = pointer to select multiplexor
155 * Use: Initializes the background resolver for use.
158 extern void bres_init(sel_state */*s*/);
160 /*----- That's all, folks -------------------------------------------------*/