#include <resolv.h>
#include <asm/types.h>
#include <linux/pkt_sched.h>
+#include <time.h>
+#include <sys/time.h>
+
#include "utils.h"
dst->bitlen = 32;
}
if (slash) {
- if (get_integer(&plen, slash+1, 0) || plen > dst->bitlen) {
+ if (get_unsigned(&plen, slash+1, 0) || plen > dst->bitlen) {
err = -1;
goto done;
}
+ dst->flags |= PREFIXLEN_SPECIFIED;
dst->bitlen = plen;
}
}
}
-__u8* hexstring_n2a(const __u8 *str, int len, __u8 *buf, int blen)
+char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen)
{
- __u8 *ptr = buf;
+ char *ptr = buf;
int i;
for (i=0; i<len; i++) {
return buf;
}
-__u8* hexstring_a2n(const __u8 *str, __u8 *buf, int blen)
+__u8* hexstring_a2n(const char *str, __u8 *buf, int blen)
{
int cnt = 0;
memset(buf+cnt, 0, blen-cnt);
return buf;
}
+
+int print_timestamp(FILE *fp)
+{
+ struct timeval tv;
+ char *tstr;
+
+ memset(&tv, 0, sizeof(tv));
+ gettimeofday(&tv, NULL);
+
+ tstr = asctime(localtime(&tv.tv_sec));
+ tstr[strlen(tstr)-1] = 0;
+ fprintf(fp, "Timestamp: %s %lu usec\n", tstr, tv.tv_usec);
+ return 0;
+}
+
+int cmdlineno;
+
+/* Like glibc getline but handle continuation lines and comments */
+size_t getcmdline(char **linep, size_t *lenp, FILE *in)
+{
+ size_t cc;
+ char *cp;
+
+ if ((cc = getline(linep, lenp, in)) < 0)
+ return cc; /* eof or error */
+ ++cmdlineno;
+
+ cp = strchr(*linep, '#');
+ if (cp)
+ *cp = '\0';
+
+ while ((cp = strstr(*linep, "\\\n")) != NULL) {
+ char *line1 = NULL;
+ size_t len1 = 0;
+ size_t cc1;
+
+ if ((cc1 = getline(&line1, &len1, in)) < 0) {
+ fprintf(stderr, "Missing continuation line\n");
+ return cc1;
+ }
+
+ ++cmdlineno;
+ *cp = 0;
+
+ cp = strchr(line1, '#');
+ if (cp)
+ *cp = '\0';
+
+ *linep = realloc(*linep, strlen(*linep) + strlen(line1) + 1);
+ if (!*linep) {
+ fprintf(stderr, "Out of memory\n");
+ return -1;
+ }
+ cc += cc1 - 2;
+ strcat(*linep, line1);
+ free(line1);
+ }
+ return cc;
+}
+
+/* split command line into argument vector */
+int makeargs(char *line, char *argv[], int maxargs)
+{
+ static const char ws[] = " \t\r\n";
+ char *cp;
+ int argc = 0;
+
+ for (cp = strtok(line, ws); cp; cp = strtok(NULL, ws)) {
+ if (argc >= (maxargs - 1)) {
+ fprintf(stderr, "Too many arguments to command\n");
+ exit(1);
+ }
+ argv[argc++] = cp;
+ }
+ argv[argc] = NULL;
+
+ return argc;
+}