From owner-freebsd-net@freebsd.org Fri Mar 4 15:30:26 2016 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0B0F79DB978 for ; Fri, 4 Mar 2016 15:30:26 +0000 (UTC) (envelope-from pavel.odintsov@gmail.com) Received: from mail-io0-x22f.google.com (mail-io0-x22f.google.com [IPv6:2607:f8b0:4001:c06::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CC2DFD97; Fri, 4 Mar 2016 15:30:25 +0000 (UTC) (envelope-from pavel.odintsov@gmail.com) Received: by mail-io0-x22f.google.com with SMTP id n190so65828507iof.0; Fri, 04 Mar 2016 07:30:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=y3hYgIzbvuMTfVZdf7QrbWvP7uzY6TBY/nf9bsUpD58=; b=vSdXJud/VmEwyjtPwJ2MasFiCqkm4kXsyxgmGJwHlWoCf05I7nAZ8YhZFf4bcyJ9fv Ao8o3N1kVGm0h/ZLcSQPxyY3egGhNueWB4ufPWnHYjrC4Rk7pE58Q71ARloqMeV9/1Jg tmwIuj92zY17hhnqfULfltflJj3uLuyme+qGDkadxeSc6ohC20BdYZR72wzKFr900XQY Q4gCWdITI4ECL54mFJpDuvtsC17OSg0dZ5gTtNLJBISPrSX9+Ty0Np3Jayry+vXPY5jn Ux+qQj+rY/R0sM3rNEKpJ2NwCkNee3DH/ehoEPbGCrq/35wf0IM/FnxclBW6qtLlv/3g V44A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=y3hYgIzbvuMTfVZdf7QrbWvP7uzY6TBY/nf9bsUpD58=; b=c2pXPteqUz641cTHEjAFOeCqBZD/rkR+o8op3xuWHq3xU8o3o4kstC37z9eLJRY1wz 8Vo3GJE8QCtHrrIbSRd7Eog4bTm4LLHT2yd1VlwcvIvzg1keDh9Uf41xO70BomWiLNzF tJYungdjau/7mziwZt3sicYTVfymmmqw45X5YkCkN2hYBTA1iVSWbpfjINGhuW8ZYLzj w3kLoTjGQWzymRRbQ9XM+gEKchkuWwZvAEf43iSV6BXbD336487avxDlNpo+BNg3WarW ZRnearL2Px4uY0kbqQ2zlLa70jeoQM/ol7m5W/lI11J8vSwBX8l4SKSRYimkrbNxDGrr rbAg== X-Gm-Message-State: AD7BkJJwVIT9EjzAZKxCTPojUlyewAFIXVg2ZzpnmcLBqleG6xcYBzYTwms2GeyFLOiCE+IKcT44nnvS9pQaLg== MIME-Version: 1.0 X-Received: by 10.107.1.2 with SMTP id 2mr9893523iob.194.1457105425211; Fri, 04 Mar 2016 07:30:25 -0800 (PST) Received: by 10.79.36.134 with HTTP; Fri, 4 Mar 2016 07:30:25 -0800 (PST) In-Reply-To: References: Date: Fri, 4 Mar 2016 18:30:25 +0300 Message-ID: Subject: Re: libifconfig: A C API for ifconfig From: Pavel Odintsov To: Marie Helene Kvello-Aune Cc: Alan Somers , FreeBSD Net Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2016 15:30:26 -0000 Hello! Great idea! Amazing! :) On Fri, Mar 4, 2016 at 6:25 PM, Marie Helene Kvello-Aune wrote: > Hey! > > Yes, I am aware of libxo, and I hope that libxo-ification of /sbin/ifconfig > will be easier to do once the 'hairy' bits aren't a part of /sbin/ifconfig > any more. :) > > - Marie Helene > > On Fri, Mar 4, 2016 at 4:20 PM Alan Somers wrote: > >> On Fri, Mar 4, 2016 at 8:10 AM, Marie Helene Kvello-Aune < >> marieheleneka@gmail.com> wrote: >> >>> Hey! >>> >>> I'm currently working on a library called 'libifconfig' which will provide >>> a C API to do the actual work that /sbin/ifconfig currently does, except >>> that of lib80211. What sparked this project was a wish to simplify >>> maintenance of the ifconfig program by making it primarily focus on the >>> user's command line interaction, and not so much on the specifics of how >>> those things are done behind the scenes. >>> >>> One advantage to having such a library is to reduce code duplication and >>> thus improve maintainability, and another is that it would make it easier >>> for third party programs to query the network stack without having to >>> spawn >>> ifconfig and parse its output. I'm sure there's more, but those were the >>> ones at the top of my head when writing this e-mail. >>> >>> Currently, the API is implemented so that the application provides an >>> interface name, required value if any (say, to set description or name), >>> or >>> a reference to a value if retrieving information, such as an interfaces >>> description or MTU. >>> >>> The calling application won't have to provide a socket, as this is part of >>> the 'behind the scenes' things that the library takes care of. The API >>> will >>> ask only for the information that is required to do what it's supposed to >>> do, nothing more and nothing less. >>> >>> Each API call will return a value of either "0" for success or "-1" for >>> failure and there will be an instance (libifconfig_errstate) of a struct >>> containing all information relevant to the error. I found this was the >>> most >>> sensible way of properly communicating exactly what went wrong with a >>> call, >>> as some API methods do several system calls behind the scenes. I found it >>> necessary for the API to be this communicative as /sbin/ifconfig is rather >>> detailed in its error messages, and I don't want /sbin/ifconfig's >>> behaviour to be altered in any way as a result of this libification. >>> >>> The implementation of libifconfig currently exist only on my machine, but >>> I >>> will submit a patch to reviews.freebsd.org to solicit feedback once I've >>> cleaned up the code some and implemented & verified the error feedback >>> mechanism. >>> >>> Copy-pasting some of the simple stuff from the header file to give a feel >>> for how I envision the API: >>> >>> int libifconfig_get_description(const char *name, char **description); >>> int libifconfig_set_description(const char *name, const char >>> *newdescription); >>> int libifconfig_unset_description(const char *name); >>> >>> int libifconfig_set_mtu(const char *name, const int mtu); >>> int libifconfig_get_mtu(const char *name, int *mtu); >>> >>> >>> Your feedback is quite welcome. :) >>> >>> Regards, >>> Marie Helene Kvello-Aune >>> >> >> This sounds like an awesome idea. ifconfig is my least favorite program >> to parse. BTW, are you aware of the ongoing libxo work? That effort fixes >> the problem of parsing the output of utilities like ifconfig, though it >> doesn't do anything to simplify their maintenance. >> >> -Alan >> >> > _______________________________________________ > freebsd-net@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" -- Sincerely yours, Pavel Odintsov