Added patches for freeBSD support. Thanks to Nick Kostirya kostirya@gmail.com