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

📄 tmain.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/socktest/tmain.c,v 1.2 2001/11/09 21:57:54 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: tmain.c,v $ * Revision 1.2  2001/11/09 21:57:54  josh * socktest path modifications, first pass * * Revision 1.1.1.1  2001/11/05 17:49:14  tneale * Tornado shuffle * * Revision 1.4  2001/03/02 19:16:31  paul * Added an etc.ini configuration section. * * Revision 1.3  2001/01/19 22:24:55  paul * Update copyright. * * Revision 1.2  2000/10/27 18:06:09  paul * Removed hardwired default server address, made server option mandatory. * * Revision 1.1  2000/10/16 19:22:44  paul * Renamed from test_main.c * * Revision 1.8  2000/03/17 00:14:48  meister * Update copyright message * * Revision 1.6  1999/05/12 19:03:36  paul * Fixed -s option. * * Revision 1.5  1999/05/03 19:22:29  paul * Added test_close(). * * Revision 1.4  1999/02/18 04:16:06  wes * Socket Merge: new code (socket tests). * * Revision 1.3.2.11  1999/01/06 21:42:28  paul * switched to getopt command-line processing * added server command-line option * * Revision 1.3.2.10  1998/12/22 20:26:47  wes * First cut at multi-threaded socket test. * * Revision 1.3.2.9  1998/11/20 16:19:58  paul * freestanding ttcp * * Revision 1.3.2.8  1998/11/06 23:36:51  paul * rototill to support tcp * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include "test.h"int test_flags;unsigned long server = 0;struct {  char *name;  void (*func)(int);  int set;} cmd[] = {  { "socket", test_socket, 0 },  { "bind", test_bind, 0 },  { "connect", test_connect, 0 },  { "accept", test_accept, 0 },  { "getsockname", test_getsockname, 0 },  { "getpeername", test_getpeername, 0 },  { "send", test_send, 0 },  { "sendto", test_sendto, 0 },  { "sendmsg", test_sendmsg, 0 },  { "recv", test_recv, 0 },  { "recvfrom", test_recvfrom, 0 },  { "recvmsg", test_recvmsg, 0 },  { "ioctl", test_ioctl, 0 },  { "select", test_select, 0 },  { "shutdown", test_shutdown, 0 },  { "close", test_close, 0 },#ifndef TEST_BSD  { "multitask", test_multitask, 0 },#endif  { 0, 0, 0 }};static voidusage(void){  int j;  printf("socktest -[utqv] -s server <test names>\n"	 "\t-u\tUDP\n"	 "\t-t\tTCP\n"	 "\t-q\tquiet (errors only)\n"	 "\t-v\tverbose (extra information)\n"	 "\t-s##\tip address of echo/discard server\n"	 "\nAvailable tests are:\n");  for (j = 0; cmd[j].name; ++j)    printf("\t%s\n", cmd[j].name);}#ifndef TEST_BSD/* You can add the following section to your etc.ini file.  This is * necessary for systems that don't have a command line (e.g. pSOS), * but can also be used for convenience (e.g. to store the server * address, so you don't have to enter it on the command line every * time). [etc snark socktest] protocol = udp  protocol = tcp ;output = quiet ;output = verbose server = 10.0.0.3 ;test = * test = socket test = bind test = connect test = accept test = getsockname test = getpeername test = send test = sendto test = sendmsg test = recv test = recvfrom test = recvmsg test = ioctl test = select test = shutdown test = close test = multitask */#include <wrn/wm/demo/snarklib.h>#include <wrn/wm/demo/read_ini.h>static voidini_config(void){  struct ini_handle *ini_handle = ini_open(256);  static char snark_section[] = "etc snark socktest";  char *s;  int j;  for (s = ini_iter_start(ini_handle, snark_section, "protocol"); s;       s = ini_iter_next(ini_handle)) {    if (strcmp(s, "udp") == 0)      test_flags |= TEST_UDP;    else if (strcmp(s, "tcp") == 0)      test_flags |= TEST_TCP;  }    for (s = ini_iter_start(ini_handle, snark_section, "output"); s;       s = ini_iter_next(ini_handle)) {    if (strcmp(s, "quiet") == 0)      quiet = 1;    else if (strcmp(s, "verbose") == 0)      verbose = 1;  }    for (s = ini_iter_start(ini_handle, snark_section, "server"); s;       s = ini_iter_next(ini_handle)) {    server = inet_addr(s);  }    for (s = ini_iter_start(ini_handle, snark_section, "test"); s;       s = ini_iter_next(ini_handle)) {    if (s[0] == '*' && s[1] == '\0') {      for (j = 0; cmd[j].name; ++j) {	cmd[j].set = 1;      }      continue;    }    for (j = 0; cmd[j].name; ++j) {      if (strcmp(s, cmd[j].name) == 0) {	cmd[j].set = 1;	break;      }    }#if 0    if (!cmd[j].name) {      printf("unknown test \"%s\"\n", s);      usage();      return;    }#endif  }  ini_close(ini_handle);}#endifstatic voidcmdline_config(int argc, char * const *argv){  int i, j;  extern int getopt(int, char * const *, const char *);  extern char *optarg;  extern int optind;  /* options must precede test names */  while ((j = getopt(argc, argv, "utqvs:")) != -1)      switch (j) {      case 'u':	test_flags |= TEST_UDP;	break;      case 't':	test_flags |= TEST_TCP;	break;      case 'q':	quiet = 1;	break;      case 'v':	verbose = 1;	break;      case 's':	server = inet_addr(optarg);	break;      default:	usage();	return;      }  for (i = optind; i < argc; ++i) {    if (argv[i][0] == '*' && argv[i][1] == '\0') {      for (j = 0; cmd[j].name; ++j) {	cmd[j].set = 1;      }      continue;    }    for (j = 0; cmd[j].name; ++j) {      if (strcmp(argv[i], cmd[j].name) == 0) {	cmd[j].set = 1;	break;      }    }#if 0    if (!cmd[j].name) {      printf("unknown test \"%s\"\n", argv[i]);      usage();      return;    }#endif  }}voidmain(int argc, char * const *argv){  int j, tested;    test_init();#if defined(SIGPIPE) && defined(SIG_IGN)  signal(SIGPIPE, SIG_IGN);#endif#ifndef TEST_BSD  ini_config();#endif  cmdline_config(argc, argv);    if (test_flags == 0)    test_flags = TEST_UDP | TEST_TCP;  if (verbose)    quiet = 0;  if (server == 0) {    usage();    return;  }  for (j = tested = 0; cmd[j].name; ++j) {    if (cmd[j].set) {      cmd[j].func(test_flags);      ++tested;    }  }    if (tested == 0) {    for (j = 0; cmd[j].name; ++j)      cmd[j].func(test_flags);  }  test_summarize();}

⌨️ 快捷键说明

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