⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settings.cpp

📁 在Linux/Unix环境下发包测试性能的工具
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*---------------------------------------------------------------  * 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:  * *      * 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,  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE * 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  * http://www.ncsa.uiuc.edu * ________________________________________________________________  * * Settings.cpp * by Mark Gates <mgates@nlanr.net> * & Ajay Tirumala <tirumala@ncsa.uiuc.edu> * ------------------------------------------------------------------- * Stores and parses the initial values for all the global variables. * ------------------------------------------------------------------- * headers * uses *   <stdlib.h> *   <stdio.h> *   <string.h> * *   <unistd.h> * ------------------------------------------------------------------- */#define HEADERS()#include "headers.h"#include "Settings.hpp"#include "Locale.h"#include "SocketAddr.h"#include "util.h"#include "gnu_getopt.h"void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtSettings );/* ------------------------------------------------------------------- * command line options * * The option struct essentially maps a long option name (--foobar) * or environment variable ($FOOBAR) to its short option char (f). * ------------------------------------------------------------------- */#define LONG_OPTIONS()const struct option long_options[] ={{"singleclient",     no_argument, NULL, '1'},{"bandwidth",  required_argument, NULL, 'b'},{"client",     required_argument, NULL, 'c'},{"dualtest",         no_argument, NULL, 'd'},{"format",     required_argument, NULL, 'f'},{"help",             no_argument, NULL, 'h'},{"interval",   required_argument, NULL, 'i'},{"len",        required_argument, NULL, 'l'},{"print_mss",        no_argument, NULL, 'm'},{"num",        required_argument, NULL, 'n'},{"output",     required_argument, NULL, 'o'},{"port",       required_argument, NULL, 'p'},{"tradeoff",         no_argument, NULL, 'r'},{"server",           no_argument, NULL, 's'},{"time",       required_argument, NULL, 't'},{"udp",              no_argument, NULL, 'u'},{"version",          no_argument, NULL, 'v'},{"window",     required_argument, NULL, 'w'},{"reportexclude", required_argument, NULL, 'x'},{"reportstyle",required_argument, NULL, 'y'},// more esoteric options{"bind",       required_argument, NULL, 'B'},{"compatibility",    no_argument, NULL, 'C'},{"daemon",           no_argument, NULL, 'D'},{"file_input", required_argument, NULL, 'F'},{"stdin_input",      no_argument, NULL, 'I'},{"mss",        required_argument, NULL, 'M'},{"nodelay",          no_argument, NULL, 'N'},{"listenport", required_argument, NULL, 'L'},{"parallel",   required_argument, NULL, 'P'},{"remove",           no_argument, NULL, 'R'},{"tos",        required_argument, NULL, 'S'},{"ttl",        required_argument, NULL, 'T'},{"single_udp",       no_argument, NULL, 'U'},{"ipv6_domian",      no_argument, NULL, 'V'},{"suggest_win_size", no_argument, NULL, 'W'},{0, 0, 0, 0}};#define ENV_OPTIONS()const struct option env_options[] ={{"IPERF_SINGLECLIENT",     no_argument, NULL, '1'},{"IPERF_BANDWIDTH",  required_argument, NULL, 'b'},{"IPERF_CLIENT",     required_argument, NULL, 'c'},{"IPERF_DUALTEST",         no_argument, NULL, 'd'},{"IPERF_FORMAT",     required_argument, NULL, 'f'},// skip help{"IPERF_INTERVAL",   required_argument, NULL, 'i'},{"IPERF_LEN",        required_argument, NULL, 'l'},{"IPERF_PRINT_MSS",        no_argument, NULL, 'm'},{"IPERF_NUM",        required_argument, NULL, 'n'},{"IPERF_PORT",       required_argument, NULL, 'p'},{"IPERF_TRADEOFF",         no_argument, NULL, 'r'},{"IPERF_SERVER",           no_argument, NULL, 's'},{"IPERF_TIME",       required_argument, NULL, 't'},{"IPERF_UDP",              no_argument, NULL, 'u'},// skip version{"TCP_WINDOW_SIZE",  required_argument, NULL, 'w'},{"IPERF_REPORTEXCLUDE", required_argument, NULL, 'x'},{"IPERF_REPORTSTYLE",required_argument, NULL, 'y'},// more esoteric options{"IPERF_BIND",       required_argument, NULL, 'B'},{"IPERF_COMPAT",           no_argument, NULL, 'C'},{"IPERF_DAEMON",           no_argument, NULL, 'D'},{"IPERF_FILE_INPUT", required_argument, NULL, 'F'},{"IPERF_STDIN_INPUT",      no_argument, NULL, 'I'},{"IPERF_MSS",        required_argument, NULL, 'M'},{"IPERF_NODELAY",          no_argument, NULL, 'N'},{"IPERF_LISTENPORT", required_argument, NULL, 'L'},{"IPERF_PARALLEL",   required_argument, NULL, 'P'},{"IPERF_TOS",        required_argument, NULL, 'S'},{"IPERF_TTL",        required_argument, NULL, 'T'},{"IPERF_SINGLE_UDP",       no_argument, NULL, 'U'},{"IPERF_IPV6_DOMAIN",      no_argument, NULL, 'V'},{"IPERF_SUGGEST_WIN_SIZE", required_argument, NULL, 'W'},{0, 0, 0, 0}};#define SHORT_OPTIONS()const char short_options[] = "1b:c:df:hi:l:mn:o:p:rst:uvw:x:y:B:CDF:IL:M:NP:RS:T:UVW";/* ------------------------------------------------------------------- * defaults * ------------------------------------------------------------------- */#define DEFAULTS()const long kDefault_UDPRate = 1024 * 1024; // -u  if set, 1 Mbit/secconst int  kDefault_UDPBufLen = 1470;      // -u  if set, read/write 1470 bytes// 1470 bytes is small enough to be sending one packet per datagram on ethernet// 1450 bytes is small enough to be sending one packet per datagram on ethernet//  **** with IPv6 ****/* ------------------------------------------------------------------- * Initialize all settings to defaults. * ------------------------------------------------------------------- */void Settings_Initialize( thread_Settings *main ) {    // Everything defaults to zero or NULL with    // this memset. Only need to set non-zero values    // below.    memset( main, 0, sizeof(thread_Settings) );    main->mSock = INVALID_SOCKET;    main->mReportMode = kReport_Default;    // option, defaults    main->flags         = FLAG_MODETIME | FLAG_STDOUT; // Default time and stdout    //main->mUDPRate      = 0;           // -b,  ie. TCP mode    //main->mHost         = NULL;        // -c,  none, required for client    main->mMode         = kTest_Normal;  // -d,  mMode == kTest_DualTest    main->mFormat       = 'a';           // -f,  adaptive bits    // skip help                         // -h,    //main->mBufLenSet  = false;         // -l,	    main->mBufLen       = 8 * 1024;      // -l,  8 Kbyte    //main->mInterval     = 0;           // -i,  ie. no periodic bw reports    //main->mPrintMSS   = false;         // -m,  don't print MSS    // mAmount is time also              // -n,  N/A    //main->mOutputFileName = NULL;      // -o,  filename    main->mPort         = 5001;          // -p,  ttcp port    // mMode    = kTest_Normal;          // -r,  mMode == kTest_TradeOff    main->mThreadMode   = kMode_Unknown; // -s,  or -c, none    main->mAmount       = 1000;          // -t,  10 seconds    // mUDPRate > 0 means UDP            // -u,  N/A, see kDefault_UDPRate    // skip version                      // -v,    //main->mTCPWin       = 0;           // -w,  ie. don't set window    // more esoteric options    //main->mLocalhost    = NULL;        // -B,  none    //main->mCompat     = false;         // -C,  run in Compatibility mode    //main->mDaemon     = false;         // -D,  run as a daemon    //main->mFileInput  = false;         // -F,    //main->mFileName     = NULL;        // -F,  filename     //main->mStdin      = false;         // -I,  default not stdin    //main->mListenPort   = 0;           // -L,  listen port    //main->mMSS          = 0;           // -M,  ie. don't set MSS    //main->mNodelay    = false;         // -N,  don't set nodelay    //main->mThreads      = 0;           // -P,    //main->mRemoveService = false;      // -R,    //main->mTOS          = 0;           // -S,  ie. don't set type of service    main->mTTL          = 1;             // -T,  link-local TTL    //main->mDomain     = kMode_IPv4;    // -V,    //mian->mSuggestWin = false;         // -W,  Suggest the window size.} // end Settingsvoid Settings_Copy( thread_Settings *from, thread_Settings **into ) {    *into = new thread_Settings;    memcpy( *into, from, sizeof(thread_Settings) );    if ( from->mHost != NULL ) {        (*into)->mHost = new char[ strlen(from->mHost) + 1];        strcpy( (*into)->mHost, from->mHost );    }    if ( from->mOutputFileName != NULL ) {        (*into)->mOutputFileName = new char[ strlen(from->mOutputFileName) + 1];        strcpy( (*into)->mOutputFileName, from->mOutputFileName );    }    if ( from->mLocalhost != NULL ) {        (*into)->mLocalhost = new char[ strlen(from->mLocalhost) + 1];        strcpy( (*into)->mLocalhost, from->mLocalhost );    }    if ( from->mFileName != NULL ) {        (*into)->mFileName = new char[ strlen(from->mFileName) + 1];        strcpy( (*into)->mFileName, from->mFileName );    }    // Zero out certain entries    (*into)->mTID = thread_zeroid();    (*into)->runNext = NULL;    (*into)->runNow = NULL;}/* ------------------------------------------------------------------- * Delete memory: Does not clean up open file pointers or ptr_parents * ------------------------------------------------------------------- */void Settings_Destroy( thread_Settings *mSettings) {    DELETE_ARRAY( mSettings->mHost      );    DELETE_ARRAY( mSettings->mLocalhost );    DELETE_ARRAY( mSettings->mFileName  );    DELETE_ARRAY( mSettings->mOutputFileName );    DELETE_PTR( mSettings );} // end ~Settings/* ------------------------------------------------------------------- * Parses settings from user's environment variables. * ------------------------------------------------------------------- */void Settings_ParseEnvironment( thread_Settings *mSettings ) {    char *theVariable;    int i = 0;    while ( env_options[i].name != NULL ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -