Home > Enterprise >  Is a network socket an API or a REGISTRY?
Is a network socket an API or a REGISTRY?

Time:06-14

I'm studying about network sockets, but unfortunately I couldn't understand if the so-called sockets are DATA or API...

I'm more tempted to believe that a network socket is a kernel-level object that serves as an in-memory register containing data that associates a process with another process to allow communication, and that register (socket network) has data that describes the type of communication that must be performed by the kernel. Some of the information that exists in this type of record that we call a network socket is an IP address, port number, an identifier and etc... So I believe that the kernel uses this dataset (socket) to make the connection. Note that my definition is different from saying that "network sockets are an API", because in my view they are more for data than for a programming interface instance. I would like to know if my definition makes sense or am I misunderstanding this concept?

CodePudding user response:

I'm not sure if i understand well your question.

  • a network socket is more related to IPC (Inter-Process Communications) mechanisms.what is an IPC? (wikipedia). So it rely on the same principle than pipes, named pipes, shared memory etc... but act differently.

  • The way it is implemented is very dependant of the OS you are looking at. It mainly rely on kernel functions (C programming language for Linux -> see here) involving dedicated data spaces and buffers. The data space and buffer allocation is made in the same way than when you declare a string=helloworld (or more complex structures) when writing an executable in C.

  • Modern operating systems does provides upper-level interfaces for manipulating those functions (i.e opening a socket). You may call it API, but the rest of the world is calling it: SYSTEM CALLS

Hope it helps. :)

EDIT (On linux systems):

In userland (ring 3), when process open a socket, it makes calls to linux API for network/sockets, and this API (system calls), rely on kernel functions (ring 0).

Those kernel functions are C classes, storing related data in a reserved memory (as C objects).

  • So for userland: the sockets are API.
  • for kernel: sockets are DATA structures.

there is also executable code coming from static functions in the TCP/IP stack and drivers executed by the kernel point of view...and relying on the data structures created from the API system calls (from the userland)

Is it clearer? ahah ;).

  • Related