From owner-freebsd-questions@FreeBSD.ORG Sun Jan 2 19:45:12 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7FF5116A4CF for ; Sun, 2 Jan 2005 19:45:12 +0000 (GMT) Received: from fw.farid-hajji.net (fw.farid-hajji.net [213.146.115.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0BE0543D45 for ; Sun, 2 Jan 2005 19:45:12 +0000 (GMT) (envelope-from cpghost@cordula.ws) Received: from bsdbox.farid-hajji.net (bsdbox [192.168.254.3]) by fw.farid-hajji.net (Postfix) with ESMTP id A9B464AC75; Sun, 2 Jan 2005 20:45:31 +0100 (CET) Date: Sun, 2 Jan 2005 20:45:39 +0100 From: cpghost@cordula.ws To: "Andrew P." Message-ID: <20050102194539.GG2583@bsdbox.farid-hajji.net> References: <41D8395E.4020803@mail.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41D8395E.4020803@mail.ru> User-Agent: Mutt/1.5.6i cc: questions@freebsd.org Subject: Re: basic freebsd programming X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Jan 2005 19:45:12 -0000 On Sun, Jan 02, 2005 at 09:11:42PM +0300, Andrew P. wrote: > The ones that are the most interesting for me now is how to > write small daemons best and how to read ipfw info from a program. > > Of course I can refresh my C skills and gain some Unix-coding knowledge > by reading a couple' thousand pages, but I don't feel like it's > necessary for what I want to write - just a basic statistics collector. Of course you could do that in C, but if all you need is a program that reads the output of other programs, and presents stats on some port as a daemon (and a client to read that out), why not just go for a scripted solution in Perl or Python? Both languages are much better than C when it comes to parsing strings, and they are very good at networking too. IMHO, the only reason (besides efficiency) to write a monitoring program in C is if you don't want (or can't afford) to install a perl or python interpreter on the nodes that you want to monitor. > Should I explore FreeBSD source code or is there some solid piece of > documentation? That's not necessary. If you want to write that in C, you'll have to familiarize yourself with the popen(3) call for executing a program and capturing its output. Then you need a few string processing functions like str*(3) sscanf() etc... to parse the output (that's the tricky part). Finally you will need a small example of a client and server in C that uses the sockets API (that's pretty generic and not FreeBSD-specific at all, just google for it). Combine all this and voila, you've got your nice monitoring app in C. Alternatively, you could extract the info directly from the kernel by performing exactly the same steps that your utility program (ipfw...) does, but it's overkill for such a simple app. But again, consider giving Python a try. It's well worth it for such basic tasks. > Best wishes, > Andrew P. Regards, -cpghost. -- Cordula's Web. http://www.cordula.ws/