code cleanup: used 'indent' to enforce consistant style

This commit is contained in:
Brian Tierney 2009-10-19 22:35:18 +00:00
parent 2d62ee81b2
commit e434aab6a2
11 changed files with 2738 additions and 2675 deletions

File diff suppressed because it is too large Load Diff

1386
src/main.c

File diff suppressed because it is too large Load Diff

View File

@ -11,72 +11,71 @@
int
netdial(int proto, char *client, int port)
{
int s;
int s;
struct hostent *hent;
struct sockaddr_in sa;
socklen_t sn;
if((hent = gethostbyname(client)) == 0) {
perror("gethostbyname");
return(-1);
if ((hent = gethostbyname(client)) == 0)
{
perror("gethostbyname");
return (-1);
}
s = socket(AF_INET, proto, 0);
if(s < 0) {
perror("socket");
return(-1);
if (s < 0)
{
perror("socket");
return (-1);
}
memset(&sa, 0, sizeof sa);
memmove(&sa.sin_addr, hent->h_addr, 4);
sa.sin_port = htons(port);
sa.sin_family = AF_INET;
if(connect(s, (struct sockaddr *) &sa, sizeof sa) < 0 && errno != EINPROGRESS) {
perror("connect");
return(-1);
if (connect(s, (struct sockaddr *) & sa, sizeof sa) < 0 && errno != EINPROGRESS)
{
perror("connect");
return (-1);
}
/* XXX: is this necessary? */
sn = sizeof sa;
if(getpeername(s, (struct sockaddr *) &sa, &sn) >= 0) {
return(s);
if (getpeername(s, (struct sockaddr *) & sa, &sn) >= 0)
{
return (s);
}
perror("connect");
return(-1);
return (-1);
}
int
netannounce(int proto, char *local, int port)
{
int s;
int s;
struct sockaddr_in sa;
/* XXX: implement binding to a local address rather than * */
memset((void *) &sa, 0, sizeof sa);
s = socket(AF_INET, proto, 0);
if(s < 0) {
perror("socket");
return(-1);
if (s < 0)
{
perror("socket");
return (-1);
}
int opt = 1;
int opt = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt));
sa.sin_port = htons(port);
sa.sin_family = AF_INET;
if(bind(s, (struct sockaddr *) &sa, sizeof(struct sockaddr_in)) < 0) {
close(s);
perror("bind");
return(-1);
if (bind(s, (struct sockaddr *) & sa, sizeof(struct sockaddr_in)) < 0)
{
close(s);
perror("bind");
return (-1);
}
if(proto == SOCK_STREAM)
listen(s, 5);
if (proto == SOCK_STREAM)
listen(s, 5);
return s;
}

View File

@ -1,48 +1,48 @@
/*---------------------------------------------------------------
* Copyright (c) 1999,2000,2001,2002,2003
* The Board of Trustees of the University of Illinois
* All Rights Reserved.
*---------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software (Iperf) and associated
* documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit
/*---------------------------------------------------------------
* Copyright (c) 1999,2000,2001,2002,2003
* The Board of Trustees of the University of Illinois
* All Rights Reserved.
*---------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software (Iperf) and associated
* documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do
* so, subject to the following conditions:
* so, subject to the following conditions:
*
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and
* the following disclaimers.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials
* provided with the distribution.
*
*
* Neither the names of the University of Illinois, NCSA,
* nor the names of its contributors may be used to endorse
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and
* the following disclaimers.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials
* provided with the distribution.
*
*
* Neither the names of the University of Illinois, NCSA,
* nor the names of its contributors may be used to endorse
* or promote products derived from this Software without
* specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ________________________________________________________________
* National Laboratory for Applied Network Research
* National Center for Supercomputing Applications
* University of Illinois at Urbana-Champaign
* National Laboratory for Applied Network Research
* National Center for Supercomputing Applications
* University of Illinois at Urbana-Champaign
* http://www.ncsa.uiuc.edu
* ________________________________________________________________
* ________________________________________________________________
*
* socket.c
* by Mark Gates <mgates@nlanr.net>
@ -65,30 +65,34 @@ Setting the MSS may not be implemented on this OS.\n";
const char warn_mss_notset[] =
"WARNING: attempt to set TCP maximum segment size to %d, but got %d\n";
void setsock_tcp_mss( int sock, int req_mss ) {
void
setsock_tcp_mss(int sock, int req_mss)
{
#ifdef TCP_MAXSEG
int rc;
int new_mss;
int rc;
int new_mss;
Socklen_t len;
assert( sock != INVALID_SOCKET );
assert(sock != INVALID_SOCKET);
if ( req_mss > 0 ) {
/* set */
new_mss = req_mss;
len = sizeof( new_mss );
rc = setsockopt( sock, IPPROTO_TCP, TCP_MAXSEG, (char*) &new_mss, len );
if ( rc == SOCKET_ERROR ) {
fprintf( stderr, warn_mss_fail, new_mss );
return;
}
/* verify results */
rc = getsockopt( sock, IPPROTO_TCP, TCP_MAXSEG, (char*) &new_mss, &len );
WARN_errno( rc == SOCKET_ERROR, "getsockopt TCP_MAXSEG" );
if ( new_mss != req_mss ) {
fprintf( stderr, warn_mss_notset, req_mss, new_mss );
}
if (req_mss > 0)
{
/* set */
new_mss = req_mss;
len = sizeof(new_mss);
rc = setsockopt(sock, IPPROTO_TCP, TCP_MAXSEG, (char *) &new_mss, len);
if (rc == SOCKET_ERROR)
{
fprintf(stderr, warn_mss_fail, new_mss);
return;
}
/* verify results */
rc = getsockopt(sock, IPPROTO_TCP, TCP_MAXSEG, (char *) &new_mss, &len);
WARN_errno(rc == SOCKET_ERROR, "getsockopt TCP_MAXSEG");
if (new_mss != req_mss)
{
fprintf(stderr, warn_mss_notset, req_mss, new_mss);
}
}
#endif
}
@ -97,18 +101,20 @@ void setsock_tcp_mss( int sock, int req_mss ) {
* returns the TCP maximum segment size
* ------------------------------------------------------------------- */
int getsock_tcp_mss( int sock ) {
int mss = 0;
int
getsock_tcp_mss(int sock)
{
int mss = 0;
#ifdef TCP_MAXSEG
int rc;
int rc;
Socklen_t len;
assert( sock >= 0 );
assert(sock >= 0);
/* query for MSS */
len = sizeof( mss );
rc = getsockopt( sock, IPPROTO_TCP, TCP_MAXSEG, (char*) &mss, &len );
WARN_errno( rc == SOCKET_ERROR, "getsockopt TCP_MAXSEG" );
len = sizeof(mss);
rc = getsockopt(sock, IPPROTO_TCP, TCP_MAXSEG, (char *) &mss, &len);
WARN_errno(rc == SOCKET_ERROR, "getsockopt TCP_MAXSEG");
#endif
return mss;
@ -126,73 +132,91 @@ int getsock_tcp_mss( int sock ) {
* returns -1 on error, 0 on no error.
* ------------------------------------------------------------------- */
int setsock_tcp_windowsize( int inSock, int inTCPWin, int inSend ) {
int
setsock_tcp_windowsize(int inSock, int inTCPWin, int inSend)
{
#ifdef SO_SNDBUF
int rc;
int newTCPWin;
int rc;
int newTCPWin;
assert( inSock >= 0 );
assert(inSock >= 0);
if ( inTCPWin > 0 ) {
if (inTCPWin > 0)
{
#ifdef TCP_WINSHIFT
/* UNICOS requires setting the winshift explicitly */
if ( inTCPWin > 65535 ) {
int winShift = 0;
int scaledWin = inTCPWin >> 16;
while ( scaledWin > 0 ) {
scaledWin >>= 1;
winShift++;
}
/* UNICOS requires setting the winshift explicitly */
if (inTCPWin > 65535)
{
int winShift = 0;
int scaledWin = inTCPWin >> 16;
while (scaledWin > 0)
{
scaledWin >>= 1;
winShift++;
}
/* set TCP window shift */
rc = setsockopt( inSock, IPPROTO_TCP, TCP_WINSHIFT,
(char*) &winShift, sizeof( winShift ));
if ( rc < 0 ) {
return rc;
}
/* Note: you cannot verify TCP window shift, since it returns
* a structure and not the same integer we use to set it. (ugh) */
}
#endif /* TCP_WINSHIFT */
/* set TCP window shift */
rc = setsockopt(inSock, IPPROTO_TCP, TCP_WINSHIFT,
(char *) &winShift, sizeof(winShift));
if (rc < 0)
{
return rc;
}
/*
* Note: you cannot verify TCP window shift, since it returns a
* structure and not the same integer we use to set it. (ugh)
*/
}
#endif /* TCP_WINSHIFT */
#ifdef TCP_RFC1323
/* On AIX, RFC 1323 extensions can be set system-wide,
* using the 'no' network options command. But we can also set them
* per-socket, so let's try just in case. */
if ( inTCPWin > 65535 ) {
/* enable RFC 1323 */
int on = 1;
rc = setsockopt( inSock, IPPROTO_TCP, TCP_RFC1323,
(char*) &on, sizeof( on ));
if ( rc < 0 ) {
return rc;
}
}
#endif /* TCP_RFC1323 */
/*
* On AIX, RFC 1323 extensions can be set system-wide, using the 'no'
* network options command. But we can also set them per-socket, so
* let's try just in case.
*/
if (inTCPWin > 65535)
{
/* enable RFC 1323 */
int on = 1;
rc = setsockopt(inSock, IPPROTO_TCP, TCP_RFC1323,
(char *) &on, sizeof(on));
if (rc < 0)
{
return rc;
}
}
#endif /* TCP_RFC1323 */
if ( !inSend ) {
/* receive buffer -- set
* note: results are verified after connect() or listen(),
* since some OS's don't show the corrected value until then. */
newTCPWin = inTCPWin;
rc = setsockopt( inSock, SOL_SOCKET, SO_RCVBUF,
(char*) &newTCPWin, sizeof( newTCPWin ));
} else {
/* send buffer -- set
* note: results are verified after connect() or listen(),
* since some OS's don't show the corrected value until then. */
newTCPWin = inTCPWin;
rc = setsockopt( inSock, SOL_SOCKET, SO_SNDBUF,
(char*) &newTCPWin, sizeof( newTCPWin ));
}
if ( rc < 0 ) {
return rc;
}
if (!inSend)
{
/*
* receive buffer -- set note: results are verified after
* connect() or listen(), since some OS's don't show the
* corrected value until then.
*/
newTCPWin = inTCPWin;
rc = setsockopt(inSock, SOL_SOCKET, SO_RCVBUF,
(char *) &newTCPWin, sizeof(newTCPWin));
} else
{
/*
* send buffer -- set note: results are verified after connect()
* or listen(), since some OS's don't show the corrected value
* until then.
*/
newTCPWin = inTCPWin;
rc = setsockopt(inSock, SOL_SOCKET, SO_SNDBUF,
(char *) &newTCPWin, sizeof(newTCPWin));
}
if (rc < 0)
{
return rc;
}
}
#endif /* SO_SNDBUF */
#endif /* SO_SNDBUF */
return 0;
}
@ -202,26 +226,30 @@ int setsock_tcp_windowsize( int inSock, int inTCPWin, int inSend ) {
* or -1 on error.
* ------------------------------------------------------------------- */
int getsock_tcp_windowsize( int inSock, int inSend ) {
int theTCPWin = 0;
int
getsock_tcp_windowsize(int inSock, int inSend)
{
int theTCPWin = 0;
#ifdef SO_SNDBUF
int rc;
int rc;
Socklen_t len;
/* send buffer -- query for buffer size */
len = sizeof( theTCPWin );
if ( inSend ) {
rc = getsockopt( inSock, SOL_SOCKET, SO_SNDBUF,
(char*) &theTCPWin, &len );
} else {
rc = getsockopt( inSock, SOL_SOCKET, SO_RCVBUF,
(char*) &theTCPWin, &len );
len = sizeof(theTCPWin);
if (inSend)
{
rc = getsockopt(inSock, SOL_SOCKET, SO_SNDBUF,
(char *) &theTCPWin, &len);
} else
{
rc = getsockopt(inSock, SOL_SOCKET, SO_RCVBUF,
(char *) &theTCPWin, &len);
}
if ( rc < 0 ) {
return rc;
if (rc < 0)
{
return rc;
}
#endif
return theTCPWin;

View File

@ -4,24 +4,25 @@
#include "timer.h"
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
struct timer *tp;
tp = new_timer(3, 0);
sleep(2);
if(tp->expired(tp)) {
printf("timer should not have expired\n");
exit(-1);
if (tp->expired(tp))
{
printf("timer should not have expired\n");
exit(-1);
}
sleep(1);
if(!tp->expired(tp)) {
printf("timer should have expired\n");
exit(-2);
if (!tp->expired(tp))
{
printf("timer should have expired\n");
exit(-2);
}
exit(0);
}

View File

@ -6,57 +6,56 @@
#include "iperf.h"
#include "units.h"
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
iperf_size_t llu;
double d;
char s[11];
double d;
char s[11];
assert(1024.0 * 0.5 == unit_atof("0.5K"));
assert(1024.0 == unit_atof("1K"));
assert(1024.0*1024.0 == unit_atof("1M"));
assert(4.0*1024.0*1024.0*1024.0 == unit_atof("4G"));
assert(1024.0 * 1024.0 == unit_atof("1M"));
assert(4.0 * 1024.0 * 1024.0 * 1024.0 == unit_atof("4G"));
assert(1000.0 * 0.5 == unit_atof("0.5k"));
assert(1000.0 == unit_atof("1k"));
assert(1000.0*1000.0 == unit_atof("1m"));
assert(4.0*1000.0*1000.0*1000.0 == unit_atof("4g"));
assert(1000.0 * 1000.0 == unit_atof("1m"));
assert(4.0 * 1000.0 * 1000.0 * 1000.0 == unit_atof("4g"));
assert(1024 * 0.5 == unit_atoi("0.5K"));
assert(1024 == unit_atoi("1K"));
assert(1024*1024 == unit_atoi("1M"));
d = 4.0* 1024* 1024* 1024;
assert(1024 * 1024 == unit_atoi("1M"));
d = 4.0 * 1024 * 1024 * 1024;
llu = (iperf_size_t) d;
assert(llu == unit_atoi("4G"));
assert(1000 * 0.5 == unit_atoi("0.5k"));
assert(1000 == unit_atoi("1k"));
assert(1000*1000 == unit_atoi("1m"));
d = 4.0 * 1000* 1000* 1000;
assert(1000 * 1000 == unit_atoi("1m"));
d = 4.0 * 1000 * 1000 * 1000;
llu = (iperf_size_t) d;
assert(llu == unit_atoi("4g"));
unit_snprintf(s, 11, 1024.0, 'A');
assert( strncmp(s, "1.00 KByte", 11) == 0);
assert(strncmp(s, "1.00 KByte", 11) == 0);
unit_snprintf(s, 11, 1024.0 * 1024.0, 'A');
assert( strncmp(s, "1.00 MByte", 11) == 0);
assert(strncmp(s, "1.00 MByte", 11) == 0);
unit_snprintf(s, 11, 1000.0, 'k');
assert( strncmp(s, "8.00 Kbit", 11) == 0);
assert(strncmp(s, "8.00 Kbit", 11) == 0);
unit_snprintf(s, 11, 1000.0 * 1000.0, 'a');
assert( strncmp(s, "8.00 Mbit", 11) == 0);
assert(strncmp(s, "8.00 Mbit", 11) == 0);
d = 4.0 * 1024* 1024* 1024;
d = 4.0 * 1024 * 1024 * 1024;
unit_snprintf(s, 11, d, 'A');
assert( strncmp(s, "4.00 GByte", 11) == 0);
assert(strncmp(s, "4.00 GByte", 11) == 0);
unit_snprintf(s, 11, d, 'a');
assert( strncmp(s, "34.4 Gbit", 11) == 0);
assert(strncmp(s, "34.4 Gbit", 11) == 0);
return 0;
}

View File

@ -7,12 +7,12 @@
int
main(int argc, char **argv)
{
char *uuid;
char *uuid;
get_uuid(uuid);
if(strlen(uuid) != 36)
if (strlen(uuid) != 36)
{
printf("uuid is not 37 characters long %s.\n", uuid);
exit(-1);
printf("uuid is not 37 characters long %s.\n", uuid);
exit(-1);
}
exit(0);
}

View File

@ -1,48 +1,48 @@
/*---------------------------------------------------------------
* Copyright (c) 1999,2000,2001,2002,2003
* The Board of Trustees of the University of Illinois
* All Rights Reserved.
*---------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software (Iperf) and associated
* documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit
/*---------------------------------------------------------------
* Copyright (c) 1999,2000,2001,2002,2003
* The Board of Trustees of the University of Illinois
* All Rights Reserved.
*---------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software (Iperf) and associated
* documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do
* so, subject to the following conditions:
* so, subject to the following conditions:
*
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and
* the following disclaimers.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials
* provided with the distribution.
*
*
* Neither the names of the University of Illinois, NCSA,
* nor the names of its contributors may be used to endorse
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and
* the following disclaimers.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials
* provided with the distribution.
*
*
* Neither the names of the University of Illinois, NCSA,
* nor the names of its contributors may be used to endorse
* or promote products derived from this Software without
* specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ________________________________________________________________
* National Laboratory for Applied Network Research
* National Center for Supercomputing Applications
* University of Illinois at Urbana-Champaign
* National Laboratory for Applied Network Research
* National Center for Supercomputing Applications
* University of Illinois at Urbana-Champaign
* http://www.ncsa.uiuc.edu
* ________________________________________________________________
* ________________________________________________________________
*
* tcp_window_size.c
* by Mark Gates <mgates@nlanr.net>
@ -61,7 +61,8 @@
#include <assert.h>
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
/* -------------------------------------------------------------------
@ -76,91 +77,102 @@ extern "C" {
* returns -1 on error, 0 on no error.
* ------------------------------------------------------------------- */
int
set_tcp_windowsize(int sock, int bufsize, int dir)
{
int
set_tcp_windowsize(int sock, int bufsize, int dir)
{
#ifdef SO_SNDBUF
int rc;
int newbufsize;
int rc;
int newbufsize;
assert( sock >= 0 );
assert(sock >= 0);
if ( bufsize > 0 ) {
if (bufsize > 0)
{
#ifdef TCP_WINSHIFT
/* XXX: audit -- do we care about UNICOS? */
/* UNICOS requires setting the winshift explicitly */
if (bufsize > 65535) {
int winshift = 0;
int scaledwin = bufsize >> 16;
while ( scaledwin > 0 ) {
scaledwin >>= 1;
winshift++;
}
/* XXX: audit -- do we care about UNICOS? */
/* UNICOS requires setting the winshift explicitly */
if (bufsize > 65535)
{
int winshift = 0;
int scaledwin = bufsize >> 16;
while (scaledwin > 0)
{
scaledwin >>= 1;
winshift++;
}
/* set TCP window shift */
rc = setsockopt(sock, IPPROTO_TCP, TCP_WINSHIFT,
(char*) &winshift, sizeof( winshift ));
if ( rc < 0 )
return rc;
/* set TCP window shift */
rc = setsockopt(sock, IPPROTO_TCP, TCP_WINSHIFT,
(char *) &winshift, sizeof(winshift));
if (rc < 0)
return rc;
/* Note: you cannot verify TCP window shift, since it returns
* a structure and not the same integer we use to set it. (ugh) */
}
#endif /* TCP_WINSHIFT */
/*
* Note: you cannot verify TCP window shift, since it returns
* a structure and not the same integer we use to set it.
* (ugh)
*/
}
#endif /* TCP_WINSHIFT */
#ifdef TCP_RFC1323
/* On AIX, RFC 1323 extensions can be set system-wide,
* using the 'no' network options command. But we can also set them
* per-socket, so let's try just in case. */
if ( bufsize > 65535 ) {
/* enable RFC 1323 */
int on = 1;
rc = setsockopt(sock, IPPROTO_TCP, TCP_RFC1323,
(char*) &on, sizeof( on ));
if ( rc < 0 )
return rc;
}
#endif /* TCP_RFC1323 */
/*
* On AIX, RFC 1323 extensions can be set system-wide, using the
* 'no' network options command. But we can also set them
* per-socket, so let's try just in case.
*/
if (bufsize > 65535)
{
/* enable RFC 1323 */
int on = 1;
rc = setsockopt(sock, IPPROTO_TCP, TCP_RFC1323,
(char *) &on, sizeof(on));
if (rc < 0)
return rc;
}
#endif /* TCP_RFC1323 */
/* note: results are verified after connect() or listen(),
* since some OS's don't show the corrected value until then. */
newbufsize = bufsize;
rc = setsockopt(sock, SOL_SOCKET, dir, (char*) &newbufsize, sizeof newbufsize);
if (rc < 0)
return rc;
/*
* note: results are verified after connect() or listen(), since
* some OS's don't show the corrected value until then.
*/
newbufsize = bufsize;
rc = setsockopt(sock, SOL_SOCKET, dir, (char *) &newbufsize, sizeof newbufsize);
if (rc < 0)
return rc;
}
#endif /* SO_SNDBUF */
return 0;
}
#endif /* SO_SNDBUF */
return 0;
}
/* -------------------------------------------------------------------
* returns the TCP window size (on the sending buffer, SO_SNDBUF),
* or -1 on error.
* ------------------------------------------------------------------- */
int
getsock_tcp_windowsize(int sock, int dir)
{
int bufsize = 0;
int
getsock_tcp_windowsize(int sock, int dir)
{
int bufsize = 0;
#ifdef SO_SNDBUF
int rc;
socklen_t len;
int rc;
socklen_t len;
/* send buffer -- query for buffer size */
len = sizeof bufsize;
rc = getsockopt(sock, SOL_SOCKET, dir, (char*) &bufsize, &len);
/* send buffer -- query for buffer size */
len = sizeof bufsize;
rc = getsockopt(sock, SOL_SOCKET, dir, (char *) &bufsize, &len);
if (rc < 0)
return rc;
if (rc < 0)
return rc;
#endif
return bufsize;
}
return bufsize;
}
#ifdef __cplusplus
} /* end extern "C" */
#endif
} /* end extern "C" */
#endif

View File

@ -12,60 +12,63 @@
double
timeval_to_double(struct timeval *tv)
timeval_to_double(struct timeval * tv)
{
double d;
d = tv->tv_sec + tv->tv_usec /1000000;
double d;
d = tv->tv_sec + tv->tv_usec / 1000000;
return d;
}
double
timeval_diff(struct timeval *tv0, struct timeval *tv1)
timeval_diff(struct timeval * tv0, struct timeval * tv1)
{
//return timeval_to_double(tv1) - timeval_to_double(tv0);
return (tv1->tv_sec - tv0->tv_sec) + abs(tv1->tv_usec - tv0->tv_usec) / 1000000.0;
//return timeval_to_double(tv1) - timeval_to_double(tv0);
return (tv1->tv_sec - tv0->tv_sec) + abs(tv1->tv_usec - tv0->tv_usec) / 1000000.0;
}
int
timer_expired(struct timer *tp)
{
// for timer with zero time
timer_expired(struct timer * tp)
{
/* for timer with zero time */
if (tp->end.tv_sec == tp->begin.tv_sec && tp->end.tv_usec == tp->begin.tv_usec)
return 0;
return 0;
struct timeval now;
int64_t end = 0, current= 0, diff= 0;
if(gettimeofday(&now, NULL) < 0) {
perror("gettimeofday");
return -1;
int64_t end = 0, current = 0, diff = 0;
if (gettimeofday(&now, NULL) < 0)
{
perror("gettimeofday");
return -1;
}
end+= tp->end.tv_sec * 1000000 ;
end+= tp->end.tv_usec;
current+= now.tv_sec * 1000000 ;
current+= now.tv_usec;
end += tp->end.tv_sec * 1000000;
end += tp->end.tv_usec;
current += now.tv_sec * 1000000;
current += now.tv_usec;
diff = end - current;
return diff <= 0;
// currently using microsecond limit. Else we need to introduce timespec instread of timeval
}
return diff <= 0;
/*
* currently using microsecond limit. Else we need to introduce timespec
* instread of timeval
*/
}
void
update_timer(struct timer *tp, time_t sec, suseconds_t usec)
update_timer(struct timer * tp, time_t sec, suseconds_t usec)
{
if(gettimeofday(&tp->begin, NULL) < 0) {
perror("gettimeofday");
if (gettimeofday(&tp->begin, NULL) < 0)
{
perror("gettimeofday");
}
memcpy(&tp->end, &tp->begin, sizeof(struct timer));
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;
tp->expired = timer_expired;
}
@ -75,22 +78,22 @@ new_timer(time_t sec, suseconds_t usec)
struct timer *tp;
tp = (struct timer *) malloc(sizeof(struct timer));
if(gettimeofday(&tp->begin, NULL) < 0) {
perror("gettimeofday");
return NULL;
if (gettimeofday(&tp->begin, NULL) < 0)
{
perror("gettimeofday");
return NULL;
}
memcpy(&tp->end, &tp->begin, sizeof(struct timer));
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;
tp->expired = timer_expired;
return tp;
}
void
free_timer(struct timer *tp)
free_timer(struct timer * tp)
{
free(tp);
}
@ -102,44 +105,42 @@ delay(int64_t ns)
req.tv_sec = 0;
while(ns >= 1000000000L)
while (ns >= 1000000000L)
{
ns -= 1000000000L;
req.tv_sec += 1;
ns -= 1000000000L;
req.tv_sec += 1;
}
req.tv_nsec = ns;
while(nanosleep(&req, &rem) == -1 )
if (EINTR == errno)
memcpy(&req, &rem, sizeof rem);
else
return -1;
while (nanosleep(&req, &rem) == -1)
if (EINTR == errno)
memcpy(&req, &rem, sizeof rem);
else
return -1;
return 0;
}
int64_t
timer_remaining(struct timer *tp)
int64_t
timer_remaining(struct timer * tp)
{
struct timeval now;
long int end_time = 0, current_time= 0, diff= 0;
if(gettimeofday(&now, NULL) < 0) {
perror("gettimeofday");
return -1;
long int end_time = 0, current_time = 0, diff = 0;
if (gettimeofday(&now, NULL) < 0)
{
perror("gettimeofday");
return -1;
}
end_time+= tp->end.tv_sec * 1000000 ;
end_time+= tp->end.tv_usec;
current_time+= now.tv_sec * 1000000 ;
current_time+= now.tv_usec;
diff = end_time - current_time;
if(diff > 0)
return diff;
else
return 0;
}
end_time += tp->end.tv_sec * 1000000;
end_time += tp->end.tv_usec;
current_time += now.tv_sec * 1000000;
current_time += now.tv_usec;
diff = end_time - current_time;
if (diff > 0)
return diff;
else
return 0;
}

View File

@ -1,48 +1,48 @@
/*---------------------------------------------------------------
* Copyright (c) 1999,2000,2001,2002,2003
* The Board of Trustees of the University of Illinois
* All Rights Reserved.
*---------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software (Iperf) and associated
* documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit
/*---------------------------------------------------------------
* Copyright (c) 1999,2000,2001,2002,2003
* The Board of Trustees of the University of Illinois
* All Rights Reserved.
*---------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software (Iperf) and associated
* documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do
* so, subject to the following conditions:
* so, subject to the following conditions:
*
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and
* the following disclaimers.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials
* provided with the distribution.
*
*
* Neither the names of the University of Illinois, NCSA,
* nor the names of its contributors may be used to endorse
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and
* the following disclaimers.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials
* provided with the distribution.
*
*
* Neither the names of the University of Illinois, NCSA,
* nor the names of its contributors may be used to endorse
* or promote products derived from this Software without
* specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ________________________________________________________________
* National Laboratory for Applied Network Research
* National Center for Supercomputing Applications
* University of Illinois at Urbana-Champaign
* National Laboratory for Applied Network Research
* National Center for Supercomputing Applications
* University of Illinois at Urbana-Champaign
* http://www.ncsa.uiuc.edu
* ________________________________________________________________
* ________________________________________________________________
*
* stdio.c
* by Mark Gates <mgates@nlanr.net>
@ -59,16 +59,17 @@
#include "iperf.h"
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
const long KILO_UNIT = 1024;
const long MEGA_UNIT = 1024 * 1024;
const long GIGA_UNIT = 1024 * 1024 * 1024;
const long KILO_UNIT = 1024;
const long MEGA_UNIT = 1024 * 1024;
const long GIGA_UNIT = 1024 * 1024 * 1024;
const long KILO_UNIT_SI = 1000;
const long MEGA_UNIT_SI = 1000 * 1000;
const long GIGA_UNIT_SI = 1000 * 1000 * 1000;
const long KILO_UNIT_SI = 1000;
const long MEGA_UNIT_SI = 1000 * 1000;
const long GIGA_UNIT_SI = 1000 * 1000 * 1000;
/* -------------------------------------------------------------------
* unit_atof
@ -78,27 +79,42 @@ const long GIGA_UNIT_SI = 1000 * 1000 * 1000;
* Gg, Mm, Kk are giga, mega, kilo respectively
* ------------------------------------------------------------------- */
double unit_atof( const char *s ) {
double n;
char suffix = '\0';
double unit_atof(const char *s)
{
double n;
char suffix = '\0';
assert( s != NULL );
assert(s != NULL);
/* scan the number and any suffices */
sscanf( s, "%lf%c", &n, &suffix );
/* scan the number and any suffices */
sscanf(s, "%lf%c", &n, &suffix);
/* convert according to [Gg Mm Kk] */
switch ( suffix ) {
case 'G': n *= GIGA_UNIT; break;
case 'M': n *= MEGA_UNIT; break;
case 'K': n *= KILO_UNIT; break;
case 'g': n *= GIGA_UNIT_SI; break;
case 'm': n *= MEGA_UNIT_SI; break;
case 'k': n *= KILO_UNIT_SI; break;
default: break;
}
return n;
} /* end unit_atof */
/* convert according to [Gg Mm Kk] */
switch (suffix)
{
case 'G':
n *= GIGA_UNIT;
break;
case 'M':
n *= MEGA_UNIT;
break;
case 'K':
n *= KILO_UNIT;
break;
case 'g':
n *= GIGA_UNIT_SI;
break;
case 'm':
n *= MEGA_UNIT_SI;
break;
case 'k':
n *= KILO_UNIT_SI;
break;
default:
break;
}
return n;
} /* end unit_atof */
/* -------------------------------------------------------------------
* unit_atoi
@ -108,76 +124,92 @@ double unit_atof( const char *s ) {
* Gg, Mm, Kk are giga, mega, kilo respectively
* ------------------------------------------------------------------- */
iperf_size_t unit_atoi( const char *s ) {
double n;
char suffix = '\0';
iperf_size_t unit_atoi(const char *s)
{
double n;
char suffix = '\0';
assert( s != NULL );
assert(s != NULL);
/* scan the number and any suffices */
sscanf( s, "%lf%c", &n, &suffix );
/* scan the number and any suffices */
sscanf(s, "%lf%c", &n, &suffix);
/* convert according to [Gg Mm Kk] */
switch ( suffix ) {
case 'G': n *= GIGA_UNIT; break;
case 'M': n *= MEGA_UNIT; break;
case 'K': n *= KILO_UNIT; break;
case 'g': n *= GIGA_UNIT_SI; break;
case 'm': n *= MEGA_UNIT_SI; break;
case 'k': n *= KILO_UNIT_SI; break;
default: break;
}
return (iperf_size_t) n;
} /* end unit_atof */
/* convert according to [Gg Mm Kk] */
switch (suffix)
{
case 'G':
n *= GIGA_UNIT;
break;
case 'M':
n *= MEGA_UNIT;
break;
case 'K':
n *= KILO_UNIT;
break;
case 'g':
n *= GIGA_UNIT_SI;
break;
case 'm':
n *= MEGA_UNIT_SI;
break;
case 'k':
n *= KILO_UNIT_SI;
break;
default:
break;
}
return (iperf_size_t) n;
} /* end unit_atof */
/* -------------------------------------------------------------------
* constants for byte_printf
* ------------------------------------------------------------------- */
/* used as indices into conversion_bytes[], label_byte[], and label_bit[] */
enum {
UNIT_CONV,
KILO_CONV,
MEGA_CONV,
GIGA_CONV
};
enum
{
UNIT_CONV,
KILO_CONV,
MEGA_CONV,
GIGA_CONV
};
/* factor to multiply the number by */
const double conversion_bytes[] =
{
1.0, /* unit */
1.0 / 1024, /* kilo */
1.0 / 1024 / 1024, /* mega */
1.0 / 1024 / 1024 / 1024 /* giga */
};
const double conversion_bytes[] =
{
1.0, /* unit */
1.0 / 1024, /* kilo */
1.0 / 1024 / 1024, /* mega */
1.0 / 1024 / 1024 / 1024/* giga */
};
/* factor to multiply the number by for bits*/
const double conversion_bits[] =
{
1.0, /* unit */
1.0 / 1000, /* kilo */
1.0 / 1000 / 1000, /* mega */
1.0 / 1000 / 1000 / 1000 /* giga */
};
const double conversion_bits[] =
{
1.0, /* unit */
1.0 / 1000, /* kilo */
1.0 / 1000 / 1000, /* mega */
1.0 / 1000 / 1000 / 1000/* giga */
};
/* labels for Byte formats [KMG] */
const char* label_byte[] =
{
"Byte",
"KByte",
"MByte",
"GByte"
};
const char *label_byte[] =
{
"Byte",
"KByte",
"MByte",
"GByte"
};
/* labels for bit formats [kmg] */
const char* label_bit[] =
{
"bit",
"Kbit",
"Mbit",
"Gbit"
};
const char *label_bit[] =
{
"bit",
"Kbit",
"Mbit",
"Gbit"
};
/* -------------------------------------------------------------------
* unit_snprintf
@ -191,66 +223,88 @@ const char* label_bit[] =
* (4 digits + space + 5 chars max + null)
* ------------------------------------------------------------------- */
void unit_snprintf( char *s, int inLen,
double inNum, char inFormat ) {
int conv;
const char* suffix;
const char* format;
void unit_snprintf(char *s, int inLen,
double inNum, char inFormat)
{
int conv;
const char *suffix;
const char *format;
/* convert to bits for [bkmga] */
if ( ! isupper( (int)inFormat ) ) {
inNum *= 8;
}
/* convert to bits for [bkmga] */
if (!isupper((int) inFormat))
{
inNum *= 8;
}
switch (toupper(inFormat))
{
case 'B':
conv = UNIT_CONV;
break;
case 'K':
conv = KILO_CONV;
break;
case 'M':
conv = MEGA_CONV;
break;
case 'G':
conv = GIGA_CONV;
break;
switch ( toupper(inFormat) ) {
case 'B': conv = UNIT_CONV; break;
case 'K': conv = KILO_CONV; break;
case 'M': conv = MEGA_CONV; break;
case 'G': conv = GIGA_CONV; break;
default:
case 'A':
{
double tmpNum = inNum;
conv = UNIT_CONV;
default:
case 'A': {
double tmpNum = inNum;
conv = UNIT_CONV;
if (isupper((int) inFormat))
{
while (tmpNum >= 1024.0 && conv <= GIGA_CONV)
{
tmpNum /= 1024.0;
conv++;
}
} else
{
while (tmpNum >= 1000.0 && conv <= GIGA_CONV)
{
tmpNum /= 1000.0;
conv++;
}
}
break;
}
}
if ( isupper((int)inFormat) ) {
while ( tmpNum >= 1024.0 && conv <= GIGA_CONV ) {
tmpNum /= 1024.0;
conv++;
}
} else {
while ( tmpNum >= 1000.0 && conv <= GIGA_CONV ) {
tmpNum /= 1000.0;
conv++;
}
}
break;
}
}
if (!isupper((int) inFormat))
{
inNum *= conversion_bits[conv];
suffix = label_bit[conv];
} else
{
inNum *= conversion_bytes[conv];
suffix = label_byte[conv];
}
if ( ! isupper ((int)inFormat) ) {
inNum *= conversion_bits[ conv ];
suffix = label_bit[conv];
} else {
inNum *= conversion_bytes [conv];
suffix = label_byte[ conv ];
}
/* print such that we always fit in 4 places */
if ( inNum < 9.995 ) { /* 9.995 would be rounded to 10.0 */
format = "%4.2f %s"; /* #.## */
} else if ( inNum < 99.95 ) { /* 99.95 would be rounded to 100 */
format = "%4.1f %s"; /* ##.# */
} else if ( inNum < 999.5 ) { /* 999.5 would be rounded to 1000 */
format = "%4.0f %s"; /* ### */
} else { /* 1000-1024 fits in 4 places
* If not using Adaptive sizes then
* this code will not control spaces*/
format = "%4.0f %s"; /* #### */
}
snprintf( s, inLen, format, inNum, suffix );
} /* end unit_snprintf */
/* print such that we always fit in 4 places */
if (inNum < 9.995)
{ /* 9.995 would be rounded to 10.0 */
format = "%4.2f %s";/* #.## */
} else if (inNum < 99.95)
{ /* 99.95 would be rounded to 100 */
format = "%4.1f %s";/* ##.# */
} else if (inNum < 999.5)
{ /* 999.5 would be rounded to 1000 */
format = "%4.0f %s";/* ### */
} else
{ /* 1000-1024 fits in 4 places If not using
* Adaptive sizes then this code will not
* control spaces */
format = "%4.0f %s";/* #### */
}
snprintf(s, inLen, format, inNum, suffix);
} /* end unit_snprintf */
#ifdef __cplusplus
} /* end extern "C" */
} /* end extern "C" */
#endif

View File

@ -10,16 +10,16 @@
void
get_uuid(char *temp)
{
char *s;
uuid_t uu;
char *s;
uuid_t uu;
#if defined(__FreeBSD__)
uuid_create(&uu, NULL);
uuid_to_string(&uu, &s, 0);
#else
s = (char *) malloc(37); /* UUID is 36 chars + \0 */
s = (char *) malloc(37); /* UUID is 36 chars + \0 */
uuid_generate(uu);
uuid_unparse(uu, s);
uuid_unparse(uu, s);
#endif
memcpy(temp, s, 37);
memcpy(temp, s, 37);
}