# Network development: where to start? (userland)



## Armie (Apr 21, 2011)

Hello,

I'm new to FreeBSD (or any flavor BSD in that case), and come from a Windows/Linux programming background. Thus, I have never developed anything for FreeBSD.

I have an application implemented on Linux which carries out some tasks related to TUN/TAP devices (basically creates a TUN, gets a file descriptor, adds routes, reads and writes data). There does not seem to be any samples on how to do these, for Linux such examples do exist (maybe I need to get out of the Linux mindset for a while).

I have been having problems with defines and structures. For example, Linux uses TUNSETIFF for ioctl(), but I've not been able to find it on FreeBSD. 
<linux/if_tun.h> is (obviously) missing, and it seems that the proper counterpart is <net/if_tun.h> but this misses some defines. Furthermore, some structures like rtentry seem to be implemented differently.

Can anyone direct me to the proper starting place in order to do the above (or rather, port the above) on FreeBSD? Maybe OS sources or whatever, I have not been able to find anything of much help.

Regards,
Armie


----------



## SirDice (Apr 21, 2011)

Plenty of documentation

FreeBSD Architecture Handbook
FreeBSD Developers Handbook

And a whole slew of articles covering various subjects:
http://www.freebsd.org/doc/en_US.ISO8859-1/articles/

Don't forget about the man pages too, they are way better then any of the Linux man pages.

As for OS sources, you either already have them locally in /usr/src/ or you can view them online at http://www.freebsd.org/cgi/cvsweb.cgi/src/


----------



## gordon@ (Apr 22, 2011)

Check the tun(4) manpage; it's details all of the supported ioctl calls. I think you are looking for the bit about device cloning:



> tun devices are created using interface cloning.  This is done using the 'ifconfig tunN create' command.  This is the preferred method of creating tun devices.  The same method allows removal of interfaces.  For  this, use the 'ifconfig tunN destroy' command.



Check the sources for ifconfig(8) to see how device cloning works.


----------

