static char sccsid
[] = "@(#)talkd.c 1.3 (Berkeley) %G%";
* The top level of the daemon, the format is heavily borrowed
* from rwhod.c. Basically: find out who and where you are;
* disconnect all descriptors and ttys, and then endless
* loop on waiting for and processing requests
struct sockaddr_in sin
= { AF_INET
};
debugout
= (FILE *)fopen ("/usr/tmp/talkd.msgs", "w");
fprintf(stderr
, "Talkd : not super user\n");
gethostname(hostname
, sizeof (hostname
));
signal(SIGALRM
, timeout
);
cc
= recvfrom(0, (char *)&request
, sizeof (request
), 0,
if (cc
!= sizeof(request
)) {
if (cc
< 0 && errno
!= EINTR
)
if (debug
) print_request(&request
, fp
);
process_request(&request
, &response
);
/* can block here, is this what I want? */
cc
= sendto(sockt
, (char *) &response
,
sizeof (response
), 0, &request
.ctl_addr
,
sizeof (request
.ctl_addr
));
if (cc
!= sizeof(response
))
if (debug
) close (debugout
);
if (time(0) - lastmsgtime
>= MAXIDLE
)
#define swapshort(a) (((a << 8) | ((unsigned short) a >> 8)) & 0xffff)
#define swaplong(a) ((swapshort(a) << 16) | (swapshort(((unsigned)a >> 16))))
* heuristic to detect if need to swap bytes
if (req
->ctl_addr
.sin_family
== swapshort(AF_INET
)) {
req
->id_num
= swaplong(req
->id_num
);
req
->pid
= swaplong(req
->pid
);
req
->addr
.sin_family
= swapshort(req
->addr
.sin_family
);
req
->ctl_addr
.sin_family
=
swapshort(req
->ctl_addr
.sin_family
);