home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / MCAST.ZIP / APPS / BLATHER.C next >
Encoding:
C/C++ Source or Header  |  1993-11-10  |  2.5 KB  |  118 lines

  1. /*
  2.  * blather - a program to generate vat control messages
  3.  *
  4.  * Usage: blather ["ID string"] [ttl] [multicast address] [port]
  5.  *
  6.  *   Lister is a primarly useless program that I hacked together to
  7.  * prove that my multicast code was sending correctly. It will send out
  8.  * a ID string to the specified multicast address/port at 5 second 
  9.  * intervals. By default it will send a silly ID out on MBone Audio with
  10.  * a ttl of 32. Each time an update is sent out, a message will be 
  11.  * displayed. To quit, hit any key (be patient, it can take up to 5 secs)
  12.  *
  13.  * Jim Martin
  14.  * jim@noc.rutgers.edu
  15.  * 11/10/93
  16.  */
  17.  
  18.  
  19. #include <stdio.h>
  20. #include <stdarg.h>
  21. #include <stdlib.h>
  22. #include <conio.h>
  23. #include <string.h>
  24. #include <tcp.h>
  25. #include <mem.h>
  26. #include <dos.h>
  27.  
  28. struct CtrlMsg {
  29.   unsigned char version:2;
  30.   unsigned char flags:6;
  31.   unsigned char type;
  32.   unsigned short confid;
  33.   char data;
  34. };
  35.  
  36.  
  37.  
  38. void main(int argc, char **argv)
  39. {
  40.     udp_Socket telsock;
  41.     static udp_Socket *s;
  42.     longword host;
  43.     int ttl;
  44.     word port;
  45.     char id[512];
  46.     struct CtrlMsg *header;
  47.  
  48.     /* override defaults with command line if available */
  49.         if (argc>1)
  50.             strcpy(id,argv[1]);
  51.         else
  52.             strcpy(id,"A random PC blathering for no apparent reason");
  53.         
  54.         if (argc>2)
  55.              ttl=atoi(argv[2]);
  56.     else
  57.          ttl=32;
  58.  
  59.     if (argc>3)
  60.         host=resolve(argv[3]);
  61.     else
  62.             host = resolve("224.2.0.1");
  63.  
  64.     if (argc>4)
  65.         port=atoi(argv[4]);
  66.     else
  67.         port=3457;
  68.  
  69.  
  70.  
  71.         /* First initialize the header structure */
  72.         header = (struct CtrlMsg *)malloc(sizeof(struct CtrlMsg)+strlen(id));
  73.         memset(header, (int)NULL, sizeof(struct CtrlMsg)+strlen(id));
  74.         header->type=1;
  75.         strcpy(&header->data,id);
  76.  
  77.         /* And now for the networking */
  78.     sock_init();
  79.  
  80.     s = (udp_Socket *) &telsock;
  81.  
  82.     /* Open the UDP connection (?!) */
  83.     if( !udp_open( s, port, host, port, NULL)){
  84.         printf("Unable to open udp connection\n");
  85.         exit(0);
  86.     }
  87.  
  88.     /* Join the multicast group */
  89.     if( ! join_mcast_group( host ))
  90.            printf("Unable to join group!!!\n");
  91.  
  92.     /* Set the TTL */
  93.         udp_SetTTL(s, ttl);
  94.  
  95.     /* And loop until we get a keypress */
  96.     while ( !kbhit() ){
  97.         tcp_tick(NULL);
  98.         sock_write( s, (byte *)header, sizeof(struct CtrlMsg)+strlen(id));
  99.         printf("Sent an ID of: %s \n",id);
  100.         sleep(5);
  101.     }
  102.  
  103. sock_err:
  104.     sock_close( s );
  105.  
  106.     /* Leave the multicast group */
  107.     if( ! leave_mcast_group( host ))
  108.             printf("Unable to leave group!!!\n");
  109.  
  110.     exit( 0 );
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.