Open the file in "rb" mode instead of "r"
Add the source code in the book The Definitive Guide to Linux Network Programming