mirror of
https://github.com/wiire-a/pixiewps.git
synced 2025-07-27 15:54:29 +02:00
Get elapsed time in a proper way
This commit is contained in:
parent
58e04d5aa0
commit
801f1b1605
@ -806,8 +806,9 @@ usage_err:
|
|||||||
pfound = crack(wps, wps->pin);
|
pfound = crack(wps, wps->pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct timeval diff;
|
||||||
gettimeofday(&t_end, 0);
|
gettimeofday(&t_end, 0);
|
||||||
unsigned long ms_elapsed = get_elapsed_ms(&t_start, &t_end);
|
timeval_subtract(&diff, &t_end, &t_start);
|
||||||
|
|
||||||
printf("\n Pixiewps %s\n", SHORT_VERSION);
|
printf("\n Pixiewps %s\n", SHORT_VERSION);
|
||||||
if (wps->verbosity > 1) {
|
if (wps->verbosity > 1) {
|
||||||
@ -859,8 +860,7 @@ usage_err:
|
|||||||
else {
|
else {
|
||||||
printf("\n [-] WPA-PSK not found!");
|
printf("\n [-] WPA-PSK not found!");
|
||||||
}
|
}
|
||||||
|
printf("\n\n [*] Time taken: %lu s %lu ms\n\n", diff.tv_sec, diff.tv_usec / 1000);
|
||||||
printf("\n\n [*] Time taken: %lu s %lu ms\n\n", ms_elapsed / 1000, ms_elapsed % 1000);
|
|
||||||
|
|
||||||
if (decrypted5) {
|
if (decrypted5) {
|
||||||
free(decrypted5);
|
free(decrypted5);
|
||||||
@ -1378,8 +1378,9 @@ usage_err:
|
|||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct timeval diff;
|
||||||
gettimeofday(&t_end, 0);
|
gettimeofday(&t_end, 0);
|
||||||
unsigned long ms_elapsed = get_elapsed_ms(&t_start, &t_end);
|
timeval_subtract(&diff, &t_end, &t_start);
|
||||||
|
|
||||||
k--;
|
k--;
|
||||||
|
|
||||||
@ -1454,7 +1455,7 @@ usage_err:
|
|||||||
else {
|
else {
|
||||||
printf("\n [-] WPS pin not found!");
|
printf("\n [-] WPS pin not found!");
|
||||||
}
|
}
|
||||||
printf("\n\n [*] Time taken: %lu s %lu ms\n\n", ms_elapsed / 1000, ms_elapsed % 1000);
|
printf("\n\n [*] Time taken: %lu s %lu ms\n\n", diff.tv_sec, diff.tv_usec / 1000);
|
||||||
|
|
||||||
if (wps->warning) {
|
if (wps->warning) {
|
||||||
printf("%s", wps->warning);
|
printf("%s", wps->warning);
|
||||||
|
25
src/utils.h
25
src/utils.h
@ -230,10 +230,29 @@ unsigned int get_unix_datetime(char *s, time_t *datetime)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the difference of time between the two in milliseconds */
|
/* Subtract the ‘struct timeval’ values X and Y
|
||||||
unsigned long get_elapsed_ms(struct timeval *start, struct timeval *end)
|
Return 1 if the difference is negative, otherwise 0
|
||||||
|
Reference: https://www.gnu.org/software/libc/manual/html_node/Elapsed-Time.html */
|
||||||
|
int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
|
||||||
{
|
{
|
||||||
return (((end->tv_sec - start->tv_sec) * 1000000 + (end->tv_usec - start->tv_usec)) / 1000);
|
/* Perform the carry for the later subtraction by updating y */
|
||||||
|
if (x->tv_usec < y->tv_usec) {
|
||||||
|
const int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
||||||
|
y->tv_usec -= 1000000 * nsec;
|
||||||
|
y->tv_sec += nsec;
|
||||||
|
}
|
||||||
|
if (x->tv_usec - y->tv_usec > 1000000) {
|
||||||
|
const int nsec = (x->tv_usec - y->tv_usec) / 1000000;
|
||||||
|
y->tv_usec += 1000000 * nsec;
|
||||||
|
y->tv_sec -= nsec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute the time remaining to wait, tv_usec is certainly positive */
|
||||||
|
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||||
|
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||||
|
|
||||||
|
/* Return 1 if result is negative */
|
||||||
|
return x->tv_sec < y->tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert an unsigned integer to a char array without termination */
|
/* Convert an unsigned integer to a char array without termination */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user