That example might have worked at one time (no guarantee), but I would be very surprised if the examples are checked regularly to be sure they continue to work. Unfortunately, you have to expect to have to fix up examples some of the time.
Sometimes the exact wording of a compiler message is critical to understanding its meaning, so rather than paraphrase the messages you get, it is best to reproduce them exactly when you post questions whose answers might depend on the exact meaning of a compiler message.
A few times, I have cured problems similar to what you describe by including -Wextensions among the compiler options. That is one thing I would suggest you try.
I don't understand why you added your own definitions for u_short and gethostid() instead of adding #include for the two header files you mentioned that contain those declarations. Using the header files is also something I would suggest you try right away.
I don't know quite what you mean when you say: "... a lot more of these definitions and declarations are not added into memory ...". On a J-series system, most of the library stuff is included from DLLs, and so will not be included in your runnable object file. So maybe you are over-thinking on that point. On the other hand, if you mean that you get a lot of undefined symbols when you try to run the file, then something is wrong. It might be necessary to name the DLLs that contain the sockets library functions among the compiler options, but I believe that should not be necessary -- most of the DLLs are registered in a directory that the linker knows to consult automatically.
So my suggestion is to try the two things I mentioned above. If that cures the problem, good. If it still don't not work, post again with more details about exactly what you are seeing that indicates a problem.