Linux – /dev/tcp Not Present

clinuxtcp

I am porting C/pro*c code from UNIX to Linux. The code is:

#define __NFDBIT       (8 * sizeof(unsigned long))
#define __FD_SETSIZ    1024
#define __FDSET_LONG   (__FD_SETSIZ/__NFDBIT)
typedef struct {
    unsigned long fds_bits [__FDSET_LONG];
} __ernel_fd_set;

typedef __ernel_fd_set           fd_set_1;
int main()
{
    fd_set_1 listen_set;
    int listen_sd;
    int socket_id;
    FD_ZERO(&listen_set);
    socket_id = t_open("/dev/tcp", O_RDWR|O_NONBLOCK, (struct t_info *) 0);
    if ( socket_id <0 )
    {
        exit(FAILURE);
    }
    return 0;
}

In UNIX the value of socket_id is > 0 in Linux it is -1. Reason is in UNIX, there is a /dev/tcp. This is not present on Linux. Also in UNIX this tcp file is character special file which is different from normal file.

Is there any way to create same character special file in Linux as in UNIX or how to proceed this further?

Best Answer

t_open() and its associated /dev/tcp and such are part of the TLI/XTI interface, which lost the battle for TCP/IP APIs to BSD sockets.

On Linux, there is a /dev/tcp of sorts. It isn't a real file or kernel device. It's something specially provided by Bash, and it exists only for redirections. This means that even if one were to create an in-kernel /dev/tcp facility, it would be masked in interactive use 99%[*] of the time by the shell.

The best solution really is to switch to BSD sockets. Sorry.

You might be able to get the strxnet XTI emulation layer to work, but you're better off putting your time into getting off XTI. It's a dead API, unsupported not just on Linux, but also on the BSDs, including OS X.

(By the way, the strxnet library won't even build on the BSDs, because it depends on LiS, a component of the Linux kernel. It won't even configure on a stock BSD or OS X system, apparently because it also depends on GNU sed.)

[*] I base this wild guess on the fact that Bash is the default shell for non-root users in all Linux distros I've used. You therefore have to go out of your way on Linux, as a rule, to get something other than Bash.

Related Question