home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / nmap254b.zip / portlist.h < prev    next >
C/C++ Source or Header  |  2001-08-10  |  6KB  |  136 lines

  1.  
  2. /***********************************************************************/
  3. /* portlist.c -- Functions for manipulating various lists of ports     */
  4. /* maintained internally by Nmap.                                      */
  5. /*                                                                     */
  6. /***********************************************************************/
  7. /*  The Nmap Security Scanner is (C) 1995-2001 Insecure.Com LLC. This  */
  8. /*  program is free software; you can redistribute it and/or modify    */
  9. /*  it under the terms of the GNU General Public License as published  */
  10. /*  by the Free Software Foundation; Version 2.  This guarantees your  */
  11. /*  right to use, modify, and redistribute this software under certain */
  12. /*  conditions.  If this license is unacceptable to you, we may be     */
  13. /*  willing to sell alternative licenses (contact sales@insecure.com). */
  14. /*                                                                     */
  15. /*  If you received these files with a written license agreement       */
  16. /*  stating terms other than the (GPL) terms above, then that          */
  17. /*  alternative license agreement takes precendence over this comment. */
  18. /*                                                                     */
  19. /*  Source is provided to this software because we believe users have  */
  20. /*  a right to know exactly what a program is going to do before they  */
  21. /*  run it.  This also allows you to audit the software for security   */
  22. /*  holes (none have been found so far).                               */
  23. /*                                                                     */
  24. /*  Source code also allows you to port Nmap to new platforms, fix     */
  25. /*  bugs, and add new features.  You are highly encouraged to send     */
  26. /*  your changes to fyodor@insecure.org for possible incorporation     */
  27. /*  into the main distribution.  By sending these changes to Fyodor or */
  28. /*  one the insecure.org development mailing lists, it is assumed that */
  29. /*  you are offering Fyodor the unlimited, non-exclusive right to      */
  30. /*  reuse, modify, and relicense the code.  This is important because  */
  31. /*  the inability to relicense code has caused devastating problems    */
  32. /*  for other Free Software projects (such as KDE and NASM).  Nmap     */
  33. /*  will always be available Open Source.  If you wish to specify      */
  34. /*  special license conditions of your contributions, just say so      */
  35. /*  when you send them.                                                */
  36. /*                                                                     */
  37. /*  This program is distributed in the hope that it will be useful,    */
  38. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of     */
  39. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  */
  40. /*  General Public License for more details (                          */
  41. /*  http://www.gnu.org/copyleft/gpl.html ).                            */
  42. /*                                                                     */
  43. /***********************************************************************/
  44.  
  45. /* $Id: portlist.h,v 1.7 2001/08/10 05:53:08 fyodor Exp $ */
  46.  
  47. #ifndef PORTLIST_H
  48. #define PORTLIST_H
  49.  
  50. #include <nbase.h>
  51.  
  52. /* struct port stuff */
  53. #define PORT_UNKNOWN 0
  54. #define PORT_CLOSED 1
  55. #define PORT_OPEN 2
  56. #define PORT_FIREWALLED 3
  57. #define PORT_TESTING 4
  58. #define PORT_FRESH 5
  59. #define PORT_UNFIREWALLED 6
  60. #define PORT_HIGHEST_STATE 7 /* ***IMPORTANT -- BUMP THIS UP WHEN STATES ARE 
  61.                 ADDED *** */
  62.  
  63. #define CONF_NONE 0
  64. #define CONF_LOW 1
  65. #define CONF_HIGH 2
  66.  
  67.  
  68. struct port {
  69.   u16 portno;
  70.   u8 proto;
  71.   char *owner;
  72.   int rpc_status; /* RPC_STATUS_UNTESTED means we haven't checked
  73.             RPC_STATUS_UNKNOWN means the port appears to be RPC
  74.             but we couldn't find a match
  75.             RPC_STATUS_GOOD_PROG means rpc_program gives the prog #
  76.             RPC_STATUS_NOT_RPC means the port doesn't appear to 
  77.             be RPC */
  78.   unsigned long rpc_program; /* Only valid if rpc_state == RPC_STATUS_GOOD_PROG */
  79.   unsigned int rpc_lowver;
  80.   unsigned int rpc_highver;
  81.   int state; 
  82.   int confidence; /* How sure are we about the state? */
  83.  
  84.   struct port *next; /* Internal use only -- we sometimes like to link them
  85.             together */
  86. };
  87.  
  88.  
  89.  
  90. typedef struct portlist {
  91.   struct port **udp_ports;
  92.   struct port **tcp_ports;
  93.   struct port **ip_prots;
  94.   int state_counts[PORT_HIGHEST_STATE]; /* How many ports in list are in each
  95.                        state */
  96.   int state_counts_udp[PORT_HIGHEST_STATE];
  97.   int state_counts_tcp[PORT_HIGHEST_STATE];
  98.   int state_counts_ip[PORT_HIGHEST_STATE];
  99.   int ignored_port_state; /* The state of the port we ignore for output */
  100.   int numports; /* Total number of ports in list in ANY state */
  101. } portlist;
  102.  
  103. int addport(portlist *plist, u16 portno, u8 protocol, char *owner, int state);
  104. int deleteport(portlist *plist, u16 portno, u8 protocol);
  105.  
  106. /* A function for iterating through the ports.  Give NULL for the
  107.    first "afterthisport".  Then supply the most recent returned port
  108.    for each subsequent call.  When no more matching ports remain, NULL
  109.    will be returned.  To restrict returned ports to just one protocol,
  110.    specify IPPROTO_TCP or IPPROTO_UDP for allowed_protocol.  A 0 for
  111.    allowed_protocol matches either.  allowed_state works in the same
  112.    fashion as allowed_protocol. This function returns ports in numeric
  113.    order from lowest to highest, except that if you ask for both TCP &
  114.    UDP, every TCP port will be returned before we start returning UDP
  115.    ports */
  116. struct port *nextport(portlist *plist, struct port *afterthisport, 
  117.               u8 allowed_protocol, int allowed_state);
  118.  
  119. struct port *lookupport(portlist *ports, u16 portno, u8 protocol);
  120.  
  121. /* Decide which port we want to ignore in output (for example, we don't want
  122.  to show closed ports if there are 40,000 of them.) */
  123. void assignignoredportstate(portlist *plist);
  124.  
  125. /* RECYCLES the port so that it can later be obtained again using 
  126.    make_empty_port */
  127. void free_port(struct port *pt);
  128.  
  129. struct port *make_empty_port();
  130.  
  131. /* Empties out a portlist so that it can be reused (or freed).  All the 
  132.    internal structures that must be freed are done so here. */
  133. void resetportlist(portlist *plist);
  134.  
  135. #endif
  136.