kern.file weirdness

Eirik Nygaard eirikn at
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:
	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.

Type: -16333
Type: -14424
Type: -14424

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

Eirik Nygaard
eirikn at xxxxxxxxxxxx
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00011.pgp
Type: application/octet-stream
Size: 187 bytes
Desc: "Description: PGP signature"
URL: <>

More information about the Submit mailing list