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 hostan makes a "HOST ANalysis". It gathers information
6 about the host environment it is running in without modifying its state
10 #include "xiosysincludes.h"
21 static int iffan(FILE *outfile
);
23 int hostan(FILE *outfile
) {
24 fprintf(outfile
, "\nC TYPE SIZES\n");
25 fprintf(outfile
, "sizeof(char) = %u\n", (unsigned int)sizeof(char));
26 fprintf(outfile
, "sizeof(short) = %u\n", (unsigned int)sizeof(short));
27 fprintf(outfile
, "sizeof(int) = %u\n", (unsigned int)sizeof(int));
28 fprintf(outfile
, "sizeof(long) = %u\n", (unsigned int)sizeof(long));
29 #if HAVE_TYPE_LONGLONG
30 fprintf(outfile
, "sizeof(long long) = %u\n", (unsigned int)sizeof(long long));
32 fprintf(outfile
, "sizeof(size_t) = %u\n", (unsigned int)sizeof(size_t));
33 #include <sys/time.h> /* select(); OpenBSD: struct timespec */
34 fprintf(outfile
, "sizeof(struct timespec) = %u\n", (unsigned int)sizeof(struct timespec
));
35 fprintf(outfile
, "sizeof(struct diag_dgram) = %u\n", (unsigned int)sizeof(struct diag_dgram
));
36 fprintf(outfile
, "((struct diag_dgram *)0)->op-((struct diag_dgram *)0) = %u\n", (unsigned int)((char *)(&((struct diag_dgram
*)0)->op
)-(char *)((struct diag_dgram
*)0)));
37 fprintf(outfile
, "((struct diag_dgram *)0)->now-((struct diag_dgram *)0) = %u\n", (unsigned int)((char *)(&((struct diag_dgram
*)0)->now
)-(char *)((struct diag_dgram
*)0)));
38 fprintf(outfile
, "((struct diag_dgram *)0)->exitcode-((struct diag_dgram *)0) = %u\n", (unsigned int)((char *)(&((struct diag_dgram
*)0)->exitcode
)-(char *)((struct diag_dgram
*)0)));
39 fprintf(outfile
, "((struct diag_dgram *)0)->text-((struct diag_dgram *)0) = %u\n", (unsigned int)((((struct diag_dgram
*)0)->text
)-(char *)((struct diag_dgram
*)0)));
40 #if _WITH_SOCKET && (_WITH_IP4 || _WITH_IP6)
41 fprintf(outfile
, "\nIP INTERFACES\n");
47 #if _WITH_SOCKET && (_WITH_IP4 || _WITH_IP6)
48 static int iffan(FILE *outfile
) {
49 /* Linux: man 7 netdevice */
50 /* FreeBSD, NetBSD: man 4 networking */
51 /* Solaris: man 7 if_tcp */
53 /* currently we support Linux and a little FreeBSD */
54 #ifdef SIOCGIFCONF /* not Solaris */
56 #define IFBUFSIZ 32*sizeof(struct ifreq) /*1024*/
58 unsigned char buff
[IFBUFSIZ
];
62 if ((s
= Socket(PF_INET
, SOCK_DGRAM
, IPPROTO_IP
)) < 0) {
63 Error1("socket(PF_INET, SOCK_DGRAM, IPPROTO_IP): %s", strerror(errno
));
67 for (i
=0; i
< IFBUFSIZ
; ++i
) {
70 ic
.ifc_len
= sizeof(buff
);
71 ic
.ifc_ifcu
.ifcu_buf
= (caddr_t
)buff
;
72 if (Ioctl(s
, SIOCGIFCONF
, &ic
) < 0) {
73 Error3("ioctl(%d, SIOCGIFCONF, %p): %s", s
, &ic
, strerror(errno
));
77 for (i
= 0; i
< ic
.ifc_len
; i
+= sizeof(struct ifreq
)) {
78 struct ifreq
*ifp
= (struct ifreq
*)((caddr_t
)ic
.ifc_req
+ i
);
79 #if 0 || defined(SIOCGIFINDEX) /* not NetBSD, OpenBSD */
83 #if 0 || defined(SIOCGIFINDEX) /* not NetBSD, OpenBSD */
84 strcpy(ifr
.ifr_name
, ifp
->ifr_name
);
85 if (Ioctl(s
, SIOCGIFINDEX
, &ifr
) < 0) {
86 Error3("ioctl(%d, SIOCGIFINDEX, {\"%s\"}): %s",
87 s
, ifr
.ifr_name
, strerror(errno
));
90 #if HAVE_STRUCT_IFREQ_IFR_INDEX
91 fprintf(outfile
, "%2d: %s\n", ifr
.ifr_index
, ifp
->ifr_name
);
92 #elif HAVE_STRUCT_IFREQ_IFR_IFINDEX
93 fprintf(outfile
, "%2d: %s\n", ifr
.ifr_ifindex
, ifp
->ifr_name
);
94 #endif /* HAVE_STRUCT_IFREQ_IFR_INDEX */
95 #else /* !defined(SIOCGIFINDEX) */
96 fprintf(outfile
, "%2d: %s\n", i
/(int)sizeof(struct ifreq
), ifp
->ifr_name
);
97 #endif /* defined(SIOCGIFINDEX) */
100 #endif /* defined(SIOCGIFCONF) */
103 #endif /* _WITH_SOCKET */