Nmap Development mailing list archives
[PATCH] Using atexit() for CloseLibs() under AmigaOS
From: Kris Katterjohn <kjak () ispwest com>
Date: Sun, 05 Mar 2006 12:41:36 -0600
The attached patch registers CloseLibs() with atexit() instead of extern'ing CloseLibs() everywhere and #defining exit() to {CloseLibs();exit()}. It also makes OpenLibs() and CloseLibs() static. I don't have an Amiga I can work with, but I tested it out the best I could. I basically created dummy functions, structs, and #defines and compiled with [Open|Close]Libs() and using atexit(). I put puts("in ..."); in the functions and it seems to work fine. Doing a 'grep -R atexit .' in the nmap directory yields some results, mainly in libpcap, but in other files as well. Since atexit() is apparently in the standard library that comes on Amiga (as it should be since atexit was in C89), I'm not sure why atexit() wasn't used to begin with. Is there a reason? Thanks, Kris Katterjohn
--- nmap-4.01.orig/main.cc 2006-01-19 12:55:29.000000000 -0600 +++ nmap-4.01/main.cc 2006-03-05 11:58:43.000000000 -0600 @@ -117,20 +117,21 @@ struct Library *SocketBase = NULL, *MiamiBase = NULL, *MiamiBPFBase = NULL, *MiamiPCapBase = NULL; static const char ver[] = "$VER:" NMAP_NAME " v"NMAP_VERSION " [Amiga.sf]"; -BOOL OpenLibs(void) { - if(!( MiamiBase = OpenLibrary(MIAMINAME,21))) return FALSE; - if(!( SocketBase = OpenLibrary("bsdsocket.library", 4))) return FALSE; - if(!( MiamiBPFBase = OpenLibrary(MIAMIBPFNAME,3))) return FALSE; - if(!(MiamiPCapBase = OpenLibrary(MIAMIPCAPNAME,5))) return FALSE; -return TRUE; -} - -void CloseLibs(void) { +static void CloseLibs(void) { if ( MiamiPCapBase ) CloseLibrary( MiamiPCapBase ); if ( MiamiBPFBase ) CloseLibrary( MiamiBPFBase ); if ( SocketBase ) CloseLibrary( SocketBase ); if ( MiamiBase ) CloseLibrary( MiamiBase ); } + +static BOOL OpenLibs(void) { + if(!( MiamiBase = OpenLibrary(MIAMINAME,21))) return FALSE; + if(!( SocketBase = OpenLibrary("bsdsocket.library", 4))) return FALSE; + if(!( MiamiBPFBase = OpenLibrary(MIAMIBPFNAME,3))) return FALSE; + if(!(MiamiPCapBase = OpenLibrary(MIAMIPCAPNAME,5))) return FALSE; + atexit(CloseLibs); + return TRUE; +} #endif /* global options */ @@ -401,9 +402,6 @@ int main(int argc, char *argv[], char *e } arg_parse_free(myargv); } -#ifdef __amigaos__ - CloseLibs(); -#endif return 0; } --- nmap-4.01.orig/nmap.cc 2006-02-07 01:15:37.000000000 -0600 +++ nmap-4.01/nmap.cc 2006-03-05 11:56:26.000000000 -0600 @@ -119,10 +119,6 @@ extern char *optarg; extern int optind; extern NmapOps o; /* option structure */ -#ifdef __amigaos__ -extern void CloseLibs(void); -#endif - /* parse the --scanflags argument. It can be a number >=0 or a string consisting of TCP flag names like "URGPSHFIN". Returns -1 if the argument is invalid. */ static int parse_scanflags(char *arg) { int flagval = 0; --- nmap-4.01.orig/nmap_amigaos.h 2005-04-14 20:23:33.000000000 -0500 +++ nmap-4.01/nmap_amigaos.h 2006-03-05 11:56:14.000000000 -0600 @@ -147,7 +147,4 @@ struct addrinfo { struct addrinfo *ai_next; /* next structure in linked list */ }; - -#define exit(x); {CloseLibs();exit(x);} - #endif /* _NMAP_AMIGAOS_H_ */ --- nmap-4.01.orig/nmap_error.cc 2005-07-19 00:07:59.000000000 -0500 +++ nmap-4.01/nmap_error.cc 2006-03-05 11:57:17.000000000 -0600 @@ -104,10 +104,6 @@ #include <windows.h> #endif /* WIN32 */ -#ifdef __amigaos__ -extern void CloseLibs(void); -#endif - void fatal(const char *fmt, ...) { va_list ap; va_start(ap, fmt); --- nmap-4.01.orig/scan_engine.cc 2006-02-07 01:15:37.000000000 -0600 +++ nmap-4.01/scan_engine.cc 2006-03-05 11:57:11.000000000 -0600 @@ -576,10 +576,6 @@ private: }; -#ifdef __amigaos__ -extern void CloseLibs(void); -#endif - bool ultrascan_port_pspec_update(UltraScanInfo *USI, HostScanStats *hss, const probespec *pspec, int newstate); --- nmap-4.01.orig/tcpip.cc 2006-02-07 01:15:37.000000000 -0600 +++ nmap-4.01/tcpip.cc 2006-03-05 11:56:37.000000000 -0600 @@ -133,10 +133,6 @@ extern NmapOps o; -#ifdef __amigaos__ -extern void CloseLibs(void); -#endif - #ifdef WIN32 #include "pcap-int.h"
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev
Current thread:
- [PATCH] Using atexit() for CloseLibs() under AmigaOS Kris Katterjohn (Mar 05)
- Re: [PATCH] Using atexit() for CloseLibs() under AmigaOS Fyodor (Mar 05)