home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / alt / hackers / 1379 < prev    next >
Encoding:
Text File  |  1992-09-08  |  2.4 KB  |  98 lines

  1. Newsgroups: alt.hackers
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!spool.mu.edu!umn.edu!lynx!carina.unm.edu!schaker
  3. From: schaker@carina.unm.edu (The Big Bwana)
  4. Subject: Ling-ling
  5. Message-ID: <kvrnjcl@lynx.unm.edu>
  6. Date: Tue, 08 Sep 92 17:12:59 GMT
  7. Organization: University of New Mexico, Albuquerque
  8. Keywords: comsat(8)
  9. Approved: foo@bar
  10. Lines: 86
  11.  
  12.  
  13. This is just an obhack with little or no verberhea.  This way, I get credit
  14. and can post some verbage later.  (It does work that way, right?  ;^)
  15.  
  16. I'll let the real hackers out there figure this out.  The non-hackers
  17. might be SOL.  I do not apologize for the inelegance.  It's a hack,
  18. and I was under the gun for time.  I didn't bother to clean it up.
  19. I suspect the socket stuff will work on all systems, but I can't be
  20. sure.
  21.  
  22. BTW, Ling-ling is my chow that barks at lots of things.  She'll even
  23. bark for no reason at all.
  24.  
  25.                 stef
  26.  
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <strings.h>
  31. #include <sys/types.h>
  32. #include <sys/socket.h>
  33. #include <netinet/in.h>
  34. #include <netdb.h>
  35.  
  36. main(argc, argv)
  37.     int argc;
  38.     char *argv[];
  39. {
  40.     int s, cc, len, offset;
  41.     char *hostname, hn[50], user[50], message[100];
  42.     struct hostent *hent;
  43.     struct sockaddr_in saddr;
  44.  
  45.     if (argc < 2)
  46.     Usage(argv[0]);
  47.     if ((len = strlen(argv[1])) == 0)
  48.     Usage(argv[0]);
  49.     if (argc < 3)
  50.     offset = 0;
  51.     else
  52.     offset = atoi(argv[2]);
  53.  
  54.     strcpy(user, argv[1]);
  55.     if ((hostname = index(argv[1], '@')) != NULL)
  56.     user[hostname - argv[1]] = '\0';
  57.     if (hostname == NULL) {
  58.     gethostname(hn, 50);
  59.     hostname = hn;
  60.     } else
  61.     hostname++;
  62.     if ((hent = gethostbyname(hostname)) == NULL) {
  63.     fprintf(stderr, "could not find hostname \"%s\"\n", hostname);
  64.     exit(1);
  65.     }
  66.     saddr.sin_family = hent->h_addrtype;
  67.     saddr.sin_port = htons(512);
  68.     bcopy(hent->h_addr, &saddr.sin_addr, sizeof(struct in_addr));
  69.  
  70.     if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  71.     perror("socket");
  72.     exit (1);
  73.     }
  74.  
  75.     sprintf(message, "%s@%d", user, offset);
  76.     len = strlen(message);
  77.  
  78.     if ((cc=sendto(s, message, len, 0, (struct sockaddr *) &saddr,
  79.         sizeof(struct sockaddr))) < 0) {
  80.     perror("sendto");
  81.     exit(1);
  82.     }
  83.     close(s);
  84.     exit(0);
  85. }
  86.  
  87. Usage(name)
  88.     char *name;
  89. {
  90.     fprintf(stderr, "Usage: %s user@host [offset]\n", name);
  91.     exit(1);
  92. }
  93. -- 
  94.     _---_     Stefan Chakerian
  95.    / o o \    schaker@triton.unm.edu, schaker@unmb.bitnet
  96.   | \___/ |   
  97.    \_____/    Don't anthropomorphize computers.  They don't like it.
  98.