|
NAMENet::Interface::Developer api, notes, hintsDESCRIPTIONThis contains development notes and API documentation for the Net::Interface module. It is hoped that others will help fill in the missing pieces for OS's and address families that are currently unsupported.ARCHITECTURENet::Interface gathers information about the network interfaces in an OS independent fashion by first attempting to use "getifaddrs" if "getifaddrs" is not supported on the OS it falls back to using system "ioctl's" and the "ifreq, in6_ifreq, lifreq" structures defined on the local host. Linux differs somewhat since ipV6 information is available only directly from the kernel on older versions where "getifaddrs" is not available. The "ifreq" and friends information is used to generate a "getifaddrs" response.Herein lies the need for continued development by the opensource community. Many OS's have peculiar "ioctl" variants and SIOC's variants that require unique code solutions. I'm sure that all of them are not presently included. Net::Interface is built in 5 layers, listed below from the base up. description: files code1) AF_xxx families: ni_af_inetcommon.c (C)Code modules for AF families. Currently supported are AF_INET, AF_INET6. There is partial support for AF_LINK and AF_PACKET for retrieval of MAC address from the interface where it is needed. Where the code is reasonably universal for a particular address family and the methods used to retrieve the information from the OS, it resides in an af_xxxx.c file.2) IFREQ families: ni_xx_ifreq.c (C)Code modules for IFREQ families. Currently supported are:
3) "getifaddrs" ni_getifaddrs.c (C)The "getifaddrs" code module contains the decision mechanism for how data is retrieved for a particular build of Net::Interface. At build time, portions of the code are #ifdef'd in/out depending on the availabiltiy of resource from the underlying OS. In addition, at run time, if the system does not have native "getifaddrs" then a decision tree is used depending on the response to calls for data to the various code modules described in section 2).4) Sub-system Interface.xs (PERLXS)This file asks for the data about the interfaces with a generic call to "getifaddrs". The data returned resides in memory allocated by the OS and must be freed or a memory leak will result as it is not tracked by Perl's garbage collector. "Interface.xs" moves the interface data from allocated memory to Perl managed memory where it can be reclaimed by the garbage collection mechanism if/when the user space program turns it loose. This eliminates the need for a "close" operation to free the OS's allocated memory.5) User space Interface.pm (Perl)DATA FLOW BLOCK DIAGRAMThe pure perl portion of this module performs most of the presentation operations for the user that are published in the API for Net::Interface.*\ \ \ | / / /* * user space * ************************* ^ Net::Interface | Architecture Block Diagram v ************************* * Interface.pm * ************************* | ************************* * Interface.xs * ************************* | ************************* ************************* * system getifaddrs * * ni_getifreqs * * via *<-if missing ->* via * * (ni_getifaddrer.c) * * (ni_ifreq.c) * ************************* * (ni_lifreq.c) * * (ni_in6_ifreq.c) * * (ni_linuxproc.c) * ************************* | ************************* * (ni_af_inetcommon.c) * ************************* DEVELOPER APIAccess to the pieces of code in the block diagram above are available through a developer API. These codes snippets from Interfaces.xs describe the access.void __developer(ref) SV *ref ALIAS: d_ni_ifreq = NI_IFREQ d_ni_lifreq = NI_LIFREQ d_ni_in6_ifreq = NI_IN6_IFREQ d_ni_linuxproc = NI_LINUXPROC PREINIT: char * process; int er = ni_developer(ix); and..... void gifaddrs_base(ref) SV * ref ALIAS: # base = 0 gifa_ifreq = NI_IFREQ gifa_lifreq = NI_LIFREQ gifa_in6_ifreq = NI_IN6_IFREQ gifa_linuxproc = NI_LINUXPROC PREINIT: struct ifaddrs * ifap; int rv; CODE: if ((rv = ni_getifaddrs(&ifap,ix)) == -1) { printf("failed PUNT!\n"); XSRETURN_EMPTY; Both function sets result in a printed description to the terminal window to facilitate code creation and debug. Currently the ref is unused. It is expected that future developement will modify or add to function access. # test.pl for developer # use strict; use Net::Interface; # to call OS native getifaddrs if present print "\nifreq\n"; gifaddrs_base Net::Interface(); # to call ni_linuxproc fallback getifaddrs print "\nlxp\n"; gifa_linuxproc Net::Interface(); # to call ni_linuxproc ifreq emulation print "\nglxp\n"; d_ni_linuxproc Net::Interface(); See: test.pl.developer DEVELOPER API DESCRIPTIONIf you have gotten this far, it is time to read some of the code. AF_familes and IFREQ_families are accessed through constuctor structs found at the bottom of each of the ni_af_xxx and ni_xx_ifreq source files. Their vectoring components are described in "ni_func.h" near the bottom and in "ni_util.c" in the section labeled constructor registration the essence of which is described here.struct ni_ifconf_flavor * ni_ifcf_get(enum ni_FLAVOR type) struct ni_ifconf_flavor * ni_safe_ifcf_get(enum ni_FLAVOR type); nifp = ni_ifcf_get(NI_IFREQ); Returns a pointer "nifp" to the structure for a particular flavor of ifreq. If a flavor is unsupported on a particular architecture a NULL is returned by the first invocation and NI_IFREQ by the second. Currently supported flavors are: enum ni_FLAVOR { NI_NULL, reserved for the getifaddrs base system call NI_IFREQ, NI_LIFREQ, NI_IN6_IFREQ, NI_LINUXPROC }; struct ni_ifconf_flavor { enum ni_FLAVOR ni_type; int (*gifaddrs) int siocgifindex; int siocsifaddr; int siocgifaddr; int siocdifaddr; int siocaifaddr; int siocsifdstaddr; int siocgifdstaddr; int siocsifflags; int siocgifflags; int siocsifmtu; int siocgifmtu; int siocsifbrdaddr; int siocgifbrdaddr; int siocsifnetmask; int siocgifnetmask; int siocsifmetric; int siocgifmetric; int ifr_offset; void (*fifaddrs) howto free ifaddrs int (*refreshifr) howto refresh ifreq void * (*getifreqs) howto get ifreq int (*developer) developer access struct ni_ifconf_flavor * ni_ifcf_next; }; MACROS
FUNCTIONS
COPYRIGHTCopyright 2008-2009 - Michael Robinton This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License in the file named "Copying" for more details. You should also have received a copy of the GNU General Public License along with this program in the file named "Copying". If not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330 Boston, MA 02111-1307, USA or visit their web page on the internet at: http://www.gnu.org/copyleft/gpl.html. POD ERRORSHey! The above document had some coding errors, which are explained below:
Visit the GSP FreeBSD Man Page Interface. |