xref: /csrg-svn/sys/tests/netiso/Tesis.c (revision 49346)
1 /*
2  * Copyright (c) 1988, 1990 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 /* Modifications
8  * Copyright (c) 1990 Robert Hagens
9  */
10 #ifndef lint
11 static char sccsid[] = "@(#)Tesis.c	1.1 (Berkeley) 05/07/91";
12 #endif /* not lint */
13 
14 /*
15  * This is a test program to listen to esis packets.
16  */
17 #include <sys/param.h>
18 #include <sys/uio.h>
19 #include <sys/socket.h>
20 #include <sys/ioctl.h>
21 #include <net/route.h>
22 #include <net/if.h>
23 #define  TCPT_NTIMERS 4
24 #include <netiso/iso.h>
25 #include <netiso/tp_param.h>
26 #include <netiso/tp_user.h>
27 
28 #include <stdio.h>
29 #include <errno.h>
30 #include <ctype.h>
31 #include <netdb.h>
32 
33 
34 #define dbprintf if(verbose)printf
35 #define try(a,b,c) {x = (a b); dbprintf("%s%s returns %d\n",c,"a",x);\
36 		if(x<0) {perror("a"); myexit(0);}}
37 
38 
39 struct  ifreq ifr;
40 short port = 3000;
41 struct  sockaddr_iso faddr, laddr = { sizeof(laddr), AF_ISO };
42 struct  sockaddr_iso *siso = &laddr;
43 char **xenvp;
44 
45 long size, count = 10, forkp, confp, echop, mynamep, verbose = 1, playtag = 0;
46 long records, intercept = 0, isode_mode;
47 
48 char buf[2048];
49 char your_it[] = "You're it!";
50 
51 char *Servername;
52 
53 main(argc, argv, envp)
54 int argc;
55 char *argv[];
56 char *envp[];
57 {
58 	tisink();
59 }
60 #define BIG 2048
61 #define MIDLIN 512
62 char readbuf[BIG];
63 struct iovec iov[1] = {
64 	readbuf,
65 	sizeof readbuf,
66 };
67 char name[MIDLIN];
68 union {
69     struct {
70 	    struct cmsghdr	cmhdr;
71 	    char		cmdata[128 - sizeof(struct cmsghdr)];
72     } cm;
73     char data[128];
74 } cbuf;
75 #define control cbuf.data
76 struct msghdr msghdr = {
77 	name, sizeof(name),
78 	iov, sizeof(iov)/sizeof(iov[1]),
79 	control, sizeof control,
80 	0 /* flags */
81 };
82 
83 tisink()
84 {
85 	int x, s, pid, on = 1, loop = 0, n, fromlen, flags = 0;
86 	extern int errno;
87 
88 	try(socket, (AF_ISO, SOCK_DGRAM, ISOPROTO_ESIS),"");
89 	s = x;
90 
91 	for(;;) {
92 		fromlen = sizeof(name);
93 		try(recvfrom, (s, readbuf, sizeof(readbuf), flags,
94 			name, &fromlen), "");
95 		n = x;
96 		dumpit("connection from:", name, fromlen);
97 		dumpit("packet is:", readbuf, n);
98 	}
99 }
100 answerback(flags, n, ns)
101 {
102 	msghdr.msg_controllen = 0;
103 	msghdr.msg_iovlen = 1;
104 	iov->iov_len = n;
105 	n = sendmsg(ns, &msghdr, flags);
106 	dbprintf("echoed %d\n", n);
107 	return n;
108 }
109 
110 dumpit(what, where, n)
111 char *what; unsigned short *where; int n;
112 {
113 	unsigned short *s = where;
114 	unsigned short *z = where + (n+1)/2;
115 	int count = 0;
116 	printf(what);
117 	while(s < z) {
118 		count++;
119 		printf("%x ",*s++);
120 		if ((count & 15) == 0)
121 			putchar('\n');
122 	}
123 	if (count & 15)
124 		putchar('\n');
125 	fflush(stdout);
126 }
127 myexit(n)
128 {
129 	fflush(stderr);
130 	printf("got %d records\n", records);
131 	fflush(stdout);
132 	exit(n);
133 }
134