]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/smwgc.c
finalize -3
[1ts-debian.git] / zephyr / lib / smwgc.c
1 /*      Copyright (c) 1988 by the Massachusetts Institute of Technology.
2  *      All Rights Reserved.
3  */
4 #include <zephyr/zephyr.h>
5
6 main()
7 {
8     FILE *fp;
9     char buf[512],*ptr;
10     int auth,retval;
11     u_short port;
12     ZNotice_t notice;
13     ZSubscription_t sub;
14     struct sockaddr_in from;
15         
16     if ((retval = ZInitialize()) != ZERR_NONE) {
17         com_err("foo",retval,"initing");
18         exit(1);
19     } 
20
21     port = 0;
22     if ((retval = ZOpenPort(&port)) != ZERR_NONE) {
23         com_err("foo",retval,"opening port");
24         exit(1);
25     }
26     printf("Using port %d\n",(int)port);
27     sprintf(buf,"/tmp/wg.%d",getuid());
28     fp = fopen(buf,"w");
29     if (!fp) {
30         com_err("foo",errno,"opening file");
31         exit(1);
32     } 
33     fprintf(fp,"%d\n",(int)port);
34     fclose(fp);
35
36     printf("All ready...\n");
37
38     sub.class = "MESSAGE";
39     sub.classinst = "PERSONAL";
40     sub.recipient = ZGetSender();
41
42     if ((retval = ZSubscribeTo(&sub,1,port)) != ZERR_NONE) {
43         com_err("foo",retval,"subscribing");
44         exit(1);
45     } 
46     for (;;) {
47         if ((retval = ZReceiveNotice(&notice,&from)) != ZERR_NONE) {
48             com_err("foo",retval,"receiving packet");
49             continue;
50         }
51         auth = ZCheckAuthentication(&notice,&from);
52         printf("Class = %s Instance = %s Sender = %s\nTime = %s Auth = %d\n",
53                notice.z_class,notice.z_class_inst,notice.z_sender,
54                ctime(&notice.z_time.tv_sec),auth);
55         printf("Len = %d\n",notice.z_message_len);
56 /*      ptr = notice.z_message;
57         for (;ptr<notice.z_message+notice.z_message_len;) {
58             printf("%s\n",ptr);
59             ptr += strlen(ptr)+1;
60         }
61         printf("\n");*/
62         ZFreeNotice(&notice);
63     }
64 }