7 /* send biff notification
9 /* #include <biff_notify.h>
11 /* void biff_notify(text, len)
15 /* biff_notify() sends a \fBBIFF\fR notification request to the
16 /* \fBcomsat\fR daemon.
20 /* Null-terminated text (username@mailbox-offset).
22 /* Length of text, including null terminator.
24 /* The \fBBIFF\fR "service" can be a noticeable load for
25 /* systems that have many logged-in users.
29 /* The Secure Mailer license must be distributed with this software.
32 /* IBM T.J. Watson Research
34 /* Yorktown Heights, NY 10598, USA
40 #include <sys/socket.h>
41 #include <netinet/in.h>
45 /* Utility library. */
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
;
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");
70 if ((hp
= gethostbyname("localhost")) == 0) {
71 msg_warn("host not found: localhost");
74 if ((int) hp
->h_length
> (int) sizeof(sin
.sin_addr
)) {
75 msg_warn("bad address size %d for localhost", hp
->h_length
);
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");
94 if (sendto(sock
, text
, len
, 0, (struct sockaddr
*) & sin
, sizeof(sin
)) != len
)
95 msg_warn("biff_notify: %m");