version 1.1.1.1, 2016/10/18 13:28:18
|
version 1.1.1.2, 2021/03/17 00:36:46
|
Line 48
|
Line 48
|
* by Mark Gates <mgates@nlanr.net> |
* by Mark Gates <mgates@nlanr.net> |
* and Ajay Tirumalla <tirumala@ncsa.uiuc.edu> |
* and Ajay Tirumalla <tirumala@ncsa.uiuc.edu> |
* ------------------------------------------------------------------- |
* ------------------------------------------------------------------- |
* input and output numbers, converting with kilo, mega, giga | * input and output numbers, converting with kilo, mega, giga, tera |
* ------------------------------------------------------------------- */ |
* ------------------------------------------------------------------- */ |
|
|
#include <stdio.h> |
#include <stdio.h> |
Line 60
|
Line 60
|
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/time.h> |
#include <sys/time.h> |
#include <netinet/tcp.h> |
|
|
|
|
|
#include "iperf.h" |
#include "iperf.h" |
Line 70 extern "C"
|
Line 69 extern "C"
|
{ |
{ |
#endif |
#endif |
|
|
const long KILO_UNIT = 1024; | const double KILO_UNIT = 1024.0; |
const long MEGA_UNIT = 1024 * 1024; | const double MEGA_UNIT = 1024.0 * 1024.0; |
const long GIGA_UNIT = 1024 * 1024 * 1024; | const double GIGA_UNIT = 1024.0 * 1024.0 * 1024.0; |
| const double TERA_UNIT = 1024.0 * 1024.0 * 1024.0 * 1024.0; |
|
|
const long KILO_RATE_UNIT = 1000; | const double KILO_RATE_UNIT = 1000.0; |
const long MEGA_RATE_UNIT = 1000 * 1000; | const double MEGA_RATE_UNIT = 1000.0 * 1000.0; |
const long GIGA_RATE_UNIT = 1000 * 1000 * 1000; | const double GIGA_RATE_UNIT = 1000.0 * 1000.0 * 1000.0; |
| const double TERA_RATE_UNIT = 1000.0 * 1000.0 * 1000.0 * 1000.0; |
|
|
/* ------------------------------------------------------------------- |
/* ------------------------------------------------------------------- |
* unit_atof |
* unit_atof |
Line 96 extern "C"
|
Line 97 extern "C"
|
/* scan the number and any suffices */ |
/* scan the number and any suffices */ |
sscanf(s, "%lf%c", &n, &suffix); |
sscanf(s, "%lf%c", &n, &suffix); |
|
|
/* convert according to [Gg Mm Kk] */ | /* convert according to [Tt Gg Mm Kk] */ |
switch (suffix) |
switch (suffix) |
{ |
{ |
|
case 't': case 'T': |
|
n *= TERA_UNIT; |
|
break; |
case 'g': case 'G': |
case 'g': case 'G': |
n *= GIGA_UNIT; |
n *= GIGA_UNIT; |
break; |
break; |
Line 132 extern "C"
|
Line 136 extern "C"
|
/* scan the number and any suffices */ |
/* scan the number and any suffices */ |
sscanf(s, "%lf%c", &n, &suffix); |
sscanf(s, "%lf%c", &n, &suffix); |
|
|
/* convert according to [Gg Mm Kk] */ | /* convert according to [Tt Gg Mm Kk] */ |
switch (suffix) |
switch (suffix) |
{ |
{ |
|
case 't': case 'T': |
|
n *= TERA_RATE_UNIT; |
|
break; |
case 'g': case 'G': |
case 'g': case 'G': |
n *= GIGA_RATE_UNIT; |
n *= GIGA_RATE_UNIT; |
break; |
break; |
Line 157 extern "C"
|
Line 164 extern "C"
|
* |
* |
* Given a string of form #x where # is a number and x is a format |
* Given a string of form #x where # is a number and x is a format |
* character listed below, this returns the interpreted integer. |
* character listed below, this returns the interpreted integer. |
* Gg, Mm, Kk are giga, mega, kilo respectively | * Tt, Gg, Mm, Kk are tera, giga, mega, kilo respectively |
* ------------------------------------------------------------------- */ |
* ------------------------------------------------------------------- */ |
|
|
iperf_size_t unit_atoi(const char *s) |
iperf_size_t unit_atoi(const char *s) |
Line 170 extern "C"
|
Line 177 extern "C"
|
/* scan the number and any suffices */ |
/* scan the number and any suffices */ |
sscanf(s, "%lf%c", &n, &suffix); |
sscanf(s, "%lf%c", &n, &suffix); |
|
|
/* convert according to [Gg Mm Kk] */ | /* convert according to [Tt Gg Mm Kk] */ |
switch (suffix) |
switch (suffix) |
{ |
{ |
|
case 't': case 'T': |
|
n *= TERA_UNIT; |
|
break; |
case 'g': case 'G': |
case 'g': case 'G': |
n *= GIGA_UNIT; |
n *= GIGA_UNIT; |
break; |
break; |
Line 198 extern "C"
|
Line 208 extern "C"
|
UNIT_CONV, |
UNIT_CONV, |
KILO_CONV, |
KILO_CONV, |
MEGA_CONV, |
MEGA_CONV, |
GIGA_CONV | GIGA_CONV, |
| TERA_CONV |
}; |
}; |
|
|
/* factor to multiply the number by */ |
/* factor to multiply the number by */ |
Line 207 extern "C"
|
Line 218 extern "C"
|
1.0, /* unit */ |
1.0, /* unit */ |
1.0 / 1024, /* kilo */ |
1.0 / 1024, /* kilo */ |
1.0 / 1024 / 1024, /* mega */ |
1.0 / 1024 / 1024, /* mega */ |
1.0 / 1024 / 1024 / 1024/* giga */ | 1.0 / 1024 / 1024 / 1024, /* giga */ |
| 1.0 / 1024 / 1024 / 1024 / 1024 /* tera */ |
}; |
}; |
|
|
/* factor to multiply the number by for bits*/ |
/* factor to multiply the number by for bits*/ |
Line 216 extern "C"
|
Line 228 extern "C"
|
1.0, /* unit */ |
1.0, /* unit */ |
1.0 / 1000, /* kilo */ |
1.0 / 1000, /* kilo */ |
1.0 / 1000 / 1000, /* mega */ |
1.0 / 1000 / 1000, /* mega */ |
1.0 / 1000 / 1000 / 1000/* giga */ | 1.0 / 1000 / 1000 / 1000, /* giga */ |
| 1.0 / 1000 / 1000 / 1000 / 1000 /* tera */ |
}; |
}; |
|
|
|
|
/* labels for Byte formats [KMG] */ | /* labels for Byte formats [KMGT] */ |
const char *label_byte[] = |
const char *label_byte[] = |
{ |
{ |
"Byte", |
"Byte", |
"KByte", |
"KByte", |
"MByte", |
"MByte", |
"GByte" | "GByte", |
| "TByte" |
}; |
}; |
|
|
/* labels for bit formats [kmg] */ | /* labels for bit formats [kmgt] */ |
const char *label_bit[] = |
const char *label_bit[] = |
{ |
{ |
"bit", |
"bit", |
"Kbit", |
"Kbit", |
"Mbit", |
"Mbit", |
"Gbit" | "Gbit", |
| "Tbit" |
}; |
}; |
|
|
/* ------------------------------------------------------------------- |
/* ------------------------------------------------------------------- |
Line 276 extern "C"
|
Line 291 extern "C"
|
case 'G': |
case 'G': |
conv = GIGA_CONV; |
conv = GIGA_CONV; |
break; |
break; |
|
case 'T': |
|
conv = TERA_CONV; |
|
break; |
|
|
default: |
default: |
case 'A': |
case 'A': |
Line 285 extern "C"
|
Line 303 extern "C"
|
|
|
if (isupper((int) inFormat)) |
if (isupper((int) inFormat)) |
{ |
{ |
while (tmpNum >= 1024.0 && conv <= GIGA_CONV) | while (tmpNum >= 1024.0 && conv < TERA_CONV) |
{ |
{ |
tmpNum /= 1024.0; |
tmpNum /= 1024.0; |
conv++; |
conv++; |
} |
} |
} else |
} else |
{ |
{ |
while (tmpNum >= 1000.0 && conv <= GIGA_CONV) | while (tmpNum >= 1000.0 && conv < TERA_CONV) |
{ |
{ |
tmpNum /= 1000.0; |
tmpNum /= 1000.0; |
conv++; |
conv++; |