tags:

views:

145

answers:

2

So I'm getting started on socket programming, and I keep seeing this AF_INET. Yet, I've never seen anything else used in its place. My lecturers are not that helpful, and just say "You just need it". So my questions:

  • What is the purpose of AF_INET?
  • Is anything else ever used instead of it?
    • If not, why is it there? For possible changes in the future?
    • If so, what and why?
+5  A: 

The primary purpose of AF_INET was to allow for other possible network protocols or address families (AF is for address family; PF_INET is for the (IPv4) internet protocol family). For example, there probably are a few Netware SPX/IPX networks around still; there were other network systems like DECNet, StarLAN and SNA, not to mention the ill-begotten ISO OSI (Open Systems Interconnection), and these did not necessarily use the now ubiquitous IP address to identify the peer host in network connections.

The ubiquitous alternative to AF_INET (which, in retrospect, should have been named AF_INET4) is AF_INET6, for the IPv6 address family. IPv4 uses 32-bit addresses; IPv6 uses 128-bit addresses.

You may see some other values - but they are unusual. It is there to allow for alternatives and future directions. The sockets interface is actually very general indeed - which is one of the reasons it has thrived where other networking interfaces have withered.

Life has (mostly) gotten simpler - be grateful.

Jonathan Leffler
Thanks for your response - I'm deducing that your answer to my first question is that its purpose is to define what network protocol to use? Could you please be more specific on the other questions, though?
Smashery
Good point about AF_INET6; other address families are supported on some OSs.
MarkR
+1 Thanks for your clarification!
Smashery
+4  A: 

Hi,

AF_INET is the address family that is used for the socket you're creating (in this case an Internet Protocol address). The Linux kernel, for example, supports 29 other address families such as UNIX sockets and IPX, and also communications with IRDA and Bluetooth (AF_IRDA and AF_BLUETOOTH, but it is doubtful you'll use these at such a low level).

For the most part sticking with AF_INET for socket programming over a network is the safest option.

Hope this helps,

George Shore