home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / nmap254b.zip / nmap_error.c < prev    next >
C/C++ Source or Header  |  2001-03-07  |  4KB  |  103 lines

  1.  
  2. /***********************************************************************/
  3. /* error.c -- Some simple error handling routines.                     */
  4. /*                                                                     */
  5. /***********************************************************************/
  6. /*  The Nmap Security Scanner is (C) 1995-2001 Insecure.Com LLC. This  */
  7. /*  program is free software; you can redistribute it and/or modify    */
  8. /*  it under the terms of the GNU General Public License as published  */
  9. /*  by the Free Software Foundation; Version 2.  This guarantees your  */
  10. /*  right to use, modify, and redistribute this software under certain */
  11. /*  conditions.  If this license is unacceptable to you, we may be     */
  12. /*  willing to sell alternative licenses (contact sales@insecure.com). */
  13. /*                                                                     */
  14. /*  If you received these files with a written license agreement       */
  15. /*  stating terms other than the (GPL) terms above, then that          */
  16. /*  alternative license agreement takes precendence over this comment. */
  17. /*                                                                     */
  18. /*  Source is provided to this software because we believe users have  */
  19. /*  a right to know exactly what a program is going to do before they  */
  20. /*  run it.  This also allows you to audit the software for security   */
  21. /*  holes (none have been found so far).                               */
  22. /*                                                                     */
  23. /*  Source code also allows you to port Nmap to new platforms, fix     */
  24. /*  bugs, and add new features.  You are highly encouraged to send     */
  25. /*  your changes to fyodor@insecure.org for possible incorporation     */
  26. /*  into the main distribution.  By sending these changes to Fyodor or */
  27. /*  one the insecure.org development mailing lists, it is assumed that */
  28. /*  you are offering Fyodor the unlimited, non-exclusive right to      */
  29. /*  reuse, modify, and relicense the code.  This is important because  */
  30. /*  the inability to relicense code has caused devastating problems    */
  31. /*  for other Free Software projects (such as KDE and NASM).  Nmap     */
  32. /*  will always be available Open Source.  If you wish to specify      */
  33. /*  special license conditions of your contributions, just say so      */
  34. /*  when you send them.                                                */
  35. /*                                                                     */
  36. /*  This program is distributed in the hope that it will be useful,    */
  37. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of     */
  38. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  */
  39. /*  General Public License for more details (                          */
  40. /*  http://www.gnu.org/copyleft/gpl.html ).                            */
  41. /*                                                                     */
  42. /***********************************************************************/
  43.  
  44. /* $Id: nmap_error.c,v 1.3 2001/03/07 20:34:56 fyodor Exp $ */
  45.  
  46. #include "nmap_error.h"
  47.  
  48. #ifdef WIN32
  49. #include <windows.h>
  50. #endif /* WIN32 */
  51.  
  52. void fatal(char *fmt, ...) {
  53. va_list  ap;
  54. va_start(ap, fmt);
  55. fflush(stdout);
  56. vfprintf(stderr, fmt, ap);
  57. fprintf(stderr, "\nQUITTING!\n");
  58. va_end(ap);
  59. exit(1);
  60. }
  61.  
  62. void error(char *fmt, ...) {
  63. va_list  ap;
  64. va_start(ap, fmt);
  65. fflush(stdout);
  66. vfprintf(stderr, fmt, ap);
  67. fprintf(stderr, "\n");
  68. va_end(ap);
  69. return;
  70. }
  71.  
  72. void pfatal(char *err, ...) {
  73. #ifdef WIN32
  74.     int lasterror =0;
  75.     char *errstr = NULL;
  76. #endif
  77.     va_list  ap;va_start(ap, err);
  78.     fflush(stdout);
  79.     vfprintf(stderr, err, ap);
  80.     va_end(ap);
  81. #ifdef WIN32
  82.     lasterror = GetLastError();
  83.     FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, lasterror, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
  84.         (LPTSTR) &errstr,  0, NULL);
  85.     fprintf(stderr, ": %s (%d)\n", errstr, lasterror);
  86.     HeapFree(GetProcessHeap(), 0, errstr);
  87. #else
  88.     perror(" ");
  89. #endif /* WIN32 perror() compatability switch */
  90.     fflush(stderr);
  91.     exit(1);
  92. }
  93.  
  94. void gh_perror(char *err, ...) {
  95. va_list  ap;va_start(ap, err);
  96. fflush(stdout);
  97. vfprintf(stderr, err, ap);
  98. va_end(ap);
  99. perror(" ");
  100. fflush(stderr);
  101. return;
  102. }
  103.