home *** CD-ROM | disk | FTP | other *** search
/ Steganos Hacker Tools / SHT151.iso / programme / scanner / nmapNTsp1 / Win_2000.exe / nmapNT-src / utils.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-06  |  3.4 KB  |  120 lines

  1. #ifndef UTILS_H
  2. #define UTILS_H
  3. #ifdef WIN32
  4. #include <winclude.h>
  5. #else
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <stdarg.h>
  9. #include <string.h>
  10. #include <errno.h>
  11. #include <ctype.h>
  12. #include <sys/types.h>
  13. #include <netinet/in.h>
  14. #include <sys/time.h>
  15. #include <unistd.h>
  16. #include <assert.h>
  17. #include <sys/mman.h>
  18. #include "config.h"
  19. #endif
  20. #if TIME_WITH_SYS_TIME
  21. # include <sys/time.h>
  22. # include <time.h>
  23. #else
  24. # if HAVE_SYS_TIME_H
  25. #  include <sys/time.h>
  26. # else
  27. #  include <time.h>
  28. # endif
  29. #endif
  30.  
  31. #include "error.h"
  32. #include "nmap.h"
  33. #include "global_structures.h"
  34.  
  35. #ifndef MAX
  36. #define MAX(x,y) (((x)>(y))?(x):(y))
  37. #endif
  38. #ifndef MIN
  39. #define MIN(x,y) (((x)<(y))?(x):(y))
  40. #endif
  41. #ifndef ABS
  42. #define ABS(x) (((x) >= 0)?(x):(-x)) 
  43. #endif
  44. #ifndef MOD_DIFF
  45. #define MOD_DIFF(a,b) ((unsigned long) (MIN((unsigned long)(a) - (unsigned long ) (b), (unsigned long )(b) - (unsigned long) (a))))
  46. #endif
  47. #ifndef FALSE
  48. #define FALSE 0
  49. #endif
  50. #ifndef TRUE
  51. #define TRUE 1
  52. #endif
  53.  
  54. #define NIPQUAD(addr) \
  55.         (((addr) >> 0)  & 0xff), \
  56.         (((addr) >> 8)  & 0xff), \
  57.         (((addr) >> 16) & 0xff), \
  58.         (((addr) >> 24) & 0xff)
  59.  
  60. #define MAX_PARSE_ARGS 254 /* +1 for integrity checking + 1 for null term */
  61.  
  62. /* Timeval subtraction in microseconds */
  63. #define TIMEVAL_SUBTRACT(a,b) (((a).tv_sec - (b).tv_sec) * 1000000 + (a).tv_usec - (b).tv_usec)
  64. /* Timeval subtract in milliseconds */
  65. #define TIMEVAL_MSEC_SUBTRACT(a,b) ((((a).tv_sec - (b).tv_sec) * 1000) + ((a).tv_usec - (b).tv_usec) / 1000)
  66. /* Timeval subtract in seconds */
  67. #define TIMEVAL_SEC_SUBTRACT(a,b) ((a).tv_sec - (b).tv_sec + ((a).tv_usec - (b).tv_usec + 500)/1000)
  68.  
  69.  
  70. void *safe_malloc(int size);
  71. #ifndef HAVE_STRCASESTR
  72. char *strcasestr(char *haystack, char *pneedle);
  73. #endif
  74. void hdump(unsigned char *packet, int len);
  75. void lamont_hdump(unsigned char *bp, int length);
  76. int Strncpy(char *dest, const char *src, size_t n);
  77. int get_random_bytes(void *buf, int numbytes);
  78. int get_random_int();
  79. unsigned short get_random_ushort();
  80. unsigned int get_random_uint();
  81. /* Scramble the contents of an array*/
  82. void genfry(unsigned char *arr, int elem_sz, int num_elem);
  83. void shortfry(unsigned short *arr, int num_elem);
  84. /* Like the perl equivialent -- It removes the terminating newline from string
  85.    IF one exists.  It then returns the POSSIBLY MODIFIED string */
  86. char *chomp(char *string);
  87. ssize_t Write(int fd, const void *buf, size_t count);
  88.  
  89. unsigned long gcd_ulong(unsigned long a, unsigned long b);
  90. unsigned int gcd_uint(unsigned int a, unsigned int b);
  91. unsigned long gcd_n_ulong(long nvals, unsigned long *val);
  92. unsigned int gcd_n_uint(int nvals, unsigned int *val);
  93.  
  94. int arg_parse(const char *command, char ***argv);
  95. void arg_parse_free(char **argv);
  96.  
  97. #ifndef HAVE_USLEEP
  98. #ifdef HAVE_NANOSLEEP
  99. void usleep(unsigned long usec);
  100. #endif
  101. #endif
  102.  
  103. #ifndef HAVE_STRERROR
  104. char *strerror(int errnum);
  105. #endif
  106.  
  107.  
  108. /* mmap() an entire file into the address space.  Returns a pointer
  109.    to the beginning of the file.  The mmap'ed length is returned
  110.    inside the length parameter.  If there is a problem, NULL is
  111.    returned, the value of length is undefined, and errno is set to
  112.    something appropriate.  The user is responsible for doing
  113.    an munmap(ptr, length) when finished with it.  openflags should 
  114.    be O_RDONLY or O_RDWR, or O_WRONLY
  115. */
  116. char *mmapfile(char *fname, int *length, int openflags);
  117.  
  118.  
  119. #endif
  120.