5
/* send biff notification
7
/* #include <biff_notify.h>
9
/* void biff_notify(text, len)
13
/* biff_notify() sends a \fBBIFF\fR notification request to the
14
/* \fBcomsat\fR daemon.
18
/* Null-terminated text (username@mailbox-offset).
20
/* Length of text, including null terminator.
22
/* The \fBBIFF\fR "service" can be a noticeable load for
23
/* systems that have many logged-in users.
27
/* The Secure Mailer license must be distributed with this software.
30
/* IBM T.J. Watson Research
32
/* Yorktown Heights, NY 10598, USA
38
#include <sys/socket.h>
39
#include <netinet/in.h>
43
/* Utility library. */
47
/* Application-specific. */
49
#include <biff_notify.h>
51
/* biff_notify - notify recipient via the biff "protocol" */
53
void biff_notify(const char *text, int len)
55
static struct sockaddr_in sin;
61
* Initialize a socket address structure, or re-use an existing one.
63
if (sin.sin_family == 0) {
64
if ((sp = getservbyname("biff", "udp")) == 0) {
65
msg_warn("service not found: biff/udp");
68
if ((hp = gethostbyname("localhost")) == 0) {
69
msg_warn("host not found: localhost");
72
if ((int) hp->h_length > (int) sizeof(sin.sin_addr)) {
73
msg_warn("bad address size %d for localhost", hp->h_length);
76
sin.sin_family = hp->h_addrtype;
77
sin.sin_port = sp->s_port;
78
memcpy((char *) &sin.sin_addr, hp->h_addr_list[0], hp->h_length);
82
* Open a socket, or re-use an existing one.
84
if (sock < 0 && (sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
85
msg_warn("socket: %m");
92
if (sendto(sock, text, len, 0, (struct sockaddr *) & sin, sizeof(sin)) != len)
93
msg_warn("biff_notify: %m");