kern.file weirdness

Eirik Nygaard eirikn at kerneled.com
Sat Nov 22 02:53:55 PST 2003


I am working on removing perlism in userland and have come over a little
problem when I am rewriting sockstat. I try to get all the open fd's from
the kern.file sysctl with this code:
void
get_files(void)
{
	size_t size;
	
	if (sysctlbyname("kern.file", NULL, &size, NULL, 0) < 0)
		err(1, "sysctlbyname()");
	if ((files = malloc(size)) == NULL)
		err(1, "malloc()");
	if (sysctlbyname("kern.file", files, &size, NULL, 0) < 0) 
		err(1, "sysctlbyname()");
	
	nfiles = size / sizeof(struct file);
	{
		int i;
		for(i = 0; i < nfiles; i++)
			printf("Type: %d\n", files[i].f_type);
	}
	
}

but it only gives me bogus results for some reason.

Output: 
Type: -16333
Type: -14424
[...]
Type: -14424

Would be grateful if someone knows what I am doing wrong here.

-- 
Eirik Nygaard
eirikn at xxxxxxxxxxxx
Attachment:
pgp00011.pgp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00011.pgp
Type: application/octet-stream
Size: 187 bytes
Desc: "Description: PGP signature"
URL: <http://lists.dragonflybsd.org/pipermail/submit/attachments/20031122/efb561ae/attachment-0012.obj>


More information about the Submit mailing list