nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* source: hostan.c */ |
2 | /* Copyright Gerhard Rieger */ |
||
3 | /* Published under the GNU General Public License V.2, see file COPYING */ |
||
4 | |||
5 | /* the subroutine hostan makes a "HOST ANalysis". It gathers information |
||
6 | about the host environment it is running in without modifying its state |
||
7 | (almost). |
||
8 | */ |
||
9 | |||
10 | #include "xiosysincludes.h" |
||
11 | #include "mytypes.h" |
||
12 | #include "compat.h" |
||
13 | #include "error.h" |
||
14 | #include "sycls.h" |
||
15 | #include "sysutils.h" |
||
16 | #include "filan.h" |
||
17 | #include "error.h" |
||
18 | |||
19 | #include "hostan.h" |
||
20 | |||
21 | static int iffan(FILE *outfile); |
||
22 | |||
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)); |
||
31 | #endif |
||
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"); |
||
42 | iffan(outfile); |
||
43 | #endif |
||
44 | return 0; |
||
45 | } |
||
46 | |||
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 */ |
||
52 | |||
53 | /* currently we support Linux and a little FreeBSD */ |
||
54 | #ifdef SIOCGIFCONF /* not Solaris */ |
||
55 | |||
56 | #define IFBUFSIZ 32*sizeof(struct ifreq) /*1024*/ |
||
57 | int s; |
||
58 | unsigned char buff[IFBUFSIZ]; |
||
59 | struct ifconf ic; |
||
60 | int i; |
||
61 | |||
62 | if ((s = Socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) { |
||
63 | Error1("socket(PF_INET, SOCK_DGRAM, IPPROTO_IP): %s", strerror(errno)); |
||
64 | return -1; |
||
65 | } |
||
66 | |||
67 | for (i=0; i < IFBUFSIZ; ++i) { |
||
68 | buff[i] = 255; |
||
69 | } |
||
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)); |
||
74 | return -1; |
||
75 | } |
||
76 | |||
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 */ |
||
80 | struct ifreq ifr; |
||
81 | #endif |
||
82 | |||
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)); |
||
88 | return 1; |
||
89 | } |
||
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) */ |
||
98 | } |
||
99 | Close(s); |
||
100 | #endif /* defined(SIOCGIFCONF) */ |
||
101 | return 0; |
||
102 | } |
||
103 | #endif /* _WITH_SOCKET */ |