# Available Network Interfaces?



## ckp98 (Feb 24, 2011)

I'm looking for a way to programmatically determine the available network interfaces on FreeBSD 8.1 install as well as an netstat packet statistics. Ideally in C or Python, and avoiding simply parsing ifconfig and other sys utilities. Are there any lower level ways to do this? 

I'm also attempting to build a FreeBSD network firewall appliance with automated installation and a basic ncurses (dialog) user interface for deployment across a few sites I manage. It looks like PXE boot is still the best solution for automated installation and configuration (though scarcely documented). Does anyone have any experience with either of these who would be willing to share their recommendations and words of wisdom?

Rolling my own is a must here, not looking to run pfsense, etc. 

Thanks!


----------



## SirDice (Feb 24, 2011)

ckp98 said:
			
		

> Ideally in C or Python, and avoiding simply parsing ifconfig and other sys utilities. Are there any lower level ways to do this?


Why don't you have a look in the source of ifconfig?
http://www.freebsd.org/cgi/cvsweb.cgi/src/sbin/ifconfig/




> It looks like PXE boot is still the best solution for automated installation and configuration (though scarcely documented).


FreeBSD Jumpstart Guide


----------



## ckp98 (Feb 24, 2011)

I've been trying to sort through it, but it is quite complex. Does anyone know of a reliable python library that can do this?

Is the jumpstart guide still relevant? It looks quite dated...


----------



## darwimy (Feb 24, 2011)

Reading network interface stats can be done using ifmib(). An example how to use it in C can be found e.g. in the LCDproc client machine_FreeBSD.c (function machine_get_iface_stats() at the end of the file).


----------



## SirDice (Feb 25, 2011)

ckp98 said:
			
		

> Is the jumpstart guide still relevant? It looks quite dated...


The process hasn't changed, only the FreeBSD versions


----------



## danger@ (Feb 25, 2011)

well `$ ifconfig -l` would be the easiest way, if you want to do it in C, just check the source of ifconfig...


----------



## Fred (Mar 3, 2011)

Or use getifaddrs(3), which is available under both Linux and BSD.


----------

