xref: /original-bsd/sys/tests/netiso/tpcb.c (revision 2932bec8)
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[] = "@(#)tpcb.c	7.1 (Berkeley) 05/04/92";
16 #endif /* not lint */
17 
18 #include <sys/param.h>
19 #include <sys/mbuf.h>
20 #include <sys/socket.h>
21 #include <sys/socketvar.h>
22 #include <sys/ioctl.h>
23 #include <net/route.h>
24 #include <net/if.h>
25 #define  TCPT_NTIMERS 4
26 #include <netiso/iso.h>
27 #include <netiso/tp_param.h>
28 #include <netiso/tp_user.h>
29 #include <netiso/tp_pcb.h>
30 #include <netiso/tp_events.h>
31 
32 #include <errno.h>
33 #include <netdb.h>
34 #include <nlist.h>
35 #include <kvm.h>
36 #include <paths.h>
37 #include <stdio.h>
38 /*
39  * This is a kernel debugging aid.
40  * dumps out a tp_pcb.
41  */
42 #define mem(e) (((struct tp_pcb *)0)->e)
43 #define Offsetof(e) ((int)&mem(e))
44 #define Sizeof(e) sizeof mem(e)
45 #if defined(__STDC__) || defined(__cplusplus)
46 #define Entry(n, e) { #n , Offsetof(e), Sizeof(e), }
47 #else
48 #define Entry(n, e) { "n" , Offsetof(e), Sizeof(e), }
49 #endif
50 struct tpcb_info {
51 	char	*name;
52 	int	offset;
53 	int	size;
54 } tpcb_info[];
55 
56 int tflag = 0;
57 int Iflag = 0;
58 int Aflag = 0;
59 
60 char *vmunix = _PATH_UNIX;
61 char *kmemf = 0;
62 struct nlist nl[] = {
63 {"_tp_refinfo"},
64 0
65 };
66 struct tp_pcb tp_pcb;
67 
68 #define kget(p, d) \
69 	(kvm_read((void *)(p), &(d), sizeof (d)))
70 main(argc, argv)
71 	int argc;
72 	char **argv;
73 {
74 	int loc, n;
75 	char *end;
76 	argc--; argv++;
77 	if (strcmp("-k", argv[0]) == 0) {
78 		vmunix = argv[1];
79 		kmemf = argv[2];
80 		argc -= 3;
81 		argv += 3;
82 	}
83 	if (kvm_openfiles(vmunix, kmemf, NULL) == -1) {
84 		fprintf(stderr, "tpcb: kvm_openfiles: %s\n", kvm_geterr());
85 		exit(1);
86 	}
87 	if (kvm_nlist(nl) < 0 || nl[0].n_type == 0) {
88 		fprintf(stderr, "%s: no namelist\n", vmunix);
89 		exit(1);
90 	}
91 	if (argc < 1) {
92 		fprintf(stderr, "tpcb: no args");
93 		exit(1);
94 	}
95 	sscanf(argv[0], "%x", &loc);
96 	n = kget(loc, tp_pcb);
97 	parse(--argc, ++argv);
98 }
99 
100 #define kdata(t) (data = *(t *)(ti->offset + (char *)&tp_pcb))
101 
102 printone(ti)
103 register struct tpcb_info  *ti;
104 {
105 	static int column = 0; int data = -1;
106 	switch (ti->size) {
107 	case 1: kdata(u_char); break;
108 	case 2: kdata(u_short); break;
109 	case 4: kdata(u_long); break;
110 	}
111 	column += printf("%s 0x%x, ", ti->name, data);
112 	if (column > 65) {
113 		column = 0;
114 		putchar('\n');
115 	}
116 }
117 
118 parse(argc, argv)
119 	register int argc;
120 	register char **argv;
121 {
122 	register struct tpcb_info *ti;
123 	if (argc > 0) {
124 	    for (; argc-- > 0; argv++)
125 		for (ti = tpcb_info; ti->name; ti++)
126 		    if (strcmp(ti->name, *argv) == 0) {
127 			    printone(ti);
128 			    break;
129 		    }
130 	} else
131 	    for (ti = tpcb_info; ti->name; ti++)
132 		printone(ti);
133 }
134 
135 struct tpcb_info tpcb_info[] = {
136 Entry(next, tp_next),
137 Entry(prev, tp_prev),
138 Entry(nextlisten, tp_nextlisten),
139 Entry(state, tp_state),
140 Entry(retrans, tp_retrans),
141 Entry(npcb, tp_npcb),
142 Entry(nlproto, tp_nlproto),
143 Entry(sock, tp_sock),
144 Entry(lref, tp_lref),
145 Entry(fref, tp_fref),
146 Entry(seqmask, tp_seqmask),
147 Entry(seqbit, tp_seqbit),
148 Entry(seqhalf, tp_seqhalf),
149 Entry(ucddata, tp_ucddata),
150 Entry(fcredit, tp_fcredit),
151 Entry(maxfcredit, tp_maxfcredit),
152 Entry(dupacks, tp_dupacks),
153 Entry(cong_win, tp_cong_win),
154 Entry(ssthresh, tp_ssthresh),
155 Entry(snduna, tp_snduna),
156 Entry(sndnew, tp_sndnew),
157 Entry(sndnum, tp_sndnum),
158 Entry(sndnxt, tp_sndnxt),
159 Entry(sndnxt_m, tp_sndnxt_m),
160 Entry(Nwindow, tp_Nwindow),
161 Entry(rcvnxt, tp_rcvnxt),
162 Entry(sent_lcdt, tp_sent_lcdt),
163 Entry(sent_uwe, tp_sent_uwe),
164 Entry(sent_rcvnxt, tp_sent_rcvnxt),
165 Entry(lcredit, tp_lcredit),
166 Entry(maxlcredit, tp_maxlcredit),
167 Entry(rsyq, tp_rsyq),
168 Entry(rsycnt, tp_rsycnt),
169 Entry(win_recv, tp_win_recv),
170 Entry(l_tpdusize, tp_l_tpdusize),
171 Entry(rtv, tp_rtv),
172 Entry(rtt, tp_rtt),
173 Entry(rttseq, tp_rttseq),
174 Entry(rttemit, tp_rttemit),
175 Entry(idle, tp_idle),
176 Entry(rxtcur, tp_rxtcur),
177 Entry(rxtshift, tp_rxtshift),
178 Entry(domain, tp_domain),
179 Entry(fsuffixlen, tp_fsuffixlen),
180 Entry(fsuffix, tp_fsuffix[0]),
181 Entry(lsuffixlen, tp_lsuffixlen),
182 Entry(lsuffix, tp_lsuffix[0]),
183 { "fport", Offsetof(tp_fsuffix[0]), sizeof(short), },
184 { "lport", Offsetof(tp_lsuffix[0]), sizeof(short), },
185 Entry(vers, tp_vers),
186 Entry(peer_acktime, tp_peer_acktime),
187 Entry(refstate, tp_refstate),
188 Entry(fasttimeo, tp_fasttimeo),
189 Entry(inact, tp_timer[TM_inact]),
190 Entry(retrans, tp_timer[TM_retrans]),
191 Entry(sendack, tp_timer[TM_sendack]),
192 Entry(data_retrans, tp_timer[TM_data_retrans]),
193 Entry(reference, tp_timer[TM_reference]),
194 Entry(Xsnd, tp_Xsnd),
195 Entry(Xsndnxt, tp_Xsndnxt),
196 Entry(Xuna, tp_Xuna),
197 Entry(Xrcvnxt, tp_Xrcvnxt),
198 Entry(s_subseq, tp_s_subseq),
199 Entry(r_subseq, tp_r_subseq),
200 Entry(dt_ticks, tp_dt_ticks),
201 Entry(inact_ticks, tp_inact_ticks),
202 Entry(keepalive_ticks, tp_keepalive_ticks),
203 Entry(cr_ticks, tp_cr_ticks),
204 Entry(xpd_ticks, tp_xpd_ticks),
205 0};
206