Which Unix-like system really provides the /dev/tcp special file?












9















I know /dev/tcp/<host>/<port> is a magic path handled specifically by some shells in redirections. But according to man bash:




If the operating system on which bash is running provides these special files, bash will use them; otherwise it will emulate them internally
[...]




On the Linux box I am using right now, the /dev/tcp special file is not present, so the Bash will emulate it. But, is there actually a Unix-like system that does provide the /dev/tcp special file with the same semantic as the one supported by the Bash?










share|improve this question























  • It would require an emulated directory. Making emulated directories is possible only with specific filesystems, for example procfs or sysfs can do that. /dev is a tmpfs on current linuxes, and it was on the root partition in older ones. This is why it is impossible currently. It could be made possible easily with a sysfs or procfs extension (both fs are very flexible and similar (actually probably no one knows why they aren't the same)), no one does it today, but it could be made in around 100 lines of code.

    – peterh
    Jan 14 at 11:58













  • But is there any other OS that does it already? At some point, I thought Plan 9 did it but I was wrong.

    – Sylvain Leroux
    Jan 14 at 12:42






  • 1





    I don't know, probably not (as far I know, it is a bash invention). I voted your question up, because the answer is interesting also to me. As far I know, no popular x86-capable unix OS can do this.

    – peterh
    Jan 14 at 12:44


















9















I know /dev/tcp/<host>/<port> is a magic path handled specifically by some shells in redirections. But according to man bash:




If the operating system on which bash is running provides these special files, bash will use them; otherwise it will emulate them internally
[...]




On the Linux box I am using right now, the /dev/tcp special file is not present, so the Bash will emulate it. But, is there actually a Unix-like system that does provide the /dev/tcp special file with the same semantic as the one supported by the Bash?










share|improve this question























  • It would require an emulated directory. Making emulated directories is possible only with specific filesystems, for example procfs or sysfs can do that. /dev is a tmpfs on current linuxes, and it was on the root partition in older ones. This is why it is impossible currently. It could be made possible easily with a sysfs or procfs extension (both fs are very flexible and similar (actually probably no one knows why they aren't the same)), no one does it today, but it could be made in around 100 lines of code.

    – peterh
    Jan 14 at 11:58













  • But is there any other OS that does it already? At some point, I thought Plan 9 did it but I was wrong.

    – Sylvain Leroux
    Jan 14 at 12:42






  • 1





    I don't know, probably not (as far I know, it is a bash invention). I voted your question up, because the answer is interesting also to me. As far I know, no popular x86-capable unix OS can do this.

    – peterh
    Jan 14 at 12:44
















9












9








9


1






I know /dev/tcp/<host>/<port> is a magic path handled specifically by some shells in redirections. But according to man bash:




If the operating system on which bash is running provides these special files, bash will use them; otherwise it will emulate them internally
[...]




On the Linux box I am using right now, the /dev/tcp special file is not present, so the Bash will emulate it. But, is there actually a Unix-like system that does provide the /dev/tcp special file with the same semantic as the one supported by the Bash?










share|improve this question














I know /dev/tcp/<host>/<port> is a magic path handled specifically by some shells in redirections. But according to man bash:




If the operating system on which bash is running provides these special files, bash will use them; otherwise it will emulate them internally
[...]




On the Linux box I am using right now, the /dev/tcp special file is not present, so the Bash will emulate it. But, is there actually a Unix-like system that does provide the /dev/tcp special file with the same semantic as the one supported by the Bash?







devices tcp character-special-files






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 14 at 11:25









Sylvain LerouxSylvain Leroux

478212




478212













  • It would require an emulated directory. Making emulated directories is possible only with specific filesystems, for example procfs or sysfs can do that. /dev is a tmpfs on current linuxes, and it was on the root partition in older ones. This is why it is impossible currently. It could be made possible easily with a sysfs or procfs extension (both fs are very flexible and similar (actually probably no one knows why they aren't the same)), no one does it today, but it could be made in around 100 lines of code.

    – peterh
    Jan 14 at 11:58













  • But is there any other OS that does it already? At some point, I thought Plan 9 did it but I was wrong.

    – Sylvain Leroux
    Jan 14 at 12:42






  • 1





    I don't know, probably not (as far I know, it is a bash invention). I voted your question up, because the answer is interesting also to me. As far I know, no popular x86-capable unix OS can do this.

    – peterh
    Jan 14 at 12:44





















  • It would require an emulated directory. Making emulated directories is possible only with specific filesystems, for example procfs or sysfs can do that. /dev is a tmpfs on current linuxes, and it was on the root partition in older ones. This is why it is impossible currently. It could be made possible easily with a sysfs or procfs extension (both fs are very flexible and similar (actually probably no one knows why they aren't the same)), no one does it today, but it could be made in around 100 lines of code.

    – peterh
    Jan 14 at 11:58













  • But is there any other OS that does it already? At some point, I thought Plan 9 did it but I was wrong.

    – Sylvain Leroux
    Jan 14 at 12:42






  • 1





    I don't know, probably not (as far I know, it is a bash invention). I voted your question up, because the answer is interesting also to me. As far I know, no popular x86-capable unix OS can do this.

    – peterh
    Jan 14 at 12:44



















It would require an emulated directory. Making emulated directories is possible only with specific filesystems, for example procfs or sysfs can do that. /dev is a tmpfs on current linuxes, and it was on the root partition in older ones. This is why it is impossible currently. It could be made possible easily with a sysfs or procfs extension (both fs are very flexible and similar (actually probably no one knows why they aren't the same)), no one does it today, but it could be made in around 100 lines of code.

– peterh
Jan 14 at 11:58







It would require an emulated directory. Making emulated directories is possible only with specific filesystems, for example procfs or sysfs can do that. /dev is a tmpfs on current linuxes, and it was on the root partition in older ones. This is why it is impossible currently. It could be made possible easily with a sysfs or procfs extension (both fs are very flexible and similar (actually probably no one knows why they aren't the same)), no one does it today, but it could be made in around 100 lines of code.

– peterh
Jan 14 at 11:58















But is there any other OS that does it already? At some point, I thought Plan 9 did it but I was wrong.

– Sylvain Leroux
Jan 14 at 12:42





But is there any other OS that does it already? At some point, I thought Plan 9 did it but I was wrong.

– Sylvain Leroux
Jan 14 at 12:42




1




1





I don't know, probably not (as far I know, it is a bash invention). I voted your question up, because the answer is interesting also to me. As far I know, no popular x86-capable unix OS can do this.

– peterh
Jan 14 at 12:44







I don't know, probably not (as far I know, it is a bash invention). I voted your question up, because the answer is interesting also to me. As far I know, no popular x86-capable unix OS can do this.

– peterh
Jan 14 at 12:44












1 Answer
1






active

oldest

votes


















8














I think the Bash documentation is somewhat misleading on this topic. Looking at the code, even going back to version 2.04 where network redirections were introduced, /dev/tcp and /dev/udp works as follows:




  • at build time, the configure script checks to see whether various networking features are supported; if so, if network redirections are enabled (which is the case by default), internal networking code is built in;

  • at run time, if the internal networking code is built in, /dev/tcp and /dev/udp (in the right format) are handled internally; otherwise, a warning is produced (“/dev/(tcp|udp)/host/port not supported without networking”) and Bash attempts to open the given path on the system;

  • if network redirections are configured out, nothing special is done.


What this boils down to is:




  • if network redirection is enabled:


    • if networking is supported on the target platform, /dev/tcp and /dev/udp will always be handled internally;

    • otherwise, Bash will warn and try to open the file “blindly”; if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail;



  • if network redirection is disabled, no special handling is performed; as above, if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail.


/dev/tcp does exist on some systems, but as far as I’m aware none support the same abstraction as Bash. On Solaris, /dev/tcp is used with the ndd tool to query and change network configuration. In XTI (see also the Open Group if you’re a member), the t_open function can be used with /dev/tcp to open a TCP connection, but it doesn’t use path-based setup, there’s a separate data structure to specify the target host and port (and other parameters).






share|improve this answer
























  • The feature itself comes from ksh93. /dev/tcp on SysV systems would be a handle on the STREAMS tcp module.

    – Stéphane Chazelas
    Jan 14 at 17:00











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494389%2fwhich-unix-like-system-really-provides-the-dev-tcp-special-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









8














I think the Bash documentation is somewhat misleading on this topic. Looking at the code, even going back to version 2.04 where network redirections were introduced, /dev/tcp and /dev/udp works as follows:




  • at build time, the configure script checks to see whether various networking features are supported; if so, if network redirections are enabled (which is the case by default), internal networking code is built in;

  • at run time, if the internal networking code is built in, /dev/tcp and /dev/udp (in the right format) are handled internally; otherwise, a warning is produced (“/dev/(tcp|udp)/host/port not supported without networking”) and Bash attempts to open the given path on the system;

  • if network redirections are configured out, nothing special is done.


What this boils down to is:




  • if network redirection is enabled:


    • if networking is supported on the target platform, /dev/tcp and /dev/udp will always be handled internally;

    • otherwise, Bash will warn and try to open the file “blindly”; if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail;



  • if network redirection is disabled, no special handling is performed; as above, if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail.


/dev/tcp does exist on some systems, but as far as I’m aware none support the same abstraction as Bash. On Solaris, /dev/tcp is used with the ndd tool to query and change network configuration. In XTI (see also the Open Group if you’re a member), the t_open function can be used with /dev/tcp to open a TCP connection, but it doesn’t use path-based setup, there’s a separate data structure to specify the target host and port (and other parameters).






share|improve this answer
























  • The feature itself comes from ksh93. /dev/tcp on SysV systems would be a handle on the STREAMS tcp module.

    – Stéphane Chazelas
    Jan 14 at 17:00
















8














I think the Bash documentation is somewhat misleading on this topic. Looking at the code, even going back to version 2.04 where network redirections were introduced, /dev/tcp and /dev/udp works as follows:




  • at build time, the configure script checks to see whether various networking features are supported; if so, if network redirections are enabled (which is the case by default), internal networking code is built in;

  • at run time, if the internal networking code is built in, /dev/tcp and /dev/udp (in the right format) are handled internally; otherwise, a warning is produced (“/dev/(tcp|udp)/host/port not supported without networking”) and Bash attempts to open the given path on the system;

  • if network redirections are configured out, nothing special is done.


What this boils down to is:




  • if network redirection is enabled:


    • if networking is supported on the target platform, /dev/tcp and /dev/udp will always be handled internally;

    • otherwise, Bash will warn and try to open the file “blindly”; if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail;



  • if network redirection is disabled, no special handling is performed; as above, if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail.


/dev/tcp does exist on some systems, but as far as I’m aware none support the same abstraction as Bash. On Solaris, /dev/tcp is used with the ndd tool to query and change network configuration. In XTI (see also the Open Group if you’re a member), the t_open function can be used with /dev/tcp to open a TCP connection, but it doesn’t use path-based setup, there’s a separate data structure to specify the target host and port (and other parameters).






share|improve this answer
























  • The feature itself comes from ksh93. /dev/tcp on SysV systems would be a handle on the STREAMS tcp module.

    – Stéphane Chazelas
    Jan 14 at 17:00














8












8








8







I think the Bash documentation is somewhat misleading on this topic. Looking at the code, even going back to version 2.04 where network redirections were introduced, /dev/tcp and /dev/udp works as follows:




  • at build time, the configure script checks to see whether various networking features are supported; if so, if network redirections are enabled (which is the case by default), internal networking code is built in;

  • at run time, if the internal networking code is built in, /dev/tcp and /dev/udp (in the right format) are handled internally; otherwise, a warning is produced (“/dev/(tcp|udp)/host/port not supported without networking”) and Bash attempts to open the given path on the system;

  • if network redirections are configured out, nothing special is done.


What this boils down to is:




  • if network redirection is enabled:


    • if networking is supported on the target platform, /dev/tcp and /dev/udp will always be handled internally;

    • otherwise, Bash will warn and try to open the file “blindly”; if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail;



  • if network redirection is disabled, no special handling is performed; as above, if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail.


/dev/tcp does exist on some systems, but as far as I’m aware none support the same abstraction as Bash. On Solaris, /dev/tcp is used with the ndd tool to query and change network configuration. In XTI (see also the Open Group if you’re a member), the t_open function can be used with /dev/tcp to open a TCP connection, but it doesn’t use path-based setup, there’s a separate data structure to specify the target host and port (and other parameters).






share|improve this answer













I think the Bash documentation is somewhat misleading on this topic. Looking at the code, even going back to version 2.04 where network redirections were introduced, /dev/tcp and /dev/udp works as follows:




  • at build time, the configure script checks to see whether various networking features are supported; if so, if network redirections are enabled (which is the case by default), internal networking code is built in;

  • at run time, if the internal networking code is built in, /dev/tcp and /dev/udp (in the right format) are handled internally; otherwise, a warning is produced (“/dev/(tcp|udp)/host/port not supported without networking”) and Bash attempts to open the given path on the system;

  • if network redirections are configured out, nothing special is done.


What this boils down to is:




  • if network redirection is enabled:


    • if networking is supported on the target platform, /dev/tcp and /dev/udp will always be handled internally;

    • otherwise, Bash will warn and try to open the file “blindly”; if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail;



  • if network redirection is disabled, no special handling is performed; as above, if the system somehow supports /dev/(tcp|udp)/host/port, that will be used, otherwise in all likelihood the redirection will fail.


/dev/tcp does exist on some systems, but as far as I’m aware none support the same abstraction as Bash. On Solaris, /dev/tcp is used with the ndd tool to query and change network configuration. In XTI (see also the Open Group if you’re a member), the t_open function can be used with /dev/tcp to open a TCP connection, but it doesn’t use path-based setup, there’s a separate data structure to specify the target host and port (and other parameters).







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 14 at 13:27









Stephen KittStephen Kitt

172k24386464




172k24386464













  • The feature itself comes from ksh93. /dev/tcp on SysV systems would be a handle on the STREAMS tcp module.

    – Stéphane Chazelas
    Jan 14 at 17:00



















  • The feature itself comes from ksh93. /dev/tcp on SysV systems would be a handle on the STREAMS tcp module.

    – Stéphane Chazelas
    Jan 14 at 17:00

















The feature itself comes from ksh93. /dev/tcp on SysV systems would be a handle on the STREAMS tcp module.

– Stéphane Chazelas
Jan 14 at 17:00





The feature itself comes from ksh93. /dev/tcp on SysV systems would be a handle on the STREAMS tcp module.

– Stéphane Chazelas
Jan 14 at 17:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494389%2fwhich-unix-like-system-really-provides-the-dev-tcp-special-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory