home *** CD-ROM | disk | FTP | other *** search
/ Steganos Hacker Tools / SHT151.iso / programme / scanner / nmapNTsp1 / Win_2000.exe / nmapNT-src / rpc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-14  |  18.3 KB  |  543 lines

  1. #include "rpc.h"
  2.  
  3. extern struct ops o;
  4. static int services_initialized = 0;
  5. static struct rpc_info ri;
  6. static int udp_rpc_socket = -1;
  7. static int tcp_rpc_socket = -1;
  8. static unsigned long rpc_xid_base = -1; /* The XID we send in queries is 
  9.                        this random base number + the 
  10.                        RPC prog number we are scanning
  11.                        for */
  12. static int tcp_readlen=0; /* used in get_rpc_results but can be reset in 
  13.                 send_rpc_query */
  14.  
  15. static void rpc_services_init() {
  16.   char filename[512];
  17.   FILE *fp;
  18.   unsigned char *tmpptr, *p;
  19.   char line[1024];
  20.   int lineno = 0;
  21.  
  22.   services_initialized = 1;
  23.   ri.num_alloc = 256;
  24.   ri.num_used = 0;
  25.   ri.names = cp_alloc(ri.num_alloc * sizeof(char *));
  26.   ri.numbers = cp_alloc(ri.num_alloc * sizeof(unsigned long));
  27.  
  28.   if (nmap_fetchfile(filename, sizeof(filename), "nmap-rpc") == -1) {
  29.     error("Unable to find nmap-rpc!  Resorting to /etc/rpc");
  30.     strcpy(filename, "/etc/rpc");
  31.   }
  32.  
  33.   fp = fopen(filename, "r");
  34.   if (!fp) {
  35.     fatal("Unable to open %s for reading rpc information", filename);
  36.   }
  37.  
  38.   while(fgets(line, sizeof(line), fp)) {
  39.     lineno++;
  40.     p = line;
  41.  
  42.     if (ri.num_used == ri.num_alloc) {
  43.       tmpptr = cp_alloc(ri.num_alloc * 3 * sizeof(char *));
  44.       memcpy(tmpptr, ri.names, ri.num_alloc * sizeof(char *));
  45.       ri.names = (char **) tmpptr;
  46.       tmpptr = cp_alloc(ri.num_alloc * 3 * sizeof(unsigned long));
  47.       memcpy(tmpptr, ri.numbers, ri.num_alloc * sizeof(char *));
  48.       ri.numbers = (unsigned long *) tmpptr;
  49.       ri.num_alloc *= 3;
  50.     }
  51.  
  52.     while(*p && *p != '#' && !isalnum(*p)) p++;
  53.  
  54.     if (!*p || *p == '#') continue;
  55.  
  56.     tmpptr = strpbrk(p, " \t");
  57.     if (!tmpptr) 
  58.       continue;
  59.     *tmpptr = '\0';
  60.     
  61.     ri.names[ri.num_used] = cp_strdup(p);
  62.     p = tmpptr + 1;
  63.  
  64.     while(*p && !isdigit(*p)) p++;
  65.  
  66.     if (!*p)
  67.       continue;
  68.  
  69.     ri.numbers[ri.num_used] = strtoul(p, NULL, 10);
  70.     ri.num_used++;
  71.   }
  72.   fclose(fp);
  73.   return;
  74. }
  75.  
  76. char *nmap_getrpcnamebynum(unsigned long num) {
  77.   int i;
  78.  
  79.   if (!services_initialized) {
  80.     rpc_services_init();
  81.   }
  82.  
  83.   for(i=0; i < ri.num_used; i++) {
  84.     if (ri.numbers[i] == num)
  85.       return ri.names[i];
  86.   }
  87.   return NULL;
  88. }
  89.  
  90. int get_rpc_procs(unsigned long **programs, int *num_programs) {
  91.   if (!services_initialized) {
  92.     rpc_services_init();
  93.   }
  94.   
  95.   *programs = ri.numbers;
  96.   *num_programs = ri.num_used;
  97.   if (ri.num_used == 0) fatal("Unable to find any valid rpc procedures in your rpc file!  RPC scanning won't work for you");
  98.   return 0;
  99. }
  100.  
  101. /* Send an RPC query to the specified host/port on the specified protocol
  102.    looking for the specified RPC program.  We cache our sending sockets
  103.    to avoid recreating and (with TCP) reconnect() ing them each time */
  104. int send_rpc_query(struct in_addr *target_host, unsigned short portno,
  105.            int ipproto, unsigned long program, int scan_offset, 
  106.            int trynum,struct interface_info *ainfo) {
  107.   static struct in_addr last_target_host;
  108.   static int last_ipproto = -1;
  109.   static unsigned short last_portno = 0; 
  110.   struct sockaddr_in sock;
  111.   char rpch_buf[256]; 
  112.   struct rpc_hdr *rpch;
  113.   int res;
  114.  
  115.   /* static int numruns = 0;
  116.      if (numruns++ > 2)
  117.      fatal("Done");  */
  118.  
  119.   rpch = (struct rpc_hdr *) ((char *)rpch_buf + sizeof(unsigned long));
  120.   bzero(rpch, sizeof(struct rpc_hdr));
  121.  
  122.  
  123.   while(rpc_xid_base == -1)
  124.     rpc_xid_base = (unsigned long) get_random_uint();
  125.   
  126.   if (o.debugging > 1) {
  127.     printf("Sending RPC probe for program %li to %hi/%s -- scan_offset=%d trynum=%d xid=%lX\n", program, portno, (ipproto == IPPROTO_TCP)? "tcp" : "udp", scan_offset, trynum, rpc_xid_base + ((portno & 0x3FFF) << 16) + (trynum << 30) +  scan_offset);
  128.   }
  129.  
  130.   /* First we check whether we have to create a new connection -- we 
  131.      need to if we have a new target_host, or a new portno, or the socket
  132.      we want to use is -1 */
  133.   if (ipproto == IPPROTO_TCP && 
  134.       (last_target_host.s_addr != target_host->s_addr ||
  135.        last_portno != portno || last_ipproto != IPPROTO_TCP)) {
  136.     /* New host or port -- kill our old tcp socket */
  137.     if (tcp_rpc_socket != -1) {
  138.       close(tcp_rpc_socket);
  139.       tcp_rpc_socket = -1;
  140.       tcp_readlen = 0;
  141.     }
  142.   }
  143.   last_ipproto = ipproto;
  144.   last_target_host.s_addr = target_host->s_addr;
  145.   last_portno = portno;
  146.   
  147.   bzero(&sock, sizeof(&sock));
  148.   sock.sin_family = AF_INET;
  149.   sock.sin_addr.s_addr = target_host->s_addr;
  150.   sock.sin_port = htons(portno);
  151.     
  152.   if (ipproto == IPPROTO_TCP && tcp_rpc_socket == -1) {
  153.     if ((tcp_rpc_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
  154.       pfatal("Socket troubles in send_rpc_query");
  155.     /* I should unblock the socket here and timeout the connect() */
  156.     res = connect(tcp_rpc_socket, (struct sockaddr *) &sock, 
  157.           sizeof(struct sockaddr_in));
  158.     if (res == -1) {
  159.       if (o.debugging) {
  160.     gh_perror("Failed to connect to port %d of %s in send_rpc_query",
  161.           portno, inet_ntoa(*target_host));
  162.       }
  163.       close(tcp_rpc_socket);
  164.       tcp_rpc_socket = -1;
  165.       return -1;
  166.     }
  167.     unblock_socket(tcp_rpc_socket);
  168.   } else if (ipproto == IPPROTO_UDP && udp_rpc_socket == -1) {
  169.     if ((udp_rpc_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
  170.       pfatal("UDP socket troubles in send_rpc_query");
  171.     unblock_socket(udp_rpc_socket);
  172.   }
  173.   
  174.   /* OK, now that we have our sockets together, we form and send a
  175.      query ... */
  176.   rpch->type_msg = htonl(RPC_MSG_CALL); /* rpc request                 */
  177.   rpch->version_rpc=htonl(2);           /* portmapper v.2 (hmm, and v3&&4?) */
  178.   /*rpch->prog_proc=0;*/                    /* proc_null() rpc function     */
  179.   /*rpch->authcred_flavor=0;*/              /* AUTH_NULL for credentials    */
  180.   /*rpch->authcred_length=0;*/              /* length of credentials is zero*/
  181.   /*rpch->authveri_flavor=0;*/              /* no verifiers field          */
  182.   /*rpch->authveri_length=0;*/              /* zero length verifier field  */
  183.   
  184.   /* Bits are TTPPPPPPPPPPPPPP BBBBBBBBBBBBBBBB */
  185.   /* Where T are trynum bits, P is the lowest 14 bits of the port number,
  186.      and B is the scan[] offset */
  187.   rpch->xid = htonl(rpc_xid_base + ((portno & 0x3FFF) << 16) + 
  188.             (trynum << 30) +  scan_offset); 
  189.   rpch->prog_id = htonl(program);
  190.   rpch->prog_ver = htonl(31337 + (rpc_xid_base & 0xFFFFF));
  191.   
  192.   if (ipproto == IPPROTO_UDP) {
  193.     /* Simply send this sucker we have created ... */
  194.     do {  
  195.       if (o.debugging > 1)
  196. hdump((char *) rpch, sizeof(struct rpc_hdr));
  197. /*      res = sendto(udp_rpc_socket, (char *)rpch, sizeof(struct rpc_hdr), 0,*/
  198.       res = Sendto("send_rpc_query",udp_rpc_socket, (char *)rpch, sizeof(struct rpc_hdr), 0,
  199.            (struct sockaddr *) &sock, sizeof(struct sockaddr_in),ainfo);
  200.     } while(res == -1 && (errno == EINTR || errno == ENOBUFS));
  201.     if (res == -1) {
  202.       if (o.debugging) {
  203.     gh_perror("Sendto in send_rpc_query");
  204.     close(udp_rpc_socket);
  205.     udp_rpc_socket = -1;
  206.       }
  207.       return -1;
  208.     }
  209.   } else {
  210.     /* TCP socket */
  211.     /* 0x80000000 means only 1 record marking */
  212.     *(unsigned long *)rpch_buf = htonl(sizeof(struct rpc_hdr) | 0x80000000);
  213.     res = Write(tcp_rpc_socket, rpch_buf, sizeof(struct rpc_hdr) + sizeof(unsigned long));
  214.     if (res == -1) {
  215.       if (o.debugging) {
  216.     gh_perror("Write in send_rpc_query");
  217.       }
  218.       close(tcp_rpc_socket);
  219.       tcp_rpc_socket = -1;
  220.       return -1;
  221.     }
  222.   }
  223.   return 0;
  224. }
  225.  
  226. int rpc_are_we_done(char *msg, int msg_len, struct hoststruct *target, 
  227.             struct portinfo *scan, struct scanstats *ss, 
  228.             struct portinfolist *pil, struct rpcscaninfo *rsi) {
  229.  
  230.   struct rpc_hdr_rcv *rpc_pack;
  231.   unsigned long scan_offset;
  232.   int trynum;
  233.   struct portinfo *current;
  234.  
  235.   rpc_pack = (struct rpc_hdr_rcv *) msg;     
  236.   if (msg_len < 24 || msg_len > 32 || (msg_len < 32 && rpc_pack->accept_stat == PROG_MISMATCH)) {
  237.     /* This is not a valid reply -- we kill the port 
  238.        (from an RPC perspective) */ 
  239.     if (o.debugging > 1) {
  240.       printf("Port %hi/%s labelled NON_RPC because of invalid sized message (%d)\n", rsi->rpc_current_port->portno, (rsi->rpc_current_port->proto == IPPROTO_TCP)? "TPC" : "UDP", msg_len);
  241.     }
  242.     rsi->rpc_status = RPC_STATUS_NOT_RPC;
  243.     ss->numqueries_outstanding = 0;
  244.     return 1;
  245.   }
  246.  
  247.   /* Now it is time to decode the scan offset */
  248.   scan_offset = ntohl(rpc_pack->xid);
  249.   scan_offset -= rpc_xid_base;
  250.   if (((scan_offset >> 16) & 0x3FFF) != (rsi->rpc_current_port->portno & 0x3FFF)) {
  251.     /* Doh -- this doesn't seem right */
  252.     if (o.debugging > 1) {
  253.       printf("Port %hi/%s labelled NON_RPC because ((scan_offset >> 16) & 0x3FFF) is %li\n", rsi->rpc_current_port->portno, (rsi->rpc_current_port->proto == IPPROTO_TCP)? "TPC" : "UDP", ((scan_offset >> 16) & 0x3FFF));
  254.     }
  255.     rsi->rpc_status = RPC_STATUS_NOT_RPC;
  256.     ss->numqueries_outstanding = 0;
  257.     return 1;
  258.   }
  259.   trynum = scan_offset >> 30;
  260.   scan_offset &= 0xFFFF;
  261.   if (scan_offset >= rsi->rpc_number) {
  262.     error("Invalid scan_offset returned in RPC packet");
  263.     rsi->rpc_status = RPC_STATUS_NOT_RPC;
  264.     ss->numqueries_outstanding = 0;
  265.     return 1;
  266.   }
  267.   if (ntohl(rpc_pack->type_msg) != RPC_MSG_REPLY) {
  268.     error("Strange -- RPC type is %d shoulb be RPC_MSG_REPLY (1)", ntohl(rpc_pack->type_msg));
  269.     return 0;
  270.   }
  271.   if (ntohl(rpc_pack->auth_flavor) != 0 /* AUTH_NULL */ ||
  272.       ntohl(rpc_pack->opaque_length != 0)) {
  273.     error("Strange -- auth flavor/opaque_length are %d/%d should generally be 0/0", rpc_pack->auth_flavor, rpc_pack->opaque_length);
  274.     rsi->rpc_status = RPC_STATUS_NOT_RPC;
  275.     ss->numqueries_outstanding = 0;
  276.     return 1;
  277.   }
  278.  
  279.   /* OK, now that we know what this is a response to, we delete the
  280.       appropriate entry from our scanlist */
  281.   current = &scan[scan_offset];
  282.     
  283.    
  284.   if (current->state != PORT_TESTING && current->state != PORT_CLOSED &&
  285.       current->state != PORT_FIREWALLED) {
  286.     error("Supposed scan_offset refers to port in state %s (should be testing,closed, or firewalld)", statenum2str(current->state));
  287.     rsi->rpc_status = RPC_STATUS_NOT_RPC;
  288.     ss->numqueries_outstanding = 0;
  289.     return 1;
  290.   }
  291.      
  292.   if (trynum > current->trynum) {
  293.     error("Bogus trynum %d when we are only up to %d in get_rpc_results", trynum, current->trynum);
  294.     rsi->rpc_status = RPC_STATUS_NOT_RPC;
  295.     ss->numqueries_outstanding = 0;
  296.     return 1;
  297.   }
  298.  
  299.   if (current->next > -1) scan[current->next].prev = current->prev;
  300.   if (current->prev > -1) scan[current->prev].next = current->next;
  301.   if (current == pil->testinglist)
  302.     pil->testinglist = (current->next >= 0)?  &scan[current->next] : NULL;
  303.   current->next = -1;
  304.   current->prev = -1;
  305.      
  306.      /* Adjust timeouts ... */
  307.   adjust_timeouts(current->sent[trynum], &(target->to));
  308.      
  309.   /* If a non-zero trynum finds a port that hasn't been discovered, the
  310.     earlier packets(s) were probably dropped.  So we decrease our 
  311.     numqueries_ideal, otherwise we increase it slightly */
  312.   if (trynum == 0) {
  313.     ss->numqueries_ideal = MIN(ss->numqueries_ideal + (ss->packet_incr/ss->numqueries_ideal), ss->max_width);
  314.   } else  {
  315.     if (!ss->alreadydecreasedqueries) {
  316.       ss->alreadydecreasedqueries = 1;
  317.       ss->numqueries_ideal *= ss->fallback_percent;
  318.       if (ss->numqueries_ideal < 1.0) ss->numqueries_ideal = 1.0;
  319.       if (o.debugging) 
  320.     { 
  321.       log_write(LOG_STDOUT, "Lost a packet, decreasing window to %d\n", (int) ss->numqueries_ideal);
  322.     }
  323.     }
  324.   }
  325.  
  326.   if (current->state == PORT_TESTING)
  327.     ss->numqueries_outstanding--;
  328.      
  329.   if (ntohl(rpc_pack->accept_stat) == PROG_UNAVAIL) {
  330.     current->state = PORT_CLOSED;
  331.     if (o.debugging > 1) {
  332.       error("Port %hi/%s claims that it is not RPC service %li", rsi->rpc_current_port->portno, (rsi->rpc_current_port->proto == IPPROTO_TCP)? "TCP" : "UDP",  current->portno);
  333.     }
  334.     rsi->valid_responses_this_port++;
  335.     return 0;
  336.   } else if (ntohl(rpc_pack->accept_stat) == PROG_MISMATCH) {
  337.     if (o.debugging > 1) {
  338.       error("Port %hi/%s claims IT IS RPC service %li", rsi->rpc_current_port->portno, (rsi->rpc_current_port->proto == IPPROTO_TCP)? "TCP" : "UDP",  current->portno);
  339.     }
  340.     current->state = PORT_OPEN;
  341.     rsi->rpc_status = RPC_STATUS_GOOD_PROG;
  342.     rsi->rpc_program = current->portno;
  343.     rsi->rpc_lowver = ntohl(rpc_pack->low_version);
  344.     rsi->rpc_highver = ntohl(rpc_pack->high_version);
  345.     rsi->valid_responses_this_port++;
  346.     ss->numqueries_outstanding = 0;
  347.     return 1;
  348.   } else if (ntohl(rpc_pack->accept_stat) == SUCCESS) {
  349.     error("Umm -- RPC returned success for bogus version -- thats OK I guess");
  350.     rsi->rpc_status = RPC_STATUS_GOOD_PROG;
  351.     rsi->rpc_program = current->portno;
  352.     rsi->rpc_lowver = rsi->rpc_highver = 0;
  353.     rsi->valid_responses_this_port++;
  354.     ss->numqueries_outstanding = 0;
  355.     return 1;
  356.   } else {
  357.     fatal("Illegal rpc accept_stat");
  358.   }
  359.   return 0;
  360. }
  361.  
  362. void get_rpc_results(struct hoststruct *target, struct portinfo *scan,
  363.              struct scanstats *ss, struct portinfolist *pil, 
  364.              struct rpcscaninfo *rsi) {
  365.  
  366. int max_sd = -1;
  367. fd_set fds_r; 
  368. int sres;
  369. struct timeval tv;
  370. int res;
  371. static char readbuf[512];
  372. struct sockaddr_in from;
  373. int fromlen = sizeof(struct sockaddr_in);
  374. char *current_msg;
  375. unsigned long current_msg_len;
  376.  
  377.  if ((udp_rpc_socket == -1 && tcp_rpc_socket == -1) || ss->numqueries_outstanding <= 0)
  378.    return;
  379.  
  380.  FD_ZERO(&fds_r);
  381.  
  382.  if (udp_rpc_socket >= 0 && rsi->rpc_current_port->proto == IPPROTO_UDP) {
  383.    FD_SET(udp_rpc_socket, &fds_r);
  384.    max_sd = udp_rpc_socket;
  385.  }
  386.  else if (tcp_rpc_socket >= 0 && rsi->rpc_current_port->proto == IPPROTO_TCP) {
  387.    FD_SET(tcp_rpc_socket, &fds_r);
  388.    if (tcp_rpc_socket > max_sd)
  389.      max_sd = tcp_rpc_socket;
  390.  } else {
  391.    error("Unable to find listening socket in get_rpc_results");
  392.    return;
  393.  }
  394.  
  395.  
  396.  while (ss->numqueries_outstanding > 0) {
  397.  
  398.    
  399.    /* Insure there is no timeout ... */
  400.    if (o.host_timeout) {    
  401.      gettimeofday(&tv, NULL);
  402.      if (TIMEVAL_MSEC_SUBTRACT(tv, target->host_timeout) >= 0) {
  403.        target->timedout = 1;
  404.        return;
  405.      }
  406.    }
  407.  
  408.    tv.tv_sec = target->to.timeout / 1000000;
  409.    tv.tv_usec = target->to.timeout % 1000000;
  410.    sres = select(max_sd + 1, &fds_r, NULL, NULL, &tv);
  411.    if (!sres)
  412.      break;
  413.    if (sres == -1 && errno == EINTR)
  414.      continue;
  415.    if (udp_rpc_socket >= 0 && FD_ISSET(udp_rpc_socket, &fds_r)) {
  416.      res = recvfrom(udp_rpc_socket, readbuf, sizeof(readbuf), 0, (struct sockaddr *) &from, &fromlen);
  417.    
  418.      if (res < 0) {
  419.        /* Doh! */
  420.        if (o.debugging || o.verbose)
  421.      gh_perror("recvfrom in get_rpc_results");
  422.        ss->numqueries_outstanding = 0;
  423.        rsi->rpc_status = RPC_STATUS_NOT_RPC;
  424.        return;
  425.      }
  426.      if (o.debugging > 1)
  427.        printf("Received %d byte UDP packet\n", res);
  428.      /* Now we check that the response is from the expected host/port */
  429.      if (from.sin_addr.s_addr != target->host.s_addr ||
  430.      from.sin_port != htons(rsi->rpc_current_port->portno)) {
  431.        if (o.debugging > 1) {
  432.      printf("Received UDP packet from %d.%d.%d.%d/%hi when expecting packet from %d.%d.%d.%d/%hi\n", NIPQUAD(from.sin_addr.s_addr), ntohs(from.sin_port), NIPQUAD(target->host.s_addr), rsi->rpc_current_port->portno);
  433.        }
  434.        continue;
  435.      }
  436.  
  437.      if (rpc_are_we_done(readbuf, res, target, scan, ss, pil, rsi) != 0) {
  438.        return;
  439.      }
  440.    } else if (tcp_rpc_socket >= 0 && FD_ISSET(tcp_rpc_socket, &fds_r)) {
  441.      do {     
  442.        res = read(tcp_rpc_socket, readbuf + tcp_readlen, sizeof(readbuf) - tcp_readlen);
  443.      } while(res == -1 && errno == EINTR);
  444.      if (res <= 0) {
  445.        if (o.debugging) {
  446.      if (res == -1)
  447.        gh_perror("Failed to read() from tcp rpc socket in get_rpc_results");
  448.      else {
  449.        error("Lamer on port %li closed RPC socket on me in get_rpc_results", rsi->rpc_current_port->portno);
  450.      }
  451.        }
  452.        ss->numqueries_outstanding = 0;
  453.        rsi->rpc_status = RPC_STATUS_NOT_RPC;
  454.        return;
  455.      }
  456.  
  457.      tcp_readlen += res;
  458.  
  459.      if (tcp_readlen < 28) {
  460.        /* This is suspiciously small -- I'm assuming this is not the first
  461.       part of a valid RPC packet */
  462.        if (o.debugging > 1) {
  463.      printf("Port %hi/%s labelled NON_RPC because tcp_readlen is %d (should be at least 28)\n", rsi->rpc_current_port->portno, (rsi->rpc_current_port->proto == IPPROTO_TCP)? "TCP" : "UDP", tcp_readlen);
  464.        }
  465.        ss->numqueries_outstanding = 0;
  466.        rsi->rpc_status = RPC_STATUS_NOT_RPC;
  467.        return;
  468.      }
  469.      /* I'm ignoring the multiple msg fragment possibility for now */
  470.      current_msg_len = ntohl((*(unsigned long *)readbuf)) & 0x7FFFFFFF;
  471.                              
  472.      if (current_msg_len > tcp_readlen - 4) {
  473.        if (o.debugging > 1) {
  474.      printf("Port %hi/%s labelled NON_RPC because current_msg_len is %li while tcp_readlen is %d\n", rsi->rpc_current_port->portno, (rsi->rpc_current_port->proto == IPPROTO_TCP)? "TCP" : "UDP", current_msg_len, tcp_readlen);
  475.        }
  476.        ss->numqueries_outstanding = 0;
  477.        rsi->rpc_status = RPC_STATUS_NOT_RPC;
  478.        return;
  479.      }
  480.      current_msg = readbuf + 4;
  481.  
  482.      do {
  483.        if (rpc_are_we_done(current_msg, current_msg_len, target, scan, ss, 
  484.                pil, rsi) != 0) 
  485.      return;
  486.  
  487.        current_msg += current_msg_len;
  488.        if ((current_msg - readbuf) + 4 < tcp_readlen) {       
  489.      current_msg_len = ntohl(*(unsigned long *) current_msg) & 0x7FFFFFFF;
  490.      current_msg += 4;
  491.        } else {
  492.      if ((current_msg - readbuf) < tcp_readlen) {
  493.        tcp_readlen -= current_msg - readbuf;
  494.        memmove(readbuf, current_msg, tcp_readlen);
  495.      } else tcp_readlen = 0;
  496.      break;       
  497.        }
  498.  
  499.        if (current_msg_len < 24 || current_msg_len > 32) {
  500.      ss->numqueries_outstanding = 0;
  501.      if (o.debugging > 1) {
  502.        printf("Port %hi/%s labelled NON_RPC because current_msg_len is %li\n", rsi->rpc_current_port->portno, (rsi->rpc_current_port->proto == IPPROTO_TCP)? "TCP" : "UDP", current_msg_len);
  503.      }
  504.      rsi->rpc_status = RPC_STATUS_NOT_RPC;
  505.      return;
  506.        }
  507.  
  508.        if ((current_msg - readbuf) + current_msg_len > tcp_readlen) {
  509.      tcp_readlen -= current_msg - readbuf;
  510.      memmove(readbuf +4 , current_msg, tcp_readlen);
  511.      *(unsigned long *)&readbuf = htonl(current_msg_len);
  512.      tcp_readlen += 4;
  513.      break;
  514.        }
  515.      } while(1);
  516.    }
  517.  }
  518.  return;
  519. }
  520.  
  521.  
  522. void close_rpc_query_sockets() {
  523.   if (udp_rpc_socket != -1) {
  524.     close(udp_rpc_socket);
  525.     udp_rpc_socket = -1;
  526.   }
  527.  
  528.   if (tcp_rpc_socket != -1) {
  529.     close(tcp_rpc_socket);
  530.     tcp_rpc_socket = -1;
  531.   }
  532. }
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.