Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is AF_INET, and why do I need it?

Tags:

sockets

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?
like image 572
Smashery Avatar asked Oct 20 '09 11:10

Smashery


People also ask

Why do we use Af_inet?

For the most part sticking with AF_INET for socket programming over a network is the safest option. Meaning, AF_INET refers to addresses from the internet, IP addresses specifically.

What does Af_inet mean?

AF_INET refers to Address from the Internet and it requires a pair of (host, port) where the host can either be a URL of some particular website or its address and the port number is an integer.

What is Af_inet Python?

AF_INET is the Internet address family for IPv4. SOCK_STREAM is the socket type for TCP, the protocol that will be used to transport messages in the network. The . bind() method is used to associate the socket with a specific network interface and port number: # echo-server.py # ... with socket.

What is the use of Sock_stream?

SOCK_STREAM : Provides sequenced, two-way byte streams with a transmission mechanism for stream data. This socket type transmits data on a reliable basis, in order, and with out-of-band capabilities. In the UNIX domain [ AF_UNIX ], the SOCK_STREAM socket type works like a pipe.


1 Answers

AF_INET is an address family that is used to designate the type of addresses that your socket can communicate with (in this case, Internet Protocol v4 addresses). When you create a socket, you have to specify its address family, and then you can only use addresses of that type with the socket. The Linux kernel, for example, supports 29 other address families such as UNIX (AF_UNIX) sockets and IPX (AF_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. There is also AF_INET6 for Internet Protocol v6 addresses.

Hope this helps,

like image 129
George Shore Avatar answered Sep 28 '22 07:09

George Shore