|
|
1.1 ! root 1: /* ! 2: * Wall. ! 3: */ ! 4: #include <stdio.h> ! 5: #include <utmp.h> ! 6: ! 7: #define NMSG 512 ! 8: ! 9: char cant[] = "Cannot send to %.*s on %.*s.\n"; ! 10: ! 11: char msg[NMSG]; ! 12: char *ttyname(); ! 13: int nmsg; ! 14: ! 15: main(argc, argv) ! 16: char *argv[]; ! 17: { ! 18: register char *mytty; ! 19: register tfd, ufd; ! 20: struct utmp utmp; ! 21: char tfn[5+sizeof(utmp.ut_line)+1]; ! 22: ! 23: getmsg(); ! 24: if ((ufd = open("/etc/utmp", 0)) < 0) { ! 25: fprintf(stderr, "Cannot open utmp.\n"); ! 26: exit(1); ! 27: } ! 28: mytty = ttyname(fileno(stderr)); ! 29: while (read(ufd, &utmp, sizeof(utmp)) == sizeof(utmp)) { ! 30: if (utmp.ut_line[0] == '\0') ! 31: continue; ! 32: sprintf(tfn, "/dev/%.*s", sizeof(utmp.ut_line), utmp.ut_line); ! 33: if (mytty!=NULL && strcmp(mytty, tfn)==0) ! 34: continue; ! 35: if ((tfd = open(tfn, 1)) < 0) { ! 36: fprintf(stderr, cant, sizeof(utmp.ut_name), ! 37: utmp.ut_name, sizeof(utmp.ut_line), utmp.ut_line); ! 38: continue; ! 39: } ! 40: write(tfd, msg, nmsg); ! 41: close(tfd); ! 42: } ! 43: close(ufd); ! 44: } ! 45: ! 46: getmsg() ! 47: { ! 48: register char *p1, *p2; ! 49: register c; ! 50: ! 51: p1 = msg; ! 52: p2 = "\007Broadcast message .....\n"; ! 53: while ((c = *p2++) != '\0') ! 54: *p1++ = c; ! 55: while ((c = getchar()) != EOF) { ! 56: if (p1 >= &msg[NMSG]) { ! 57: fprintf(stderr, "Message too long.\n"); ! 58: exit(1); ! 59: } ! 60: *p1++ = c; ! 61: } ! 62: nmsg = p1-msg; ! 63: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.