172 { "END", 14,
173 offsetof(history_l_fields_buf_t, history_l_etime), print_default_cb},
174 { "RBYTES", 9,
175 offsetof(history_l_fields_buf_t, history_l_rbytes), print_default_cb},
176 { "OBYTES", 9,
177 offsetof(history_l_fields_buf_t, history_l_obytes), print_default_cb},
178 { "BANDWIDTH", 15,
179 offsetof(history_l_fields_buf_t, history_l_bandwidth),
180 print_default_cb},
181 NULL_OFMT}
182 ;
183
184 static char *progname;
185
186 /*
187 * Handle to libdladm. Opened in main() before the sub-command
188 * specific function is called.
189 */
190 static dladm_handle_t handle = NULL;
191
192 const char *usage_ermsg = "flowstat [-r | -t] [-i interval] "
193 "[-l link] [flow]\n"
194 " flowstat [-S] [-A] [-i interval] [-p] [ -o field[,...]]\n"
195 " [-u R|K|M|G|T|P] [-l link] [flow]\n"
196 " flowstat -h [-a] [-d] [-F format]"
197 " [-s <DD/MM/YYYY,HH:MM:SS>]\n"
198 " [-e <DD/MM/YYYY,HH:MM:SS>] -f <logfile> "
199 "[<flow>]";
200
201 static void
202 usage(void)
203 {
204 (void) fprintf(stderr, "%s\n", gettext(usage_ermsg));
205
206 /* close dladm handle if it was opened */
207 if (handle != NULL)
208 dladm_close(handle);
209
210 exit(1);
211 }
212
213 boolean_t
214 flowstat_unit(char *oarg, char *unit)
215 {
216 if ((strcmp(oarg, "R") == 0) || (strcmp(oarg, "K") == 0) ||
217 (strcmp(oarg, "M") == 0) || (strcmp(oarg, "G") == 0) ||
218 (strcmp(oarg, "T") == 0) || (strcmp(oarg, "P") == 0)) {
219 *unit = oarg[0];
1060 (void) putc('\n', stderr);
1061
1062 /* close dladm handle if it was opened */
1063 if (handle != NULL)
1064 dladm_close(handle);
1065
1066 exit(EXIT_FAILURE);
1067 }
1068
1069 static void
1070 die_optdup(int opt)
1071 {
1072 die("the option -%c cannot be specified more than once", opt);
1073 }
1074
1075 static void
1076 die_opterr(int opt, int opterr, const char *usage)
1077 {
1078 switch (opterr) {
1079 case ':':
1080 die("option '-%c' requires a value\nusage: %s", opt,
1081 gettext(usage));
1082 break;
1083 case '?':
1084 default:
1085 die("unrecognized option '-%c'\nusage: %s", opt,
1086 gettext(usage));
1087 break;
1088 }
1089 }
1090
1091 /* PRINTFLIKE2 */
1092 static void
1093 die_dlerr(dladm_status_t err, const char *format, ...)
1094 {
1095 va_list alist;
1096 char errmsg[DLADM_STRSIZE];
1097
1098 format = gettext(format);
1099 (void) fprintf(stderr, "%s: ", progname);
1100
1101 va_start(alist, format);
1102 (void) vfprintf(stderr, format, alist);
1103 va_end(alist);
1104 (void) fprintf(stderr, ": %s\n", dladm_status2str(err, errmsg));
1105
|
172 { "END", 14,
173 offsetof(history_l_fields_buf_t, history_l_etime), print_default_cb},
174 { "RBYTES", 9,
175 offsetof(history_l_fields_buf_t, history_l_rbytes), print_default_cb},
176 { "OBYTES", 9,
177 offsetof(history_l_fields_buf_t, history_l_obytes), print_default_cb},
178 { "BANDWIDTH", 15,
179 offsetof(history_l_fields_buf_t, history_l_bandwidth),
180 print_default_cb},
181 NULL_OFMT}
182 ;
183
184 static char *progname;
185
186 /*
187 * Handle to libdladm. Opened in main() before the sub-command
188 * specific function is called.
189 */
190 static dladm_handle_t handle = NULL;
191
192 const char *usage_ermsg = "usage: flowstat [-r | -t] [-i interval] "
193 "[-l link] [flow]\n"
194 " flowstat [-p | -u R|K|M|G|T|P] [ -o field[,...]] "
195 "[-l link] [flow]\n"
196 " flowstat [-A] [-l link] [flow]\n"
197 " flowstat [-S] [-i interval] [-l link] [flow]\n"
198 " flowstat -h [-a] [-d] [-F format] "
199 "[-s <DD/MM/YYYY,HH:MM:SS>]\n"
200 " [-e <DD/MM/YYYY,HH:MM:SS>] -f <logfile> [<flow>]";
201
202 static void
203 usage(void)
204 {
205 (void) fprintf(stderr, "%s\n", gettext(usage_ermsg));
206
207 /* close dladm handle if it was opened */
208 if (handle != NULL)
209 dladm_close(handle);
210
211 exit(1);
212 }
213
214 boolean_t
215 flowstat_unit(char *oarg, char *unit)
216 {
217 if ((strcmp(oarg, "R") == 0) || (strcmp(oarg, "K") == 0) ||
218 (strcmp(oarg, "M") == 0) || (strcmp(oarg, "G") == 0) ||
219 (strcmp(oarg, "T") == 0) || (strcmp(oarg, "P") == 0)) {
220 *unit = oarg[0];
1061 (void) putc('\n', stderr);
1062
1063 /* close dladm handle if it was opened */
1064 if (handle != NULL)
1065 dladm_close(handle);
1066
1067 exit(EXIT_FAILURE);
1068 }
1069
1070 static void
1071 die_optdup(int opt)
1072 {
1073 die("the option -%c cannot be specified more than once", opt);
1074 }
1075
1076 static void
1077 die_opterr(int opt, int opterr, const char *usage)
1078 {
1079 switch (opterr) {
1080 case ':':
1081 die("option '-%c' requires a value\n%s", opt,
1082 gettext(usage));
1083 break;
1084 case '?':
1085 default:
1086 die("unrecognized option '-%c'\n%s", opt,
1087 gettext(usage));
1088 break;
1089 }
1090 }
1091
1092 /* PRINTFLIKE2 */
1093 static void
1094 die_dlerr(dladm_status_t err, const char *format, ...)
1095 {
1096 va_list alist;
1097 char errmsg[DLADM_STRSIZE];
1098
1099 format = gettext(format);
1100 (void) fprintf(stderr, "%s: ", progname);
1101
1102 va_start(alist, format);
1103 (void) vfprintf(stderr, format, alist);
1104 va_end(alist);
1105 (void) fprintf(stderr, ": %s\n", dladm_status2str(err, errmsg));
1106
|