(void) nsDNSService::gService->mLookups.Remove(&key);
nsDNSService::gService->mLookups.Remove(&key);
nsDNSLookup::InitiateLookup(void){    nsresult rv = NS_OK;	    PRStatus status = PR_SUCCESS;        PRBool numeric = PR_TRUE;    PRBool hex = PR_TRUE;    PRBool colon = PR_FALSE;    for (const char *hostCheck = mHostName; *hostCheck; hostCheck++) {        if (!nsCRT::IsAsciiDigit(*hostCheck) && (*hostCheck != '.') ) {            numeric = PR_FALSE;            if (*hostCheck == ':') {                colon = PR_TRUE;            } else if ((*hostCheck < 'A') && (*hostCheck > 'F') &&                       (*hostCheck < 'a') && (*hostCheck > 'f')) {                hex = PR_FALSE;                break;            }        }    }    if (numeric || (colon && hex)) {        // presume it is numeric and try to converting to an IP-Address        PRNetAddr *netAddr = (PRNetAddr*)nsMemory::Alloc(sizeof(PRNetAddr));            if (!netAddr) return NS_ERROR_OUT_OF_MEMORY;        status = PR_StringToNetAddr(mHostName, netAddr);;        if (PR_SUCCESS == status) {            // slam the IP in and move on.            mHostEntry.bufLen = PR_NETDB_BUF_SIZE;            PRUint32 hostNameLen = nsCRT::strlen(mHostName);            mHostEntry.hostEnt.h_name = (char*)BufAlloc(hostNameLen + 1,                                                        (char**)&mHostEntry.bufPtr,                                                        &mHostEntry.bufLen,                                                        0);            memcpy(mHostEntry.hostEnt.h_name, mHostName, hostNameLen + 1);            mHostEntry.hostEnt.h_aliases = (char**)BufAlloc(1 * sizeof(char*),                                                            (char**)&mHostEntry.bufPtr,                                                            &mHostEntry.bufLen,                                                            sizeof(char **));            mHostEntry.hostEnt.h_aliases[0] = nsnull;            mHostEntry.hostEnt.h_addrtype = PR_AF_INET6;            mHostEntry.hostEnt.h_length = sizeof(PRIPv6Addr);            mHostEntry.hostEnt.h_addr_list = (char**)BufAlloc(2 * sizeof(char*),                                                              (char**)&mHostEntry.bufPtr,                                                              &mHostEntry.bufLen,                                                              sizeof(char **));            mHostEntry.hostEnt.h_addr_list[0] = (char*)BufAlloc(mHostEntry.hostEnt.h_length,                                                                (char**)&mHostEntry.bufPtr,                                                                &mHostEntry.bufLen,                                                                0);            if (PR_NetAddrFamily(netAddr) == PR_AF_INET6) {                memcpy(mHostEntry.hostEnt.h_addr_list[0], &netAddr->ipv6.ip, mHostEntry.hostEnt.h_length);            } else {                PR_ConvertIPv4AddrToIPv6(netAddr->inet.ip,                                         (PRIPv6Addr *)mHostEntry.hostEnt.h_addr_list[0]);            }            mHostEntry.hostEnt.h_addr_list[1] = nsnull;            rv = CompleteLookup(NS_OK);            // XXX remove from hashtable and release - for now            nsStringKey key(mHostName);            (void) nsDNSService::gService->mLookups.Remove(&key);        }        nsMemory::Free(netAddr);        if(PR_SUCCESS == status) // it WAS numeric, we're done.            return rv;    }    // Incoming hostname is not a numeric ip address. Need to do the actual    // dns lookup.#if defined(XP_MAC)    OSErr   err;        err = OTInetStringToAddress(nsDNSService::gService->mServiceRef, (char *)mHostName, (InetHostInfo *)&mInetHostInfo);    if (err != noErr)        rv = NS_ERROR_UNEXPECTED;#endif /* XP_MAC */#ifdef XP_OS2    // temporary SYNC version    status = PR_GetHostByName(mHostName,                               mHostEntry.buffer,                               PR_NETDB_BUF_SIZE,                               &(mHostEntry.hostEnt));    if (PR_SUCCESS != status) rv = NS_ERROR_UNKNOWN_HOST;                 return CompleteLookup(rv);#elif defined(XP_PC)    mMsgID = nsDNSService::gService->AllocMsgID();    if (mMsgID == 0)        return NS_ERROR_UNEXPECTED;    {        nsAutoMonitor mon(nsDNSService::gService->mMonitor);    // protect against lookup completing before WSAAsyncGetHostByName returns, better to refcount lookup        mLookupHandle = WSAAsyncGetHostByName(nsDNSService::gService->mDNSWindow, mMsgID,                                          mHostName, (char *)&mHostEntry.hostEnt, PR_NETDB_BUF_SIZE);        // check for error conditions        if (mLookupHandle == nsnull) {            rv = NS_ERROR_UNEXPECTED;  // or call WSAGetLastError() for details;		    // While we would like to use mLookupHandle to allow for canceling the request in		    // the future, there is a bug with winsock2 on win95 that causes WSAAsyncGetHostByName		    // to always return the same value.  We have worked around this problem by using the		    // msgID to identify which lookup has completed, rather than the handle, however, we		    // still need to identify when this is a problem (by comparing the return values of		    // the first two calls made to WSAAsyncGetHostByName), to avoid using the handle on		    // those systems.  For more info, see bug 23709.        }    }#endif /* XP_PC */#ifdef XP_UNIX    // temporary SYNC version    status = PR_GetIPNodeByName(mHostName,                                 PR_AF_INET6,                                PR_AI_DEFAULT,                                mHostEntry.buffer,                                 PR_NETDB_BUF_SIZE,                                 &(mHostEntry.hostEnt));    if (PR_SUCCESS != status) rv = NS_ERROR_UNKNOWN_HOST;    rv = CompleteLookup(rv);    // XXX remove from hashtable and release - for now    nsStringKey key(mHostName);    (void) nsDNSService::gService->mLookups.Remove(&key);    #endif /* XP_UNIX */    return rv;}