2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
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 /* global variables for configuring filan */
32 bool filan_followsymlinks
;
36 int sockoptan(int fd
, const struct sockopt
*optname
, int socklay
, FILE *outfile
);
37 int tcpan(int fd
, FILE *outfile
);
38 int tcpan2(int fd
, FILE *outfile
);
39 const char *getfiletypestring(int st_mode
);
41 static int printtime(FILE *outfile
, time_t time
);
43 static int headprinted
;
45 /* analyse a file system entry, referred by file name */
46 int filan_file(const char *filename
, FILE *outfile
) {
50 struct stat64 buf
= {0};
52 struct stat buf
= {0};
53 #endif /* !HAVE_STAT64 */
55 if (filan_followsymlinks
) {
57 result
= Stat64(filename
, &buf
);
59 result
= Stat(filename
, &buf
);
60 #endif /* !HAVE_STAT64 */
62 Warn3("stat(\"%s\", %p): %s", filename
, &buf
, strerror(errno
));
66 result
= Lstat64(filename
, &buf
);
68 result
= Lstat(filename
, &buf
);
69 #endif /* !HAVE_STAT64 */
71 Warn3("lstat(\"%s\", %p): %s", filename
, &buf
, strerror(errno
));
74 switch (buf
.st_mode
&S_IFMT
) {
76 case S_IFSOCK
: /* probably, it's useless to make a socket and describe it */
81 Open(filename
, O_RDONLY
|O_NOCTTY
|O_NONBLOCK
87 Warn2("open(\"%s\", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE, 0700): %s",
88 filename
, strerror(errno
));
92 result
= filan_stat(&buf
, fd
, -1, outfile
);
97 /* analyze a file descriptor */
98 int filan_fd(int fd
, FILE *outfile
) {
100 struct stat64 buf
= {0};
102 struct stat buf
= {0};
103 #endif /* !HAVE_STAT64 */
106 Debug1("checking file descriptor %u", fd
);
108 result
= Fstat64(fd
, &buf
);
110 result
= Fstat(fd
, &buf
);
111 #endif /* !HAVE_STAT64 */
113 if (errno
== EBADF
) {
114 Debug2("fstat(%d): %s", fd
, strerror(errno
));
116 Warn2("fstat(%d): %s", fd
, strerror(errno
));
120 Debug2("fd %d is a %s", fd
, getfiletypestring(buf
.st_mode
));
122 result
= filan_stat(&buf
, fd
, fd
, outfile
);
125 /* even more dynamic info */
126 { /* see if data is available */
129 ufds
.events
= POLLIN
|POLLPRI
|POLLOUT
145 if (Poll(&ufds
, 1, 0) < 0) {
146 Warn4("poll({%d, %hd, %hd}, 1, 0): %s",
147 ufds
.fd
, ufds
.events
, ufds
.revents
, strerror(errno
));
149 fputs("poll: ", outfile
);
150 if (ufds
.revents
& POLLIN
) fputs("IN,", outfile
);
151 if (ufds
.revents
& POLLPRI
) fputs("PRI,", outfile
);
152 if (ufds
.revents
& POLLOUT
) fputs("OUT,", outfile
);
153 if (ufds
.revents
& POLLERR
) fputs("ERR,", outfile
);
154 if (ufds
.revents
& POLLNVAL
) fputs("NVAL,", outfile
);
156 if (ufds
.revents
& POLLIN
) {
158 if ((result
= Ioctl(fd
, FIONREAD
, &sizet
) >= 0)) {
159 fprintf (outfile
, "; FIONREAD="F_Zu
, sizet
);
162 #endif /* defined(FIONREAD) */
163 #if _WITH_SOCKET && defined(MSG_DONTWAIT)
164 if ((ufds
.revents
& POLLIN
) && isasocket(fd
)) {
165 char _peername
[SOCKADDR_MAX
];
166 struct sockaddr
*pa
= (struct sockaddr
*)_peername
;
167 struct msghdr msgh
= {0};
168 char peekbuff
[1]; /* [0] fails with some compilers */
169 #if HAVE_STRUCT_IOVEC
175 fputs("; ", outfile
);
177 msgh
.msg_namelen
= sizeof(*pa
);
178 #if HAVE_STRUCT_IOVEC
179 iovec
.iov_base
= peekbuff
;
180 iovec
.iov_len
= sizeof(peekbuff
);
181 msgh
.msg_iov
= &iovec
;
184 #if HAVE_STRUCT_MSGHDR_MSGCONTROL
185 msgh
.msg_control
= ctrlbuff
;
187 #if HAVE_STRUCT_MSGHDR_MSGCONTROLLEN
188 msgh
.msg_controllen
= sizeof(ctrlbuff
);
190 #if HAVE_STRUCT_MSGHDR_MSGFLAGS
193 if ((bytes
= Recvmsg(fd
, &msgh
, MSG_PEEK
|MSG_DONTWAIT
)) < 0) {
194 Warn1("recvmsg(): %s", strerror(errno
));
196 fprintf(outfile
, "recvmsg="F_Zd
", ", bytes
);
199 #endif /* _WITH_SOCKET && defined(MSG_DONTWAIT) */
201 #endif /* HAVE_POLL */
204 fputc('\n', outfile
);
214 #endif /* !HAVE_STAT64 */
215 , int statfd
, int dynfd
, FILE *outfile
) {
220 if (filan_rawoutput
) {
221 fputs(" FD type\tdevice\tinode\tmode\tlinks\tuid\tgid"
232 "\tatime\t\tmtime\t\tctime\t\tcloexec\tflags"
233 #if defined(F_GETOWN)
237 } else /* !rawoutput */ {
238 fputs(" FD type\tdevice\tinode\tmode\tlinks\tuid\tgid"
249 "\tatime\t\t\t\tmtime\t\t\t\tctime\t\t\t\tcloexec\tflags"
250 #if defined(F_GETOWN)
255 } /* endif !rawoutput */
257 #if defined(F_GETSIG)
258 fputs("\tsigio", outfile
);
259 #endif /* defined(F_GETSIG) */
260 fputc('\n', outfile
);
263 if (filan_rawoutput
) {
264 snprintf(stdevstr
, 8, F_dev
, buf
->st_dev
);
266 snprintf(stdevstr
, 8, "%hu,%hu", (unsigned short)(buf
->st_dev
>>8), (unsigned short)(buf
->st_dev
&0xff));
268 fprintf(outfile
, "%4d: %s\t%s\t"
273 #endif /* HAVE_STAT64 */
274 "\t"F_mode
"\t"F_st_nlink
"\t"F_uid
"\t"F_gid
283 #endif /* HAVE_STAT64 */
292 #endif /* HAVE_STAT64 */
295 (dynfd
>=0?dynfd
:statfd
), getfiletypestring(buf
->st_mode
),
298 buf
->st_mode
, buf
->st_nlink
, buf
->st_uid
,
301 (unsigned short)(buf
->st_rdev
>>8), (unsigned short)(buf
->st_rdev
&0xff),
308 , buf
->st_blocks
/* on Linux, this applies to stat and stat64 */
312 printtime(outfile
, buf
->st_atime
);
313 printtime(outfile
, buf
->st_mtime
);
314 printtime(outfile
, buf
->st_ctime
);
318 fputc('\t', outfile
);
319 time
= asctime(localtime(&buf
->st_mtime
));
320 if (strchr(time
, '\n')) *strchr(time
, '\n') = '\0';
321 fputs(time
, outfile
);
323 fputc('\t', outfile
);
324 time
= asctime(localtime(&buf
->st_ctime
));
325 if (strchr(time
, '\n')) *strchr(time
, '\n') = '\0';
326 fputs(time
, outfile
);
330 /* here comes dynamic info - it is only meaningful with preexisting FDs */
331 if (dynfd
>= 0) { /*!indent */
333 #if defined(F_GETOWN)
336 #if defined(F_GETSIG)
338 #endif /* defined(F_GETSIG) */
340 cloexec
= Fcntl(dynfd
, F_GETFD
);
341 flags
= Fcntl(dynfd
, F_GETFL
);
342 #if defined(F_GETOWN)
343 sigown
= Fcntl(dynfd
, F_GETOWN
);
345 #if defined(F_GETSIG)
346 sigio
= Fcntl(dynfd
, F_GETSIG
);
347 #endif /* defined(F_GETSIG) */
348 fprintf(outfile
, "\t%d\tx%06x", cloexec
, flags
);
349 #if defined(F_GETOWN)
350 fprintf(outfile
, "\t%d", sigown
);
352 #if defined(F_GETSIG)
353 fprintf(outfile
, "\t%d", sigio
);
354 #endif /* defined(F_GETSIG) */
357 #if defined(F_GETOWN)
360 #if defined(F_GETSIG)
362 #endif /* defined(F_GETSIG) */
366 /* ever heard of POSIX streams? here we handle these */
367 filan_streams_analyze(statfd
, outfile
);
369 /* now see for type specific infos */
370 if (statfd
>= 0) { /*!indent */
371 switch (buf
->st_mode
&S_IFMT
) {
372 case (S_IFIFO
): /* 1, FIFO */
374 case (S_IFCHR
): /* 2, character device */
375 cdevan(statfd
, outfile
);
377 case (S_IFDIR
): /* 4, directory */
379 case (S_IFBLK
): /* 6, block device */
381 case (S_IFREG
): /* 8, regular file */
383 case (S_IFLNK
): /* 10, symbolic link */
386 case (S_IFSOCK
): /* 12, socket */
388 sockan(statfd
, outfile
);
390 Warn("SOCKET support not compiled in");
392 #endif /* !_WITH_SOCKET */
394 #endif /* S_IFSOCK */
406 result
= Fcntl(fd
, F_GETFD
);
407 fcntl(fd
, F_GETFL
, );
408 fcntl(fd
, F_GETLK
, );
410 fcntl(fd
, F_GETOWN
, );
413 fcntl(fd
, F_GETSIG
, );
418 int devinfo(int fd
) {
424 /* returns 0 on success (not a stream descriptor, or no module)
425 returns <0 on failure */
426 static int filan_streams_analyze(int fd
, FILE *outfile
) {
428 # define SL_NMODS 8 /* max number of module names we can store */
429 struct str_list modnames
;
432 if (!isastream(fd
)) {
433 fprintf(outfile
, "\t(no STREAMS modules)");
436 #if 0 /* uncomment for debugging */
437 fprintf(outfile
, "\tfind=%d", ioctl(fd
, I_FIND
, "ldterm"));
439 modnames
.sl_nmods
= ioctl(fd
, I_LIST
, 0);
440 if (modnames
.sl_nmods
< 0) {
441 fprintf(stderr
, "ioctl(%d, I_LIST, 0): %s\n", fd
, strerror(errno
));
444 modnames
.sl_modlist
= Malloc(modnames
.sl_nmods
*(sizeof(struct str_mlist
)));
445 if (modnames
.sl_modlist
== NULL
) {
446 fprintf(stderr
, "out of memory\n");
449 if (ioctl(fd
, I_LIST
, &modnames
) < 0) {
450 fprintf(stderr
, "ioctl(%d, I_LIST, %p): %s\n",
451 fd
, &modnames
, strerror(errno
));
452 free(modnames
.sl_modlist
);
455 fprintf(outfile
, "\tSTREAMS: ");
456 for (i
= 0; i
< modnames
.sl_nmods
; ++i
) {
457 fprintf(outfile
, "\"%s\"", modnames
.sl_modlist
[i
].l_name
);
458 if (i
+1 < modnames
.sl_nmods
) fputc(',', outfile
);
460 free(modnames
.sl_modlist
);
461 #endif /* defined(I_LIST) */
466 /* character device analysis */
467 int cdevan(int fd
, FILE *outfile
) {
471 if ((ret
= Isatty(fd
)) < 0) {
472 Warn2("isatty(%d): %s", fd
, strerror(errno
));
476 struct termios termarg
;
480 if ((name
= Ttyname(fd
)) == NULL
) {
481 /*Warn2("ttyname(%d): %s", fd, strerror(errno));*/
482 fputs("\tNULL", outfile
);
484 fprintf(outfile
, "\t%s", name
);
486 if (Tcgetattr(fd
, &termarg
) < 0) {
487 Warn3("tcgetattr(%d, %p): %s", fd
, &termarg
, strerror(errno
));
490 fprintf(outfile
, " \tIFLAGS=%08x OFLAGS=%08x CFLAGS=%08x LFLAGS=%08x",
491 (unsigned int)termarg
.c_iflag
,
492 (unsigned int)termarg
.c_oflag
,
493 (unsigned int)termarg
.c_cflag
,
494 (unsigned int)termarg
.c_lflag
);
496 /* and the control characters */
497 if (filan_rawoutput
) {
498 for (i
=0; i
<NCCS
; ++i
) {
499 fprintf(outfile
, " cc[%d]=%d", i
, termarg
.c_cc
[i
]);
502 for (i
=0; i
<NCCS
; ++i
) {
505 ch
= termarg
.c_cc
[i
];
507 s
[0] = ch
; s
[1]= '\0';
508 } else if (ch
< ' ') {
509 s
[0] = '^'; s
[1] = ch
+'@'; s
[2] = '\0';
512 s
[1] = (ch
>>4)>=10?(ch
>>4)-10+'A':(ch
>>4)+'0';
513 s
[2] = (ch
&0x0f)>=10?(ch
&0x0f)-10+'A':(ch
&0x0f)+'0';
516 fprintf(outfile
, " cc[%d]=%s", i
, s
);
520 #endif /* _WITH_TERMIOS */
526 int sockan(int fd
, FILE *outfile
) {
527 #define FILAN_OPTLEN 256
528 #define FILAN_NAMELEN 256
531 char nambuff
[FILAN_NAMELEN
];
532 /* in Linux these optcodes are 'enum', but on AIX they are bits! */
533 static const struct sockopt sockopts
[] = {
535 {SO_REUSEADDR
, "REUSEADDR"},
537 {SO_PROTOCOL
, "PROTOCOL"},
538 #elif defined(SO_PROTOTYPE)
539 {SO_PROTOTYPE
, "PROTOTYPE"},
543 {SO_DONTROUTE
, "DONTROUTE"},
544 {SO_BROADCAST
, "BROADCAST"},
545 {SO_SNDBUF
, "SNDBUF"},
546 {SO_RCVBUF
, "RCVBUF"},
547 {SO_KEEPALIVE
, "KEEPALIVE"},
548 {SO_OOBINLINE
, "OOBINLINE"},
550 {SO_NO_CHECK
, "NO_CHECK"},
553 {SO_PRIORITY
, "PRIORITY"},
555 {SO_LINGER
, "LINGER"},
557 {SO_BSDCOMPAT
, "BSDCOMPAT"},
560 {SO_REUSEPORT
, "REUSEPORT"},
561 #endif /* defined(SO_REUSEPORT) */
563 {SO_PASSCRED
, "PASSCRED"},
566 {SO_PEERCRED
, "PEERCRED"},
569 {SO_RCVLOWAT
, "RCVLOWAT"},
572 {SO_SNDLOWAT
, "SNDLOWAT"},
575 {SO_RCVTIMEO
, "RCVTIMEO"},
578 {SO_SNDTIMEO
, "SNDTIMEO"},
580 #ifdef SO_SECURITY_AUTHENTICATION
581 {SO_SECURITY_AUTHENTICATION
, "SECURITY_AUTHENTICATION"},
583 #ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
584 {SO_SECURITY_ENCRYPTION_TRANSPORT
, "SECURITY_ENCRYPTION_TRANSPORT"},
586 #ifdef SO_SECURITY_ENCRYPTION_NETWORK
587 {SO_SECURITY_ENCRYPTION_NETWORK
, "SECURITY_ENCRYPTION_NETWORK"},
589 #ifdef SO_BINDTODEVICE
590 {SO_BINDTODEVICE
, "BINDTODEVICE"},
592 #ifdef SO_ATTACH_FILTER
593 {SO_ATTACH_FILTER
, "ATTACH_FILTER"},
595 #ifdef SO_DETACH_FILTER
596 {SO_DETACH_FILTER
, "DETACH_FILTER"},
600 char c
[FILAN_OPTLEN
];
601 int i
[FILAN_OPTLEN
/sizeof(int)];
603 const struct sockopt
*optname
;
604 union sockaddr_union sockname
, peername
; /* the longest I know of */
606 #if 0 && defined(SIOCGIFNAME)
607 /*Linux struct ifreq ifc = {{{ 0 }}};*/
608 struct ifreq ifc
= {{ 0 }};
611 optlen
= FILAN_OPTLEN
;
612 result
= Getsockopt(fd
, SOL_SOCKET
, SO_TYPE
, optval
.c
, &optlen
);
614 Debug4("getsockopt(%d, SOL_SOCKET, SO_TYPE, %p, {"F_socklen
"}): %s",
615 fd
, optval
.c
, optlen
, strerror(errno
));
617 # define TYPENAMEMAX 16
618 char typename
[TYPENAMEMAX
];
619 sockettype(*optval
.i
, typename
, sizeof(typename
));
621 Debug3("fd %d: socket of type %d (\"%s\")", fd
, *optval
.i
,
625 optname
= sockopts
; while (optname
->so
) {
626 optlen
= FILAN_OPTLEN
;
628 Getsockopt(fd
, SOL_SOCKET
, optname
->so
, (void *)optval
.c
, &optlen
);
630 Debug5("getsockopt(%d, SOL_SOCKET, %d, %p, {"F_socklen
"}): %s",
631 fd
, optname
->so
, optval
.c
, optlen
, strerror(errno
));
632 fputc('\t', outfile
);
633 } else if (optlen
== sizeof(int)) {
634 Debug2("getsockopt(,,, {%d}, %d)",
636 /*Info2("%s: %d", optname->name, optval.i);*/
637 fprintf(outfile
, "%s=%d\t", optname
->name
, *optval
.i
);
639 Debug3("getsockopt(,,, {%d,%d}, %d)",
640 optval
.i
[0], optval
.i
[1], optlen
);
641 fprintf(outfile
, "%s={%d,%d}\t", optname
->name
,
642 optval
.i
[0], optval
.i
[1]);
647 namelen
= sizeof(sockname
);
648 result
= Getsockname(fd
, (struct sockaddr
*)&sockname
, &namelen
);
651 Warn2("getsockname(%d): %s", fd
, strerror(errno
));
654 fputc('\t', outfile
);
655 fputs(sockaddr_info((struct sockaddr
*)&sockname
, namelen
, nambuff
, sizeof(nambuff
)),
658 namelen
= sizeof(peername
);
659 result
= Getpeername(fd
, (struct sockaddr
*)&peername
, &namelen
);
662 Warn2("getpeername(%d): %s", fd
, strerror(errno
));
664 /* only valid if getpeername() succeeded */
665 fputs(" <-> ", outfile
);
666 fprintf(outfile
, "%s\t",
667 sockaddr_info((struct sockaddr
*)&peername
, namelen
,
668 nambuff
, sizeof(nambuff
)));
671 #if 0 && defined(SIOCGIFNAME)
672 if ((result
= Ioctl(fd
, SIOCGIFNAME
, &ifc
)) < 0) {
673 Warn3("ioctl(%d, SIOCGIFNAME, %p): %s", fd
, &ifc
, strerror(errno
));
675 fprintf(outfile
, "IFNAME=\"%s\"\t", ifc
.ifr_name
);
677 #endif /* SIOCGIFNAME */
679 switch (((struct sockaddr
*)&sockname
)->sa_family
) {
682 /* no options for unix domain sockets known yet -> no unixan() */
688 result
= ipan(fd
, outfile
);
693 result
= ipan(fd
, outfile
);
694 result
|= ip6an(fd
, outfile
);
698 fputs("**** NO FURTHER ANALYSIS FOR THIS SOCKET TYPE IMPLEMENTED", outfile
);
705 #endif /* _WITH_SOCKET */
708 #if WITH_IP4 || WITH_IP6
709 /* prints the option values for the IP protocol and the IP based protocols */
710 /* no distinction between IP4 and IP6 yet */
711 int ipan(int fd
, FILE *outfile
) {
712 /* in Linux these optcodes are 'enum', but on AIX they are bits! */
713 static const struct sockopt ipopts
[] = {
717 {IP_HDRINCL
, "IP_HDRINCL"},
720 {IP_OPTIONS
, "IP_OPTIONS"},
722 #ifdef IP_ROUTER_ALERT
723 {IP_ROUTER_ALERT
, "IP_ROUTER_ALERT"},
726 {IP_RECVOPTS
, "IP_RECVOPTS"},
729 {IP_RETOPTS
, "IP_RETOPTS"},
732 {IP_PKTINFO
, "IP_PKTINFO"},
735 {IP_PKTOPTIONS
, "IP_PKTOPTIONS"},
737 #ifdef IP_MTU_DISCOVER
738 {IP_MTU_DISCOVER
, "IP_MTU_DISCOVER"},
741 {IP_RECVERR
, "IP_RECVERR"},
744 {IP_RECVTTL
, "IP_RECVTTL"},
747 {IP_RECVTOS
, "IP_RECVTOS"},
749 #ifdef IP_TRANSPARENT
750 {IP_TRANSPARENT
, "IP_TRANSPARENT"},
756 {IP_FREEBIND
, "IP_FREEBIND"},
758 #ifdef IP_MULTICAST_TTL
759 {IP_MULTICAST_TTL
, "IP_MULTICAST_TTL"},
761 #ifdef IP_MULTICAST_LOOP
762 {IP_MULTICAST_LOOP
, "IP_MULTICAST_LOOP"},
765 const struct sockopt
*optname
;
767 socklen_t optlen
= sizeof(optproto
);
769 optname
= ipopts
; while (optname
->so
) {
770 sockoptan(fd
, optname
, SOL_IP
, outfile
);
773 /* want to pass the fd to the next layer protocol. */
774 #if defined(SO_PROTOCOL) || defined(SO_PROTOTYPE)
775 if (Getsockopt(fd
, SOL_SOCKET
,
778 #elif defined(SO_PROTOTYPE)
781 &optproto
, &optlen
) >= 0) {
784 case IPPROTO_TCP
: tcpan(fd
, outfile
); break;
788 #endif /* defined(SO_PROTOCOL) || defined(SO_PROTOTYPE) */
795 /* prints the option values for the IPv6 protocol */
796 int ip6an(int fd
, FILE *outfile
) {
797 static const struct sockopt ip6opts
[] = {
799 {IPV6_V6ONLY
, "IPV6_V6ONLY"},
802 const struct sockopt
*optname
;
804 optname
= ip6opts
; while (optname
->so
) {
805 sockoptan(fd
, optname
, SOL_IPV6
, outfile
);
810 #endif /* WITH_IP6 */
814 int tcpan(int fd
, FILE *outfile
) {
815 static const struct sockopt tcpopts
[] = {
817 { TCP_NODELAY
, "TCP_NODELAY" },
820 { TCP_MAXSEG
, "TCP_MAXSEG" },
823 { TCP_STDURG
, "TCP_STDURG" },
826 { TCP_RFC1323
, "TCP_RFC1323" },
829 { TCP_CORK
, "TCP_CORK" },
832 { TCP_KEEPIDLE
, "TCP_KEEPIDLE" },
835 { TCP_KEEPINTVL
, "TCP_KEEPINTVL" },
838 { TCP_KEEPCNT
, "TCP_KEEPCNT" },
841 { TCP_SYNCNT
, "TCP_SYNCNT" },
844 { TCP_LINGER2
, "TCP_LINGER2" },
846 #ifdef TCP_DEFER_ACCEPT
847 { TCP_DEFER_ACCEPT
, "TCP_ACCEPT" },
849 #ifdef TCP_WINDOW_CLAMP
850 { TCP_WINDOW_CLAMP
, "TCP_WINDOW_CLAMP" },
853 { TCP_INFO
, "TCP_INFO" },
856 { TCP_QUICKACK
, "TCP_QUICKACK" },
859 { TCP_MD5SIG
, "TCP_MD5SIG" },
862 { TCP_NOOPT
, "TCP_NOOPT" },
865 { TCP_NOPUSH
, "TCP_NOPUSH" },
867 #ifdef TCP_SACK_DISABLE
868 { TCP_SACK_DISABLE
, "TCP_SACK_DISABLE" },
870 #ifdef TCP_SIGNATURE_ENABLE
871 { TCP_SIGNATURE_ENABLE
, "TCP_SIGNATURE_ENABLE" },
873 #ifdef TCP_ABORT_THRESHOLD
874 { TCP_ABORT_THRESHOLD
, "TCP_ABORT_THRESHOLD" },
876 #ifdef TCP_CONN_ABORT_THRESHOLD
877 { TCP_CONN_ABORT_THRESHOLD
, "TCP_CONN_ABORT_THRESHOLD" },
880 { TCP_KEEPINIT
, "TCP_KEEPINIT" },
883 { TCP_PAWS
, "TCP_PAWS" },
886 { TCP_SACKENA
, "TCP_SACKENA" },
889 { TCP_TSOPTENA
, "TCP_TSOPTENA" },
893 const struct sockopt
*optname
;
895 optname
= tcpopts
; while (optname
->so
) {
896 sockoptan(fd
, optname
, SOL_TCP
, outfile
);
905 #endif /* WITH_TCP */
907 #if WITH_TCP && defined(TCP_INFO)
909 int tcpan2(int fd
, FILE *outfile
) {
910 struct tcp_info tcpinfo
;
911 socklen_t tcpinfolen
= sizeof(tcpinfo
);
914 result
= Getsockopt(fd
, SOL_TCP
, TCP_INFO
, &tcpinfo
, &tcpinfolen
);
916 Debug4("getsockopt(%d, SOL_TCP, TCP_INFO, %p, {"F_Zu
"}): %s",
917 fd
, &tcpinfo
, sizeof(tcpinfo
), strerror(errno
));
920 fprintf(outfile
, "%s={%u}\t", "TCPI_STATE", tcpinfo
.tcpi_state
);
921 #if 0 /* on BSD these components are prefixed with __ - I get tired... */
922 fprintf(outfile
, "%s={%u}\t", "TCPI_CA_STATE", tcpinfo
.tcpi_ca_state
);
923 fprintf(outfile
, "%s={%u}\t", "TCPI_RETRANSMITS", tcpinfo
.tcpi_retransmits
);
924 fprintf(outfile
, "%s={%u}\t", "TCPI_PROBES", tcpinfo
.tcpi_probes
);
925 fprintf(outfile
, "%s={%u}\t", "TCPI_BACKOFF", tcpinfo
.tcpi_backoff
);
927 fprintf(outfile
, "%s={%u}\t", "TCPI_OPTIONS", tcpinfo
.tcpi_options
);
928 fprintf(outfile
, "%s={%u}\t", "TCPI_SND_WSCALE", tcpinfo
.tcpi_snd_wscale
);
929 fprintf(outfile
, "%s={%u}\t", "TCPI_RCV_WSCALE", tcpinfo
.tcpi_rcv_wscale
);
930 //fprintf(outfile, "%s={%u}\t", "TCPI_DELIVERY_RATE_APP_LIMITED", tcpinfo.tcpi_delivery_rate_app_limited);
931 //fprintf(outfile, "%s={%u}\t", "TCPI_FASTOPEN_CLIENT_FAIL", tcpinfo.tcpi_fastopen_client_fail);
932 // fprintf(outfile, "%s={%u}\t", "TCPI_", tcpinfo.tcpi_);
937 #endif /* WITH_TCP */
941 int sockoptan(int fd
, const struct sockopt
*optname
, int socklay
, FILE *outfile
) {
942 #define FILAN_OPTLEN 256
944 char c
[FILAN_OPTLEN
];
945 int i
[FILAN_OPTLEN
/sizeof(int)];
950 optlen
= FILAN_OPTLEN
;
952 Getsockopt(fd
, socklay
, optname
->so
, (void *)optval
.c
, &optlen
);
954 Debug6("getsockopt(%d, %d, %d, %p, {"F_socklen
"}): %s",
955 fd
, socklay
, optname
->so
, optval
.c
, optlen
, strerror(errno
));
956 fputc('\t', outfile
);
958 } else if (optlen
== 0) {
959 Debug1("getsockopt(,,, {}, %d)", optlen
);
960 fprintf(outfile
, "%s=\"\"\t", optname
->name
);
961 } else if (optlen
== sizeof(int)) {
962 Debug2("getsockopt(,,, {%d}, %d)",
964 fprintf(outfile
, "%s=%d\t", optname
->name
, *optval
.i
);
966 char outbuf
[FILAN_OPTLEN
*9+128], *cp
= outbuf
;
968 for (i
= 0; i
< optlen
/sizeof(unsigned int); ++i
) {
969 cp
+= sprintf(cp
, "%08x ", (unsigned int)optval
.i
[i
]);
971 *--cp
= '\0'; /* delete trailing space */
972 Debug2("getsockopt(,,, {%s}, %d)", outbuf
, optlen
);
974 fprintf(outfile
, "%s={%s}\t", optname
->name
, outbuf
);
979 #endif /* _WITH_SOCKET */
983 int isasocket(int fd
) {
989 #endif /* HAVE_STAT64 */
997 Info3("fstat(%d, %p): %s", fd
, &props
, strerror(errno
));
1000 /* note: when S_ISSOCK was undefined, it always gives 0 */
1001 return S_ISSOCK(props
.st_mode
);
1003 #endif /* _WITH_SOCKET */
1006 const char *getfiletypestring(int st_mode
) {
1009 switch (st_mode
&S_IFMT
) {
1010 case S_IFIFO
: s
= "pipe"; break;
1011 case S_IFCHR
: s
= "chrdev"; break;
1012 case S_IFDIR
: s
= "dir"; break;
1013 case S_IFBLK
: s
= "blkdev"; break;
1014 case S_IFREG
: s
= "file"; break;
1015 case S_IFLNK
: s
= "symlink"; break;
1016 case S_IFSOCK
: s
= "socket"; break;
1018 default: s
= "undef"; break;
1023 static int printtime(FILE *outfile
, time_t time
) {
1026 if (filan_rawoutput
) {
1027 fprintf(outfile
, "\t"F_time
, time
);
1029 fputc('\t', outfile
);
1030 s
= asctime(localtime(&time
));
1031 if (strchr(s
, '\n')) *strchr(s
, '\n') = '\0';