Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Sep 2006 18:29:29 +0300
From:      "Taras Danko" <gortaur@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   How to find a certain socket?
Message-ID:  <89b086450609200829t2ef4dd9ft13c2051644101ba8@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi.
I need to find and close a certain socket from kernel module. My
current implementation iterates over the "allproc" list  and checks
every process'  file descriptors list  to find needed socket. But
maybe there is an easier way to do this? Some nixes have "inpcbtable"
which holds all the open sockets on the system. Is there anything
similar in FreeBSD?

And the second question: whats the correct way to close the socket
which was found?
My implementation:

 .....
mysocket = myproc->p_fd->fd_ofiles[i]->f_data;
myproc->p_fd->fd_ofiles[i]->f_data = NULL;
myproc->p_fd->fd_ofiles[i]->f_ops = &badfileops;
soclose(mysocket);
 .....

The socket closes but it causes a kernel panic in 90% of cases and
file descriptor doesnt actualy released (as fstat shows), but is
marked as "error" (because of "badfileops" I suppose). Maybe I should
acqure some mutex lock or something before starting manipulations with
socket? Any exampe code will be very much appreciated.

Its my first steps in fbsd kernel programming so please xcuse me for
newbie questions.

Taras Danko.
- - - - - - - - - - - - - - - - - - - - - -
contact me:
email: gortaur@gmail.com
icq:     166956956



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?89b086450609200829t2ef4dd9ft13c2051644101ba8>