fixes for man page bugs reported by Hugh Redelmeier.
[oss-qm-packages.git] / lib / ddp_gr.c
blob3453e2fafe911e54f3d0762179fd9e08b5cf9407
1 /*
2 * lib/ddp_gr.c Prinbting of DDP (AppleTalk) routing table
3 * used by the NET-LIB.
5 * NET-LIB
7 * Version: $Id: ddp_gr.c,v 1.4 2002/06/02 05:25:15 ecki Exp $
9 * Author: Ajax <ajax@firest0rm.org>
11 * Modification:
12 * 2002-06-02 integrated into main source by Bernd Eckenfels
16 /* TODO: name lookups (/etc/atalk.names? NBP?) */
18 #include "config.h"
20 #if HAVE_AFATALK
21 #include <asm/types.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <linux/atalk.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <errno.h>
28 #include <ctype.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <netinet/in.h>
32 #include "net-support.h"
33 #include "pathnames.h"
34 #include "intl.h"
36 /* stolen from inet_gr.c */
37 #define flags_decode(i,o) do { \
38 o[0] = '\0'; \
39 if (i & RTF_UP) strcat(o, "U"); \
40 if (i & RTF_GATEWAY) strcat(o, "G"); \
41 if (i & RTF_REJECT) strcat(o, "!"); \
42 if (i & RTF_HOST) strcat(o, "H"); \
43 if (i & RTF_REINSTATE) strcat(o, "R"); \
44 if (i & RTF_DYNAMIC) strcat(o, "D"); \
45 if (i & RTF_MODIFIED) strcat(o, "M"); \
46 if (i & RTF_DEFAULT) strcat(o, "d"); \
47 if (i & RTF_ALLONLINK) strcat(o, "a"); \
48 if (i & RTF_ADDRCONF) strcat(o, "c"); \
49 if (i & RTF_NONEXTHOP) strcat(o, "o"); \
50 if (i & RTF_EXPIRES) strcat(o, "e"); \
51 if (i & RTF_CACHE) strcat(o, "c"); \
52 if (i & RTF_FLOW) strcat(o, "f"); \
53 if (i & RTF_POLICY) strcat(o, "p"); \
54 if (i & RTF_LOCAL) strcat(o, "l"); \
55 if (i & RTF_MTU) strcat(o, "u"); \
56 if (i & RTF_WINDOW) strcat(o, "w"); \
57 if (i & RTF_IRTT) strcat(o, "i"); \
58 if (i & RTF_NOTCACHED) strcat(o, "n"); \
59 } while (0)
61 int DDP_rprint(int options)
63 FILE *fp;
64 char *dest, *gw, *dev, *flags;
65 char oflags[32];
66 char *hdr = "Destination Gateway Device Flags";
68 fp = fopen(_PATH_PROCNET_ATALK_ROUTE, "r");
70 if (!fp) {
71 perror("Error opening " _PATH_PROCNET_ATALK_ROUTE);
72 fprintf(stderr, "DDP (AppleTalk) not configured on this system.\n");
73 return 1;
76 fscanf(fp, "%as %as %as %as\n", &dest, &gw, &flags, &dev);
77 free(dest); free(gw); free(dev); free(flags);
79 printf("%s\n", hdr);
81 while (fscanf(fp, "%as %as %as %as\n", &dest, &gw, &flags, &dev) == 4) {
82 int iflags = atoi(flags);
83 flags_decode(iflags, oflags);
84 printf("%-16s%-16s%-16s%-s\n", dest, gw, dev, oflags);
85 free(dest); free(gw); free(dev); free(flags);
88 fclose(fp);
90 return 0;
93 #endif