コード例 #1
0
ファイル: unix.c プロジェクト: UNGLinux/Obase
void
unixpr(u_long off, u_long pcbaddr)
{
	struct file *fp;
	struct socket sock, *so = &sock;
	char *filebuf;
	struct protosw *unixsw = (struct protosw *)off;

	filebuf = kvm_getfiles(kvmd, KERN_FILE, 0, &fcnt);
	if (filebuf == NULL) {
		printf("Out of memory (file table).\n");
		return;
	}
	file = (struct file *)(filebuf + sizeof(fp));
	fileNFILE = file + fcnt;
	for (fp = file; fp < fileNFILE; fp++) {
		if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
			continue;
		if (kread((u_long)fp->f_data, so, sizeof (*so)))
			continue;
		/* kludge */
		if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
			if (so->so_pcb)
				unixdomainpr(so, fp->f_data, pcbaddr);
	}
}
コード例 #2
0
void
unixpr(u_long off)
{
	struct file *fp;
	struct socket sock, *so = &sock;
	char *filebuf;
	struct protosw *unixsw = (struct protosw *)off;

	if (use_sysctl) {
		struct kinfo_pcb *pcblist;
		int mib[8];
		size_t namelen = 0, size = 0, i;
		const char *mibnames[] = {
			"net.local.stream.pcblist",
			"net.local.dgram.pcblist",
			"net.local.seqpacket.pcblist",
			NULL,
		};
		const char **mibname;
		static int first = 1;

		for (mibname = mibnames; *mibname; mibname++) {
			memset(mib, 0, sizeof(mib));

			if (sysctlnametomib(*mibname, mib,
					    &namelen) == -1)
				err(1, "sysctlnametomib: %s", *mibname);

			if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
			    NULL, &size, NULL, 0) == -1)
				err(1, "sysctl (query)");

			if ((pcblist = malloc(size)) == NULL)
				err(1, "malloc");
			memset(pcblist, 0, size);

			mib[6] = sizeof(*pcblist);
			mib[7] = size / sizeof(*pcblist);

			if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), 
					pcblist, &size, NULL, 0) == -1)
				err(1, "sysctl (copy)");

			for (i = 0; i < size / sizeof(*pcblist); i++) {
				struct kinfo_pcb *ki = &pcblist[i];
				struct sockaddr_un *sun;
				int remote = 0;

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

				sun = (struct sockaddr_un *)&ki->ki_dst;
				if (sun->sun_path[0] != '\0') {
					remote = 1;
				} else {
					sun = (struct sockaddr_un *)&ki->ki_src;
				}

				unixdomainpr0(ki->ki_pcbaddr, ki->ki_type, 
					      ki->ki_rcvq, ki->ki_sndq,
					      ki->ki_vnode, ki->ki_conn, 
					      ki->ki_refs, ki->ki_nextref, 
					      ki->ki_sockaddr, sun, remote);
			}

			free(pcblist);
		}

	} else {
		filebuf = (char *)kvm_getfiles(get_kvmd(), KERN_FILE, 
					       0, &ns_nfiles);
		if (filebuf == 0) {
			printf("file table read error: %s", 
			       kvm_geterr(get_kvmd()));
			return;
		}
		file = (struct file *)(filebuf + sizeof(fp));
		fileNFILE = file + ns_nfiles;
		for (fp = file; fp < fileNFILE; fp++) {
			if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET)
				continue;
			if (kread((u_long)fp->f_data, (char *)so, sizeof (*so)))
				continue;
			/* kludge */
			if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2)
				if (so->so_pcb)
					unixdomainpr(so, fp->f_data);
		}
	}
}