Slashdot Mirror


Unix Network Programming, Vol. 1

prostoalex writes "Reviewing Richard Stevens' Unix Network Programming is akin to reviewing the New Testament for a Christian audience, or The Elements of Style for English majors. Everyone who is somehow involved in network programming on Unix/Linux systems generally refers to the tome as ultimate learning resource and the best reference out there." Read on for the rest of Alex's review. Unix Network Programming, Vol. 1: The Sockets Networking API, Third Edition author W. Richard Stevens, Bill Fenner, Andrew M. Rudoff pages 1024 publisher Addison-Wesley rating 9 reviewer Alex Moskalyuk ISBN 0131411551 summary Ultimate reference guide for network programming, protocol implementation, server-client applications on Unix

Those just starting in the field will eventually come across so many "Stevens book" references that it will eventually end up in their library. In a nutshell: Unix Network Programming is a must for anyone involved in writing network-enabled clients or server applications, requiring a variety of protocols.

The first edition of the book came out in 1990, and quickly became the college textbook and professional reference for anyone trying to get experience in the field. This is the third edition of first volume of Unix Network Programming, titled The Sockets Networking API. Volume 2 deals with Interprocess Communications and so far exists only in the 2nd edition. W. Richard Stevens didn't live to see the 3rd edition published, and the new book has Bill Fenner and Andrew M. Rudoff listed as co-authors.

The table of contents for Unix Network Programming provides a very good overview of what's packed into 31 chapters and 5 appendices that provide 950 pages of information on network programming (Addison Wesley states it's 1024 pages, but page 947 is the start of the bibliography, followed by an index which was designed by W. Richard Stevens himself for better usability). The book starts with the basics, with an introduction to network protocols and OSI model in chapters 1 and 2. The authors move on to socket programming (supporting TCP, UDP, and SCTP protocols), providing a working example of a TCP client-server application (Chapter 5) as well as SCTP client-server (Chapter 10). DNS service is covered in Chapter 10, with some additions dealing with IPv6 implementations.

The largest part of the book -- Advanced Sockets -- covers a wide range of technologies and generally it's not expected that you cover this part chapter by chapter. Chapter 12 would be of special use for anyone dealing with IPv4 and IPv6 implementations simultaneously. The authors provide an example of an IPv4 client working with an IPv6 server and vice versa. Then it proceeds to daemon processes, I/O operations on Unix, threads, raw sockets, advanced techniques for programming UDP and SCTP sockets, broadcasting and multicasting technologies, finishing off with the chapter on streams.

To avoid recapping the table of contents, it's worth mentioning that if you're an experienced network developer and have read previous editions of Stevens' book, you will find that that the book has been updated with IPv6 APIs and example code (including interoperation with IPv4 in aforementioned Chapter 12), information on the POSIX Single Unix Spec v3, a chapter on key management for IPsec (19), and three new chapters (9,10,23) on SCTP.

But wait a minute, what about the second edition, didn't it have 34 chapters, while this third one has only 31? Description of the XTI (X/Open Transport Interface) is gone, and that used to fill chapters 28,29,30,31 and 32 of the previous edition. The authors note that XTI API "has fallen out of common use and even the most recent POSIX specification does not bother to cover it." T/TCP (TCP for Transactions) is dropped as well, so if your applications still rely on either XTI or T/TCP, perhaps donating the 2nd edition to the local church library can wait.

The information above would be of interest to the professionals in the field, but what about the beginners? Can a reader expect to become proficient with developing network applications by absorbing Stevens' book? Unix Network Programming indeed makes a very good effort to be as inviting and simple as possible to the first-time reader, even while it is trying to be informative for those who've read the chapters several times. The authors generally start with the description of the solved problem, then specify the ways to solve the problem in English -- only after that do they introduce an example solution in C. The code is quite clean and universal to be re-used on Unix boxes with C++, Perl, etc. Where a proper OS function call is necessary, it's used with an explanation of what it does, and where the functionality asks for a new function, the authors introduce their own.

Don't let the word Unix in the title fool you into thinking that you will need a separate book for Win32 platform (or Linux, for that matter). Apparently, there are differences in OS-specific function calls, but as far as protocols and implementation of specific functionality, the book would provide useful examples for Microsoft developers as well. What about Apple Mac OS X? On page xxi the authors claim the code has been tested on Mac OS X on PowerPC, HP-UX 11i on PA-RISC, AIX 5.1 on PowerPC, FreeBSD 4.8 on x86, Linux 2.4.7 on x86, FreeBSD 5.1 on SPARC and Solaris 9 on SPARC.

If you're reading the book for the first time, but have been through a network class before, you might skip Chapters 1 and 2, where the basics of network interaction (port numbers, OSI model, Internet protocol suite, netstat command, TCP connections, etc.) are covered. It makes sense to peruse the starting chapters if you are not familiar with SCTP.

Since many colleges in the United States and around the world use this title for their network programming classes, a handful of exercises follows each chapter. The questions are not programming projects, just quick self-test opportunities, e.g. Chapter 18 (Routing Sockets) is followed by the question: "What would you expect the sdl_len field of a datalink socket address structure to contain for a device named eth10 whose link-layer address is a 64-bit IEEE EUI-64 address?"

Some of the things from Stevens' book (like the desire to write a wrapper function for everything) might drive you crazy, although if you accept the author's style and follow the textbook by typing up and trying the source code, you will end up with a rather nice API library for all occasions by the time you get through the first two parts. It would also certainly be nice if the book, despite the title, included at least an appendix on Windows-specific implementations for those developing clients for the Microsoft platform.

Unix Network Programming is indispensable if any part of your professional or academic career involves writing client-server applications or programs requiring network communications. A good knowledge of C and familiarity with Unix internals is required, while the book is gentle enough to provide good guidance for the beginner in the network programming field. As W. Richard Stevens' mentioned in one of the interviews, "When I hit something that I don't understand, I take a detour and learn something new. This often makes my books late by a few months, but I think accuracy and completeness are essential."

You can purchase Unix Network Programming, Vol. 1: The Sockets Networking API, Third Edition from bn.com. Slashdot welcomes readers' book reviews -- to submit a review for consideration, read the book review guidelines, then visit the submission page.

14 of 160 comments (clear)

  1. In Wayne's World II by Anonymous Coward · · Score: 5, Informative

    according to:

    http://www.roguewave.com/support/docs/hppdocs/tp ru g/29-1.html

    An excellent introduction and reference for the various Unix C IPC mechanisms. Also famous as the book that the girl of Garth's dreams is carrying at the end of Wayne's World II.

    1. Re:In Wayne's World II by Anonymous Coward · · Score: 1, Informative

      VM are separated by the VM software, so you should not be able to communicate between them. I've had to write TCP/IP applications between CMS and MV (it's been awhile, so those may be the wrong OS names). It feels silly, but they are, after, virtually separate machines.

  2. other must have books by richard stevens by gokulpod · · Score: 5, Informative
    --
    My mom never taught me to sign.
    1. Re:other must have books by richard stevens by goodviking · · Score: 5, Informative

      And my personal favorite:

      Advanced Programming in the UNIX Enviornment

      otherwise known as "Why didn't I just start with this in the first place."

      In general, I've found that Stevens, as well as Douglas Comer are two authors who can always be trusted to deliver material that is both relevant and enlightening.

    2. Re:other must have books by richard stevens by jcoy42 · · Score: 3, Informative

      Yes, APUE is excellent- but after reading that, take a look at Beginning Linux Programming from Wrox Press. This book give the best bite sized simple, coherent examples I have seen anywhere.

      The only down side to the book is it tends to skirt around error checking- which is required to provide simple summaries.

      If you've read APUE, check out Beginning Linux Programming- and don't let the word Beginning throw you-it covers advanced topics quite well.

      BTW- my opinions are based on the 1st edition, for the at the time when it originally came out.

      --
      Never trust an atom. They make up everything.
  3. Re:SCTP? by DAldredge · · Score: 5, Informative

    Stream Control Transmission Protocol
    http://www.iec.org/online/tutorials/sctp /

  4. Also available... by Anonymous Coward · · Score: 0, Informative

    ...without the slashdot referral fee, from Amazon and B&N

  5. Re:akin to... by Rudeboy777 · · Score: 3, Informative

    More like reviewing OT-III. (Obligatory link to piss off the Scientologists and attract legal action)

    --

    From hell's heart I fstab at /dev/hdc

  6. Looks like a referrer to me. by Anonymous Coward · · Score: 3, Informative

    ref=sr_11_1/103-0663527-6482268

    So, your referral fee is somehow better than Slashdots? For you maybe.

  7. True that by ncc74656 · · Score: 5, Informative
    Don't let the word Unix in the title fool you into thinking that you will need a separate book for Win32 platform (or Linux, for that matter). Apparently, there are differences in OS-specific function calls, but as far as protocols and implementation of specific functionality, the book would provide useful examples for Microsoft developers as well.

    I have both this book and Microsoft's take on network coding. The Stevens book has been much more useful, and not just because I've needed to write Windows clients and Linux servers that interoperate. There aren't many differences between Windows Sockets and the BSD socket interface:

    • A socket descriptor is a SOCKET instead of an int.
    • You close a socket when you're done with it with closesocket() instead of close().
    • You call WSAStartup() before doing any socket stuff and call WSACleanup() when you're done.
    • WSAGetLastError() retrieves any errors that occur.
    • #include <winsock.h> loads all the socket-related headers you need, and you link with ws2_32.lib.

    If you keep this info in mind, you can apply most of what's in the Stevens book under Win32 nearly as easily as you can under Linux/*BSD/whatever. You'll also end up with network code that's reasonably easy to port elsewhere...more so than if you go for a larger percentage of Microsoft-specific socket calls (many BSD-style calls have WSA* near-equivalents that you can use).

    --
    20 January 2017: the End of an Error.
    1. Re:True that by joe_bruin · · Score: 2, Informative

      i second this.
      having written network code that runs on both linux and windows, this book covers pretty much anything you need to write a program that will work with winsock/winsock2 as well as unix (even though it never specifically addresses windows). you will need to translate some of the calls to ms's names, but the functionality is essentially the same (even the ioctls are similar, although mapping those gets to be a real pain). just be sure to check the winsock docs.

      a few minor things to watch out for:

      most bsd networking calls return -1 on failure, but windows returns either SOCKET_ERROR or INVALID_SOCKET (which have different values), depending on the call.

      windows changes many signed values to unsigned.

  8. Re:1st, 2nd and now the 3rd edition by fenner · · Score: 2, Informative

    Rich's untimely death occurred before the planned Volume III, which was to cover the applications section of the 1st edition. I've toyed with the idea of starting an outline for this book, but have so far just been relaxing from producing the 3rd edition =)

  9. Repeat! by tibbetts · · Score: 2, Informative

    This book was already reviewed on Slashdot.

    Okay, okay, that was five years ago (to the day!), but how much can really have changed?

    --
    :wq
  10. Re:A Great Resource by PixelThis · · Score: 2, Informative

    I purchased my copy of the first edition in '91. It finally lost it's cover around 1995.
    The cost of replacing the book would have been around $70 US.
    The cost of having the book rebound was only $25.

    *[Elementary school mathematics happens]*

    I had a nicely functional book and $45 left in my pocket.

    --