1 /* Copyright (c) 1999 SuSE GmbH Nuerenberg, Germany
2 Author: Thorsten Kukuk <kukuk@suse.de> */
10 #include <sys/socket.h>
13 /* Version number of the daemon interface */
14 #define NSCD_VERSION 2
15 /* Path for the Unix domain socket. */
16 #define _PATH_NSCDSOCKET "/var/run/.nscd_socket"
18 /* Available services. */
28 LASTDBREQ = GETHOSTBYADDRv6,
29 SHUTDOWN, /* Shut the server down. */
30 GETSTAT, /* Get the server statistic. */
31 INVALIDATE, /* Invalidate one special cache. */
35 /* Header common to all requests */
37 int version; /* Version number of the daemon interface. */
38 request_type type; /* Service requested. */
39 #if defined(__alpha__)
40 int64_t key_len; /* Key length is 64bit on Alpha. */
42 int32_t key_len; /* Key length, 32bit on most plattforms. */
46 /* Create a socket connected to a name. */
47 static int nscd_open_socket (void)
49 struct sockaddr_un addr;
52 sock = socket (PF_UNIX, SOCK_STREAM, 0);
56 addr.sun_family = AF_UNIX;
57 assert (sizeof (addr.sun_path) >= sizeof (_PATH_NSCDSOCKET));
58 strcpy (addr.sun_path, _PATH_NSCDSOCKET);
59 if (connect (sock, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
68 * nscd_flush_cache - flush specyfied service bufor in nscd cache
70 int nscd_flush_cache (char *service)
72 int sock = nscd_open_socket ();
79 req.version = NSCD_VERSION;
80 req.type = INVALIDATE;
81 req.key_len = strlen (service) + 1;
82 nbytes = write (sock, &req, sizeof (request_header));
83 if (nbytes != sizeof (request_header)) {
88 nbytes = write (sock, (void *) service, req.key_len);
91 return (nbytes != req.key_len ? (-1) : 0);