|
|
1.1 root 1: /*
2: * Copyright (c) 1988, 1990 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution is only permitted until one year after the first shipment
6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
7: * binary forms are permitted provided that: (1) source distributions retain
8: * this entire copyright notice and comment, and (2) distributions including
9: * binaries display the following acknowledgement: This product includes
10: * software developed by the University of California, Berkeley and its
11: * contributors'' in the documentation or other materials provided with the
12: * distribution and in all advertising materials mentioning features or use
13: * of this software. Neither the name of the University nor the names of
14: * its contributors may be used to endorse or promote products derived from
15: * this software without specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: */
20: #ifndef lint
21: static char sccsid[] = "@(#)tisrc.c 7.1 (Berkeley) 6/27/90";
22: #endif /* not lint */
23:
24: /*
25: * This is a test program to be a source for TP4 connections.
26: */
27: #include <sys/types.h>
28: #include <sys/socket.h>
29: #include <sys/uio.h>
30: #include <sys/ioctl.h>
31: #include <net/route.h>
32: #include <net/if.h>
33: #define TCPT_NTIMERS 4
34: #include <netiso/iso.h>
35: #include <netiso/tp_user.h>
36:
37: #include <stdio.h>
38: #include <errno.h>
39: #include <ctype.h>
40: #include <netdb.h>
41:
42:
43: #define dbprintf if(verbose)printf
44: #define try(a,b,c) {x = (a b);dbprintf("%s%s returns %d\n",c,"a",x);\
45: if (x < 0) {perror("a"); exit(1);}}
46:
47: struct iso_addr eon = {20, 0x47, 0, 6, 3, 0, 0, 0, 25 /*EGP for Berkeley*/};
48: struct sockaddr_iso to_s = { sizeof(to_s), AF_ISO }, *to = &to_s;
49: fd_set readfds, writefds, exceptfds;
50: long size, count = 10;
51: int verbose = 1, selectp, type = SOCK_SEQPACKET, nobuffs, errno, playtag = 0;
52: int verify = 0;
53: short portnumber = 3000;
54: char your_it[] = "You're it!";
55: char *port, *conndata, data_msg[2048];
56: struct iovec iov[1] = {data_msg};
57: union {
58: struct {
59: struct cmsghdr cmhdr;
60: char cmdata[128 - sizeof (struct cmsghdr)];
61: } cm;
62: char data[128];
63: } cm;
64: struct msghdr msg = { 0, 0, iov, 1, 0, 0, 0};
65:
66: main(argc, argv)
67: int argc;
68: char *argv[];
69: {
70: register char **av = argv;
71: register char *cp;
72: struct iso_addr iso_addr();
73: u_long len;
74: int handy;
75:
76: while(--argc > 0) {
77: av++;
78: if(strcmp(*av,"Servername")==0) {
79: av++;
80: port = *av;
81: argc--;
82: } else if(strcmp(*av,"conndata")==0) {
83: av++;
84: conndata = *av;
85: argc--;
86: } else if(strcmp(*av,"host")==0) {
87: av++;
88: to_s.siso_addr = iso_addr(*av);
89: argc--;
90: } else if(strcmp(*av,"port")==0) {
91: av++;
92: sscanf(*av,"%hd",&portnumber);
93: argc--;
94: } else if(strcmp(*av,"count")==0) {
95: av++;
96: sscanf(*av,"%ld",&count);
97: argc--;
98: } else if(strcmp(*av,"size")==0) {
99: av++;
100: sscanf(*av,"%ld",&size);
101: iov->iov_len = size;
102: } else if(strcmp(*av,"stream")==0) {
103: type = SOCK_STREAM;
104: } else if (strcmp(*av,"eon") == 0) {
105: unsigned long l, inet_addr();
106:
107: l = inet_addr(*++av); argc--;
108: to_s.siso_addr = eon;
109: bcopy((char *)&l, &to_s.siso_data[15], 4);
110: }
111: }
112: if (port) {
113: to_s.siso_tlen = strlen(port);
114: len = 1 + to_s.siso_nlen + strlen(port)
115: + sizeof(*to) - sizeof(struct iso_addr);
116: if (len > sizeof(*to)) {
117: to = (struct sockaddr_iso *)malloc(len);
118: bzero(to, len);
119: *to = to_s;
120: to->siso_len = len;
121: }
122: bcopy(port, TSEL(to), strlen(port));
123: } else {
124: to_s.siso_tlen = sizeof(portnumber);
125: portnumber = htons(portnumber);
126: bcopy((char *)&portnumber, TSEL(to), sizeof(portnumber));
127: }
128:
129: tisrc();
130: }
131:
132: tisrc() {
133: int x, s, pid, on = 1, flags = 8, n;
134:
135: try(socket, (AF_ISO, type, 0),"");
136: s = x;
137:
138: /*try(setsockopt, (s, SOL_SOCKET, SO_DEBUG, &on, sizeof (on)), "");*/
139:
140: if (conndata) doconndata(s);
141:
142: try(connect, (s, (struct sockaddr *) to, to->siso_len), "");
143:
144: if (selectp) {
145: FD_ZERO(&writefds); FD_SET(s, &writefds);
146: select(1, &writefds, 0, 0, 0);
147: }
148: while (count-- > 0) {
149: if (size <= 0 && get_record(&flags) == EOF)
150: exit(0);
151: n = put_record(s, flags);
152: if (n < iov->iov_len) {
153: if (n==-1 && errno == 55) {
154: nobuffs++;
155: count++;
156: continue;
157: }
158: fprintf(stderr, "wrote %d < %d, count %d,",
159: n, iov->iov_len, count);
160: perror("due to");
161: }
162: }
163: if (playtag) {
164: printf("Tag time!\n");
165: iov->iov_base = your_it;
166: iov->iov_len = sizeof your_it;
167: sendmsg(s, &msg, MSG_EOR);
168: sendmsg(s, &msg, MSG_EOR);
169: iov->iov_base = data_msg;
170: iov->iov_len = sizeof data_msg;
171: try(recvmsg, (s, &msg, flags), " playtag ");
172: }
173: if(nobuffs) {
174: printf("looped %d times waiting for bufs\n", nobuffs);
175: }
176: }
177: int localsize;
178: char dupbuf[4096];
179:
180: put_record(s, flags)
181: int s, flags;
182: {
183: int fd, buflen;
184: char *buf;
185: struct sockaddr *to;
186: int x, saved_x;
187:
188: msg.msg_flags = flags;
189: if (verbose) {
190: unsigned short *zp, *zlim;
191: if (msg.msg_controllen) {
192: zp = (unsigned short *)&(cm.cm.cmhdr.cmsg_len);
193: printf("(CMessage Type is %x) ", cm.cm.cmhdr.cmsg_type);
194: printf("CMsg data: ");
195: x = msg.msg_controllen;
196: zlim = zp + ((x + 1) / 2);
197: while (zp < zlim) printf("%x ", *zp++);
198: putchar ('\n');
199: }
200: if (iov->iov_len) {
201: printf("sending: %s %s",
202: (flags & MSG_OOB ? "(OOB Data)" : ""),
203: (flags & MSG_EOR ? "(Record Mark)" : ""));
204: x = localsize;
205: zp = (unsigned short *)data_msg;
206: zlim = zp + ((x + 1) / 2);
207: while (zp < zlim) printf("%x ", *zp++);
208: putchar ('\n');
209: }
210: }
211: if (verify) {
212: buflen = iov->iov_len;
213: bcopy(iov->iov_base, dupbuf, buflen);
214: }
215: try(sendmsg, (s, &msg, flags), " put_record ");
216: saved_x = x;
217: while (verify && buflen > 0) {
218: iov->iov_len = buflen;
219: iov->iov_base = dupbuf;
220: try(recvmsg, (s, &msg, flags), " put_record ");
221: printf("verify got %d\n", x);
222: buflen -= x;
223: }
224: msg.msg_control = 0;
225: return (saved_x);
226: }
227: int *datasize = &iov->iov_len;
228: char *cp, *cplim;
229:
230: get_control_data(type)
231: {
232:
233: datasize = (int *)&msg.msg_controllen;
234: cp = cm.cm.cmdata;
235: cplim = cp + sizeof(cm.cm.cmdata);
236: cm.cm.cmhdr.cmsg_level = SOL_TRANSPORT;
237: cm.cm.cmhdr.cmsg_type = type;
238: msg.msg_control = cm.data;
239: }
240:
241: doconndata(s)
242: {
243: get_control_data(TPOPT_CONN_DATA);
244: *datasize = strlen(conndata) + sizeof(cm.cm.cmhdr);
245: cm.cm.cmhdr.cmsg_len = *datasize;
246: bcopy(conndata, cp, *datasize);
247: put_record(s, 0);
248: }
249:
250:
251:
252: get_record(flags)
253: int *flags;
254: {
255: int factor = 1, x = 0;
256: char workbuf[10240];
257:
258: *flags = 0;
259: *datasize = 0;
260: datasize = &iov->iov_len;
261: cp = data_msg;
262: cplim = cp + sizeof(data_msg);
263:
264: for(;;) {
265: x = scanf("%s", workbuf);
266: if (x == EOF)
267: break;
268: if (strcmp(workbuf, "disc") == 0)
269: x = get_control_data(TPOPT_DISC_DATA);
270: else if (strcmp(workbuf, "cfrm") == 0)
271: x = get_control_data(TPOPT_CFRM_DATA);
272: else if (strcmp(workbuf, "oob") == 0)
273: *flags |= MSG_OOB;
274: else if (strcmp(workbuf, "eom") == 0)
275: *flags |= MSG_EOR;
276: else if (strcmp(workbuf, "factor") == 0) {
277: x = scanf("%d", &factor);
278: if (factor <= 0) factor = 1;
279: if (x == EOF)
280: break;
281: } else {
282: int len = strlen(workbuf);
283: localsize = 0;
284: while ((factor-- > 0) &&
285: ((cp + len) < cplim)) {
286: strcpy(cp, workbuf);
287: cp += len;
288: localsize += len;
289: }
290: *datasize = localsize;
291: if (datasize != &iov->iov_len) {
292: *datasize += sizeof(cm.cm.cmhdr);
293: cm.cm.cmhdr.cmsg_len = *datasize;
294: }
295: break;
296: }
297: }
298: errno = 0;
299: return (x);
300: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.