From owner-freebsd-hackers@FreeBSD.ORG Wed Sep 20 15:29:32 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E73A716A403 for ; Wed, 20 Sep 2006 15:29:32 +0000 (UTC) (envelope-from gortaur@gmail.com) Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id 602EF43D6E for ; Wed, 20 Sep 2006 15:29:30 +0000 (GMT) (envelope-from gortaur@gmail.com) Received: by nz-out-0102.google.com with SMTP id 13so139948nzn for ; Wed, 20 Sep 2006 08:29:29 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=BFCHfXvRC2aZBEUu0IO6kpYR2cxzG+ogD5VZOYYG3RIxeyxAtznv8HcwbmNBqHRdGlYAAJiystZW8C7Uld6RnpOqKSUTf2R6ej/SkbjDbXiBYxDvHgkiFgX0OecGlm2mThI/JnMOjYPACi6YFwHY4QB0lqkDf+VoUVhmMnJLuoQ= Received: by 10.65.121.9 with SMTP id y9mr16678160qbm; Wed, 20 Sep 2006 08:29:29 -0700 (PDT) Received: by 10.65.231.16 with HTTP; Wed, 20 Sep 2006 08:29:29 -0700 (PDT) Message-ID: <89b086450609200829t2ef4dd9ft13c2051644101ba8@mail.gmail.com> Date: Wed, 20 Sep 2006 18:29:29 +0300 From: "Taras Danko" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: How to find a certain socket? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Sep 2006 15:29:33 -0000 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