[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.36 and 1.37

version 1.36, 2001/09/02 19:07:17 version 1.37, 2001/09/02 19:11:46
Line 79 
Line 79 
 void    usage __P((int));  void    usage __P((int));
   
 int  int
 main(argc, argv)  main(int argc, char *argv[])
         int argc;  
         char *argv[];  
 {  {
         int ch, s, ret;          int ch, s, ret;
         char *host, *uport, *endp;          char *host, *uport, *endp;
Line 236 
Line 234 
   
                                 len = sizeof(z);                                  len = sizeof(z);
                                 rv = recvfrom(s, buf, sizeof(buf), MSG_PEEK,                                  rv = recvfrom(s, buf, sizeof(buf), MSG_PEEK,
                                         (struct sockaddr *)&z, &len);                                      (struct sockaddr *)&z, &len);
                                 if (rv < 0)                                  if (rv < 0)
                                         errx(1, "%s", strerror(errno));                                          errx(1, "%s", strerror(errno));
   
                                 rv = connect(s, (struct sockaddr *)&z,                                  rv = connect(s, (struct sockaddr *)&z, len);
                                         len);  
                                 if (rv < 0)                                  if (rv < 0)
                                         errx(1, "%s", strerror(errno));                                          errx(1, "%s", strerror(errno));
   
                                 connfd = s;                                  connfd = s;
                         } else {                          } else {
                                 connfd = accept(s, (struct sockaddr *)&cliaddr,                                  connfd = accept(s, (struct sockaddr *)&cliaddr,
                                                                         &len);                                      &len);
                         }                          }
   
                         readwrite(connfd);                          readwrite(connfd);
Line 294 
Line 291 
                                         sv = NULL;                                          sv = NULL;
                                 else {                                  else {
                                         sv = getservbyport(                                          sv = getservbyport(
                                                 ntohs(atoi(portlist[i])),                                              ntohs(atoi(portlist[i])),
                                                 uflag ? "udp" : "tcp");                                              uflag ? "udp" : "tcp");
                                 }                                  }
   
                                 printf("Connection to %s %s port [%s/%s] succeeded!\n",                                  printf("Connection to %s %s port [%s/%s] succeeded!\n",
                                         host, portlist[i], uflag ? "udp" : "tcp",                                      host, portlist[i], uflag ? "udp" : "tcp",
                                         sv ? sv->s_name : "*");                                      sv ? sv->s_name : "*");
                         }                          }
                         if (!zflag)                          if (!zflag)
                                 readwrite(s);                                  readwrite(s);
Line 319 
Line 316 
  * port or source address if needed. Return's -1 on failure.   * port or source address if needed. Return's -1 on failure.
  */   */
 int  int
 remote_connect(host, port, hints)  remote_connect(char *host, char *port, struct addrinfo hints)
         char *host, *port;  
         struct addrinfo hints;  
 {  {
         struct addrinfo *res, *res0;          struct addrinfo *res, *res0;
         int s, error;          int s, error;
Line 332 
Line 327 
         res0 = res;          res0 = res;
         do {          do {
                 if ((s = socket(res0->ai_family, res0->ai_socktype,                  if ((s = socket(res0->ai_family, res0->ai_socktype,
                                 res0->ai_protocol)) < 0)                      res0->ai_protocol)) < 0)
                         continue;                          continue;
   
                 /* Bind to a local port or source address if specified */                  /* Bind to a local port or source address if specified */
Line 355 
Line 350 
                                 errx(1, "%s", gai_strerror(error));                                  errx(1, "%s", gai_strerror(error));
   
                         if (bind(s, (struct sockaddr *)ares->ai_addr,                          if (bind(s, (struct sockaddr *)ares->ai_addr,
                                                         ares->ai_addrlen) < 0) {                               ares->ai_addrlen) < 0) {
                                 errx(1, "bind failed: %s", strerror(errno));                                  errx(1, "bind failed: %s", strerror(errno));
                                 freeaddrinfo(ares);                                  freeaddrinfo(ares);
                                 continue;                                  continue;
Line 384 
Line 379 
  * address. Return's -1 on failure.   * address. Return's -1 on failure.
  */   */
 int  int
 local_listen(host, port, hints)  local_listen(char *host, char *port, struct addrinfo hints)
         char *host, *port;  
         struct addrinfo hints;  
 {  {
         struct addrinfo *res, *res0;          struct addrinfo *res, *res0;
         int s, ret, x = 1;          int s, ret, x = 1;
Line 408 
Line 401 
         res0 = res;          res0 = res;
         do {          do {
                 if ((s = socket(res0->ai_family, res0->ai_socktype,                  if ((s = socket(res0->ai_family, res0->ai_socktype,
                                 res0->ai_protocol)) == 0)                      res0->ai_protocol)) == 0)
                         continue;                          continue;
   
                 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));                  ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
Line 416 
Line 409 
                         err(1, NULL);                          err(1, NULL);
   
                 if (bind(s, (struct sockaddr *)res0->ai_addr,                  if (bind(s, (struct sockaddr *)res0->ai_addr,
                                                 res0->ai_addrlen) == 0)                      res0->ai_addrlen) == 0)
                         break;                          break;
   
                 close(s);                  close(s);
Line 438 
Line 431 
  * Loop that polls on the network file descriptor and stdin.   * Loop that polls on the network file descriptor and stdin.
  */   */
 void  void
 readwrite(nfd)  readwrite(int nfd)
         int nfd;  
 {  {
         struct pollfd *pfd;          struct pollfd *pfd;
         char buf[BUFSIZ];          char buf[BUFSIZ];
Line 489 
Line 481 
 }  }
 /* Deal with RFC854 WILL/WONT DO/DONT negotiation */  /* Deal with RFC854 WILL/WONT DO/DONT negotiation */
 void  void
 atelnet(nfd, buf, size)  atelnet(int nfd, unsigned char *buf, unsigned int size)
         int nfd;  
         unsigned char *buf;  
         unsigned int size;  
 {  {
         int ret;          int ret;
         unsigned char *p, *end;          unsigned char *p, *end;
Line 530 
Line 519 
  * that we should try to connect too.   * that we should try to connect too.
  */   */
 void  void
 build_ports(p)  build_ports(char *p)
         char *p;  
 {  {
         char *n, *endp;          char *n, *endp;
         int hi, lo, cp;          int hi, lo, cp;
Line 593 
Line 581 
  * Also fails after around 100 ports checked.   * Also fails after around 100 ports checked.
  */   */
 int  int
 udptest(s)  udptest(int s)
         int s;  
 {  {
         int i, rv, ret;          int i, rv, ret;
   
Line 633 
Line 620 
 }  }
   
 void  void
 usage(ret)  usage(int ret)
         int ret;  
 {  {
         fprintf(stderr, "usage: nc [-46hklnrtuvz] [-i interval] [-p source port]\n");          fprintf(stderr, "usage: nc [-46hklnrtuvz] [-i interval] [-p source port]\n");
         fprintf(stderr, "\t  [-s ip address] [-w timeout] [-x proxy address [:port]]\n");          fprintf(stderr, "\t  [-s ip address] [-w timeout] [-x proxy address [:port]]\n");

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.37