Sysmap = (struct pte *) malloc((u_int)(nl[N_SYSSIZE].n_value * sizeof(struct pte))); if (!Sysmap) { fputs("trpt: can't get memory for Sysmap.\n", stderr); exit(1); } off = nl[N_SYSMAP].n_value & ~KERNBASE; (void)lseek(memf, off, L_SET); (void)read(memf, (char *)Sysmap, (int)(nl[N_SYSSIZE].n_value * sizeof(struct pte))); #endif } (void)klseek(memf, (off_t)nl[N_TCP_DEBX].n_value, L_SET); if (read(memf, (char *)&tcp_debx, sizeof(tcp_debx)) != sizeof(tcp_debx)) { perror("trpt: tcp_debx"); exit(3); } (void)klseek(memf, (off_t)nl[N_TCP_DEBUG].n_value, L_SET); if (read(memf, (char *)tcp_debug, sizeof(tcp_debug)) != sizeof(tcp_debug)) { perror("trpt: tcp_debug"); exit(3); }
if (kvm_nlist(kd, nl)) errx(2, "%s: no namelist", system ? system : _PATH_UNIX);  if (kvm_read(kd, nl[N_TCP_DEBX].n_value, (char *)&tcp_debx, sizeof(tcp_debx)) != sizeof(tcp_debx)) errx(3, "tcp_debx: %s", kvm_geterr(kd));  if (kvm_read(kd, nl[N_TCP_DEBUG].n_value, (char *)tcp_debug, sizeof(tcp_debug)) != sizeof(tcp_debug)) errx(3, "tcp_debug: %s", kvm_geterr(kd));
main(argc, argv)	int argc;	char **argv;{	extern char *optarg;	extern int optind;	int ch, i, jflag, npcbs, numeric();	char *system, *core, *malloc();	off_t lseek();	jflag = npcbs = 0;	while ((ch = getopt(argc, argv, "afjp:st")) != -1)		switch (ch) {		case 'a':			++aflag;			break;		case 'f':			++follow;			setlinebuf(stdout);			break;		case 'j':			++jflag;			break;		case 'p':			if (npcbs >= TCP_NDEBUG) {				fputs("trpt: too many pcb's specified\n",				    stderr);				exit(1);			}			(void)sscanf(optarg, "%x", (int *)&tcp_pcbs[npcbs++]);			break;		case 's':			++sflag;			break;		case 't':			++tflag;			break;		case '?':		default:			(void)fprintf(stderr,"usage: trpt [-afjst] [-p hex-address] [system [core]]\n");			exit(1);		}	argc -= optind;	argv += optind;	core = _PATH_KMEM;	if (argc > 0) {		system = *argv;		argc--, argv++;		if (argc > 0) {			core = *argv;			argc--, argv++;			++kflag;		}	}	else		system = _PATH_UNIX;	/*	 * Discard setgid priviledges if not the running kernel so that bad	 * guys can't print interesting stuff from kernel memory.	 */	if (!strcmp(core, _PATH_KMEM) || !strcmp(system, _PATH_UNIX)) {		setegid(getgid());		setgid(getgid());	}	if (nlist(system, nl) < 0 || !nl[0].n_value) {		fprintf(stderr, "trpt: %s: no namelist\n", system);		exit(1);	}	if ((memf = open(core, O_RDONLY)) < 0) {		perror(core);		exit(2);	}	if (kflag) {#ifdef NEWVM		fputs("trpt: can't do core files yet\n", stderr);		exit(1);#else		off_t off;		Sysmap = (struct pte *)		   malloc((u_int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));		if (!Sysmap) {			fputs("trpt: can't get memory for Sysmap.\n", stderr);			exit(1);		}		off = nl[N_SYSMAP].n_value & ~KERNBASE;		(void)lseek(memf, off, L_SET);		(void)read(memf, (char *)Sysmap,		    (int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));#endif	}	(void)klseek(memf, (off_t)nl[N_TCP_DEBX].n_value, L_SET);	if (read(memf, (char *)&tcp_debx, sizeof(tcp_debx)) !=	    sizeof(tcp_debx)) {		perror("trpt: tcp_debx");		exit(3);	}	(void)klseek(memf, (off_t)nl[N_TCP_DEBUG].n_value, L_SET);	if (read(memf, (char *)tcp_debug, sizeof(tcp_debug)) !=	    sizeof(tcp_debug)) {		perror("trpt: tcp_debug");		exit(3);	}	/*	 * If no control blocks have been specified, figure	 * out how many distinct one we have and summarize	 * them in tcp_pcbs for sorting the trace records	 * below.	 */	if (!npcbs) {		for (i = 0; i < TCP_NDEBUG; i++) {			register struct tcp_debug *td = &tcp_debug[i];			register int j;			if (td->td_tcb == 0)				continue;			for (j = 0; j < npcbs; j++)				if (tcp_pcbs[j] == td->td_tcb)					break;			if (j >= npcbs)				tcp_pcbs[npcbs++] = td->td_tcb;		}		if (!npcbs)			exit(0);	}	qsort(tcp_pcbs, npcbs, sizeof(caddr_t), numeric);	if (jflag) {		for (i = 0;;) {			printf("%lx", (long)tcp_pcbs[i]);			if (++i == npcbs)				break;			fputs(", ", stdout);		}		putchar('\n');	}	else for (i = 0; i < npcbs; i++) {		printf("\n%lx:\n", (long)tcp_pcbs[i]);		dotrace(tcp_pcbs[i]);	}	exit(0);}