views:

205

answers:

3

Everyone referred to it as Socket Programming or Network Programming in C and we started using it by using by including sys/socket.h & netinet/in.h. We thought it was 100% true. But question raised in my mind when I saw this book

Internetworking With TCP/IP Volume III: Client-Server Programming and Applications, which was available in 4 different versions

  1. Linux/POSIX Sockets
  2. AT&T TLI (Transport Layer Interface) Sockets
  3. BSD (Berkeley) sockets
  4. Window Sockets

I'm confused. This clearly shows that there is no standard for Socket API.

also I'm surprised to see sys/socket.h & netinet/in.h which are part of POSIX C library in the http://en.wikipedia.org/wiki/Berkeley_sockets . I'm more confused now.

  1. Why isn't there a standard for this?
  2. What more socket APIs are available?
  3. What are the differences between each of these Socket API?
  4. When People say Just "Network Programming in C" / "Socket Programming" what exactly they are referring to?
  5. Links for any further information?
+2  A: 

The Linux, BSD, and Windows sockets APIs (at least; I don't know about the AT&T TLI API) are pretty similar to each other. The Windows API, for example, is/was originally based on the BSD API.

ChrisW
Yep, 4 different names doesn't actually mean 4 completely different implementations. At least with the 3 you mention, it's pretty much the same thing with a few platform-specific quirks.
Kylotan
+2  A: 

Why isn't there a standard for this?

There are. You named several. Anyone can publish a "standard", there doesn't need to be just one nor is there some controlling authority with the power to confer "The One True Way". In terms of networking the real standards are the network protocols themselves. Everyone must inter-operate with them or nothing works together. How any given platform implements the APIs to accomplish that goal can vary.

What are the differences between each of these Socket API?

Linux/POSIX/BSD are all similar. Windows is a little different but since it still has to support the underlying protocols the functionality ends up being pretty much the same. Honestly I am not sure who uses AT&T TLI anymore, if they ever did.

What more socket APIs are available?

There are probably plenty but it is a question of who uses them anymore. IBM used to have a bunch and so did most every other major manufacturer back in the day. But I think these for have for the most part been retired to the history dust bin since most everyone uses TCP.

When People say Just "Network Programming in C" / "Socket Programming" what exactly they are referring to?

Nothing precise. Technically the C language doesn't know anything about network programming. However many vendors (e.g. Unix, Linux, Windows, etc) provide C libraries to perform networking operations, hence the many APIs you noted above.

Duck
+3  A: 

Why isn't there a standard for this?

The de facto standard is BSD sockets, upon which the Linux, POSIX and Windows sockets APIs are based.

What more socket APIs are available?

Nothing that's still widely used. Before BSD sockets and its derivatives took over the world, there were many. Most of the ones that remain are probably in the embedded world, and even those are going away as mainstream OSes continue to swallow more and more of the embedded market.

This battle was pretty much fought and over by the mid 90's. BSD sockets won.

What are the differences between each of these Socket API?

There are minor differences among the BSD, Linux and POSIX variants, nothing more serious than any other differences among Unixy operating systems.

The reason they have a Linux/POSIX version of the book probably has more to do with marketing than anything technical. It answers a question the publisher probably saw a lot, "Why do I need a BSD book, I'm running Linux, not BSD!" Or, more commonly these days: "What's BSD?"

From a 10,000 foot view, Winsock is very different from BSD sockets, but because it's a fairly strict superset of BSD sockets, you can still move your knowledge over. Most of the differences are pure extensions to BSD sockets, mostly to do with the differences in the Windows kernel architecture and the way Windows programs are typically built. For instance, the first really big extension was asynchronous sockets, which makes it much easier to use sockets in a single-threaded Windows GUI program than using pure BSD sockets. Later extensions support special features available in the NT derived kernels that have no simple analog in Unixy systems, like event objects and overlapped I/O.

For what it's worth, there are extensions to plain old BSD sockets in some Unixy systems, too, like the aio_*() stuff in Solaris and other systems.

If your program has to be source compatible with many systems, you either ignore these differences and program to the common base shared by all these systems, or you build some kind of translation layer that lets you use platform features transparently. Apache does the latter for instance, making use of the fastest networking features on each platform, while the core web server code doesn't care exactly how the networking gets done. Many other programs choose the portable path, since they're not performance critical, and saving programmer time is therefore more important.

When People say Just "Network Programming in C" / "Socket Programming" what exactly they are referring to?

BSD sockets or some variant.

Links for any further information?

The Winsock Programmer's FAQ. Specifically, you might want to look at its resources section, and the FAQ article BSD Sockets Compatibility.

(Disclaimer: I'm the FAQ's maintainer.)

Warren Young