While it is good to understand networking by generating your own packets, you don't need to write a program to do that. My advice is to generate packets using Ostinato - the process of generating packets as a user in Ostinato is low level enough for you to understanding the networking packets, layers, headers and fields.
It would also be worthwhile to look at packet captures in Wireshark at the same time.
Ideally you should have someone with networking knowledge to be able to answer questions that you will invariably have - a book is good, but not good enough to answer questions :-)
If you would still like to write your own program, use libpcap (or WinPCAP on Windows) - start with this
Sending Packets Tutorial
Good luck!
Disclosure: I'm the developer of Ostinato