home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / Broadcast / displaymsg / displaymsg.c next >
Text File  |  1993-01-13  |  2KB  |  65 lines

  1. /* Copyright (c) 1992 by Clarance Howatt, Gary Ritchie, Andrew Penn
  2.  *    You may modify and (hopefully) improve this code if you keep the
  3.  *    original copyright messages, don't sell it, and share your improvements
  4.  *    with with the World.
  5.  *
  6.  * NAME
  7.  *     displaymsg -- unix utility
  8.  *
  9.  * DESCRIPTION
  10.  *     Display a message in a panel.  There must be someone logged in,
  11.  *     and they must have Broadcast.daemon running for this to work.
  12.  *
  13.  * COMMENTS/PROBLEMS
  14.  *     This program and the associated daemon represent a potential 
  15.  *     security hole.  Use at your own risk.
  16.  *
  17.  * AUTHOR/DATE CREATED
  18.  *     Gary Ritchie/December 22, 1992
  19.  *
  20.  * REVISIONS
  21.  *
  22.  */
  23.  
  24. #import <appkit/appkit.h>
  25. #import <shared.h>
  26. #import <pwd.h>
  27. #import <BroadcastSpeaker.h>
  28.  
  29. int main(int argc, char *argv[])
  30. {
  31.     port_t thePort;
  32.     id theSpeaker;
  33.     int result;
  34.     struct passwd *password;
  35.     char *host;
  36.     
  37.     if (argc != 2 && argc != 3) {
  38.         NXLogError("usage: %s \"message string\" [host]\n", argv[0]);
  39.     exit(1);
  40.     }
  41.  
  42.     if (argc == 3)
  43.         host = argv[2];
  44.     else
  45.         host = NULL;
  46.     thePort = NXPortFromName(BROADCASTPORT, host);
  47.     if (!thePort) {
  48.         NXLogError("Unable to connect to Broadcast daemon.\n");
  49.     exit(2);
  50.     }
  51.  
  52.     password = getpwuid(getuid());
  53.     
  54.     theSpeaker = [[BroadcastSpeaker alloc] init];
  55.     [theSpeaker setSendPort:thePort];
  56.     result = [theSpeaker broadcast:argv[1] from:password->pw_name];
  57.     if (result) {
  58.         NXLogError("Broadcast failed.\n");
  59.     }
  60.     [theSpeaker free];
  61.     port_deallocate(task_self(), thePort);    
  62.  
  63.     return 0;
  64. }
  65.