From 3744317e1cb834f3d54c47aa3159ec1f7c5bf11e Mon Sep 17 00:00:00 2001 From: rusty Date: Fri, 27 Apr 2001 08:39:00 +0000 Subject: Fabrice Marie's timestamp extensions fixes. --- extensions/libipt_time.c | 50 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'extensions/libipt_time.c') diff --git a/extensions/libipt_time.c b/extensions/libipt_time.c index 07af0f4..1d7690c 100644 --- a/extensions/libipt_time.c +++ b/extensions/libipt_time.c @@ -47,9 +47,10 @@ init(struct ipt_entry_match *m, unsigned int *nfcache) static int split_time(char **part1, char **part2, const char *str_2_parse) { - unsigned short int i,j; + unsigned short int i,j=0; char *rpart1 = *part1; char *rpart2 = *part2; + unsigned char found_column = 0; /* Check the length of the string */ if (strlen(str_2_parse) > 5) @@ -57,15 +58,16 @@ split_time(char **part1, char **part2, const char *str_2_parse) /* parse the first part until the ':' */ for (i=0; i<2; i++) { - if (str_2_parse[i] != ':') { + if (str_2_parse[i] == ':') + found_column = 1; + else rpart1[i] = str_2_parse[i]; - } } - if (str_2_parse[i] != ':') - ++i; + if (!found_column) + i++; + j=i; /* parse the second part */ - j=++i; - for (i=j; i<5; i++) + for (; ihour_start = hours; - timeinfo->minute_start = minutes; + timeinfo->time_start = (hours * 60) + minutes; *flags |= IPT_TIME_START; break; /* timestop */ @@ -187,8 +194,7 @@ parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "Can't specify --timestop twice"); parse_time_string(&hours, &minutes, optarg); - timeinfo->hour_stop = hours; - timeinfo->minute_stop = minutes; + timeinfo->time_stop = (hours * 60) + minutes; *flags |= IPT_TIME_STOP; break; @@ -239,6 +245,13 @@ print_days(int daynum) } } +static void +divide_time(int fulltime, int *hours, int *minutes) +{ + *hours = fulltime / 60; + *minutes = fulltime % 60; +} + /* Prints out the matchinfo. */ static void print(const struct ipt_ip *ip, @@ -246,9 +259,13 @@ print(const struct ipt_ip *ip, int numeric) { struct ipt_time_info *time = ((struct ipt_time_info *)match->data); + int hour_start, hour_stop, minute_start, minute_stop; + + divide_time(time->time_start, &hour_start, &minute_start); + divide_time(time->time_stop, &hour_stop, &minute_stop); printf(" TIME from %d:%d to %d:%d on ", - time->hour_start, time->minute_start, - time->hour_stop, time->minute_stop); + hour_start, minute_start, + hour_stop, minute_stop); print_days(time->days_match); printf(" "); } @@ -258,10 +275,13 @@ static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match) { struct ipt_time_info *time = ((struct ipt_time_info *)match->data); + int hour_start, hour_stop, minute_start, minute_stop; + divide_time(time->time_start, &hour_start, &minute_start); + divide_time(time->time_stop, &hour_stop, &minute_stop); printf(" --timestart %.2d:%.2d --timestop %.2d:%.2d --days ", - time->hour_start, time->minute_start, - time->hour_stop, time->minute_stop); + hour_start, minute_start, + hour_stop, minute_stop); print_days(time->days_match); printf(" "); } -- cgit v1.2.3