-static void
-face_format(struct mcomp *c1)
-{
- char *cp;
- struct mailname *mp;
-
- if ((cp = c1->c_text) == NULL)
- return;
-
- if ((cp = getname(cp))) {
- if ((mp = getm(cp, NULL, 0, AD_NAME, NULL))) {
- char *h, *o;
- if ((h = mp->m_host) == NULL)
- h = LocalName();
- if ((o = OfficialName(h)))
- h = o;
- c1->c_face = concat("address ", h, " ", mp->m_mbox,
- NULL);
- }
-
- while ((cp = getname(cp)))
- continue;
- }
-}
-
-
-/*
-** faceproc is two elements defining the image agent's location:
-** Internet host
-** UDP port
-*/
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-
-#ifdef HAVE_ARPA_INET_H
-# include <arpa/inet.h>
-#endif
-
-static int
-doface(struct mcomp *c1)
-{
- int result, sd;
- static int inited = OK;
- static struct sockaddr_storage ss;
- static socklen_t socklen;
- static int socktype;
- static int protocol;
-
- if (inited == OK) {
- char *cp;
- char **ap = brkstring(cp = getcpy(faceproc), " ", "\n");
- struct addrinfo hints, *res;
-
- if (ap[0] == NULL || ap[1] == NULL) {
-bad_faceproc: ;
- free(cp);
- return (inited = NOTOK);
- }
-
- memset(&hints, 0, sizeof(hints));
-#ifdef AI_ADDRCONFIG
- hints.ai_flags = AI_ADDRCONFIG;
-#endif
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_DGRAM;
-
- if (getaddrinfo(ap[0], ap[1], &hints, &res) != 0)
- goto bad_faceproc;
-
- memcpy(&ss, res->ai_addr, res->ai_addrlen);
- socklen = res->ai_addrlen;
- socktype = res->ai_socktype;
- protocol = res->ai_protocol;
- freeaddrinfo(res);
-
- inited = DONE;
- }
- if (inited == NOTOK)
- return NOTOK;
-
- if ((sd = socket(ss.ss_family, socktype, protocol)) == NOTOK)
- return NOTOK;
-
- result = sendto(sd, c1->c_text, strlen(c1->c_text), 0,
- (struct sockaddr *) &ss, socklen);
-
- close(sd);
-
- return (result != NOTOK ? OK : NOTOK);
-}
-
-/*
-** COMMENTED OUT
-** This version doesn't use sockets
-*/
-#if 0
-
-static int
-doface(struct mcomp *c1)
-{
- int i, len, vecp;
- pid_t child_id;
- int result, pdi[2], pdo[2];
- char *bp, *cp;
- char buffer[BUFSIZ], *vec[10];
-
- if (pipe(pdi) == NOTOK)
- return NOTOK;
- if (pipe(pdo) == NOTOK) {
- close(pdi[0]);
- close(pdi[1]);
- return NOTOK;
- }
-
- for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
- sleep(5);
-
- switch (child_id) {
- case NOTOK:
- /* oops... fork error */
- return NOTOK;
-
- case OK:
- /* child process */
- SIGNAL(SIGINT, SIG_IGN);
- SIGNAL(SIGQUIT, SIG_IGN);
- if (pdi[0] != fileno(stdin)) {
- dup2(pdi[0], fileno(stdin));
- close(pdi[0]);
- }
- close(pdi[1]);
- close(pdo[0]);
- if (pdo[1] != fileno(stdout)) {
- dup2(pdo[1], fileno(stdout));
- close(pdo[1]);
- }
- vecp = 0;
- vec[vecp++] = mhbasename(faceproc);
- vec[vecp++] = "-e";
- if (sleepsw != NOTOK) {
- vec[vecp++] = "-s";
- snprintf(buffer, sizeof(buffer), "%d",
- sleepsw);
- vec[vecp++] = buffer;
- }
- vec[vecp] = NULL;
- execvp(faceproc, vec);
- fprintf(stderr, "unable to exec ");
- perror(faceproc);
- _exit(-1); /* NOTREACHED */
-
- default:
- /* parent process */
- close(pdi[0]);
- i = strlen(c1->c_text);
- if (write(pdi[1], c1->c_text, i) != i)
- adios("pipe", "error writing to");
- free(c1->c_text), c1->c_text = NULL;
- close(pdi[1]);
-
- close(pdo[1]);
- cp = NULL, len = 0;
- result = DONE;
- while ((i=read(pdo[0], buffer, strlen(buffer))) > 0) {
- if (cp) {
- int j;
- char *dp;
- dp = mh_xrealloc(cp, (unsigned) (j = len + i));
- memcpy(dp + len, buffer, i);
- cp = dp, len = j;
- } else {
- cp = mh_xmalloc((unsigned) i);
- memcpy(cp, buffer, i);
- len = i;
- }
- if (result == DONE)
- for (bp = buffer + i - 1; bp >= buffer; bp--)
- if (!isascii(*bp) ||
- iscntrl(*bp)) {
- result = OK;
- break;
- }
- }
- close(pdo[0]);
-
-/* no waiting for child... */
-
- if (result == OK) { /* binary */
- if (write(1, cp, len) != len)
- adios("writing", "error");
- free(cp);
- }
- else /* empty */
- if ((c1->c_text = cp) == NULL)
- result = OK;
- break;
- }
-
- return result;
-}
-#endif /* COMMENTED OUT */
-
-