Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / local / biff_notify.c
blobac491d7c32d4a9d95ef3fe4d319ff6ccf3581edc
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* biff_notify 3
6 /* SUMMARY
7 /* send biff notification
8 /* SYNOPSIS
9 /* #include <biff_notify.h>
11 /* void biff_notify(text, len)
12 /* const char *text;
13 /* ssize_t len;
14 /* DESCRIPTION
15 /* biff_notify() sends a \fBBIFF\fR notification request to the
16 /* \fBcomsat\fR daemon.
18 /* Arguments:
19 /* .IP text
20 /* Null-terminated text (username@mailbox-offset).
21 /* .IP len
22 /* Length of text, including null terminator.
23 /* BUGS
24 /* The \fBBIFF\fR "service" can be a noticeable load for
25 /* systems that have many logged-in users.
26 /* LICENSE
27 /* .ad
28 /* .fi
29 /* The Secure Mailer license must be distributed with this software.
30 /* AUTHOR(S)
31 /* Wietse Venema
32 /* IBM T.J. Watson Research
33 /* P.O. Box 704
34 /* Yorktown Heights, NY 10598, USA
35 /*--*/
37 /* System library. */
39 #include "sys_defs.h"
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <netdb.h>
43 #include <string.h>
45 /* Utility library. */
47 #include <msg.h>
49 /* Application-specific. */
51 #include <biff_notify.h>
53 /* biff_notify - notify recipient via the biff "protocol" */
55 void biff_notify(const char *text, ssize_t len)
57 static struct sockaddr_in sin;
58 static int sock = -1;
59 struct hostent *hp;
60 struct servent *sp;
63 * Initialize a socket address structure, or re-use an existing one.
65 if (sin.sin_family == 0) {
66 if ((sp = getservbyname("biff", "udp")) == 0) {
67 msg_warn("service not found: biff/udp");
68 return;
70 if ((hp = gethostbyname("localhost")) == 0) {
71 msg_warn("host not found: localhost");
72 return;
74 if ((int) hp->h_length > (int) sizeof(sin.sin_addr)) {
75 msg_warn("bad address size %d for localhost", hp->h_length);
76 return;
78 sin.sin_family = hp->h_addrtype;
79 sin.sin_port = sp->s_port;
80 memcpy((char *) &sin.sin_addr, hp->h_addr_list[0], hp->h_length);
84 * Open a socket, or re-use an existing one.
86 if (sock < 0 && (sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
87 msg_warn("socket: %m");
88 return;
92 * Biff!
94 if (sendto(sock, text, len, 0, (struct sockaddr *) & sin, sizeof(sin)) != len)
95 msg_warn("biff_notify: %m");