0

I am reading UNIX® Network Programming Volume 1, Third Edition: The Sockets Networking API, and on page 1.7 OSI Model, the authors introduce the "OSI model" and the equivalent "Internet protocol suite".

Looking at the man page for socket(2), I understood that the domain parameter is used to choose the "network" layer, and the type parameter defines the "transport" layer.

If that understanding is correct, what if I use AF_BLUETOOTH on a Wifi data link? I imagine it will not connect to the destination endpoint. So, the programmer must know in advance the data link, in order to set the domain parameter correctly? If he/she uses other BSD functions in order to discover the available data links, how he/she will know which domain value to use? Is there a way to know, while the program is running, which type should be used, based on the data link?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
canellas
  • 491
  • 5
  • 17
  • 1
    A socket in unix-alike sytems is not necessarily a network connector, so the OSI model does not necessarily apply. If you need to send data via Wifi, for example, you´d (probably) choose AF_INET or AF_INET6, then list the available network interfaces and choose the one most applicable. If you were writing some driver to access a bluetooth device´s storage,on the other hand, you´d use AF_BLUETOOTH. – C. Gonzalez Sep 12 '19 at 16:49
  • Thanks, but I think the main question remains: for any data link, which is the right `domain` to be choosen? I believe it exists (or in my mind, it should exist) a table relating data links to `domain`. Does that make sense? – canellas Sep 12 '19 at 17:13
  • That would not be very practical IMO. For example,AF_INET does not care for the datalink (provided the OS has drivers that offer support for IP on several devices), in that sense it is a layer (1 + 2) via device drivers, 3 domain. AF_BLUETOOTH would be a datalink proper, layer 1 + 2. Anyhow, maybe others have different opinions. – C. Gonzalez Sep 12 '19 at 18:57
  • May be I am missing something. The situation I have in mind is this: I wrote a program that will try to establish a connection using, for instance, AF_INET, but the only data link available to the other endpoint is bluetooth. My program would not be able to connect, even though there is a physical link to the other machine. But if I could check which data links are available (this I know it is possible), and based on that, choose the correct `domain` value, then my program would still be able to connect to the other computer. Am I making sense? – canellas Sep 12 '19 at 20:34
  • 2
    If the machine is [tethered](http://www.scaine.net/site/2013/10/ubuntu-to-android-tethering-over-bluetooth/) to, say, a mobile phone via bluetooth, your application doesn´t even need to know that. If, on the other hand, there is no *network* connection available (no WiFi, no tethering etc.) your application should end with an appropriate error message (like a browser does). – C. Gonzalez Sep 12 '19 at 21:11
  • The arguments to `socket` are closely related: first, you choose the domain (say, `AF_INET`), then you must choose type (`SOCK_STREAM`), and protocol (`IPPROTO_TCP`) that are implemented within the domain. You can't arbitrarily match up types/protocols with any domain. Now, multiple domains *can* implement the same type (`SOCK_STREAM` works in both `AF_INET` and `AF_UNIX`), but that's by no means guaranteed. – Gil Hamilton Sep 17 '19 at 22:37
  • ... In theory, one could implement TCP, say, on a network other than IP, but nothing could talk to it other than what you specifically wrote, because TCP's implementation, history and usage is closely tied to IP. One *could* implement an IP *link* over bluetooth (or even an avian carrier, as in https://tools.ietf.org/html/rfc1149), but within applications, `socket` would still be used with `AF_INET{,6}` and `SOCK_STREAM`, etc. And you'd still use IP addresses to identify the peers. (The bluetooth part would be a detail of the network interface -- not visible to the application.) – Gil Hamilton Sep 17 '19 at 22:47

0 Answers0