Beispiel #1
0
static void
p_tree(struct radix_node *rn)
{

again:
	kread((u_long)rn, &rnode, sizeof(rnode));
	if (rnode.rn_b < 0) {
		if (Aflag)
			printf("%-16p ", hideroot ? 0 : rn);
		if (rnode.rn_flags & RNF_ROOT) {
			if (Aflag)
				printf("(root node)%s",
				    rnode.rn_dupedkey ? " =>\n" : "\n");
		} else if (do_rtent) {
			kread((u_long)rn, &rtentry, sizeof(rtentry));
			p_krtentry(&rtentry);
			if (Aflag)
				p_rtnode();
		} else {
			p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key),
			    0, 0, 44);
			putchar('\n');
		}
		if ((rn = rnode.rn_dupedkey))
			goto again;
	} else {
		if (Aflag && do_rtent) {
			printf("%-16p ", hideroot ? 0 : rn);
			p_rtnode();
		}
		rn = rnode.rn_r;
		p_tree(rnode.rn_l);
		p_tree(rn);
	}
}
Beispiel #2
0
/*
 * Dump the contents of a domain structure
 */
void
domain_dump(u_long off, u_long pcb, short protocol)
{
	struct domain dom;
	char name[256];

	if (off == 0)
		return;
	kread(off, &dom, sizeof(dom));
	kread((u_long)dom.dom_name, name, sizeof(name));

#define	p(fmt, v, sep) printf(#v " " fmt sep, dom.v);
	printf("domain %#lx\n ", hideroot ? 0 : off);
	p("%d", dom_family, "\n ");
	printf("dom_name %.*s\n", (int)sizeof(name), name);
#undef	p

	switch (dom.dom_family) {
	case AF_INET:
	case AF_INET6:
		inpcb_dump(pcb, protocol, dom.dom_family);
		break;
	case AF_UNIX:
		unpcb_dump(pcb);
		break;
	}
}
static void
unixdomainpr(struct socket *so, void *soaddr)
{
	struct unpcb unp, runp;
	struct sockaddr_un sun, rsun;
	static int first = 1;
	int remote = 0;

	if (kread((u_long)so->so_pcb, (char *)&unp, sizeof (unp)))
		return;
	if (unp.unp_addr)
		if (kread((u_long)unp.unp_addr, (char *)&sun, sizeof (sun)))
			unp.unp_addr = 0;

	if (!unp.unp_addr) {
		memset(&rsun, 0, sizeof(rsun));
		if (unp.unp_conn &&
		    kread((u_long)unp.unp_conn, (char *)&runp, sizeof (runp)) == 0 &&
		    runp.unp_addr &&
		    kread((u_long)runp.unp_addr, (char *)&rsun, sizeof (rsun)) == 0 &&
		    rsun.sun_path[0] != '\0')
			remote = 1;
	}

	if (first) {
		unixdomainprhdr();
		first = 0;
	}

	unixdomainpr0((u_long)so->so_pcb, so->so_type, so->so_rcv.sb_cc,
		      so->so_snd.sb_cc, (u_long)unp.unp_vnode,
		      (u_long)unp.unp_conn, (u_long)unp.unp_refs,
		      (u_long)unp.unp_nextref, (u_long)unp.unp_addr,
		      remote ? &rsun : &sun, remote);
}
Beispiel #4
0
void
mrt6_stats(u_long mrpaddr, u_long mstaddr)
{
	struct mrt6stat mrtstat;
	u_int mrtproto;

	if (mrpaddr == 0) {
		printf("mrt6_stats: symbol not in namelist\n");
		return;
	}

	kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
	switch (mrtproto) {
	case 0:
		 printf("no IPv6 multicast routing compiled into this system\n");
		 return;

	case IPPROTO_PIM:
		 break;

	default:
		printf("IPv6 multicast routing protocol %u, unknown\n",
		    mrtproto);
		return;
	}

	if (mstaddr == 0) {
		printf("mrt6_stats: symbol not in namelist\n");
		return;
	}

	kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
	printf("multicast forwarding:\n");
	printf(" %10qu multicast forwarding cache lookup%s\n",
	    mrtstat.mrt6s_mfc_lookups, plural(mrtstat.mrt6s_mfc_lookups));
	printf(" %10qu multicast forwarding cache miss%s\n",
	    mrtstat.mrt6s_mfc_misses, plurales(mrtstat.mrt6s_mfc_misses));
	printf(" %10qu upcall%s to mrouted\n",
	    mrtstat.mrt6s_upcalls, plural(mrtstat.mrt6s_upcalls));
	printf(" %10qu upcall queue overflow%s\n",
	    mrtstat.mrt6s_upq_ovflw, plural(mrtstat.mrt6s_upq_ovflw));
	printf(" %10qu upcall%s dropped due to full socket buffer\n",
	    mrtstat.mrt6s_upq_sockfull, plural(mrtstat.mrt6s_upq_sockfull));
	printf(" %10qu cache cleanup%s\n",
	    mrtstat.mrt6s_cache_cleanups, plural(mrtstat.mrt6s_cache_cleanups));
	printf(" %10qu datagram%s with no route for origin\n",
	    mrtstat.mrt6s_no_route, plural(mrtstat.mrt6s_no_route));
	printf(" %10qu datagram%s arrived with bad tunneling\n",
	    mrtstat.mrt6s_bad_tunnel, plural(mrtstat.mrt6s_bad_tunnel));
	printf(" %10qu datagram%s could not be tunneled\n",
	    mrtstat.mrt6s_cant_tunnel, plural(mrtstat.mrt6s_cant_tunnel));
	printf(" %10qu datagram%s arrived on wrong interface\n",
	    mrtstat.mrt6s_wrong_if, plural(mrtstat.mrt6s_wrong_if));
	printf(" %10qu datagram%s selectively dropped\n",
	    mrtstat.mrt6s_drop_sel, plural(mrtstat.mrt6s_drop_sel));
	printf(" %10qu datagram%s dropped due to queue overflow\n",
	    mrtstat.mrt6s_q_overflow, plural(mrtstat.mrt6s_q_overflow));
	printf(" %10qu datagram%s dropped for being too large\n",
	    mrtstat.mrt6s_pkt2large, plural(mrtstat.mrt6s_pkt2large));
}
Beispiel #5
0
/*
= RTS_AddFile
=
= All files are optional, but at least one file must be found
= Files with a .rts extension are wadlink files with multiple lumps
= Other files are single lumps with the base filename for the lump name
*/
static int32_t RTS_AddFile(const char *filename)
{
    wadinfo_t  header;
    int32_t i, handle, length, startlump;
    filelump_t *fileinfo, *fileinfoo;

    // read the entire file in
    //      FIXME: shared opens

    handle = kopen4loadfrommod(filename, 0);
    if (handle < 0)
    {
        initprintf("RTS file \"%s\" was not found\n",filename);
        return -1;
    }

    startlump = rts_numlumps;

    // WAD file
    i = kread(handle, &header, sizeof(header));
    if (i != sizeof(header) || Bmemcmp(header.identification, "IWAD", 4))
    {
        initprintf("RTS file \"%s\" too short or doesn't have IWAD id\n", filename);
        kclose(handle);
        return -1;
    }

    header.numlumps = B_LITTLE32(header.numlumps);
    header.infotableofs = B_LITTLE32(header.infotableofs);

    length = header.numlumps*sizeof(filelump_t);
    fileinfo = fileinfoo = (filelump_t *)Xmalloc(length);

    klseek(handle, header.infotableofs, SEEK_SET);
    kread(handle, fileinfo, length);

    {
        lumpinfo_t *lump_p = (lumpinfo_t *)Xrealloc(
            rts_lumpinfo, (rts_numlumps + header.numlumps)*sizeof(lumpinfo_t));

        rts_lumpinfo = lump_p;
    }

    rts_numlumps += header.numlumps;

    for (i=startlump; i<rts_numlumps; i++, fileinfo++)
    {
        lumpinfo_t *lump = &rts_lumpinfo[i];

        lump->handle = handle;  // NOTE: cache1d-file is not closed!
        lump->position = B_LITTLE32(fileinfo->filepos);
        lump->size = B_LITTLE32(fileinfo->size);

        Bstrncpy(lump->name, fileinfo->name, 8);
    }

    Bfree(fileinfoo);

    return 0;
}
Beispiel #6
0
int
sotoxsocket(struct socket *so, struct xsocket *xso)
{
	struct protosw proto;
	struct domain domain;

	bzero(xso, sizeof *xso);
	xso->xso_len = sizeof *xso;
	xso->xso_so = so;
	xso->so_type = so->so_type;
	xso->so_options = so->so_options;
	xso->so_linger = so->so_linger;
	xso->so_state = so->so_state;
	xso->so_pcb = so->so_pcb;
	if (kread((uintptr_t)so->so_proto, &proto, sizeof(proto)) != 0)
		return (-1);
	xso->xso_protocol = proto.pr_protocol;
	if (kread((uintptr_t)proto.pr_domain, &domain, sizeof(domain)) != 0)
		return (-1);
	xso->xso_family = domain.dom_family;
	xso->so_timeo = so->so_timeo;
	xso->so_error = so->so_error;
	if (SOLISTENING(so)) {
		xso->so_qlen = so->sol_qlen;
		xso->so_incqlen = so->sol_incqlen;
		xso->so_qlimit = so->sol_qlimit;
	} else {
		sbtoxsockbuf(&so->so_snd, &xso->so_snd);
		sbtoxsockbuf(&so->so_rcv, &xso->so_rcv);
		xso->so_oobmark = so->so_oobmark;
	}
	return (0);
}
Beispiel #7
0
long
_syspread(int fd, void *buf, long n, vlong off)
{
	if(off == ((uvlong) ~0))
		return kread(fd, buf, n, nil);
	return kread(fd, buf, n, &off);
}
Beispiel #8
0
static void
rfcommpr(kvm_t *kvmd, u_long addr)
{
	static char const * const	states[] = {
	/* NG_BTSOCKET_RFCOMM_DLC_CLOSED */	   "CLOSED",
	/* NG_BTSOCKET_RFCOMM_DLC_W4_CONNECT */	   "W4CON",
	/* NG_BTSOCKET_RFCOMM_DLC_CONFIGURING */   "CONFIG",
	/* NG_BTSOCKET_RFCOMM_DLC_CONNECTING */    "CONN",
	/* NG_BTSOCKET_RFCOMM_DLC_CONNECTED */     "OPEN",
	/* NG_BTSOCKET_RFCOMM_DLC_DISCONNECTING */ "DISCON"
	};

	ng_btsocket_rfcomm_pcb_p	this = NULL, next = NULL;
	ng_btsocket_rfcomm_pcb_t	pcb;
	struct socket			so;
	int				first = 1;
	char				local[24], remote[24];

	if (addr == 0)
		return;

        if (kread(kvmd, addr, (char *) &this, sizeof(this)) < 0)
		return;

	for ( ; this != NULL; this = next) {
		if (kread(kvmd, (u_long) this, (char *) &pcb, sizeof(pcb)) < 0)
			return;
		if (kread(kvmd, (u_long) pcb.so, (char *) &so, sizeof(so)) < 0)
			return;

		next = LIST_NEXT(&pcb, next);

		if (first) {
			first = 0;
			fprintf(stdout,
"Active RFCOMM sockets\n" \
"%-8.8s %-6.6s %-6.6s %-17.17s %-17.17s %-4.4s %-4.4s %s\n",
				"PCB",
				"Recv-Q",
				"Send-Q",
				"Local address",
				"Foreign address",
				"Chan",
				"DLCI",
				"State");
		}

		fprintf(stdout,
"%-8lx %6d %6d %-17.17s %-17.17s %-4d %-4d %s\n",
			(unsigned long) this,
			so.so_rcv.sb_ccc,
			so.so_snd.sb_ccc,
			bdaddrpr(&pcb.src, local, sizeof(local)),
			bdaddrpr(&pcb.dst, remote, sizeof(remote)),
			pcb.channel,
			pcb.dlci,
			(so.so_options & SO_ACCEPTCONN)?
				"LISTEN" : state2str(pcb.state));
	}
} /* rfcommpr */
Beispiel #9
0
static void
l2cappr(kvm_t *kvmd, u_long addr)
{
	static char const * const	states[] = {
	/* NG_BTSOCKET_L2CAP_CLOSED */		"CLOSED",
	/* NG_BTSOCKET_L2CAP_CONNECTING */	"CON",
	/* NG_BTSOCKET_L2CAP_CONFIGURING */	"CONFIG",
	/* NG_BTSOCKET_L2CAP_OPEN */		"OPEN",
	/* NG_BTSOCKET_L2CAP_DISCONNECTING */	"DISCON"
	};

	ng_btsocket_l2cap_pcb_p	this = NULL, next = NULL;
	ng_btsocket_l2cap_pcb_t	pcb;
	struct socket		so;
	int			first = 1;
	char			local[24], remote[24];

	if (addr == 0)
		return;

        if (kread(kvmd, addr, (char *) &this, sizeof(this)) < 0)
		return;

	for ( ; this != NULL; this = next) {
		if (kread(kvmd, (u_long) this, (char *) &pcb, sizeof(pcb)) < 0)
			return;
		if (kread(kvmd, (u_long) pcb.so, (char *) &so, sizeof(so)) < 0)
			return;

		next = LIST_NEXT(&pcb, next);

		if (first) {
			first = 0;
			fprintf(stdout,
"Active L2CAP sockets\n" \
"%-8.8s %-6.6s %-6.6s %-23.23s %-17.17s %-5.5s %s\n",
				"PCB",
				"Recv-Q",
				"Send-Q",
				"Local address/PSM",
				"Foreign address",
				"CID",
				"State");
		}

		fprintf(stdout,
"%-8lx %6d %6d %-17.17s/%-5d %-17.17s %-5d %s\n",
			(unsigned long) this,
			so.so_rcv.sb_ccc,
			so.so_snd.sb_ccc,
			bdaddrpr(&pcb.src, local, sizeof(local)),
			pcb.psm,
			bdaddrpr(&pcb.dst, remote, sizeof(remote)),
			pcb.cid,
			(so.so_options & SO_ACCEPTCONN)?
				"LISTEN" : state2str(pcb.state));
	}
} /* l2cappr */
Beispiel #10
0
static struct sockaddr *
kgetsa(struct sockaddr *dst)
{

	kread((u_long)dst, &pt_u.u_sa, sizeof(pt_u.u_sa));
	if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa))
		kread((u_long)dst, pt_u.u_data, pt_u.u_sa.sa_len);
	return (&pt_u.u_sa);
}
Beispiel #11
0
void
dommap(struct proc *p)
{
    struct vmspace vmspace;
    vm_map_t map;
    struct vm_map_entry entry;
    vm_map_entry_t entryp;
    struct vm_object object;
    vm_object_t objp;
    int prot, fflags;

    if (!kread(p->p_vmspace, &vmspace, sizeof(vmspace))) {
        dprintf(stderr, "can't read vmspace at %p for pid %d\n",
                (void *)p->p_vmspace, Pid);
        return;
    }

    map = &vmspace.vm_map;

    for (entryp = map->header.next; entryp != &p->p_vmspace->vm_map.header;
            entryp = entry.next) {
        if (!kread(entryp, &entry, sizeof(entry))) {
            dprintf(stderr,
                    "can't read vm_map_entry at %p for pid %d\n",
                    (void *)entryp, Pid);
            return;
        }

        if (entry.maptype == VM_MAPTYPE_SUBMAP)
            continue;

        if ((objp = entry.object.vm_object) == NULL)
            continue;

        for (; objp; objp = object.backing_object) {
            if (!kread(objp, &object, sizeof(object))) {
                dprintf(stderr,
                        "can't read vm_object at %p for pid %d\n",
                        (void *)objp, Pid);
                return;
            }
        }

        prot = entry.protection;
        fflags = (prot & VM_PROT_READ ? FREAD : 0) |
                 (prot & VM_PROT_WRITE ? FWRITE : 0);

        switch (object.type) {
        case OBJT_VNODE:
            vtrans((struct vnode *)object.handle, NULL,
                   MMAP, fflags, 0);
            break;
        default:
            break;
        }
    }
}
Beispiel #12
0
static int read_and_check(KFILE *in, unsigned int count, unsigned int max_chunk,
		int begin_i, int end_i, char *begin_s, char *end_s,
		unsigned short begin_u, unsigned short end_u)
{
	unsigned int i = 0, j;
	unsigned int cur_chunk = 1;
	struct test_data expected = {
		.i = begin_i,
		.s = begin_s,
		.u = begin_u
	};
	struct test_data d[max_chunk];
	while (i < count)
	{
		unsigned int read = kread(d, sizeof(d[0]), cur_chunk, in);
		if (read < cur_chunk && i + read != count)
			goto exit_bad_read;
		for (j = 0; j < cur_chunk; ++j)
		{
			if (d[j].i != expected.i || d[j].s != expected.s || d[j].u != expected.u)
				goto exit_mismatch;

			if (expected.i == end_i)
				expected.i = begin_i;
			else
				++expected.i;
			if (expected.s == end_s)
				expected.s = begin_s;
			else
				++expected.s;
			if (expected.u == end_u)
				expected.u = begin_u;
			else
				++expected.u;
		}

		i += cur_chunk;
		if (cur_chunk == max_chunk)
			cur_chunk = 1;
		else
			++cur_chunk;
	}
	if (kread(d, 1, 1, in) > 0)
		goto exit_bad_eokf;
	return 0;
exit_bad_read:
	printk(KERN_INFO "failed to read all data (at %uth data)\n", i);
	goto exit_fail;
exit_mismatch:
	printk(KERN_INFO "failed to match with what was expected (at %uth data)\n", i);
	goto exit_fail;
exit_bad_eokf:
	printk(KERN_INFO "failed to detect eokf after all data are finished\n");
	goto exit_fail;
exit_fail:
	return -1;
}
Beispiel #13
0
static void
dointr(void)
{
	unsigned long *intrcnt, uptime;
	uint64_t inttotal;
	size_t clen, inamlen, intrcntlen, istrnamlen;
	unsigned int i, nintr;
	char *intrname, *tintrname;

	uptime = getuptime();
	if (kd != NULL) {
		kread(X_SINTRCNT, &intrcntlen, sizeof(intrcntlen));
		kread(X_SINTRNAMES, &inamlen, sizeof(inamlen));
		if ((intrcnt = malloc(intrcntlen)) == NULL ||
		    (intrname = malloc(inamlen)) == NULL)
			err(1, "malloc()");
		kread(X_INTRCNT, intrcnt, intrcntlen);
		kread(X_INTRNAMES, intrname, inamlen);
	} else {
		for (intrcnt = NULL, intrcntlen = 1024; ; intrcntlen *= 2) {
			if ((intrcnt = reallocf(intrcnt, intrcntlen)) == NULL)
				err(1, "reallocf()");
			if (mysysctl("hw.intrcnt",
			    intrcnt, &intrcntlen, NULL, 0) == 0)
				break;
		}
		for (intrname = NULL, inamlen = 1024; ; inamlen *= 2) {
			if ((intrname = reallocf(intrname, inamlen)) == NULL)
				err(1, "reallocf()");
			if (mysysctl("hw.intrnames",
			    intrname, &inamlen, NULL, 0) == 0)
				break;
		}
	}
	nintr = intrcntlen / sizeof(unsigned long);
	tintrname = intrname;
	istrnamlen = strlen("interrupt");
	for (i = 0; i < nintr; i++) {
		clen = strlen(tintrname);
		if (clen > istrnamlen)
			istrnamlen = clen;
		tintrname += clen + 1;
	}
	(void)printf("%-*s %20s %10s\n", (int)istrnamlen, "interrupt", "total",
	    "rate");
	inttotal = 0;
	for (i = 0; i < nintr; i++) {
		if (intrname[0] != '\0' && (*intrcnt != 0 || aflag))
			(void)printf("%-*s %20lu %10lu\n", (int)istrnamlen,
			    intrname, *intrcnt, *intrcnt / uptime);
		intrname += strlen(intrname) + 1;
		inttotal += *intrcnt++;
	}
	(void)printf("%-*s %20" PRIu64 " %10" PRIu64 "\n", (int)istrnamlen,
	    "Total", inttotal, inttotal / uptime);
}
Beispiel #14
0
static void
rfcommpr_s(kvm_t *kvmd, u_long addr)
{
	static char const * const	states[] = {
	/* NG_BTSOCKET_RFCOMM_SESSION_CLOSED */	       "CLOSED",
	/* NG_BTSOCKET_RFCOMM_SESSION_LISTENING */     "LISTEN",
	/* NG_BTSOCKET_RFCOMM_SESSION_CONNECTING */    "CONNECTING",
	/* NG_BTSOCKET_RFCOMM_SESSION_CONNECTED */     "CONNECTED",
	/* NG_BTSOCKET_RFCOMM_SESSION_OPEN */          "OPEN",
	/* NG_BTSOCKET_RFCOMM_SESSION_DISCONNECTING */ "DISCONNECTING"
	};

	ng_btsocket_rfcomm_session_p	this = NULL, next = NULL;
	ng_btsocket_rfcomm_session_t	s;
	struct socket			so;
	int				first = 1;

	if (addr == 0)
		return;

        if (kread(kvmd, addr, (char *) &this, sizeof(this)) < 0)
		return;

	for ( ; this != NULL; this = next) {
		if (kread(kvmd, (u_long) this, (char *) &s, sizeof(s)) < 0)
			return;
		if (kread(kvmd, (u_long) s.l2so, (char *) &so, sizeof(so)) < 0)
			return;

		next = LIST_NEXT(&s, next);

		if (first) {
			first = 0;
			fprintf(stdout,
"Active RFCOMM sessions\n" \
"%-8.8s %-8.8s %-4.4s %-5.5s %-5.5s %-4.4s %s\n",
				"L2PCB",
				"PCB",
				"Flags",
				"MTU",
				"Out-Q",
				"DLCs",
				"State");
		}

		fprintf(stdout,
"%-8lx %-8lx %-4x %-5d %-5d %-4s %s\n",
			(unsigned long) so.so_pcb,
			(unsigned long) this,
			s.flags,
			s.mtu,
			s.outq.len,
			LIST_EMPTY(&s.dlcs)? "No" : "Yes",
			state2str(s.state));
	}
} /* rfcommpr_s */
Beispiel #15
0
static void
p_rtnode(void)
{
	struct radix_mask *rm = rnode.rn_mklist;

	if (rnode.rn_b < 0) {
		snprintf(nbuf, sizeof nbuf, " => %p",
		    hideroot ? 0 : rnode.rn_dupedkey);
		printf("\t  (%p)%s", hideroot ? 0 : rnode.rn_p,
		    rnode.rn_dupedkey ? nbuf : "");
		if (rnode.rn_mask) {
			printf(" mask ");
			p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_mask),
			    0, 0, -1);
		} else if (rm == NULL) {
			putchar('\n');
			return;
		}
	} else {
		snprintf(nbuf, sizeof nbuf, "(%d)", rnode.rn_b);
		printf("%6.6s (%p) %16p : %16p", nbuf,
		    hideroot ? 0 : rnode.rn_p,
		    hideroot ? 0 : rnode.rn_l,
		    hideroot ? 0 : rnode.rn_r);
	}

	putchar(' ');
	p_rtflags(rnode.rn_flags);

	while (rm) {
		kread((u_long)rm, &rmask, sizeof(rmask));
		snprintf(nbuf, sizeof nbuf, " %d refs, ", rmask.rm_refs);
		printf("\n\tmk = %p {(%d),%s",
		    hideroot ? 0 : rm,
		    -1 - rmask.rm_b, rmask.rm_refs ? nbuf : " ");
		p_rtflags(rmask.rm_flags);
		printf(", ");
		if (rmask.rm_flags & RNF_NORMAL) {
			struct radix_node rnode_aux;

			printf("leaf = %p ", hideroot ? 0 : rmask.rm_leaf);
			kread((u_long)rmask.rm_leaf, &rnode_aux, sizeof(rnode_aux));
			p_sockaddr(kgetsa((struct sockaddr *)rnode_aux.rn_mask),
			    0, 0, -1);
		} else
			p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask),
			    0, 0, -1);
		putchar('}');
		if ((rm = rmask.rm_mklist))
			printf(" ->");
	}
	putchar('\n');
}
Beispiel #16
0
static int conn_read (void)
{
  struct inpcbtable table;
  struct inpcb *head;
  struct inpcb *next;
  struct inpcb inpcb;
  struct tcpcb tcpcb;
  int status;

  conn_reset_port_entry ();

  /* Read the pcbtable from the kernel */
  status = kread (inpcbtable_off, &table, sizeof (table));
  if (status != 0)
    return (-1);

  /* Get the `head' pcb */
  head = (struct inpcb *) &(inpcbtable_ptr->inpt_queue);
  /* Get the first pcb */
  next = (struct inpcb *)CIRCLEQ_FIRST (&table.inpt_queue);

  while (next != head)
  {
    /* Read the pcb pointed to by `next' into `inpcb' */
    kread ((u_long) next, &inpcb, sizeof (inpcb));

    /* Advance `next' */
    next = (struct inpcb *)CIRCLEQ_NEXT (&inpcb, inp_queue);

    /* Ignore sockets, that are not connected. */
#ifdef __NetBSD__
    if (inpcb.inp_af == AF_INET6)
      continue; /* XXX see netbsd/src/usr.bin/netstat/inet6.c */
#else
    if (!(inpcb.inp_flags & INP_IPV6)
	&& (inet_lnaof(inpcb.inp_laddr) == INADDR_ANY))
      continue;
    if ((inpcb.inp_flags & INP_IPV6)
	&& IN6_IS_ADDR_UNSPECIFIED (&inpcb.inp_laddr6))
      continue;
#endif

    kread ((u_long) inpcb.inp_ppcb, &tcpcb, sizeof (tcpcb));
    conn_handle_ports (ntohs(inpcb.inp_lport), ntohs(inpcb.inp_fport), tcpcb.t_state);
  } /* while (next != head) */

  conn_submit_all ();

  return (0);
}
Beispiel #17
0
/*
 * Print routing tables.
 */
void
routepr(u_long rtree, u_long mtree, u_long af2idx, u_long rtbl_id_max,
    u_int tableid)
{
	struct radix_node_head *rnh, head;
	int i, idxmax = 0;
	u_int rtidxmax;

	printf("Routing tables\n");

	if (rtree == 0 || af2idx == 0) {
		printf("rt_tables: symbol not in namelist\n");
		return;
	}

	kread((u_long)rtree, &rt_head, sizeof(rt_head));
	kread((u_long)rtbl_id_max, &rtidxmax, sizeof(rtidxmax));
	kread((long)af2idx, &af2rtafidx, sizeof(af2rtafidx));

	for (i = 0; i <= AF_MAX; i++) {
		if (af2rtafidx[i] > idxmax)
			idxmax = af2rtafidx[i];
	}

	if ((rnt = calloc(rtidxmax + 1, sizeof(struct radix_node_head **))) ==
	    NULL)
		err(1, NULL);

	kread((u_long)rt_head, rnt, (rtidxmax + 1) *
	    sizeof(struct radix_node_head **));
	if (tableid > rtidxmax || rnt[tableid] == NULL) {
		printf("Bad table %u\n", tableid);
		return;
	}
	kread((u_long)rnt[tableid], rt_tables, (idxmax + 1) * sizeof(rnh));

	for (i = 0; i <= AF_MAX; i++) {
		if (i == AF_UNSPEC) {
			if (Aflag && (af == AF_UNSPEC || af == 0xff)) {
				kread(mtree, &rnh, sizeof(rnh));
				kread((u_long)rnh, &head, sizeof(head));
				printf("Netmasks:\n");
				p_tree(head.rnh_treetop);
			}
			continue;
		}
		if (af2rtafidx[i] == 0)
			/* no table for this AF */
			continue;
		if ((rnh = rt_tables[af2rtafidx[i]]) == NULL)
			continue;
		kread((u_long)rnh, &head, sizeof(head));
		if (af == AF_UNSPEC || af == i) {
			pr_family(i);
			do_rtent = 1;
			pr_rthdr(i, Aflag);
			p_tree(head.rnh_treetop);
		}
	}
}
Beispiel #18
0
static void
hcirawpr(kvm_t *kvmd, u_long addr)
{
	ng_btsocket_hci_raw_pcb_p	this = NULL, next = NULL;
	ng_btsocket_hci_raw_pcb_t	pcb;
	struct socket			so;
	int				first = 1;

	if (addr == 0)
		return;

        if (kread(kvmd, addr, (char *) &this, sizeof(this)) < 0)
		return;

	for ( ; this != NULL; this = next) {
		if (kread(kvmd, (u_long) this, (char *) &pcb, sizeof(pcb)) < 0)
			return;
		if (kread(kvmd, (u_long) pcb.so, (char *) &so, sizeof(so)) < 0)
			return;

		next = LIST_NEXT(&pcb, next);

		if (first) {
			first = 0;
			fprintf(stdout,
"Active raw HCI sockets\n" \
"%-8.8s %-8.8s %-6.6s %-6.6s %-6.6s %-16.16s\n",
				"Socket",
				"PCB",
				"Flags",
				"Recv-Q",
				"Send-Q",
				"Local address");
		}

		if (pcb.addr.hci_node[0] == 0) {
			pcb.addr.hci_node[0] = '*';
			pcb.addr.hci_node[1] = 0;
		}

		fprintf(stdout,
"%-8lx %-8lx %-6.6x %6d %6d %-16.16s\n",
			(unsigned long) pcb.so,
			(unsigned long) this,
			pcb.flags,
			so.so_rcv.sb_ccc,
			so.so_snd.sb_ccc,
			pcb.addr.hci_node);
	}
} /* hcirawpr */
Beispiel #19
0
void
domem()
{
    register struct kmembuckets *kp;
    register struct kmemstats *ks;
    register int i;
    int size;
    long totuse = 0, totfree = 0, totreq = 0;
    struct kmemstats kmemstats[M_LAST];
    struct kmembuckets buckets[MINBUCKET + 16];

    knlist(nl);
    kread(nl[X_BUCKET].n_value, &buckets, sizeof buckets, "kmembucket");
    (void)printf("Memory statistics by bucket size\n");
    (void)printf(
        "    Size   In Use   Free   Requests  HighWater  Couldfree\n");
    for (i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16; i++, kp++) {
        if (kp->kb_calls == 0)
            continue;
        size = 1 << i;
        (void)printf("%8d %8ld %6ld %10ld %7ld %10ld\n", size,
                     kp->kb_total - kp->kb_totalfree,
                     kp->kb_totalfree, kp->kb_calls,
                     kp->kb_highwat, kp->kb_couldfree);
        totfree += size * kp->kb_totalfree;
    }

    kread(nl[X_KMEMSTATS].n_value, &kmemstats, sizeof kmemstats,
          "kmemstats");
    (void)printf("\nMemory statistics by type\n");
    (void)printf(
        "       Type  In Use  MemUse   HighUse  Limit Requests  TypeLimit KernLimit\n");
    for (i = 0, ks = &kmemstats[0]; i < M_LAST; i++, ks++) {
        if (ks->ks_calls == 0)
            continue;
        (void)printf("%11s %6ld %7ldK %8ldK %5ldK %8ld %6u %9u\n",
                     kmemnames[i] ? kmemnames[i] : "undefined",
                     ks->ks_inuse, (ks->ks_memuse + 1023) / 1024,
                     (ks->ks_maxused + 1023) / 1024,
                     (ks->ks_limit + 1023) / 1024, ks->ks_calls,
                     ks->ks_limblocks, ks->ks_mapblocks);
        totuse += ks->ks_memuse;
        totreq += ks->ks_calls;
    }
    (void)printf("\nMemory Totals:  In Use    Free    Requests\n");
    (void)printf("              %7ldK %6ldK    %8ld\n",
                 (totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);
}
Beispiel #20
0
/*
 * Dump PIM statistics structure.
 */
void
pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
	struct pim6stat pim6stat, zerostat;
	size_t len = sizeof pim6stat;

	if (live) {
		if (zflag)
			memset(&zerostat, 0, len);
		if (sysctlbyname("net.inet6.pim.stats", &pim6stat, &len,
		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
			if (errno != ENOENT)
				warn("sysctl: net.inet6.pim.stats");
			return;
		}
	} else {
		if (off == 0)
			return;
		kread(off, &pim6stat, len);
	}

	printf("%s:\n", name);

#define	p(f, m) if (pim6stat.f || sflag <= 1) \
    printf(m, (uintmax_t)pim6stat.f, plural(pim6stat.f))
	p(pim6s_rcv_total, "\t%ju message%s received\n");
	p(pim6s_rcv_tooshort, "\t%ju message%s received with too few bytes\n");
	p(pim6s_rcv_badsum, "\t%ju message%s received with bad checksum\n");
	p(pim6s_rcv_badversion, "\t%ju message%s received with bad version\n");
	p(pim6s_rcv_registers, "\t%ju register%s received\n");
	p(pim6s_rcv_badregisters, "\t%ju bad register%s received\n");
	p(pim6s_snd_registers, "\t%ju register%s sent\n");
#undef p
}
Beispiel #21
0
Datei: dial.c Projekt: 8l/inferno
static int
call(char *clone, char *dest, DS *ds)
{
	int fd, cfd, n;
	char name[Maxpath], data[Maxpath], err[ERRMAX], *p;

	cfd = kopen(clone, ORDWR);
	if(cfd < 0){
		kerrstr(err, sizeof err);
		kwerrstr("%s (%s)", err, clone);
		return -1;
	}

	/* get directory name */
	n = kread(cfd, name, sizeof(name)-1);
	if(n < 0){
		kerrstr(err, sizeof err);
		kclose(cfd);
		kwerrstr("read %s: %s", clone, err);
		return -1;
	}
	name[n] = 0;
	for(p = name; *p == ' '; p++)
		;
	sprint(name, "%ld", strtoul(p, 0, 0));
	p = strrchr(clone, '/');
	*p = 0;
	if(ds->dir)
		snprint(ds->dir, NETPATHLEN, "%s/%s", clone, name);
	snprint(data, sizeof(data), "%s/%s/data", clone, name);

	/* connect */
	if(ds->local)
		snprint(name, sizeof(name), "connect %s %s", dest, ds->local);
	else
		snprint(name, sizeof(name), "connect %s", dest);
	if(kwrite(cfd, name, strlen(name)) < 0){
		err[0] = 0;
		kerrstr(err, sizeof err);
		kclose(cfd);
		kwerrstr("%s (%s)", err, name);
		return -1;
	}

	/* open data connection */
	fd = kopen(data, ORDWR);
	if(fd < 0){
		err[0] = 0;
		kerrstr(err, sizeof err);
		kwerrstr("%s (%s)", err, data);
		kclose(cfd);
		return -1;
	}
	if(ds->cfdp)
		*ds->cfdp = cfd;
	else
		kclose(cfd);

	return fd;
}
Beispiel #22
0
char * LoadAnm ( short anim_num )
{
    long handle;
    char *animbuf, *palptr;
    long i, j, k;
    DSPRINTF ( ds, "LoadAnm" );
    MONO_PRINT ( ds );
    // this seperate allows the anim to be precached easily
    ANIMnum = anim_num;
    // lock it
    walock[ANIM_TILE ( ANIMnum )] = 219;
    
    if ( anm_ptr[anim_num] == 0 )
    {
        handle = kopen4load ( ANIMname[ANIMnum], 0 );
        
        if ( handle == -1 )
        {
            return ( NULL );
        }
        
        length = kfilelength ( handle );
        allocache ( ( intptr_t * ) &anm_ptr[anim_num], length + sizeof ( anim_t ), &walock[ANIM_TILE ( ANIMnum )] );
        animbuf = ( char * ) ( FP_OFF ( anm_ptr[anim_num] ) + sizeof ( anim_t ) );
        kread ( handle, animbuf, length );
        kclose ( handle );
    }
    
    else
    {
        animbuf = ( char * ) ( FP_OFF ( anm_ptr[anim_num] ) + sizeof ( anim_t ) );
    }
    
    return ( animbuf );
}
Beispiel #23
0
static int32_t read_whole_file(const char *fn, char **retbufptr)
{
    int32_t fid, flen, i;
    char *buf;

    *retbufptr = NULL;

    fid = kopen4load(fn, 0);  // TODO: g_loadFromGroupOnly, kopen4loadfrommod ?

    if (fid < 0)
        return 1;

    flen = kfilelength(fid);
    if (flen == 0)
        return 5;

    buf = (char *)Xmalloc(flen+1);

    i = kread(fid, buf, flen);
    kclose(fid);

    if (i != flen)
    {
        Bfree(buf);
        return 2;
    }

    buf[flen] = 0;
    *retbufptr = buf;

    return 0;
}
Beispiel #24
0
/*
 * See include/netinet/ip_ipcomp.h
 */
PyObject *ipcompstats(PyObject *self, PyObject *args){
	struct ipcompstat ipcomps;
	PyObject *retdict;

	if (kread(nl[N_IPCOMPSTAT].n_value, (char *)&ipcomps, sizeof ipcomps)){
		return NULL;
	}

	retdict = PyDict_New();
	if (retdict == NULL)
		return NULL;

	if (!addULongLong(retdict, "hdrops",		(unsigned long long)ipcomps.ipcomps_hdrops)) return NULL;
	if (!addULongLong(retdict, "nopf",			(unsigned long long)ipcomps.ipcomps_nopf)) return NULL;
	if (!addULongLong(retdict, "notdb",			(unsigned long long)ipcomps.ipcomps_notdb)) return NULL;
	if (!addULongLong(retdict, "badkcr",		(unsigned long long)ipcomps.ipcomps_badkcr)) return NULL;
	if (!addULongLong(retdict, "qfull",			(unsigned long long)ipcomps.ipcomps_qfull)) return NULL;
	if (!addULongLong(retdict, "noxform",		(unsigned long long)ipcomps.ipcomps_noxform)) return NULL;
	if (!addULongLong(retdict, "wrap",			(unsigned long long)ipcomps.ipcomps_wrap)) return NULL;
	if (!addULongLong(retdict, "input",			(unsigned long long)ipcomps.ipcomps_input)) return NULL;
	if (!addULongLong(retdict, "output",		(unsigned long long)ipcomps.ipcomps_output)) return NULL;
	if (!addULongLong(retdict, "invalid",		(unsigned long long)ipcomps.ipcomps_invalid)) return NULL;
	if (!addULongLong(retdict, "ibytes",		(unsigned long long)ipcomps.ipcomps_ibytes)) return NULL;
	if (!addULongLong(retdict, "obytes",		(unsigned long long)ipcomps.ipcomps_obytes)) return NULL;
	if (!addULongLong(retdict, "toobig",		(unsigned long long)ipcomps.ipcomps_toobig)) return NULL;
	if (!addULongLong(retdict, "pdrops",		(unsigned long long)ipcomps.ipcomps_pdrops)) return NULL;
	if (!addULongLong(retdict, "crypto",		(unsigned long long)ipcomps.ipcomps_crypto)) return NULL;
	if (!addULongLong(retdict, "minlen",		(unsigned long long)ipcomps.ipcomps_minlen)) return NULL;
	return retdict;
}
Beispiel #25
0
/*
 * Dump raw ip6 statistics structure.
 */
void
rip6_stats(u_long off, char *name)
{
	struct rip6stat rip6stat;
	u_quad_t delivered;

	if (off == 0)
		return;
	kread(off, (char *)&rip6stat, sizeof(rip6stat));
	printf("%s:\n", name);

#define	p(f, m) if (rip6stat.f || sflag <= 1) \
    printf(m, (unsigned long long)rip6stat.f, plural(rip6stat.f))
	p(rip6s_ipackets, "\t%llu message%s received\n");
	p(rip6s_isum, "\t%llu checksum calculation%s on inbound\n");
	p(rip6s_badsum, "\t%llu message%s with bad checksum\n");
	p(rip6s_nosock, "\t%llu message%s dropped due to no socket\n");
	p(rip6s_nosockmcast,
	    "\t%llu multicast message%s dropped due to no socket\n");
	p(rip6s_fullsock,
	    "\t%llu message%s dropped due to full socket buffers\n");
	delivered = rip6stat.rip6s_ipackets -
		    rip6stat.rip6s_badsum -
		    rip6stat.rip6s_nosock -
		    rip6stat.rip6s_nosockmcast -
		    rip6stat.rip6s_fullsock;
	if (delivered || sflag <= 1)
		printf("\t%llu delivered\n", (unsigned long long)delivered);
	p(rip6s_opackets, "\t%llu datagram%s output\n");
#undef p
}
Beispiel #26
0
/*
 * See include/netinet/ip_esp.h
 */
PyObject *espstats(PyObject *self, PyObject *args){
	struct espstat esps;
	PyObject *retdict;

	if (kread(nl[N_ESPSTAT].n_value, (char *)&esps, sizeof esps)){
		return NULL;
	}

	retdict = PyDict_New();
	if (retdict == NULL)
		return NULL;

	if (!addULongLong(retdict, "hdrops",		(unsigned long long)esps.esps_hdrops)) return NULL;
	if (!addULongLong(retdict, "nopf",			(unsigned long long)esps.esps_nopf)) return NULL;
	if (!addULongLong(retdict, "notdb",			(unsigned long long)esps.esps_notdb)) return NULL;
	if (!addULongLong(retdict, "badkcr",		(unsigned long long)esps.esps_badkcr)) return NULL;
	if (!addULongLong(retdict, "qfull",			(unsigned long long)esps.esps_qfull)) return NULL;
	if (!addULongLong(retdict, "noxform",		(unsigned long long)esps.esps_noxform)) return NULL;
	if (!addULongLong(retdict, "badilen",		(unsigned long long)esps.esps_badilen)) return NULL;
	if (!addULongLong(retdict, "wrap",			(unsigned long long)esps.esps_wrap)) return NULL;
	if (!addULongLong(retdict, "badenc",		(unsigned long long)esps.esps_badenc)) return NULL;
	if (!addULongLong(retdict, "badauth",		(unsigned long long)esps.esps_badauth)) return NULL;
	if (!addULongLong(retdict, "replay",		(unsigned long long)esps.esps_replay)) return NULL;
	if (!addULongLong(retdict, "input",			(unsigned long long)esps.esps_input)) return NULL;
	if (!addULongLong(retdict, "output",		(unsigned long long)esps.esps_output)) return NULL;
	if (!addULongLong(retdict, "invalid",		(unsigned long long)esps.esps_invalid)) return NULL;
	if (!addULongLong(retdict, "ibytes",		(unsigned long long)esps.esps_ibytes)) return NULL;
	if (!addULongLong(retdict, "obytes",		(unsigned long long)esps.esps_obytes)) return NULL;
	if (!addULongLong(retdict, "toobig",		(unsigned long long)esps.esps_toobig)) return NULL;
	if (!addULongLong(retdict, "pdrops",		(unsigned long long)esps.esps_pdrops)) return NULL;
	if (!addULongLong(retdict, "crypto",		(unsigned long long)esps.esps_crypto)) return NULL;
	return retdict;
}
Beispiel #27
0
scriptfile *scriptfile_fromfile(char *fn)
{
	int fp;
	scriptfile *sf;
	char *tx;
	unsigned int flen;

	fp = kopen4load(fn,0);
	if (fp<0) return NULL;

	flen = kfilelength(fp);
	tx = (char *) malloc(flen + 2);
	if (!tx) {
		kclose(fp);
		return NULL;
	}

	sf = (scriptfile*) malloc(sizeof(scriptfile));
	if (!sf) {
		kclose(fp);
		free(tx);
		return NULL;
	}

	kread(fp, tx, flen);
	tx[flen] = tx[flen+1] = 0;

	kclose(fp);

	scriptfile_preparse(sf,tx,flen);
	sf->filename = strdup(fn);

	return sf;
}
Beispiel #28
0
int osdcmd_fileinfo(const osdfuncparm_t *parm)
{
	unsigned long crc, length;
	int i,j;
	char buf[256];

	if (parm->numparms != 1) return OSDCMD_SHOWHELP;
	
	if ((i = kopen4load((char *)parm->parms[0],0)) < 0) {
		OSD_Printf("fileinfo: File \"%s\" does not exist.\n", parm->parms[0]);
		return OSDCMD_OK;
	}

	length = kfilelength(i);

	crc32init(&crc);
	do {
		j = kread(i,buf,256);
		crc32block(&crc,buf,j);
	} while (j == 256);
	crc32finish(&crc);
	
	kclose(i);

	OSD_Printf("fileinfo: %s\n"
	           "  File size: %d\n"
		   "  CRC-32:    %08X\n",
		   parm->parms[0], length, crc);

	return OSDCMD_OK;
}
Beispiel #29
0
uint8_t  loadsound(uint16_t num)
{
    int32_t   fp, l;

    if (num >= NUM_SOUNDS || SoundToggle == 0) {
        return 0;
    }
    if (FXDevice == NumSoundCards) {
        return 0;
    }

    fp = TCkopen4load(sounds[num],0);
    if (fp == -1) {
        sprintf(&fta_quotes[113][0],"Sound %s(#%d) not found.",sounds[num],num);
        FTA(113,&ps[myconnectindex],1);
        return 0;
    }

    l = kfilelength( fp );
    soundsiz[num] = l;

    Sound[num].lock = 200;

    allocache(&Sound[num].ptr,l,(uint8_t *)&Sound[num].lock);
    kread( fp, Sound[num].ptr , l);
    kclose( fp );
    return 1;
}
Beispiel #30
0
char loadsound(unsigned short num)
{
    long   fp, l;

    if(num >= NUM_SOUNDS || SoundToggle == 0) return 0;
    if (FXDevice < 0) return 0;

    fp = kopen4load(sounds[num],loadfromgrouponly);
    if(fp == -1)
    {
        sprintf(&fta_quotes[113][0],"Sound %s(#%d) not found.",sounds[num],num);
        FTA(113,&ps[myconnectindex]);
        return 0;
    }

    l = kfilelength( fp );
    soundsiz[num] = l;

    Sound[num].lock = 200;

    allocache((long *)&Sound[num].ptr,l,(char *)&Sound[num].lock);
    kread( fp, Sound[num].ptr , l);
    kclose( fp );
    return 1;
}