PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 2, 2022

[FIXED] How to create a TCP-IP named socket file in Unix?

 November 02, 2022     file, sockets, unix     No comments   

Issue

I found out that, under 'everything is a file' philosophy in Unix, even sockets are considered as files, and can be stored in a path in file system. So, I was trying to create a TCP-IP socket file out of curiosity.

This answer shows how to create a named Unix domain socket file. But struct sockaddr_in doesn't have sin_path field. So I have no idea how to create a named TCP-IP socket file. Can anyone tell me how to do this?


Solution

... even sockets are considered as files, and can be stored in a path in file system.

Not really. There are some sockets where the endpoint is represented by a file. These are UNIX domain sockets (AF_UNIX) and their is a variant which has a message semantic (SOCK_DGRAM) similar to UDP and one which has a stream semantic (SOCK_STREAM) similar to TCP.

But, UDP and TCP sockets have a no file representation in UNIX. They have a file descriptor though similar to normal files (and read and write system calls work with these), but they are not represented by a path in the file system.

There is also something like /dev/tcp/.. to deal with sockets inside the bash shell. But this is not an actual path on the file system either, but only a fancy syntax specific to the bash shell.

For more on this see also Wikipedia: Everything is a file which specifically notes:

... Therefore, a more accurate description of this feature is Everything is a file descriptor.



Answered By - Steffen Ullrich
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing