[BACK]Return to tcpbench.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tcpbench

Diff for /src/usr.bin/tcpbench/tcpbench.c between version 1.24 and 1.25

version 1.24, 2011/08/23 04:13:38 version 1.25, 2011/09/09 00:40:54
Line 110 
Line 110 
 static void     tcp_server_accept(int, short, void *);  static void     tcp_server_accept(int, short, void *);
 static void     server_init(struct addrinfo *, struct statctx *);  static void     server_init(struct addrinfo *, struct statctx *);
 static void     client_handle_sc(int, short, void *);  static void     client_handle_sc(int, short, void *);
 static void     client_init(struct addrinfo *, int, struct statctx *);  static void     client_init(struct addrinfo *, int, struct statctx *,
       struct addrinfo *);
 static int      clock_gettime_tv(clockid_t, struct timeval *);  static int      clock_gettime_tv(clockid_t, struct timeval *);
 static void     udp_server_handle_sc(int, short, void *);  static void     udp_server_handle_sc(int, short, void *);
 static void     udp_process_slice(int, short, void *);  static void     udp_process_slice(int, short, void *);
Line 173 
Line 174 
 {  {
         fprintf(stderr,          fprintf(stderr,
             "usage: tcpbench -l\n"              "usage: tcpbench -l\n"
             "       tcpbench [-uv] [-B buf] [-k kvars] [-n connections] [-p port]\n"              "       tcpbench [-uv] [-B buf] [-b addr] [-k kvars] [-n connections]\n"
             "                [-r interval] [-S space] [-T toskeyword] [-V rtable]\n"              "                [-p port] [-r interval] [-S space] [-T toskeyword]\n"
             "                hostname\n"              "                [-V rtable] hostname\n"
             "       tcpbench -s [-uv] [-B buf] [-k kvars] [-p port]\n"              "       tcpbench -s [-uv] [-B buf] [-k kvars] [-p port]\n"
             "                [-r interval] [-S space] [-T toskeyword] [-V rtable]\n");              "                [-r interval] [-S space] [-T toskeyword] [-V rtable]\n");
         exit(1);          exit(1);
Line 821 
Line 822 
 }  }
   
 static void  static void
 client_init(struct addrinfo *aitop, int nconn, struct statctx *udp_sc)  client_init(struct addrinfo *aitop, int nconn, struct statctx *udp_sc,
       struct addrinfo *aib)
 {  {
         struct statctx *sc;          struct statctx *sc;
         struct addrinfo *ai;          struct addrinfo *ai;
Line 843 
Line 845 
                                         warn("socket");                                          warn("socket");
                                 continue;                                  continue;
                         }                          }
                           if (aib != NULL) {
                                   saddr_ntop(aib->ai_addr, aib->ai_addrlen,
                                       tmp, sizeof(tmp));
                                   if (ptb->vflag)
                                           fprintf(stderr,
                                               "Try to bind to %s\n", tmp);
                                   if (bind(sock, (struct sockaddr *)aib->ai_addr,
                                       aib->ai_addrlen) == -1)
                                           err(1, "bind");
                                   freeaddrinfo(aib);
                           }
                         if (ptb->Tflag != -1 && ai->ai_family == AF_INET) {                          if (ptb->Tflag != -1 && ai->ai_family == AF_INET) {
                                 if (setsockopt(sock, IPPROTO_IP, IP_TOS,                                  if (setsockopt(sock, IPPROTO_IP, IP_TOS,
                                     &ptb->Tflag, sizeof(ptb->Tflag)))                                      &ptb->Tflag, sizeof(ptb->Tflag)))
Line 962 
Line 975 
         extern char *optarg;          extern char *optarg;
   
         char kerr[_POSIX2_LINE_MAX], *tmp;          char kerr[_POSIX2_LINE_MAX], *tmp;
         struct addrinfo *aitop, hints;          struct addrinfo *aitop, *aib, hints;
         const char *errstr;          const char *errstr;
         struct rlimit rl;          struct rlimit rl;
         int ch, herr, nconn;          int ch, herr, nconn;
         struct nlist nl[] = { { "_tcbtable" }, { "" } };          struct nlist nl[] = { { "_tcbtable" }, { "" } };
         const char *host = NULL, *port = DEFAULT_PORT;          const char *host = NULL, *port = DEFAULT_PORT, *srcbind = NULL;
         struct event ev_sigint, ev_sigterm, ev_sighup;          struct event ev_sigint, ev_sigterm, ev_sighup;
         struct statctx *udp_sc = NULL;          struct statctx *udp_sc = NULL;
   
Line 980 
Line 993 
         ptb->rflag = DEFAULT_STATS_INTERVAL;          ptb->rflag = DEFAULT_STATS_INTERVAL;
         ptb->Tflag = -1;          ptb->Tflag = -1;
         nconn = 1;          nconn = 1;
           aib = NULL;
   
         while ((ch = getopt(argc, argv, "B:hlk:n:p:r:sS:T:uvV:")) != -1) {          while ((ch = getopt(argc, argv, "b:B:hlk:n:p:r:sS:T:uvV:")) != -1) {
                 switch (ch) {                  switch (ch) {
                   case 'b':
                           srcbind = optarg;
                           break;
                 case 'l':                  case 'l':
                         list_kvars();                          list_kvars();
                         exit(0);                          exit(0);
Line 1079 
Line 1096 
         }          }
   
         bzero(&hints, sizeof(hints));          bzero(&hints, sizeof(hints));
         if (UDP_MODE)          if (UDP_MODE) {
                 hints.ai_socktype = SOCK_DGRAM;                  hints.ai_socktype = SOCK_DGRAM;
         else                  hints.ai_protocol = IPPROTO_UDP;
           }
           else {
                 hints.ai_socktype = SOCK_STREAM;                  hints.ai_socktype = SOCK_STREAM;
                   hints.ai_protocol = IPPROTO_TCP;
           }
         if (ptb->sflag)          if (ptb->sflag)
                 hints.ai_flags = AI_PASSIVE;                  hints.ai_flags = AI_PASSIVE;
           if (srcbind != NULL) {
                   hints.ai_flags |= AI_NUMERICHOST;
                   herr = getaddrinfo(srcbind, NULL, &hints, &aib);
                   hints.ai_flags &= ~AI_NUMERICHOST;
                   if (herr != 0) {
                           if (herr == EAI_SYSTEM)
                                   err(1, "getaddrinfo");
                           else
                                   errx(1, "getaddrinfo: %s", gai_strerror(herr));
                   }
           }
         if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) {          if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) {
                 if (herr == EAI_SYSTEM)                  if (herr == EAI_SYSTEM)
                         err(1, "getaddrinfo");                          err(1, "getaddrinfo");
Line 1145 
Line 1177 
         if (ptb->sflag) {          if (ptb->sflag) {
                 server_init(aitop, udp_sc);                  server_init(aitop, udp_sc);
         } else          } else
                 client_init(aitop, nconn, udp_sc);                  client_init(aitop, nconn, udp_sc, aib);
   
         /* libevent main loop*/          /* libevent main loop*/
         event_dispatch();          event_dispatch();

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25