1 #include "unpxti.h"
2
3 int
main(int argc,char ** argv)4 main(int argc, char **argv)
5 {
6 int tfd, flags;
7 char recvline[MAXLINE + 1];
8 socklen_t addrlen;
9 struct t_unitdata *sndptr1, *sndptr2, *sndptr3, *rcvptr;
10 struct t_uderr *uderr;
11
12 if (argc != 5)
13 err_quit("usage: a.out <host1> <host2> <host3> <service or port#>");
14
15 tfd = Udp_client(argv[1], argv[4], (void **) &sndptr1, &addrlen);
16 close(tfd);
17 tfd = Udp_client(argv[2], argv[4], (void **) &sndptr2, &addrlen);
18 close(tfd);
19 tfd = Udp_client(argv[3], argv[4], (void **) &sndptr3, &addrlen);
20
21 rcvptr = T_alloc(tfd, T_UNITDATA, T_ADDR);
22 uderr = T_alloc(tfd, T_UDERROR, T_ADDR);
23
24 printf("sending to %s\n", Xti_ntop_host(&sndptr1->addr));
25 sndptr1->udata.maxlen = MAXLINE;
26 sndptr1->udata.len = 1;
27 sndptr1->udata.buf = recvline;
28 recvline[0] = 0; /* 1-byte datagram containing null byte */
29 T_sndudata(tfd, sndptr1);
30
31 printf("sending to %s\n", Xti_ntop_host(&sndptr2->addr));
32 sndptr2->udata.maxlen = MAXLINE;
33 sndptr2->udata.len = 1;
34 sndptr2->udata.buf = recvline;
35 *(sndptr2->udata.buf) = 0;
36 T_sndudata(tfd, sndptr2);
37
38 printf("sending to %s\n", Xti_ntop_host(&sndptr3->addr));
39 sndptr3->udata.maxlen = MAXLINE;
40 sndptr3->udata.len = 1;
41 sndptr3->udata.buf = recvline;
42 *(sndptr3->udata.buf) = 0;
43 T_sndudata(tfd, sndptr3);
44
45 for ( ; ; ) {
46 rcvptr->udata.maxlen = MAXLINE;
47 rcvptr->udata.buf = recvline;
48 if (t_rcvudata(tfd, rcvptr, &flags) == 0) {
49 recvline[rcvptr->udata.len] = 0; /* null terminate */
50 printf("from %s: %s", Xti_ntop_host(&rcvptr->addr), recvline);
51 } else {
52 if (t_errno == TLOOK) {
53 T_rcvuderr(tfd, uderr);
54 printf("error %ld from %s\n",
55 uderr->error, Xti_ntop_host(&uderr->addr));
56 } else
57 err_xti("t_rcvudata error");
58 }
59 }
60 exit(0);
61 }
62