remove gmtime()-related code duplication

This commit is contained in:
rofl0r 2020-10-20 01:44:56 +01:00
parent c1dd3a9ff6
commit 85af251806
1 changed files with 21 additions and 26 deletions

View File

@ -462,6 +462,13 @@ static void empty_pin_hmac(struct global *wps)
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, NULL, 0, wps->empty_psk);
}
static char* format_time(time_t t, char* buf30)
{
struct tm ts;
strftime(buf30, 30, "%c", gmtime_r(&t, &ts));
return buf30;
}
int main(int argc, char **argv)
{
struct global *wps;
@ -600,18 +607,14 @@ memory_err:
unsigned int cores = hardware_concurrency();
struct timeval t_current;
gettimeofday(&t_current, 0);
time_t r_time;
struct tm ts;
char buffer[30];
r_time = t_current.tv_sec;
gmtime_r(&r_time, &ts);
strftime(buffer, 30, "%c", &ts);
fprintf(stderr, "\n ");
printf("Pixiewps %s", LONG_VERSION); fflush(stdout);
fprintf(stderr, "\n\n"
" [*] System time: %lu (%s UTC)\n"
" [*] Number of cores available: %u\n\n",
(unsigned long) t_current.tv_sec, buffer, cores == 0 ? 1 : cores);
(unsigned long) t_current.tv_sec,
format_time(t_current.tv_sec, buffer), cores == 0 ? 1 : cores);
free(wps->error);
free(wps);
return ARG_ERROR;
@ -1270,16 +1273,13 @@ usage_err:
#if DEBUG
{
struct tm ts;
char buffer[30];
gmtime_r(&wps->start, &ts);
strftime(buffer, 30, "%c", &ts);
printf("\n [DEBUG] %s:%d:%s(): Start: %10lu (%s UTC)",
__FILE__, __LINE__, __func__, (unsigned long) wps->start, buffer);
gmtime_r(&wps->end, &ts);
strftime(buffer, 30, "%c", &ts);
__FILE__, __LINE__, __func__, (unsigned long) wps->start,
format_time(wps->start, buffer));
printf("\n [DEBUG] %s:%d:%s(): End: %10lu (%s UTC)",
__FILE__, __LINE__, __func__, (unsigned long) wps->end, buffer);
__FILE__, __LINE__, __func__, (unsigned long) wps->end,
format_time(wps->end, buffer));
fflush(stdout);
}
#endif
@ -1426,24 +1426,19 @@ usage_err:
if (found_p_mode == RTL819x) {
if (wps->nonce_seed) {
time_t seed_time;
struct tm ts;
char buffer[30];
printf("\n [*] Seed N1: %u", wps->nonce_seed);
seed_time = wps->nonce_seed;
gmtime_r(&seed_time, &ts);
strftime(buffer, 30, "%c", &ts);
printf(" (%s UTC)", buffer);
printf("\n [*] Seed ES1: %u", wps->s1_seed);
printf("\n [*] Seed N1: %u", (unsigned) seed_time);
printf(" (%s UTC)", format_time(seed_time, buffer));
seed_time = wps->s1_seed;
gmtime_r(&seed_time, &ts);
strftime(buffer, 30, "%c", &ts);
printf(" (%s UTC)", buffer);
printf("\n [*] Seed ES2: %u", wps->s2_seed);
printf("\n [*] Seed ES1: %u", (unsigned) seed_time);
printf(" (%s UTC)", format_time(seed_time, buffer));
seed_time = wps->s2_seed;
gmtime_r(&seed_time, &ts);
strftime(buffer, 30, "%c", &ts);
printf(" (%s UTC)", buffer);
printf("\n [*] Seed ES2: %u", (unsigned) seed_time);
printf(" (%s UTC)", format_time(seed_time, buffer));
}
else {
printf("\n [*] Seed N1: -");