2 /* Copyright Gerhard Rieger */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* the subroutine filan makes a "FILe descriptor ANalysis". It checks the
6 type of file descriptor and tries to retrieve as much info about it as
7 possible without modifying its state.
8 NOTE: it works on UNIX (kernel) file descriptors, not on libc files! */
11 #include "xioconfig.h" /* what features are enabled */
13 #include "sysincludes.h"
29 static int filan_streams_analyze(int fd
, FILE *outfile
);
31 /* dirty workaround so we dont get an error on AIX when being linked with
33 int allow_severity
, deny_severity
;
35 /* global variables for configuring filan */
36 bool filan_followsymlinks
;
40 int sockoptan(int fd
, const struct sockopt
*optname
, int socklay
, FILE *outfile
);
41 int tcpan(int fd
, FILE *outfile
);
42 const char *getfiletypestring(int st_mode
);
44 static int printtime(FILE *outfile
, time_t time
);
46 static int headprinted
;
48 /* analyse a file system entry, referred by file name */
49 int filan_file(const char *filename
, FILE *outfile
) {
53 struct stat64 buf
= {0};
55 struct stat buf
= {0};
56 #endif /* !HAVE_STAT64 */
58 if (filan_followsymlinks
) {
60 result
= Stat64(filename
, &buf
);
62 result
= Stat(filename
, &buf
);
63 #endif /* !HAVE_STAT64 */
65 Warn3("stat(\"%s\", %p): %s", filename
, &buf
, strerror(errno
));
69 result
= Lstat64(filename
, &buf
);
71 result
= Lstat(filename
, &buf
);
72 #endif /* !HAVE_STAT64 */
74 Warn3("lstat(\"%s\", %p): %s", filename
, &buf
, strerror(errno
));
77 switch (buf
.st_mode
&S_IFMT
) {
79 case S_IFSOCK
: /* probably, it's useless to make a socket and describe it */
84 Open(filename
, O_RDONLY
|O_NOCTTY
|O_NONBLOCK
90 Warn2("open(\"%s\", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE, 0700): %s",
91 filename
, strerror(errno
));
95 result
= filan_stat(&buf
, fd
, -1, outfile
);
100 /* analyze a file descriptor */
101 int filan_fd(int fd
, FILE *outfile
) {
103 struct stat64 buf
= {0};
105 struct stat buf
= {0};
106 #endif /* !HAVE_STAT64 */
109 Debug1("checking file descriptor %u", fd
);
111 result
= Fstat64(fd
, &buf
);
113 result
= Fstat(fd
, &buf
);
114 #endif /* !HAVE_STAT64 */
116 if (errno
== EBADF
) {
117 Debug2("fstat(%d): %s", fd
, strerror(errno
));
119 Warn2("fstat(%d): %s", fd
, strerror(errno
));
123 Debug2("fd %d is a %s", fd
, getfiletypestring(buf
.st_mode
));
125 result
= filan_stat(&buf
, fd
, fd
, outfile
);
128 /* even more dynamic info */
129 { /* see if data is available */
132 ufds
.events
= POLLIN
|POLLPRI
|POLLOUT
147 if (Poll(&ufds
, 1, 0) < 0) {
148 Warn4("poll({%d, %hd, %hd}, 1, 0): %s",
149 ufds
.fd
, ufds
.events
, ufds
.revents
, strerror(errno
));
151 fputs("poll: ", outfile
);
152 if (ufds
.revents
& POLLIN
) fputs("IN,", outfile
);
153 if (ufds
.revents
& POLLPRI
) fputs("PRI,", outfile
);
154 if (ufds
.revents
& POLLOUT
) fputs("OUT,", outfile
);
155 if (ufds
.revents
& POLLERR
) fputs("ERR,", outfile
);
156 if (ufds
.revents
& POLLNVAL
) fputs("NVAL,", outfile
);
158 if (ufds
.revents
& POLLIN
) {
160 if ((result
= Ioctl(fd
, FIONREAD
, &sizet
) >= 0)) {
161 fprintf (outfile
, "; FIONREAD="F_Zu
, sizet
);
164 #endif /* defined(FIONREAD) */
165 #if _WITH_SOCKET && defined(MSG_DONTWAIT)
166 if ((ufds
.revents
& POLLIN
) && isasocket(fd
)) {
167 char _peername
[SOCKADDR_MAX
];
168 struct sockaddr
*pa
= (struct sockaddr
*)_peername
;
169 struct msghdr msgh
= {0};
170 char peekbuff
[1]; /* [0] fails with some compilers */
171 #if HAVE_STRUCT_IOVEC
177 fputs("; ", outfile
);
179 msgh
.msg_namelen
= sizeof(*pa
);
180 #if HAVE_STRUCT_IOVEC
181 iovec
.iov_base
= peekbuff
;
182 iovec
.iov_len
= sizeof(peekbuff
);
183 msgh
.msg_iov
= &iovec
;
186 #if HAVE_STRUCT_MSGHDR_MSGCONTROL
187 msgh
.msg_control
= ctrlbuff
;
189 #if HAVE_STRUCT_MSGHDR_MSGCONTROLLEN
190 msgh
.msg_controllen
= sizeof(ctrlbuff
);
192 #if HAVE_STRUCT_MSGHDR_MSGFLAGS
195 if ((bytes
= Recvmsg(fd
, &msgh
, MSG_PEEK
|MSG_DONTWAIT
)) < 0) {
196 Warn1("recvmsg(): %s", strerror(errno
));
198 fprintf(outfile
, "recvmsg="F_Zd
", ", bytes
);
201 #endif /* _WITH_SOCKET && defined(MSG_DONTWAIT) */
205 fputc('\n', outfile
);
215 #endif /* !HAVE_STAT64 */
216 , int statfd
, int dynfd
, FILE *outfile
) {
221 if (filan_rawoutput
) {
222 fputs(" FD type\tdevice\tinode\tmode\tlinks\tuid\tgid"
233 "\tatime\t\tmtime\t\tctime\t\tcloexec\tflags"
234 #if defined(F_GETOWN)
238 } else /* !rawoutput */ {
239 fputs(" FD type\tdevice\tinode\tmode\tlinks\tuid\tgid"
250 "\tatime\t\t\t\tmtime\t\t\t\tctime\t\t\t\tcloexec\tflags"
251 #if defined(F_GETOWN)
256 } /* endif !rawoutput */
258 #if defined(F_GETSIG)
259 fputs("\tsigio", outfile
);
260 #endif /* defined(F_GETSIG) */
261 fputc('\n', outfile
);
264 if (filan_rawoutput
) {
265 snprintf(stdevstr
, 8, F_dev
, buf
->st_dev
);
267 snprintf(stdevstr
, 8, "%hu,%hu", (unsigned short)(buf
->st_dev
>>8), (unsigned short)(buf
->st_dev
&0xff));
269 fprintf(outfile
, "%4d: %s\t%s\t"
274 #endif /* HAVE_STAT64 */
275 "\t"F_mode
"\t"F_st_nlink
"\t"F_uid
"\t"F_gid
284 #endif /* HAVE_STAT64 */
293 #endif /* HAVE_STAT64 */
296 (dynfd
>=0?dynfd
:statfd
), getfiletypestring(buf
->st_mode
),
299 buf
->st_mode
, buf
->st_nlink
, buf
->st_uid
,
302 (unsigned short)(buf
->st_rdev
>>8), (unsigned short)(buf
->st_rdev
&0xff),
309 , buf
->st_blocks
/* on Linux, this applies to stat and stat64 */
313 printtime(outfile
, buf
->st_atime
);
314 printtime(outfile
, buf
->st_mtime
);
315 printtime(outfile
, buf
->st_ctime
);
319 fputc('\t', outfile
);
320 time
= asctime(localtime(&buf
->st_mtime
));
321 if (strchr(time
, '\n')) *strchr(time
, '\n') = '\0';
322 fputs(time
, outfile
);
324 fputc('\t', outfile
);
325 time
= asctime(localtime(&buf
->st_ctime
));
326 if (strchr(time
, '\n')) *strchr(time
, '\n') = '\0';
327 fputs(time
, outfile
);
331 /* here comes dynamic info - it is only meaningful with preexisting FDs */
332 if (dynfd
>= 0) { /*!indent */
334 #if defined(F_GETOWN)
337 #if defined(F_GETSIG)
339 #endif /* defined(F_GETSIG) */
341 cloexec
= Fcntl(dynfd
, F_GETFD
);
342 flags
= Fcntl(dynfd
, F_GETFL
);
343 #if defined(F_GETOWN)
344 sigown
= Fcntl(dynfd
, F_GETOWN
);
346 #if defined(F_GETSIG)
347 sigio
= Fcntl(dynfd
, F_GETSIG
);
348 #endif /* defined(F_GETSIG) */
349 fprintf(outfile
, "\t%d\tx%06x", cloexec
, flags
);
350 #if defined(F_GETOWN)
351 fprintf(outfile
, "\t%d", sigown
);
353 #if defined(F_GETSIG)
354 fprintf(outfile
, "\t%d", sigio
);
355 #endif /* defined(F_GETSIG) */
358 #if defined(F_GETOWN)
361 #if defined(F_GETSIG)
363 #endif /* defined(F_GETSIG) */
367 /* ever heard of POSIX streams? here we handle these */
368 filan_streams_analyze(statfd
, outfile
);
370 /* now see for type specific infos */
371 if (statfd
>= 0) { /*!indent */
372 switch (buf
->st_mode
&S_IFMT
) {
373 case (S_IFIFO
): /* 1, FIFO */
375 case (S_IFCHR
): /* 2, character device */
376 cdevan(statfd
, outfile
);
378 case (S_IFDIR
): /* 4, directory */
380 case (S_IFBLK
): /* 6, block device */
382 case (S_IFREG
): /* 8, regular file */
384 case (S_IFLNK
): /* 10, symbolic link */
387 case (S_IFSOCK
): /* 12, socket */
389 sockan(statfd
, outfile
);
391 Warn("SOCKET support not compiled in");
393 #endif /* !_WITH_SOCKET */
395 #endif /* S_IFSOCK */
407 result
= Fcntl(fd
, F_GETFD
);
408 fcntl(fd
, F_GETFL
, );
409 fcntl(fd
, F_GETLK
, );
411 fcntl(fd
, F_GETOWN
, );
414 fcntl(fd
, F_GETSIG
, );
419 int devinfo(int fd
) {
425 /* returns 0 on success (not a stream descriptor, or no module)
426 returns <0 on failure */
427 static int filan_streams_analyze(int fd
, FILE *outfile
) {
429 # define SL_NMODS 8 /* max number of module names we can store */
430 struct str_list modnames
;
433 if (!isastream(fd
)) {
434 fprintf(outfile
, "\t(no STREAMS modules)");
437 #if 0 /* uncomment for debugging */
438 fprintf(outfile
, "\tfind=%d", ioctl(fd
, I_FIND
, "ldterm"));
440 modnames
.sl_nmods
= ioctl(fd
, I_LIST
, 0);
441 if (modnames
.sl_nmods
< 0) {
442 fprintf(stderr
, "ioctl(%d, I_LIST, 0): %s\n", fd
, strerror(errno
));
445 modnames
.sl_modlist
= Malloc(modnames
.sl_nmods
*(sizeof(struct str_mlist
)));
446 if (modnames
.sl_modlist
== NULL
) {
447 fprintf(stderr
, "out of memory\n");
450 if (ioctl(fd
, I_LIST
, &modnames
) < 0) {
451 fprintf(stderr
, "ioctl(%d, I_LIST, %p): %s\n",
452 fd
, &modnames
, strerror(errno
));
453 free(modnames
.sl_modlist
);
456 fprintf(outfile
, "\tSTREAMS: ");
457 for (i
= 0; i
< modnames
.sl_nmods
; ++i
) {
458 fprintf(outfile
, "\"%s\"", modnames
.sl_modlist
[i
].l_name
);
459 if (i
+1 < modnames
.sl_nmods
) fputc(',', outfile
);
461 free(modnames
.sl_modlist
);
462 #endif /* defined(I_LIST) */
467 /* character device analysis */
468 int cdevan(int fd
, FILE *outfile
) {
472 if ((ret
= Isatty(fd
)) < 0) {
473 Warn2("isatty(%d): %s", fd
, strerror(errno
));
477 struct termios termarg
;
481 if ((name
= Ttyname(fd
)) == NULL
) {
482 /*Warn2("ttyname(%d): %s", fd, strerror(errno));*/
483 fputs("\tNULL", outfile
);
485 fprintf(outfile
, "\t%s", name
);
487 if (Tcgetattr(fd
, &termarg
) < 0) {
488 Warn3("tcgetattr(%d, %p): %s", fd
, &termarg
, strerror(errno
));
491 fprintf(outfile
, " \tIFLAGS=%08x OFLAGS=%08x CFLAGS=%08x LFLAGS=%08x",
492 (unsigned int)termarg
.c_iflag
,
493 (unsigned int)termarg
.c_oflag
,
494 (unsigned int)termarg
.c_cflag
,
495 (unsigned int)termarg
.c_lflag
);
497 /* and the control characters */
498 if (filan_rawoutput
) {
499 for (i
=0; i
<NCCS
; ++i
) {
500 fprintf(outfile
, " cc[%d]=%d", i
, termarg
.c_cc
[i
]);
503 for (i
=0; i
<NCCS
; ++i
) {
506 ch
= termarg
.c_cc
[i
];
508 s
[0] = ch
; s
[1]= '\0';
509 } else if (ch
< ' ') {
510 s
[0] = '^'; s
[1] = ch
+'@'; s
[2] = '\0';
513 s
[1] = (ch
>>4)>=10?(ch
>>4)-10+'A':(ch
>>4)+'0';
514 s
[2] = (ch
&0x0f)>=10?(ch
&0x0f)-10+'A':(ch
&0x0f)+'0';
517 fprintf(outfile
, " cc[%d]=%s", i
, s
);
521 #endif /* _WITH_TERMIOS */
527 int sockan(int fd
, FILE *outfile
) {
528 #define FILAN_OPTLEN 256
529 #define FILAN_NAMELEN 256
532 static const char *socktypes
[] = {
533 "undef", "STREAM", "DGRAM", "RAW", "RDM",
534 "SEQPACKET", "undef", "undef", "undef", "undef",
535 "PACKET", "undef" } ;
536 char nambuff
[FILAN_NAMELEN
];
537 /* in Linux these optcodes are 'enum', but on AIX they are bits! */
538 static const struct sockopt sockopts
[] = {
540 {SO_REUSEADDR
, "REUSEADDR"},
544 {SO_PROTOTYPE
, "PROTOTYPE"},
546 {SO_DONTROUTE
, "DONTROUTE"},
547 {SO_BROADCAST
, "BROADCAST"},
548 {SO_SNDBUF
, "SNDBUF"},
549 {SO_RCVBUF
, "RCVBUF"},
550 {SO_KEEPALIVE
, "KEEPALIVE"},
551 {SO_OOBINLINE
, "OOBINLINE"},
553 {SO_NO_CHECK
, "NO_CHECK"},
556 {SO_PRIORITY
, "PRIORITY"},
558 {SO_LINGER
, "LINGER"},
560 {SO_BSDCOMPAT
, "BSDCOMPAT"},
563 {SO_REUSEPORT
, "REUSEPORT"},
564 #endif /* defined(SO_REUSEPORT) */
566 {SO_PASSCRED
, "PASSCRED"},
569 {SO_PEERCRED
, "PEERCRED"},
572 {SO_RCVLOWAT
, "RCVLOWAT"},
575 {SO_SNDLOWAT
, "SNDLOWAT"},
578 {SO_RCVTIMEO
, "RCVTIMEO"},
581 {SO_SNDTIMEO
, "SNDTIMEO"},
583 #ifdef SO_SECURITY_AUTHENTICATION
584 {SO_SECURITY_AUTHENTICATION
, "SECURITY_AUTHENTICATION"},
586 #ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
587 {SO_SECURITY_ENCRYPTION_TRANSPORT
, "SECURITY_ENCRYPTION_TRANSPORT"},
589 #ifdef SO_SECURITY_ENCRYPTION_NETWORK
590 {SO_SECURITY_ENCRYPTION_NETWORK
, "SECURITY_ENCRYPTION_NETWORK"},
592 #ifdef SO_BINDTODEVICE
593 {SO_BINDTODEVICE
, "BINDTODEVICE"},
595 #ifdef SO_ATTACH_FILTER
596 {SO_ATTACH_FILTER
, "ATTACH_FILTER"},
598 #ifdef SO_DETACH_FILTER
599 {SO_DETACH_FILTER
, "DETACH_FILTER"},
603 char c
[FILAN_OPTLEN
];
604 int i
[FILAN_OPTLEN
/sizeof(int)];
606 const struct sockopt
*optname
;
607 union sockaddr_union sockname
, peername
; /* the longest I know of */
609 #if 0 && defined(SIOCGIFNAME)
610 /*Linux struct ifreq ifc = {{{ 0 }}};*/
611 struct ifreq ifc
= {{ 0 }};
614 optlen
= FILAN_OPTLEN
;
615 result
= Getsockopt(fd
, SOL_SOCKET
, SO_TYPE
, optval
.c
, &optlen
);
617 Debug4("getsockopt(%d, SOL_SOCKET, SO_TYPE, %p, {"F_socklen
"}): %s",
618 fd
, optval
.c
, optlen
, strerror(errno
));
620 Debug3("fd %d: socket of type %d (\"%s\")", fd
, *optval
.i
,
621 socktypes
[*optval
.i
]);
624 optname
= sockopts
; while (optname
->so
) {
625 optlen
= FILAN_OPTLEN
;
627 Getsockopt(fd
, SOL_SOCKET
, optname
->so
, (void *)optval
.c
, &optlen
);
629 Debug5("getsockopt(%d, SOL_SOCKET, %d, %p, {"F_socklen
"}): %s",
630 fd
, optname
->so
, optval
.c
, optlen
, strerror(errno
));
631 fputc('\t', outfile
);
632 } else if (optlen
== sizeof(int)) {
633 Debug2("getsockopt(,,, {%d}, %d)",
635 /*Info2("%s: %d", optname->name, optval.i);*/
636 fprintf(outfile
, "%s=%d\t", optname
->name
, *optval
.i
);
638 Debug3("getsockopt(,,, {%d,%d}, %d)",
639 optval
.i
[0], optval
.i
[1], optlen
);
640 fprintf(outfile
, "%s={%d,%d}\t", optname
->name
,
641 optval
.i
[0], optval
.i
[1]);
646 namelen
= sizeof(sockname
);
647 result
= Getsockname(fd
, (struct sockaddr
*)&sockname
, &namelen
);
650 Warn2("getsockname(%d): %s", fd
, strerror(errno
));
653 fputc('\t', outfile
);
654 fputs(sockaddr_info((struct sockaddr
*)&sockname
, namelen
, nambuff
, sizeof(nambuff
)),
657 namelen
= sizeof(peername
);
658 result
= Getpeername(fd
, (struct sockaddr
*)&peername
, &namelen
);
661 Warn2("getpeername(%d): %s", fd
, strerror(errno
));
663 /* only valid if getpeername() succeeded */
664 fputs(" <-> ", outfile
);
665 fprintf(outfile
, "%s\t",
666 sockaddr_info((struct sockaddr
*)&peername
, namelen
,
667 nambuff
, sizeof(nambuff
)));
670 #if 0 && defined(SIOCGIFNAME)
671 if ((result
= Ioctl(fd
, SIOCGIFNAME
, &ifc
)) < 0) {
672 Warn3("ioctl(%d, SIOCGIFNAME, %p): %s", fd
, &ifc
, strerror(errno
));
674 fprintf(outfile
, "IFNAME=\"%s\"\t", ifc
.ifr_name
);
676 #endif /* SIOCGIFNAME */
678 switch (((struct sockaddr
*)&sockname
)->sa_family
) {
681 /* no options for unix domain sockets known yet -> no unixan() */
687 result
= ipan(fd
, outfile
);
692 result
= ipan(fd
, outfile
);
693 result
|= ip6an(fd
, outfile
);
697 fputs("**** NO FURTHER ANALYSIS FOR THIS SOCKET TYPE IMPLEMENTED", outfile
);
704 #endif /* _WITH_SOCKET */
707 #if WITH_IP4 || WITH_IP6
708 /* prints the option values for the IP protocol and the IP based protocols */
709 /* no distinction between IP4 and IP6 yet */
710 int ipan(int fd
, FILE *outfile
) {
711 /* in Linux these optcodes are 'enum', but on AIX they are bits! */
712 static const struct sockopt ipopts
[] = {
716 {IP_HDRINCL
, "IP_HDRINCL"},
719 {IP_OPTIONS
, "IP_OPTIONS"},
721 #ifdef IP_ROUTER_ALERT
722 {IP_ROUTER_ALERT
, "IP_ROUTER_ALERT"},
725 {IP_RECVOPTS
, "IP_RECVOPTS"},
728 {IP_RETOPTS
, "IP_RETOPTS"},
731 {IP_PKTINFO
, "IP_PKTINFO"},
734 {IP_PKTOPTIONS
, "IP_PKTOPTIONS"},
736 #ifdef IP_MTU_DISCOVER
737 {IP_MTU_DISCOVER
, "IP_MTU_DISCOVER"},
740 {IP_RECVERR
, "IP_RECVERR"},
743 {IP_RECVTTL
, "IP_RECVTTL"},
746 {IP_RECVTOS
, "IP_RECVTOS"},
752 {IP_FREEBIND
, "IP_FREEBIND"},
754 #ifdef IP_MULTICAST_TTL
755 {IP_MULTICAST_TTL
, "IP_MULTICAST_TTL"},
757 #ifdef IP_MULTICAST_LOOP
758 {IP_MULTICAST_LOOP
, "IP_MULTICAST_LOOP"},
761 const struct sockopt
*optname
;
763 socklen_t optlen
= sizeof(opttype
);
765 optname
= ipopts
; while (optname
->so
) {
766 sockoptan(fd
, optname
, SOL_IP
, outfile
);
769 /* want to pass the fd to the next layer protocol. dont know how to get the
770 protocol number from the fd? use TYPE to identify TCP. */
771 if (Getsockopt(fd
, SOL_SOCKET
, SO_TYPE
, &opttype
, &optlen
) >= 0) {
774 case SOCK_STREAM
: tcpan(fd
, outfile
); break;
784 /* prints the option values for the IPv6 protocol */
785 int ip6an(int fd
, FILE *outfile
) {
786 static const struct sockopt ip6opts
[] = {
788 {IPV6_V6ONLY
, "IPV6_V6ONLY"},
791 const struct sockopt
*optname
;
793 optname
= ip6opts
; while (optname
->so
) {
794 sockoptan(fd
, optname
, SOL_IPV6
, outfile
);
799 #endif /* WITH_IP6 */
803 int tcpan(int fd
, FILE *outfile
) {
804 static const struct sockopt tcpopts
[] = {
806 { TCP_NODELAY
, "TCP_NODELAY" },
809 { TCP_MAXSEG
, "TCP_MAXSEG" },
812 { TCP_STDURG
, "TCP_STDURG" },
815 { TCP_RFC1323
, "TCP_RFC1323" },
818 { TCP_CORK
, "TCP_CORK" },
821 { TCP_KEEPIDLE
, "TCP_KEEPIDLE" },
824 { TCP_KEEPINTVL
, "TCP_KEEPINTVL" },
827 { TCP_KEEPCNT
, "TCP_KEEPCNT" },
830 { TCP_SYNCNT
, "TCP_SYNCNT" },
833 { TCP_LINGER2
, "TCP_LINGER2" },
835 #ifdef TCP_DEFER_ACCEPT
836 { TCP_DEFER_ACCEPT
, "TCP_ACCEPT" },
838 #ifdef TCP_WINDOW_CLAMP
839 { TCP_WINDOW_CLAMP
, "TCP_WINDOW_CLAMP" },
842 { TCP_INFO
, "TCP_INFO" },
845 { TCP_QUICKACK
, "TCP_QUICKACK" },
848 { TCP_MD5SIG
, "TCP_MD5SIG" },
851 { TCP_NOOPT
, "TCP_NOOPT" },
854 { TCP_NOPUSH
, "TCP_NOPUSH" },
856 #ifdef TCP_SACK_DISABLE
857 { TCP_SACK_DISABLE
, "TCP_SACK_DISABLE" },
859 #ifdef TCP_SIGNATURE_ENABLE
860 { TCP_SIGNATURE_ENABLE
, "TCP_SIGNATURE_ENABLE" },
862 #ifdef TCP_ABORT_THRESHOLD
863 { TCP_ABORT_THRESHOLD
, "TCP_ABORT_THRESHOLD" },
865 #ifdef TCP_CONN_ABORT_THRESHOLD
866 { TCP_CONN_ABORT_THRESHOLD
, "TCP_CONN_ABORT_THRESHOLD" },
869 { TCP_KEEPINIT
, "TCP_KEEPINIT" },
872 { TCP_PAWS
, "TCP_PAWS" },
875 { TCP_SACKENA
, "TCP_SACKENA" },
878 { TCP_TSOPTENA
, "TCP_TSOPTENA" },
882 const struct sockopt
*optname
;
884 optname
= tcpopts
; while (optname
->so
) {
885 sockoptan(fd
, optname
, SOL_TCP
, outfile
);
890 #endif /* WITH_TCP */
894 int sockoptan(int fd
, const struct sockopt
*optname
, int socklay
, FILE *outfile
) {
895 #define FILAN_OPTLEN 256
897 char c
[FILAN_OPTLEN
];
898 int i
[FILAN_OPTLEN
/sizeof(int)];
903 optlen
= FILAN_OPTLEN
;
905 Getsockopt(fd
, socklay
, optname
->so
, (void *)optval
.c
, &optlen
);
907 Debug6("getsockopt(%d, %d, %d, %p, {"F_socklen
"}): %s",
908 fd
, socklay
, optname
->so
, optval
.c
, optlen
, strerror(errno
));
909 fputc('\t', outfile
);
911 } else if (optlen
== 0) {
912 Debug1("getsockopt(,,, {}, %d)", optlen
);
913 fprintf(outfile
, "%s=\"\"\t", optname
->name
);
914 } else if (optlen
== sizeof(int)) {
915 Debug2("getsockopt(,,, {%d}, %d)",
917 fprintf(outfile
, "%s=%d\t", optname
->name
, *optval
.i
);
919 char outbuf
[FILAN_OPTLEN
*9+128], *cp
= outbuf
;
921 for (i
= 0; i
< optlen
/sizeof(unsigned int); ++i
) {
922 cp
+= sprintf(cp
, "%08x ", (unsigned int)optval
.i
[i
]);
924 *--cp
= '\0'; /* delete trailing space */
925 Debug2("getsockopt(,,, {%s}, %d)", outbuf
, optlen
);
927 fprintf(outfile
, "%s={%s}\t", optname
->name
, outbuf
);
932 #endif /* _WITH_SOCKET */
936 int isasocket(int fd
) {
942 #endif /* HAVE_STAT64 */
950 Info3("fstat(%d, %p): %s", fd
, &props
, strerror(errno
));
953 /* note: when S_ISSOCK was undefined, it always gives 0 */
954 return S_ISSOCK(props
.st_mode
);
956 #endif /* _WITH_SOCKET */
959 const char *getfiletypestring(int st_mode
) {
962 switch (st_mode
&S_IFMT
) {
963 case S_IFIFO
: s
= "pipe"; break;
964 case S_IFCHR
: s
= "chrdev"; break;
965 case S_IFDIR
: s
= "dir"; break;
966 case S_IFBLK
: s
= "blkdev"; break;
967 case S_IFREG
: s
= "file"; break;
968 case S_IFLNK
: s
= "symlink"; break;
969 case S_IFSOCK
: s
= "socket"; break;
971 default: s
= "undef"; break;
976 static int printtime(FILE *outfile
, time_t time
) {
979 if (filan_rawoutput
) {
980 fprintf(outfile
, "\t"F_time
, time
);
982 fputc('\t', outfile
);
983 s
= asctime(localtime(&time
));
984 if (strchr(s
, '\n')) *strchr(s
, '\n') = '\0';