-
Notifications
You must be signed in to change notification settings - Fork 5
/
ifcon.c
1890 lines (1643 loc) · 53.3 KB
/
ifcon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
*
* Copyright(c) Jeff V. Merkey 1997-2019. All rights reserved.
* Open CWorthy Look Alike Terminal Library.
*
* IFCON Linux Example Program
*
**************************************************************************/
#define __GNU_SOURCE
#include "cworthy.h"
#define IPV6_ADDR_ANY 0x0000U
#define IPV6_ADDR_UNICAST 0x0001U
#define IPV6_ADDR_MULTICAST 0x0002U
#define IPV6_ADDR_ANYCAST 0x0004U
#define IPV6_ADDR_LOOPBACK 0x0010U
#define IPV6_ADDR_LINKLOCAL 0x0020U
#define IPV6_ADDR_SITELOCAL 0x0040U
#define IPV6_ADDR_COMPATv4 0x0080U
#define IPV6_ADDR_SCOPE_MASK 0x00f0U
#define IPV6_ADDR_MAPPED 0x1000U
#define IPV6_ADDR_RESERVED 0x2000U
#define NUD_INCOMPLETE 0x01
#define NUD_REACHABLE 0x02
#define NUD_STALE 0x04
#define NUD_DELAY 0x08
#define NUD_PROBE 0x10
#define NUD_FAILED 0x20
#define NUD_NOARP 0x40
#define NUD_PERMANENT 0x80
#define NUD_NONE 0x00
#define NTF_PROXY 0x08
#define NTF_ROUTER 0x80
#define NTF_02 0x02
#define NTF_04 0x04
static int INET6_resolve(char *name, struct sockaddr_in6 *sin6)
{
struct addrinfo req, *ai;
int s;
memset(&req, '\0', sizeof req);
req.ai_family = AF_INET6;
if ((s = getaddrinfo(name, NULL, &req, &ai))) {
return -1;
}
memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6));
freeaddrinfo(ai);
return (0);
}
#ifndef IN6_IS_ADDR_UNSPECIFIED
#define IN6_IS_ADDR_UNSPECIFIED(a) \
(((__u32 *) (a))[0] == 0 && ((__u32 *) (a))[1] == 0 && \
((__u32 *) (a))[2] == 0 && ((__u32 *) (a))[3] == 0)
#endif
static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric)
{
int s;
/* Grmpf. -FvK */
if (sin6->sin6_family != AF_INET6) {
errno = EAFNOSUPPORT;
return (-1);
}
if (numeric & 0x7FFF) {
inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80);
return (0);
}
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
if (numeric & 0x8000)
strcpy(name, "default");
else
strcpy(name, "*");
return (0);
}
if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6),
name, 255 /* !! */ , NULL, 0, 0))) {
return -1;
}
return (0);
}
void INET6_reserror(char *text)
{
herror(text);
}
char *INET6_print(unsigned char *ptr)
{
static char name[80];
inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80);
return name;
}
static char *INET6_sprint(struct sockaddr *sap, int numeric)
{
static char buf[128];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return strncpy(buf, ("[NONE SET]"), sizeof(buf));
if (INET6_rresolve(buf, (struct sockaddr_in6 *) sap, numeric) != 0)
return strncpy(buf, ("[UNKNOWN]"), sizeof(buf));
return (buf);
}
static int INET6_getsock(char *bufp, struct sockaddr *sap)
{
struct sockaddr_in6 *sin6;
sin6 = (struct sockaddr_in6 *) sap;
sin6->sin6_family = AF_INET6;
sin6->sin6_port = 0;
if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0)
return (-1);
return 16;
}
static int INET6_input(int type, char *bufp, struct sockaddr *sap)
{
switch (type) {
case 1:
return (INET6_getsock(bufp, sap));
default:
return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap));
}
}
#define FLAG_EXT 3
#define FLAG_NUM_HOST 4
#define FLAG_NUM_PORT 8
#define FLAG_NUM_USER 16
#define FLAG_NUM (FLAG_NUM_HOST|FLAG_NUM_PORT|FLAG_NUM_USER)
#define FLAG_SYM 32
#define FLAG_CACHE 64
#define FLAG_FIB 128
#define FLAG_VERBOSE 256
#define RTF_UP 0x0001
#define RTF_GATEWAY 0x0002
#define RTF_HOST 0x0004
#define RTF_REINSTATE 0x0008
#define RTF_DYNAMIC 0x0010
#define RTF_MODIFIED 0x0020
#define RTF_MTU 0x0040
#ifndef RTF_MSS
#define RTF_MSS RTF_MTU
#endif
#define RTF_WINDOW 0x0080
#define RTF_IRTT 0x0100
#define RTF_REJECT 0x0200
#ifndef RTF_DEFAULT
#define RTF_DEFAULT 0x00010000
#endif
#define RTF_ALLONLINK 0x00020000
#ifndef RTF_ADDRCONF
#define RTF_ADDRCONF 0x00040000
#endif
#define RTF_NONEXTHOP 0x00200000
#define RTF_EXPIRES 0x00400000
#define RTF_CACHE 0x01000000
#define RTF_FLOW 0x02000000
#define RTF_POLICY 0x04000000
#define RTF_LOCAL 0x80000000
#define E_NOTFOUND 8
#define E_SOCK 7
#define E_LOOKUP 6
#define E_VERSION 5
#define E_USAGE 4
#define E_OPTERR 3
#define E_INTERN 2
#define E_NOSUPP 1
int active = 0;
int netsumactive = 0;
int networkactive = 0;
int menu, mainportal, logportal = -1;
pthread_t pstat;
pthread_t netsumstat;
pthread_t networkstat;
pthread_t plog;
typedef struct _ARPTYPE
{
int type;
const char *name;
} ARPTYPE;
ARPTYPE arptype[]={
0, "NET/ROM Pseudo",
1, "Ethernet",
2, "Experimental Ethernet",
3, "AX.25 Level 2",
4, "PROnet Token Ring",
5, "Chaosnet",
6, "IEEE 802.2 Ethernet/TR/TB",
7, "ARCnet",
8, "APPLEtalk",
15, "Frame Relay DLCI",
19, "ATM",
23, "Metricom STRIP",
24, "IEEE 1394 IPv4 - RFC 2734",
27, "EUI-64",
32, "InfiniBand",
256, "SLIP",
257, "CSLIP",
258, "SLIP6",
259, "CSLIP6",
260, "Notional KISS",
264, "ADAPT",
270, "ROSE",
271, "CCITT X.25",
272, "Boards with X.25 in Firmware",
280, "Controller Area Network",
512, "PPP",
513, "Cisco HDLC",
516, "LAPB",
517, "Digital's DDCMP Protocol",
518, "Raw HDLC",
768, "IPIP Tunnel",
769, "IP6IP6 Tunnel",
770, "Frame Relay Access Device",
771, "SKIP VIF",
772, "Loopback Device",
773, "Localtalk Device",
774, "Fiber Distributed Data Interface",
775, "AP1000 BIF",
776, "IPv6-in-IPv4",
777, "IP over DDP Tunnel",
778, "GRE over IP",
779, "PIMSM Interface",
780, "High Performance Parallel Interface",
781, "Nexus 64Mbps Ash",
782, "Acorn Econet",
783, "Linux-IrDA",
784, "Point to Point Fibrechannel",
785, "Fibrechannel Arbitrated Loop",
786, "Fibrechannel Public Loop",
787, "Fibrechannel Fabric",
788, "Fibrechannel Media Type 788",
789, "Fibrechannel Media Type 789",
790, "Fibrechannel Media Type 790",
791, "Fibrechannel Media Type 791",
792, "Fibrechannel Media Type 792",
793, "Fibrechannel Media Type 793",
794, "Fibrechannel Media Type 794",
795, "Fibrechannel Media Type 795",
796, "Fibrechannel Media Type 796",
797, "Fibrechannel Media Type 797",
798, "Fibrechannel Media Type 798",
799, "Fibrechannel Media Type 799",
800, "Magic Type Ident For TR",
801, "IEEE 802.11",
802, "IEEE 802.11 + Prism2 Header",
803, "IEEE 802.11 + Radiotap Header",
0xFFFF, "Void Type",
0xFFFE, "Zero Header Device",
};
const char *get_arp_type(int type)
{
unsigned int i;
for (i=0; i < (sizeof(arptype) / (sizeof(const char *) + sizeof(int)));
i++)
{
if (arptype[i].type == type)
return arptype[i].name;
}
return "Unknown Device";
}
static int ipx_getaddr(int sock, int ft, struct ifreq *ifr)
{
((struct sockaddr_ipx *) &ifr->ifr_addr)->sipx_type = ft;
return ioctl(sock, SIOCGIFADDR, ifr);
}
#if (IPX_NODE_LEN != 6)
#error "IPX_NODE_LEN != 6"
#endif
static char *IPX_print(unsigned char *ptr)
{
static char buf[64];
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) (ptr - 2);
int t;
for (t = IPX_NODE_LEN; t; t--)
if (sipx->sipx_node[t - 1])
break;
if (t && ntohl(sipx->sipx_network))
snprintf(buf, sizeof(buf), "%08lX:%02X%02X%02X%02X%02X%02X",
(long int) ntohl(sipx->sipx_network),
(int) sipx->sipx_node[0], (int) sipx->sipx_node[1],
(int) sipx->sipx_node[2], (int) sipx->sipx_node[3],
(int) sipx->sipx_node[4], (int) sipx->sipx_node[5]);
else if (!t && ntohl(sipx->sipx_network))
snprintf(buf, sizeof(buf), "%08lX",
(long int) ntohl(sipx->sipx_network));
else if (t && !ntohl(sipx->sipx_network))
snprintf(buf, sizeof(buf), "%02X%02X%02X%02X%02X%02X",
(int) sipx->sipx_node[0], (int) sipx->sipx_node[1],
(int) sipx->sipx_node[2], (int) sipx->sipx_node[3],
(int) sipx->sipx_node[4], (int) sipx->sipx_node[5]);
else
buf[0] = '\0';
return (buf);
}
static char *IPX_sprint(struct sockaddr *sap, int numeric)
{
static char buf[64];
if (sap->sa_family != AF_IPX)
return strncpy(buf, ("[NONE SET]"), sizeof(buf));
return (IPX_print((unsigned char *)sap->sa_data));
}
static char *ddp_print(unsigned char *ptr)
{
static char buf[64];
struct sockaddr_at *sat = (struct sockaddr_at *) (ptr - 2);
snprintf(buf, sizeof(buf), "%d/%d", (int) ntohs(sat->sat_addr.s_net),
(int) sat->sat_addr.s_node);
return (buf);
}
static char *ddp_sprint(struct sockaddr *sap, int numeric)
{
static char buf[64];
if (sap->sa_family != AF_APPLETALK)
return strncpy(buf, ("[NONE SET]"), sizeof(buf));
return (ddp_print((unsigned char *)sap->sa_data));
}
static char *ec_print(unsigned char *ptr)
{
static char buf[64];
struct ec_addr *ec = (struct ec_addr *) ptr;
snprintf(buf, sizeof(buf), "%d.%d", ec->net, ec->station);
return buf;
}
static char *ec_sprint(struct sockaddr *sap, int numeric)
{
struct sockaddr_ec *sec = (struct sockaddr_ec *) sap;
if (sap->sa_family != AF_ECONET)
return (char *)"[NONE SET]";
return ec_print((unsigned char *) &sec->addr);
}
unsigned int clip(int c) { return (c & 0xFF); }
ULONG warn_func(NWSCREEN *screen, ULONG index)
{
ULONG mNum, retCode;
mask_portal(mainportal);
mNum = make_menu(screen,
" Exit IFCON ",
get_screen_lines() - 12,
((get_screen_cols() - 1) / 2) -
((strlen((const char *)" Exit IFCON ") + 2) / 2),
2,
BORDER_DOUBLE,
YELLOW | BGBLUE,
YELLOW | BGBLUE,
BRITEWHITE | BGBLUE,
BRITEWHITE | BGBLUE,
0,
0,
0,
TRUE,
0);
add_item_to_menu(mNum, "Yes", 1);
add_item_to_menu(mNum, "No", 0);
retCode = activate_menu(mNum);
if (retCode == (ULONG) -1)
retCode = 0;
free_menu(mNum);
unmask_portal(mainportal);
return retCode;
}
char *comma_snprintf(char *buffer, int size, const char *format, ...)
{
unsigned int len, i;
char buf[1024], *src, *dest;
size_t vsize = size > (1024 - 1)
? 1024 - 1 : size;
va_list ap;
va_start(ap, format);
len = vsnprintf((char *)buf, vsize, format, ap);
va_end(ap);
if (len)
{
src = buf + strlen((const char *)buf);
dest = buffer + vsize;
*dest = '\0';
for (i=0; (i < strlen((const char *)buf)) &&
(dest >= buffer) && (src >= buf); i++)
{
if (i && !(i % 3))
*--dest = ',';
*--dest = *--src;
}
return (char *)dest;
}
return (char *)"";
}
struct user_net_device_stats {
unsigned long long rx_packets; /* total packets received */
unsigned long long tx_packets; /* total packets transmitted */
unsigned long long rx_bytes; /* total bytes received */
unsigned long long tx_bytes; /* total bytes transmitted */
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long rx_multicast; /* multicast packets received */
unsigned long rx_compressed;
unsigned long tx_compressed;
unsigned long collisions;
/* detailed rx_errors: */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* recved pkt with crc error */
unsigned long rx_frame_errors; /* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors; /* receiver missed packet */
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors;
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
};
int pnv = 1;
int get_dev_fields(char *bp, struct user_net_device_stats *stats)
{
switch (pnv)
{
case 3:
sscanf(bp,
"%llu %llu %lu %lu %lu %lu %lu %lu %llu %llu %lu %lu %lu %lu %lu %lu",
&stats->rx_bytes,
&stats->rx_packets,
&stats->rx_errors,
&stats->rx_dropped,
&stats->rx_fifo_errors,
&stats->rx_frame_errors,
&stats->rx_compressed,
&stats->rx_multicast,
&stats->tx_bytes,
&stats->tx_packets,
&stats->tx_errors,
&stats->tx_dropped,
&stats->tx_fifo_errors,
&stats->collisions,
&stats->tx_carrier_errors,
&stats->tx_compressed);
break;
case 2:
sscanf(bp, "%llu %llu %lu %lu %lu %lu %llu %llu %lu %lu %lu %lu %lu",
&stats->rx_bytes,
&stats->rx_packets,
&stats->rx_errors,
&stats->rx_dropped,
&stats->rx_fifo_errors,
&stats->rx_frame_errors,
&stats->tx_bytes,
&stats->tx_packets,
&stats->tx_errors,
&stats->tx_dropped,
&stats->tx_fifo_errors,
&stats->collisions,
&stats->tx_carrier_errors);
stats->rx_multicast = 0;
break;
case 1:
sscanf(bp, "%llu %lu %lu %lu %lu %llu %lu %lu %lu %lu %lu",
&stats->rx_packets,
&stats->rx_errors,
&stats->rx_dropped,
&stats->rx_fifo_errors,
&stats->rx_frame_errors,
&stats->tx_packets,
&stats->tx_errors,
&stats->tx_dropped,
&stats->tx_fifo_errors,
&stats->collisions,
&stats->tx_carrier_errors);
stats->rx_bytes = 0;
stats->tx_bytes = 0;
stats->rx_multicast = 0;
break;
}
return 0;
}
int if_getconfig(int skfd, int portal, char *ifname, int *pos, char *bp)
{
struct ifreq ifr;
int metric, mtu, flags, family, has_ip, row = pos ? *pos : 0;
struct sockaddr dstaddr, broadaddr, netmask, ifaddr, hwa;
unsigned char *hwaddr;
FILE *f;
char addr6[40], devname[20];
struct sockaddr_in6 sap;
int plen, scope, dad_status, if_idx, fd, stats_valid;
char addr6p[8][5], *w;
int has_econet = 0, has_ddp = 0, has_ipx_bb = 0, has_ipx_sn = 0;
int has_ipx_e3 = 0, has_ipx_e2 = 0;
struct sockaddr ipxaddr_bb;
struct sockaddr ipxaddr_sn;
struct sockaddr ipxaddr_e3;
struct sockaddr ipxaddr_e2;
struct sockaddr ddpaddr;
struct sockaddr ecaddr;
struct ifmap map;
unsigned long can_compress = 0, tx_queue_len, keepalive = 0,
outfill = 0;
unsigned long long rx, tx, short_rx, short_tx;
char rx_increment[5]="b";
char tx_increment[5]="b";
char display_buffer[1024];
char format_buffer[1024];
char cat_buffer[1024];
struct user_net_device_stats ifstats;
memset(&ifstats, 0, sizeof(struct user_net_device_stats));
get_dev_fields(bp, &ifstats);
stats_valid = 1;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFHWADDR, &ifr) >= 0)
{
hwa = ifr.ifr_hwaddr;
hwaddr = (unsigned char *)hwa.sa_data;
family = ifr.ifr_hwaddr.sa_family;
}
else
{
memset(&hwa, 0, sizeof(struct sockaddr));
hwaddr = (unsigned char *)hwa.sa_data;
family = 0;
}
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) >= 0)
flags = ifr.ifr_flags;
else
flags = 0;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFADDR, &ifr) >= 0)
{
has_ip = 1;
ifaddr = ifr.ifr_addr;
}
else
{
memset(&ifaddr, 0, sizeof(struct sockaddr));
has_ip = 0;
}
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0) {
metric = 0;
} else
metric = ifr.ifr_metric;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
mtu = 0;
else
mtu = ifr.ifr_mtu;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFDSTADDR, &ifr) < 0) {
memset(&dstaddr, 0, sizeof(struct sockaddr));
} else
dstaddr = ifr.ifr_dstaddr;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFBRDADDR, &ifr) < 0) {
memset(&broadaddr, 0, sizeof(struct sockaddr));
} else
broadaddr = ifr.ifr_broadaddr;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFNETMASK, &ifr) < 0) {
memset(&netmask, 0, sizeof(struct sockaddr));
} else
netmask = ifr.ifr_netmask;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0)
tx_queue_len = -1;
else
tx_queue_len = ifr.ifr_qlen;
if (family == ARPHRD_SLIP || family == ARPHRD_CSLIP ||
family == ARPHRD_SLIP6 || family == ARPHRD_CSLIP6 ||
family == ARPHRD_ADAPT)
{
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0)
outfill = 0;
else
outfill = (unsigned long) ifr.ifr_data;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0)
keepalive = 0;
else
keepalive = (unsigned long) ifr.ifr_data;
}
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
memset(&map, 0, sizeof(struct ifmap));
else
memcpy(&map, &ifr.ifr_map, sizeof(struct ifmap));
display_buffer[0] = '\0';
snprintf(format_buffer, sizeof(format_buffer), "%s Link encap:%s ",
ifname, get_arp_type(family));
strcat(display_buffer, format_buffer);
if (hwaddr)
{
snprintf(format_buffer, sizeof(format_buffer),
"HWaddr: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3],
hwaddr[4], hwaddr[5]);
strcat(display_buffer, format_buffer);
}
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
if (family == ARPHRD_CSLIP || family == ARPHRD_CSLIP6)
can_compress = 1;
fd = socket(AF_APPLETALK, SOCK_DGRAM, 0);
if (fd >= 0)
{
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0)
{
ddpaddr = ifr.ifr_addr;
has_ddp = 1;
}
close(fd);
}
fd = socket(AF_IPX, SOCK_DGRAM, 0);
if (fd >= 0)
{
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr))
{
has_ipx_bb = 1;
ipxaddr_bb = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr))
{
has_ipx_sn = 1;
ipxaddr_sn = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_8023, &ifr))
{
has_ipx_e3 = 1;
ipxaddr_e3 = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_8022, &ifr))
{
has_ipx_e2 = 1;
ipxaddr_e2 = ifr.ifr_addr;
}
close(fd);
}
fd = socket(AF_ECONET, SOCK_DGRAM, 0);
if (fd >= 0)
{
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0)
{
ecaddr = ifr.ifr_addr;
has_econet = 1;
}
close(fd);
}
if (has_ipx_bb)
{
snprintf(display_buffer, sizeof(display_buffer), ("IPX/Ethernet II addr:%s"),
IPX_sprint(&ipxaddr_bb, 1));
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
}
if (has_ipx_sn)
{
snprintf(display_buffer, sizeof(display_buffer), ("IPX/Ethernet SNAP addr:%s"),
IPX_sprint(&ipxaddr_sn, 1));
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
}
if (has_ipx_e2)
{
snprintf(display_buffer, sizeof(display_buffer), ("IPX/Ethernet 802.2 addr:%s"),
IPX_sprint(&ipxaddr_e2, 1));
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
}
if (has_ipx_e3)
{
snprintf(display_buffer, sizeof(display_buffer), ("IPX/Ethernet 802.3 addr:%s"),
IPX_sprint(&ipxaddr_e3, 1));
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
}
if (has_ddp)
{
snprintf(display_buffer, sizeof(display_buffer), ("EtherTalk Phase 2 addr:%s"),
ddp_sprint(&ddpaddr, 1));
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
}
if (has_econet)
{
snprintf(display_buffer, sizeof(display_buffer), ("econet addr:%s"),
ec_sprint(&ecaddr, 1));
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
}
display_buffer[0] = '\0';
if (flags == 0)
strcat(display_buffer, ("[NO FLAGS] "));
if (flags & IFF_UP)
strcat(display_buffer, ("UP "));
if (flags & IFF_BROADCAST)
strcat(display_buffer, ("BROADCAST "));
if (flags & IFF_DEBUG)
strcat(display_buffer, ("DEBUG "));
if (flags & IFF_LOOPBACK)
strcat(display_buffer, ("LOOPBACK "));
if (flags & IFF_POINTOPOINT)
strcat(display_buffer, ("POINTOPOINT "));
if (flags & IFF_NOTRAILERS)
strcat(display_buffer, ("NOTRAILERS "));
if (flags & IFF_RUNNING)
strcat(display_buffer, ("RUNNING "));
if (flags & IFF_NOARP)
strcat(display_buffer, ("NOARP "));
if (flags & IFF_PROMISC)
strcat(display_buffer, ("PROMISC "));
if (flags & IFF_ALLMULTI)
strcat(display_buffer, ("ALLMULTI "));
if (flags & IFF_SLAVE)
strcat(display_buffer, ("SLAVE "));
if (flags & IFF_MASTER)
strcat(display_buffer, ("MASTER "));
if (flags & IFF_MULTICAST)
strcat(display_buffer, ("MULTICAST "));
if (flags & IFF_DYNAMIC)
strcat(display_buffer, ("DYNAMIC "));
snprintf(format_buffer, sizeof(format_buffer),
" MTU:%u Metric:%u",
mtu, metric ? metric : 1);
strcat(display_buffer, format_buffer);
if (outfill || keepalive)
{
snprintf(format_buffer, sizeof(format_buffer),
" Outfill:%ld Keepalive:%ld",
outfill, keepalive);
strcat(display_buffer, format_buffer);
}
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
if (has_ip)
{
display_buffer[0] = '\0';
snprintf(format_buffer, sizeof(format_buffer),
"inet addr:%u.%u.%u.%u ",
clip(ifaddr.sa_data[2]), clip(ifaddr.sa_data[3]),
clip(ifaddr.sa_data[4]), clip(ifaddr.sa_data[5]));
strcat(display_buffer, format_buffer);
if (flags & IFF_POINTOPOINT)
{
snprintf(format_buffer, sizeof(format_buffer),
"P-t-P:%u.%u.%u.%u ",
clip(dstaddr.sa_data[2]), clip(dstaddr.sa_data[3]),
clip(dstaddr.sa_data[4]), clip(dstaddr.sa_data[5]));
strcat(display_buffer, format_buffer);
}
if (flags & IFF_BROADCAST)
{
snprintf(format_buffer, sizeof(format_buffer),
"Bcast:%u.%u.%u.%u ",
clip(broadaddr.sa_data[2]), clip(broadaddr.sa_data[3]),
clip(broadaddr.sa_data[4]), clip(broadaddr.sa_data[5]));
strcat(display_buffer, format_buffer);
}
snprintf(format_buffer, sizeof(format_buffer),
"Mask:%u.%u.%u.%u",
clip(netmask.sa_data[2]), clip(netmask.sa_data[3]),
clip(netmask.sa_data[4]), clip(netmask.sa_data[5]));
strcat(display_buffer, format_buffer);
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
}
if ((f = fopen("/proc/net/if_inet6", "r")) != NULL)
{
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x"
" %02x %02x %20s\n",
addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7],
&if_idx, &plen, &scope, &dad_status, devname) != EOF)
{
if (!strcmp(devname, ifname))
{
display_buffer[0] = '\0';
snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
INET6_input(1, addr6, (struct sockaddr *) &sap);
snprintf(format_buffer, sizeof(format_buffer),
("inet6 addr: %s/%d"),
INET6_sprint((struct sockaddr *) &sap, 1), plen);
strcat(display_buffer, format_buffer);
snprintf(format_buffer, sizeof(format_buffer), (" Scope:"));
strcat(display_buffer, format_buffer);
switch (scope)
{
case 0:
strcat(display_buffer, ("Global"));
break;
case IPV6_ADDR_LINKLOCAL:
strcat(display_buffer, ("Link"));
break;
case IPV6_ADDR_SITELOCAL:
strcat(display_buffer, ("Site"));
break;
case IPV6_ADDR_COMPATv4:
strcat(display_buffer, ("Compat"));
break;
case IPV6_ADDR_LOOPBACK:
strcat(display_buffer, ("Host"));
break;
default:
strcat(display_buffer, ("Unknown"));
}
write_portal(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
}
}
fclose(f);
}
if (stats_valid)
{
w = comma_snprintf(format_buffer, sizeof(format_buffer), "%llu",
ifstats.rx_packets);
snprintf(display_buffer, sizeof(display_buffer), "RX packets :%s",
w);
write_portal_cleol(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
w = comma_snprintf(format_buffer, sizeof(format_buffer), "%lu",
ifstats.rx_errors);
snprintf(display_buffer, sizeof(display_buffer), "RX errors :%s",
w);
write_portal_cleol(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
w = comma_snprintf(format_buffer, sizeof(format_buffer), "%lu",
ifstats.rx_dropped);
snprintf(display_buffer, sizeof(display_buffer), "RX dropped :%s",
w);
write_portal_cleol(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
w = comma_snprintf(format_buffer, sizeof(format_buffer), "%lu",
ifstats.rx_fifo_errors);
snprintf(display_buffer, sizeof(display_buffer), "RX overruns :%s",
w);
write_portal_cleol(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
w = comma_snprintf(format_buffer, sizeof(format_buffer), "%lu",
ifstats.rx_frame_errors);
snprintf(display_buffer, sizeof(display_buffer), "RX frame :%s",
w);
write_portal_cleol(portal, (const char *)display_buffer, row++, 2,
BRITEWHITE | BGBLUE);
rx = ifstats.rx_bytes;
tx = ifstats.tx_bytes;
short_rx = rx * 10;
short_tx = tx * 10;
if (rx > 1000000000000000000)
{
short_rx /= 1000000000000000000;
strcpy(rx_increment, "Eb");
}
else
if (rx > 1000000000000000)
{
short_rx /= 1000000000000000;
strcpy(rx_increment, "Pb");
}
else
if (rx > 1000000000000)
{
short_rx /= 1000000000000;
strcpy(rx_increment, "Tb");
}
else
if (rx > 1000000000)
{
short_rx /= 1000000000;
strcpy(rx_increment, "Gb");
}
else
if (rx > 1000000)
{
short_rx /= 1000000;
strcpy(rx_increment, "Mb");
}
else
if (rx > 1000)
{
short_rx /= 1000;
strcpy(rx_increment, "Kb");
}