/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
static const char usage[] =
"[-?\n@(#)$Id: fds (AT&T Research) 2009-09-09 $\n]"
"[+NAME?fds - list open file descriptor status]"
"[+DESCRIPTION?\bfds\b lists the status for each open file descriptor. "
"When invoked as a shell builtin it accesses the file descriptors of the "
"calling shell, otherwise it lists the file descriptors passed across "
"\bexec\b(2).]"
"[l:long?List file descriptor details.]"
"[u:unit?Write output to \afd\a.]#[fd]"
"[+SEE ALSO?\blogname\b(1), \bwho\b(1), \bgetgroups\b(2), \bgetsockname\b(2), \bgetsockopts\b(2)]"
;
#include <cmd.h>
#include <ls.h>
#if defined(S_IFSOCK) && _sys_socket && _hdr_arpa_inet && _hdr_netinet_in && _lib_getsockname && _lib_getsockopt && _lib_inet_ntoa
#else
#endif
#ifndef minor
#endif
#ifndef major
#endif
#ifdef S_IFSOCK
typedef struct NV_s
{
const char* name;
int value;
} NV_t;
{
#ifdef AF_LOCAL
"pipe", AF_LOCAL,
#endif
#ifdef AF_UNIX
"pipe", AF_UNIX,
#endif
#ifdef AF_FILE
"FILE", AF_FILE,
#endif
#ifdef AF_INET
"INET", AF_INET,
#endif
#ifdef AF_AX25
"AX25", AF_AX25,
#endif
#ifdef AF_IPX
"IPX", AF_IPX,
#endif
#ifdef AF_APPLETALK
"APPLETALK", AF_APPLETALK,
#endif
#ifdef AF_NETROM
"NETROM", AF_NETROM,
#endif
#ifdef AF_BRIDGE
"BRIDGE", AF_BRIDGE,
#endif
#ifdef AF_ATMPVC
"ATMPVC", AF_ATMPVC,
#endif
#ifdef AF_X25
"X25", AF_X25,
#endif
#ifdef AF_INET6
"INET6", AF_INET6,
#endif
#ifdef AF_ROSE
"ROSE", AF_ROSE,
#endif
#ifdef AF_DECnet
"DECnet", AF_DECnet,
#endif
#ifdef AF_NETBEUI
"NETBEUI", AF_NETBEUI,
#endif
#ifdef AF_SECURITY
"SECURITY", AF_SECURITY,
#endif
#ifdef AF_KEY
"KEY", AF_KEY,
#endif
#ifdef AF_NETLINK
"NETLINK", AF_NETLINK,
#endif
#ifdef AF_ROUTE
"ROUTE", AF_ROUTE,
#endif
#ifdef AF_PACKET
"PACKET", AF_PACKET,
#endif
#ifdef AF_ASH
"ASH", AF_ASH,
#endif
#ifdef AF_ECONET
"ECONET", AF_ECONET,
#endif
#ifdef AF_ATMSVC
"ATMSVC", AF_ATMSVC,
#endif
#ifdef AF_SNA
"SNA", AF_SNA,
#endif
#ifdef AF_IRDA
"IRDA", AF_IRDA,
#endif
#ifdef AF_PPPOX
"PPPOX", AF_PPPOX,
#endif
#ifdef AF_WANPIPE
"WANPIPE", AF_WANPIPE,
#endif
#ifdef AF_BLUETOOTH
"BLUETOOTH", AF_BLUETOOTH,
#endif
0
};
#endif
int
{
register char* s;
register int i;
register char* m;
register char* x;
int flags;
int details;
int open_max;
int unit;
#ifdef S_IFSOCK
char* a;
unsigned char* b;
unsigned char* e;
int type;
int port;
int prot;
#ifdef INET6_ADDRSTRLEN
#endif
#endif
details = 0;
unit = 1;
for (;;)
{
{
case 'l':
continue;
case 'u':
continue;
case '?':
break;
case ':':
break;
}
break;
}
if (unit == 1)
for (i = 0; i <= open_max; i++)
{
{
/* not open */
continue;
}
if (!details)
{
continue;
}
m = "--";
else
{
case O_RDONLY:
m = "r-";
break;
case O_WRONLY:
m = "-w";
break;
case O_RDWR:
m = "rw";
break;
default:
m = "??";
break;
}
{
continue;
}
#ifdef S_IFSOCK
{
type = 0;
prot = 0;
#ifdef SO_TYPE
type = -1;
#endif
#ifdef SO_PROTOTYPE
prot = -1;
#endif
s = 0;
switch (type)
{
case SOCK_DGRAM:
switch (addr.sin_family)
{
case AF_INET:
#ifdef AF_INET6
case AF_INET6:
#endif
s = "udp";
break;
}
break;
case SOCK_STREAM:
switch (addr.sin_family)
{
case AF_INET:
#ifdef AF_INET6
case AF_INET6:
#endif
#ifdef IPPROTO_SCTP
if (prot == IPPROTO_SCTP)
s = "sctp";
else
#endif
s = "tcp";
break;
}
break;
#ifdef SOCK_RAW
case SOCK_RAW:
s = "raw";
break;
#endif
#ifdef SOCK_RDM
case SOCK_RDM:
s = "rdm";
break;
#endif
#ifdef SOCK_SEQPACKET
case SOCK_SEQPACKET:
s = "seqpacket";
break;
#endif
}
if (!s)
{
}
port = 0;
#ifdef INET6_ADDRSTRLEN
else
#endif
{
}
else
{
a = fam;
}
if (port)
else
continue;
}
#endif
sfprintf(sp, "%02d %s%s %s /dev/inode/%u/%u\n", i, m, x, fmtmode(st.st_mode, 0), st.st_dev, st.st_ino);
}
{
}
return 0;
}