Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Unix Operating Systems Software Books Media Programming Book Reviews IT Technology

Unix Network Programming, Vol. 1 160

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.

This discussion has been archived. No new comments can be posted.

Unix Network Programming, Vol. 1

Comments Filter:
  • In Wayne's World II (Score:5, Informative)

    by Anonymous Coward on Monday December 08, 2003 @02:20PM (#7660991)
    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.

    • Can C IPC APIs (shmem/message Qs/pipes) be used in VM environments (read IBM m/cs running muliple linuxes) ?<P>
      I hate to use Corba/RPC for IPC if applications are running on the same hardware , albeit diff. VMs.
      • by Anonymous Coward
        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.
      • by Anonymous Coward
        Can someone explain why this is offtopic. A question about UNIX IPC API, which closely relates to IPC capabilities of TCP/IP ? Sigh...

    • People get this mixed up alot. The poorly named (in my opinion) Networking Programing Vol II covers IPC(message que/shared memory....) Network programming Vol I covers sockets (udp/tcp etc).

      I still think it funny the book is in waynes world..
    • There was a cool write-up of this in Salon [salon.com] right after he died. See the last couple paragraphs of the second page [salon.com]. Kind of cool for a guy that helped so many people, most of them who never got to thank him.
  • by ObviousGuy ( 578567 ) <ObviousGuy@hotmail.com> on Monday December 08, 2003 @02:21PM (#7660996) Homepage Journal
    What there ought to be is some sort of environment where developers can use a simple markup language to describe a GUI and have some easy to use hooks back to a server machine which could run some code and generate reports to be delivered back to the GUI.

    If there were only some software to fill that gap...
  • A Great Resource (Score:5, Insightful)

    by PixelThis ( 690303 ) on Monday December 08, 2003 @02:24PM (#7661025)
    This is the best darn book on network programming bar none. I wore the covers off the 1990 edition I first owned and had to get it rebound.
    • We aren't talking about your Hustler collection.
    • You actually had a book ... rebound?

      Do you also get your shoes resoled and your TV repaired? What century are you living in?

      --

      • Re:A Great Resource (Score:2, Informative)

        by PixelThis ( 690303 )
        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.

        --
        • cool. I didn't even know anybody rebound books.
          well, other then historical books, or high monetary resale books.

          I'm surprised its so cheap.

          Live and learn.
      • I usually don't bother about getting books rebound, after all, gaffer tape is pretty sturdy ...

        However, I _do_ get my shoes resoled (you don't just throw away a $A300 pair of RMWilliams boots because the soles and heels are worn) and I have been known to get TV sets repaired as well.

  • SCTP? (Score:4, Interesting)

    by jeffy124 ( 453342 ) on Monday December 08, 2003 @02:24PM (#7661026) Homepage Journal
    Looking at the ToC on Amazon's page for this book, it says Stream Control Transmission Protocol, and is in the same chapter as TCP and UDP, implying it's a transport layer protocol. I've never heard of it. Anyone know of a decent tutorial page on it?
  • akin to... (Score:5, Funny)

    by Savatte ( 111615 ) on Monday December 08, 2003 @02:26PM (#7661045) Homepage Journal
    Unix Network Programming is akin to reviewing the New Testament for a Christian audience, or The Elements of Style for English majors.

    would it also be akin to reviewing Battlefield Earth for Scientologists?
  • I checked out the 2nd edition from my school's library (I'm surprised they have it). I currently don't have time to read it, so I'm aiming for racking up the most geeky and largest fine I can @ $0.10 per day, and there's a whole semester to go!
    • I suppose renewing it is totally out of the question? Where I went to uni you couldn't graduate if you still had library fines outstanding.
      • Me, too. I still have a book, "Asimov on Numbers", that I checked out in '82 and forgot to return. OC, the not graduating part never was an issue as I dropped out after 3 & 1/2 semisters (in which I earned 20 credits). It's funny... I was a miserable student but I ended up 20+ years in the computer field. I do wish I had book lerning on various specific aspects of computing. I know I could be a MUCH better coder if I'd ever had any formal training in programming. Well, other than that class in BA
    • I was going to read it, you insensitive clod!

  • by Anonymous Coward on Monday December 08, 2003 @02:29PM (#7661065)

    .. assuming this "Unix" thing ever takes off..
  • One of my favorites (Score:5, Interesting)

    by bighoov ( 605325 ) on Monday December 08, 2003 @02:39PM (#7661148) Homepage
    I feel fortunate to have a signed first edition of the book. In 1993, while doing an internship at IBM and working on a sockets-related project, we brought Rich Stevens (how he signs his name) in to teach a two-day class. He had a knack for taking complicated subject matter and presenting it in an easy-to-understand, straightforward manner.
    • I too had the honor of being trained by Stevens back in 1994. He gave my company (IDD) an accelerated two-day version of UNIX System and Network programming. The man was a walking encyclopedia of UNIX programming knowledge, most of which he obtained by simply writing lots and lots of example code. He had an excellent teaching style and we all had a great time.

      Tragically, he died back in 1999. Info at http://www.kohala.com [kohala.com].

  • True that (Score:5, Informative)

    by ncc74656 ( 45571 ) <scott@alfter.us> on Monday December 08, 2003 @02:48PM (#7661205) Homepage Journal
    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 [amazon.com]. 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).

    • Re:True that (Score:3, Informative)

      by joe_bruin ( 266648 )
      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 f
    • In my code I use a few simple defines to map the Winsock stuff to BSD sockets and program to the Winsock interface. You can't do all the things you want to do but for simple things it suffices.

      #define SOCKET int
      #define closesocket close
      #define SOCKET_ERROR (-1)
      #define INVALID_SOCKET (-1)
      (and headers to suit, invent null wrappers for the startup/cleanup stuff too).

      Other things to watch out for:

      • You have to use recv() and send() (or recvfrom()/sendto()) rather than read/write and deal with sho
      • You have to use recv() and send() (or recvfrom()/sendto()) rather than read/write and deal with short writes correctly.

        I forgot about that...but then I usually wrap send & recv in functions that make sure the correct amount of data is sent/received. A couple of conditionals (#ifdef _MSC_VER for your Win32 code) are all it'd take to make it cross-platform...you keep sending/receiving if send/recv returns a negative value and errno==EINTR (POSIX) or WSAGetLastError()==WSAEINTR (Win32). (If you use n

    • There's a few other differences- Window's select() can't take file descriptors and cannot select on TCP and UDP simultaneously. The MSG_PEEK option on Windows is hideously broken. A few of the error conditions have different names. But by and large it matches up exactly. Very easy to write dual OS functions to get around it.
    • Re:True that (Score:3, Interesting)

      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.

      Actually, Microsoft documentation used to recommend reading "UNIX Network Programming" if you wanted to write TCP/IP programms on Windows.
    • The points in parent comment are certainly valid, but dive in a little deeper, and it looks less promising.

      • Try messing with socket options or fcntl stuff. getsockopt/setsockopt are reasonably in order, but insists on having its value as a *char. This means that code from *nix will not automatically compile on Windows - if you use a C++ compiler anyway (pointer types are not compatible). Variants of fcntl for Winsock exists, but do NOT work anything like fcntl (and they shouldn't - sockets on Windows are N
  • how can the publishers get away with selling this book for 70$? the usual excuse for technical books being expensive is that they do not sell in large quantities, but that does not apply for this one. and it is the 3rd edition. and the last review consisted mainly in removing content...

    • This is not a technical book per se, but rather a textbook. The difference is... well... depending on the book, $20-70. And of course, each edition tacks on about $5.

      But seriously... textbooks tend to be alot more thorough and dense than X in 21 days or even oreilly type books. You are not going to be able to read this in a casual manner. He is actually alot more readable than most books of this nature, but still, its a textbook nonetheless.
      • The spine and binding of a textbook are different than those found on your typical bestseller. Textbook bindings are designed to withstand much more use and/or abuse. That in itself accounts for some of the added cost. Plus, no matter how popular this book is, it still doesn't sell in the quantities that, say, the latest John Grisham or J. K. Rowling novel does.
  • Shame nobody stopped to mention that Rich Stevens passed away in 1999.

    -psy
    • Actually, the review does contain a link to a usenet announcement on Deja that was sent on the 4th of September, just days after his passing, presumably by one of his colleagues. From the thread itself, it sounded like he contributed much to his field of work and to the lives of people around him. He will be missed.
    • Did you read the review? You know, where the reviewer said "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." (with a link even) Ok, they didn't mention that it was 1999, but can you explain what is particularly relevant about that?
  • It has been years since I read this in college. I kept the book, and it is *somewhere*. Very useful. Very good for understanding how TCP/IP works because of the programming examples.

    The most useless part? The portmapper and the r* commands. Why? Because, IMHO, the portmapper really is a stupid service in the modern world (aside from protocols which now depend on it). Almost nobody in their right mind makes those kind of services. But I suppose, for completeness sake, I'm glad it was in there.
  • Sounds exactly like a book I would like to buy.

    Good job on another quality book review /.
  • Undoubtedly one of the best technical books that has ever been written. From the review: perhaps donating the 2nd edition to the local church library can wait. Also, if you happen to have the first edition of the book (or if you happen to lay your hands on one) don't give it away either. (Note: UNIX Network Programming, first edition was only a single volume edition). The first edition had an entire chapter on printer spooler application, which was not included in the second edition. (Please correct me i
    • 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 =)
  • When i first saw the article, I thought - finally, the third volume. There were some rummors that Gary Wright, that was co-author in TCP/IP Illustrated Vol.2, was going to finish UNP vol.3....

    I'd love to get this third edition, though... I was used to read UNPv1 before going to bed ... :)
  • by Micah ( 278 )
    Or you could just use Twisted [twistedmatrix.com] and make it relatively easy ...
  • I use the book at work. Its been very very helpful. However its not for those new to programming, as it not always the clearest book although the most comprehensive I've found.

    I also don't like his examples, which tend to use his own libraries which makes them more confusing.

    Note that Vol II is IPC and is similarly useful/ challenging.

  • Or in ebook? I'd love to have it with me all the time sans lugging the big book around. I'd gladly pay for the ebook.
  • ... if this book is a SCO-code-free product... you can never be sure!
  • Repeat! (Score:3, Informative)

    by tibbetts ( 7769 ) <jason@@@tibbetts...net> on Monday December 08, 2003 @04:59PM (#7662327) Homepage Journal

    This book was already reviewed [slashdot.org] on Slashdot.

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

  • In a nutshell: Unix Network Programming is a must for anyone involved in writing network-enabled clients or server applications

    I thought the publisher was Addison-Whatever, not O'Reilly?

  • Heres an interesting article [salon.com]
    about Stevens over at Salon.
  • Sorry y'all, but Stevens goofed with this series. He goes over bunches of "upcoming" APIs that just never up and came. Named semaphores? Really? What implementation of UNIX do <i>you</i> know with named semaphores? Come on. The last Stevens book on UNIX IPC and Sockets <i>programming</i> that's pretty universal is APUE.

    But even his collection of vaporware APIs is not my biggest problem with this series. It's too long. Far too long. You buy it and think "wow, it's big, I've

"If it ain't broke, don't fix it." - Bert Lantz

Working...