41
42 /*
43 * arp - display, set, and delete arp table entries
44 */
45
46 #include <stdio.h>
47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <sys/ioctl.h>
51 #include <errno.h>
52 #include <netdb.h>
53 #include <net/if.h>
54 #include <net/if_arp.h>
55 #include <stdlib.h>
56 #include <unistd.h>
57 #include <string.h>
58 #include <arpa/inet.h>
59 #include <net/if_types.h>
60 #include <net/if_dl.h>
61
62 static int file(char *);
63 static int set(int, char *[]);
64 static void get(char *);
65 static void delete(char *);
66 static void usage(void);
67
68 int
69 main(int argc, char *argv[])
70 {
71 int c, nflags = 0, argsleft;
72 int n_flag, a_flag, d_flag, f_flag, s_flag;
73
74 n_flag = a_flag = d_flag = f_flag = s_flag = 0;
75
76 #define CASE(x, y) \
77 case x: \
78 if (nflags > 0) { \
79 usage(); \
80 exit(1); \
101 }
102
103 #undef CASE
104
105 /*
106 * -n only allowed with -a
107 */
108 if (n_flag && !a_flag) {
109 usage();
110 exit(1);
111 }
112
113 argsleft = argc - optind;
114
115 if (a_flag && (argsleft == 0)) {
116 /*
117 * the easiest way to get the complete arp table
118 * is to let netstat, which prints it as part of
119 * the MIB statistics, do it.
120 */
121 (void) execl("/usr/bin/netstat", "netstat",
122 (n_flag ? "-np" : "-p"),
123 "-f", "inet", (char *)0);
124 (void) fprintf(stderr, "failed to exec netstat: %s\n",
125 strerror(errno));
126 exit(1);
127
128 } else if (s_flag && (argsleft >= 2)) {
129 if (set(argsleft, &argv[optind]) != 0)
130 exit(1);
131
132 } else if (d_flag && (argsleft == 1)) {
133 delete(argv[optind]);
134
135 } else if (f_flag && (argsleft == 1)) {
136 if (file(argv[optind]) != 0)
137 exit(1);
138
139 } else if ((nflags == 0) && (argsleft == 1)) {
140 get(argv[optind]);
141
142 } else {
143 usage();
144 exit(1);
145 }
|
41
42 /*
43 * arp - display, set, and delete arp table entries
44 */
45
46 #include <stdio.h>
47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <sys/ioctl.h>
51 #include <errno.h>
52 #include <netdb.h>
53 #include <net/if.h>
54 #include <net/if_arp.h>
55 #include <stdlib.h>
56 #include <unistd.h>
57 #include <string.h>
58 #include <arpa/inet.h>
59 #include <net/if_types.h>
60 #include <net/if_dl.h>
61 #include <zone.h>
62
63 static int file(char *);
64 static int set(int, char *[]);
65 static void get(char *);
66 static void delete(char *);
67 static void usage(void);
68
69 int
70 main(int argc, char *argv[])
71 {
72 int c, nflags = 0, argsleft;
73 int n_flag, a_flag, d_flag, f_flag, s_flag;
74
75 n_flag = a_flag = d_flag = f_flag = s_flag = 0;
76
77 #define CASE(x, y) \
78 case x: \
79 if (nflags > 0) { \
80 usage(); \
81 exit(1); \
102 }
103
104 #undef CASE
105
106 /*
107 * -n only allowed with -a
108 */
109 if (n_flag && !a_flag) {
110 usage();
111 exit(1);
112 }
113
114 argsleft = argc - optind;
115
116 if (a_flag && (argsleft == 0)) {
117 /*
118 * the easiest way to get the complete arp table
119 * is to let netstat, which prints it as part of
120 * the MIB statistics, do it.
121 */
122 char netstat_path[MAXPATHLEN];
123 const char *zroot = zone_get_nroot();
124 (void) snprintf(netstat_path, sizeof (netstat_path), "%s%s", zroot != NULL ?
125 zroot : "", "/usr/bin/netstat");
126 (void) execl(netstat_path, "netstat",
127 (n_flag ? "-np" : "-p"),
128 "-f", "inet", (char *)0);
129 (void) fprintf(stderr, "failed to exec %s: %s\n",
130 netstat_path, strerror(errno));
131 exit(1);
132
133 } else if (s_flag && (argsleft >= 2)) {
134 if (set(argsleft, &argv[optind]) != 0)
135 exit(1);
136
137 } else if (d_flag && (argsleft == 1)) {
138 delete(argv[optind]);
139
140 } else if (f_flag && (argsleft == 1)) {
141 if (file(argv[optind]) != 0)
142 exit(1);
143
144 } else if ((nflags == 0) && (argsleft == 1)) {
145 get(argv[optind]);
146
147 } else {
148 usage();
149 exit(1);
150 }
|