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

Diff for /src/usr.bin/nc/netcat.c between version 1.15 and 1.16

version 1.15, 2000/09/26 05:19:37 version 1.16, 2000/09/26 17:46:40
Line 51 
Line 51 
 #include <stdlib.h>  #include <stdlib.h>
 #include <unistd.h>  #include <unistd.h>
   
 /* Random Numbers aren't too needed here */  
 #define SRAND srandom  
 #define RAND random  
   
 #define SLEAZE_PORT 31337       /* for UDP-scan RTT trick, change if ya want */  #define SLEAZE_PORT 31337       /* for UDP-scan RTT trick, change if ya want */
 #define BIGSIZ 8192             /* big buffers */  #define BIGSIZ 8192             /* big buffers */
   
Line 76 
Line 72 
 int     netfd = -1;  int     netfd = -1;
 int     ofd = 0;                /* hexdump output fd */  int     ofd = 0;                /* hexdump output fd */
   
 /* extern int h_errno; */  
   
 int     gatesidx = 0;           /* LSRR hop count */  int     gatesidx = 0;           /* LSRR hop count */
 int     gatesptr = 4;           /* initial LSRR pointer, settable */  int     gatesptr = 4;           /* initial LSRR pointer, settable */
 u_short  Single = 1;            /* zero if scanning */  u_short  Single = 1;            /* zero if scanning */
Line 206 
Line 200 
         struct hostent *hp;          struct hostent *hp;
 {  {
         errno = 0;          errno = 0;
         h_errno = 0;  
         if (strcasecmp(hinfo->name, hp->h_name) != 0) {          if (strcasecmp(hinfo->name, hp->h_name) != 0) {
                 nlog(0, "DNS fwd/rev mismatch: %s != %s", hinfo->name, hp->h_name);                  nlog(0, "DNS fwd/rev mismatch: %s != %s", hinfo->name, hp->h_name);
                 return (1);                  return (1);
Line 232 
Line 225 
         int x;          int x;
   
         errno = 0;          errno = 0;
         h_errno = 0;  
         if (name)          if (name)
                 hinfo = (struct host_info *) calloc(1, sizeof(struct host_info));                  hinfo = (struct host_info *) calloc(1, sizeof(struct host_info));
   
Line 313 
Line 305 
          * Whatever-all went down previously, we should now have a host_info           * Whatever-all went down previously, we should now have a host_info
          * struct with at least one IP address in it.           * struct with at least one IP address in it.
          */           */
         h_errno = 0;  
         return (hinfo);          return (hinfo);
 }  }
   
Line 421 
Line 412 
   
         y = 70000;                      /* high safety count for rnd-tries */          y = 70000;                      /* high safety count for rnd-tries */
         while (y > 0) {          while (y > 0) {
                 x = (RAND() & 0xffff);                  x = (arc4random() & 0xffff);
                 if (block[x] == 1) {    /* try to find a not-done one... */                  if (block[x] == 1) {    /* try to find a not-done one... */
                         block[x] = 2;                          block[x] = 2;
                         break;                          break;
Line 509 
Line 500 
   
         /* fill in all the right sockaddr crud */          /* fill in all the right sockaddr crud */
         lclend->sin_family = AF_INET;          lclend->sin_family = AF_INET;
   
         /* fill in all the right sockaddr crud */  
         lclend->sin_family = AF_INET;  
         remend->sin_family = AF_INET;          remend->sin_family = AF_INET;
   
         /* if lad/lp, do appropriate binding */          /* if lad/lp, do appropriate binding */
Line 1062 
Line 1050 
   
 /* main :  /* main :
    now we pull it all together... */     now we pull it all together... */
   int
 main(argc, argv)  main(argc, argv)
         int     argc;          int     argc;
         char  **argv;          char  **argv;
Line 1091 
Line 1080 
   
         errno = 0;          errno = 0;
         gatesptr = 4;          gatesptr = 4;
         h_errno = 0;  
   
         /*          /*
          * We want to catch a few of these signals.           * We want to catch a few of these signals.
Line 1108 
Line 1096 
          * and hand anything left over to readwrite().           * and hand anything left over to readwrite().
          */           */
         if (argc == 1) {          if (argc == 1) {
                 cp = argv[0];                  /* Loop until we get a command to try */
                 /* XXX - 128 ? */                  for (;;) {
                 argv = (char **) calloc(1, 128 * sizeof(char *));                          cp = argv[0];
                 argv[0] = cp;   /* leave old prog name intact */                          argv = (char **) calloc(1, 128 * sizeof(char *));
                 cp = calloc(1, BIGSIZ);                          argv[0] = cp;   /* leave old prog name intact */
                 argv[1] = cp;   /* head of new arg block */                          cp = calloc(1, BIGSIZ);
                 fprintf(stderr, "Cmd line: ");                          argv[1] = cp;   /* head of new arg block */
                 fflush(stderr); /* I dont care if it's unbuffered or not! */                          fprintf(stderr, "Cmd line: ");
                 insaved = read(0, cp, BIGSIZ-1); /* we're gonna fake fgets()                          fflush(stderr); /* I dont care if it's unbuffered or not! */
                                                  * here */                          insaved = read(0, cp, BIGSIZ-1); /* we're gonna fake fgets()
                 cp[BIGSIZ-1] = '\0';                                                            * here */
                           cp[BIGSIZ-1] = '\0';
                           if (*cp != '\n' && *cp != '\t')
                                   break;
                   }
                 if (insaved <= 0)                  if (insaved <= 0)
                         nlog(1, "wrong");                          nlog(1, "wrong");
                 x = findline(cp, insaved);                  x = findline(cp, insaved);
Line 1239 
Line 1231 
         /* other misc initialization */          /* other misc initialization */
             FD_SET(0, &fds1);   /* stdin *is* initially open */              FD_SET(0, &fds1);   /* stdin *is* initially open */
         if (o_random) {          if (o_random) {
                 SRAND(time(0));  
                 randports = calloc(1, 65536);   /* big flag array for ports */                  randports = calloc(1, 65536);   /* big flag array for ports */
         }          }
         if (o_wfile) {          if (o_wfile) {
Line 1256 
Line 1247 
         if (themaddr)          if (themaddr)
                 optind++;       /* skip past valid host lookup */                  optind++;       /* skip past valid host lookup */
         errno = 0;          errno = 0;
         h_errno = 0;  
   
         /*          /*
          * Handle listen mode here, and exit afterward.  Only does one connect;           * Handle listen mode here, and exit afterward.  Only does one connect;
Line 1302 
Line 1292 
                 loport = getpinfo(argv[optind], 0);                  loport = getpinfo(argv[optind], 0);
                 if (loport == 0)                  if (loport == 0)
                         nlog(1, "invalid port %s", argv[optind]);                          nlog(1, "invalid port %s", argv[optind]);
                 if (hiport > loport) {  /* was it genuinely a range? */                  if (hiport > loport) {
                         Single = 0;     /* multi-mode, case B */                          Single = 0;
                         if (o_random) { /* maybe populate the random array */                          if (o_random) {
                                 loadports(randports, loport, hiport);                                  loadports(randports, loport, hiport);
                                 curport = nextport(randports);                                  curport = nextport(randports);
                         } else                          } else
Line 1376 
Line 1366 
                         herror(NULL);                          herror(NULL);
                 else                  else
                         putc('\n', stderr);                          putc('\n', stderr);
                   va_end(args);
         }          }
   
         if (doexit)          if (doexit)

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16