Fix compiler warnings for mingw32.

There are two classes of compiler warnings when you build with mingw32. The most common one is that windows.h is included before winsock2.h. Because windows.h includes winsock.h (the old one) you end up with problems unless winsock2.h is included first, which prevents this.  Most of these changes just reorder include directives to ensure that winsock2.h gets included first.  The only other warning fix was to change a char pointer to a const char pointer in a function declaration. It turns out this function was always called with const char pointers, which generated a 'discards const' warning.