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