Well, you better check to make sure a short is two bytes and a int is 32. Better to use something defined for this.
Instead of re inventing the world, why not look at Gtk-Gnutella, Gnut or Napshare? Then you could move on beyond the simple communications stuff.
The IP should be byte order, just make yourself a little HEX print routine and printout the WHOLE packet, remember the first 11 bytes are all the gnutella stuff then your response.
It's more fun to play with something that is working, try the code below.
http://sourceforge.net/projects/gtk-gnutella/ http://www.gnutelliums.com/linux_unix/gnut/ http://napshare.sourceforge.net/