JNIEXPORT void JNICALL
Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_start
    (JNIEnv* env, jclass clazz, jlong ptr)
{
    (void) env;
    (void) clazz;
    (void) ptr;

    do
    {
        HANDLE handle = NULL;

        if (ERROR_IO_PENDING
                != NotifyAddrChange(
                        &handle,
                        &SystemActivityNotifications_overlapped))
            break; // Break in case of an error.

        DWORD numberOfBytesTransferred;

        if (!GetOverlappedResult(
                handle,
                &SystemActivityNotifications_overlapped,
                &numberOfBytesTransferred,
                /* bWait */ TRUE))
            break; // Break in case of an error.

        SystemActivityNotifications_notify(
                net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE);
    }
    while (TRUE);
}
コード例 #2
0
ファイル: cm_daemon.c プロジェクト: snktagarwal/openafs
void cm_IpAddrDaemon(long parm)
{
    extern void smb_CheckVCs(void);
    char * name = "cm_IPAddrDaemon_ShutdownEvent";

    cm_IPAddrDaemon_ShutdownEvent = thrd_CreateEvent(NULL, FALSE, FALSE, name);
    if ( GetLastError() == ERROR_ALREADY_EXISTS )
        afsi_log("Event Object Already Exists: %s", name);

    rx_StartClientThread();

    while (daemon_ShutdownFlag == 0) {
	DWORD Result;
        
        thrd_SetEvent(cm_IPAddrDaemon_ShutdownEvent);
        Result = NotifyAddrChange(NULL,NULL);
        if (Result == NO_ERROR && daemon_ShutdownFlag == 0) {
            lastIPAddrChange = osi_Time();
            smb_SetLanAdapterChangeDetected();
            cm_SetLanAdapterChangeDetected();
            thrd_ResetEvent(cm_IPAddrDaemon_ShutdownEvent);
	}	
    }

    thrd_SetEvent(cm_IPAddrDaemon_ShutdownEvent);
}
コード例 #3
0
NS_IMETHODIMP
nsNotifyAddrListener::Run()
{
    PR_SetCurrentThreadName("Link Monitor");

    HANDLE ev = CreateEvent(nullptr, FALSE, FALSE, nullptr);
    NS_ENSURE_TRUE(ev, NS_ERROR_OUT_OF_MEMORY);

    HANDLE handles[2] = { ev, mShutdownEvent };
    OVERLAPPED overlapped = { 0 };
    bool shuttingDown = false;

    overlapped.hEvent = ev;
    while (!shuttingDown) {
        HANDLE h;
        DWORD ret = NotifyAddrChange(&h, &overlapped);

        if (ret == ERROR_IO_PENDING) {
            ret = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
            if (ret == WAIT_OBJECT_0) {
                CheckLinkStatus();
            } else {
                shuttingDown = true;
            }
        } else {
            shuttingDown = true;
        }
    }
    CloseHandle(ev);

    return NS_OK;
}
コード例 #4
0
ファイル: NicInfo.cpp プロジェクト: rneilturner/xc-windows
void NicInfo::Prime()
{
    DWORD dwRet;

    dwRet = NotifyAddrChange(&hAddrChange, &Overlap);
    if (dwRet != ERROR_IO_PENDING)
    {
        XsLog("NotifyAddrChange failed:  %d", dwRet);
    }
}
コード例 #5
0
ファイル: MonitorIPs.cpp プロジェクト: degiuli/SysStatus
void MonitorIPs::CheckIPAddress()
{
    ULONG ulSize = 0;

    Log(LOG_DEBUG,__LINE__,">> MonIPs.ChkIPAddrs");

    //Get number of bytes required
    if(GetIpAddrTable(NULL,&ulSize,0)==ERROR_INSUFFICIENT_BUFFER)
    {
        //Aloocate required memory
        PMIB_IPADDRTABLE piat = reinterpret_cast<PMIB_IPADDRTABLE>(LocalAlloc(LMEM_FIXED,ulSize));
        if(piat)
        {
            //Retrive the list of IPs
            if(GetIpAddrTable(piat,&ulSize,0)==ERROR_SUCCESS)
            {
                WaitForSingleObject(m_hSync,MINUTE);
                m_ips.clear();

                for(DWORD dwIndex=0;dwIndex<piat->dwNumEntries;dwIndex++)
                {
                    //Trace all IPs
                    string strip;
                    char ip[_MAX_PATH] = {0};

                    PMIB_IPADDRROW prow = &piat->table[dwIndex];
                    _snprintf(ip,sizeof(ip)-1,"Addr %u, Idx %u, Mask %u, BCastAddr %u, ReasmSz %u, Tp %X.",
                                 prow->dwAddr,prow->dwIndex,prow->dwMask,prow->dwBCastAddr,prow->dwReasmSize,prow->wType);
                    strip.assign(ip);
                    if(prow->wType&MIB_IPADDR_PRIMARY)
                        strip.append("Primary.");
                    if(prow->wType&MIB_IPADDR_DYNAMIC)
                        strip.append("Dynamic.");
                    if(prow->wType&MIB_IPADDR_DISCONNECTED)
                        strip.append("Disconnected.");
                    if(prow->wType&MIB_IPADDR_DELETED)
                        strip.append("Deleted.");
                    if(prow->wType&MIB_IPADDR_TRANSIENT)
                        strip.append("Transient.");
                    if(prow->wType&MIB_IPADDR_DNS_ELIGIBLE)
                        strip.append("Published in DNS.");

                    m_ips.push_back(strip);
                }
                ReleaseMutex(m_hSync);
            }
            LocalFree(piat);
        }
    }

    HANDLE h;
    NotifyAddrChange(&h, &m_o);

    Log(LOG_DEBUG,__LINE__,"<< MonIPs.ChkIPAddrs");
}
コード例 #6
0
ファイル: os_socket.c プロジェクト: S73417H/opensplice
static void
os_sockQueryInterfaceStatusReset(
    os_sockQueryInterfaceStatusInfo *info)
{
    HANDLE hand = NULL;
    DWORD ret;

    (void)WSAResetEvent(info->overlap.hEvent);
    (void)CancelIPChangeNotify(&info->overlap);
    ret = NotifyAddrChange(&hand, &info->overlap);
    if (ret != NO_ERROR) {
        if (WSAGetLastError() != WSA_IO_PENDING) {
            os_report(OS_ERROR, "os_sockQueryInterfaceStatusReset", __FILE__, __LINE__, 0,
                          "Failed to reset notifications for network interface address changes");
        }
    }
}
コード例 #7
0
/*
 * Class:     sun_net_dns_ResolverConfgurationImpl
 * Method:    notifyAddrChange0
 * Signature: ()I
 */
JNIEXPORT jint JNICALL
Java_sun_net_dns_ResolverConfigurationImpl_notifyAddrChange0(JNIEnv *env, jclass cls)
{
    OVERLAPPED ol;
    HANDLE h;
    DWORD rc, xfer;

    ol.hEvent = (HANDLE)0;
    rc = NotifyAddrChange(&h, &ol);
    if (rc == ERROR_IO_PENDING) {
        rc = GetOverlappedResult(h, &ol, &xfer, TRUE);
        if (rc != 0) {
            return 0;   /* address changed */
        }
    }

    /* error */
    return -1;
}
コード例 #8
0
ファイル: addrchange.c プロジェクト: aosm/Kerberos
DWORD WINAPI
addr_change_thread(LPVOID dummy) {

    HANDLE h_waits[2];
    HANDLE h_notify;

    OVERLAPPED overlap;
    DWORD ret;

    PDESCTHREAD(L"Address change waiter", L"App");

    ZeroMemory(&overlap, sizeof(overlap));

    h_notify = NULL;
    overlap.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    do {
        ret = NotifyAddrChange(&h_notify, &overlap);

        if (ret != ERROR_IO_PENDING) {
            goto _end_thread;   /* some error */
        }

        h_waits[0] = overlap.hEvent;
        h_waits[1] = evt_terminate;

        ret = WaitForMultipleObjects(2, h_waits, FALSE, INFINITE);

        if ( ret == WAIT_OBJECT_0 ) {
            Sleep(3000);        /* wait for things to settle down */
            kmq_post_message(KMSG_CRED, KMSG_CRED_ADDR_CHANGE, 0, 0);
        } else {
            goto _end_thread;
        }
    } while(TRUE);
    
 _end_thread:
    ExitThread(0);
    return 0;                   /* unreachable */
}
コード例 #9
0
ファイル: FskNetInterface.c プロジェクト: kouis3940/kinomajs
DWORD WINAPI networkInterfaceChangeThreadFunc( LPVOID lpParam )
{
	static OVERLAPPED overlap;
	DWORD ret;

	HANDLE hand = NULL;
	HANDLE watch[2];
	overlap.hEvent = WSACreateEvent();

	while (1) {
		ret = NotifyAddrChange(&hand, &overlap);

		if (ret != NO_ERROR) {
			if (WSAGetLastError() != WSA_IO_PENDING) {
				printf("NotifyAddrChange error...%d\n", WSAGetLastError());
				break;
			}
		}
		watch[0] = overlap.hEvent;
		watch[1] = networkInterfaceChangeQuitEvent;

		ret = WaitForMultipleObjects(2, watch, FALSE, INFINITE);
		if (ret == WAIT_OBJECT_0) {
			PostMessage(networkInterfaceTrackerWindow, gNetworkInterfaceChangedMessage, 0, 0);
//			printf("IP Address table changed..\n");
			Sleep(100);
		}
		else
			break;
	}
	CloseHandle(overlap.hEvent);
	CloseHandle(networkInterfaceChangeQuitEvent);
	DestroyWindow(networkInterfaceTrackerWindow);
	networkInterfaceChangeQuitEvent = NULL;
	networkInterfaceTrackerWindow = NULL;
	networkInterfaceChangeThread = NULL;

	return 0;
}
コード例 #10
0
ファイル: os_socket.c プロジェクト: S73417H/opensplice
void *
os_sockQueryInterfaceStatusInit(
    const char *ifName)
{
    os_sockQueryInterfaceStatusInfo *info = NULL;
    HANDLE hand = NULL;
    DWORD ret;

    info = (os_sockQueryInterfaceStatusInfo *) os_malloc(sizeof(os_sockQueryInterfaceStatusInfo));
    if (info) {
        memset(info, 0, sizeof(os_sockQueryInterfaceStatusInfo));
        info->ifName = os_strdup(ifName);
        if (!info->ifName) {
            os_free(info);
            info = NULL;
            os_report(OS_ERROR, "os_sockQueryInterfaceStatusInit", __FILE__, __LINE__, 0,
                      "Failed to allocate os_sockQueryInterfaceStatusInfo");
        }
    }

    if (info) {
        info->overlap.hEvent = WSACreateEvent();
        ret = NotifyAddrChange(&hand, &info->overlap);
        if (ret != NO_ERROR) {
            if (WSAGetLastError() != WSA_IO_PENDING) {
                os_free(info->ifName);
                os_free(info);
                info = NULL;
                os_report(OS_ERROR, "os_sockQueryInterfaceStatusInit", __FILE__, __LINE__, 0,
                          "Failed to administer for network interface address changes");
            }
        }
    }

    return info;
}
コード例 #11
0
ファイル: adapter.c プロジェクト: oneminot/reactos
/*
 * XXX Figure out the way to bind a specific adapter to a socket.
 */
DWORD WINAPI AdapterDiscoveryThread(LPVOID Context) {
    PMIB_IFTABLE Table = (PMIB_IFTABLE) malloc(sizeof(MIB_IFTABLE));
    DWORD Error, Size = sizeof(MIB_IFTABLE);
    PDHCP_ADAPTER Adapter = NULL;
    HANDLE AdapterStateChangedEvent = (HANDLE)Context;
    struct interface_info *ifi = NULL;
    struct protocol *proto;
    int i, AdapterCount = 0, Broadcast;

    /* FIXME: Kill this thread when the service is stopped */

    do {
       DH_DbgPrint(MID_TRACE,("Getting Adapter List...\n"));

       while( (Error = GetIfTable(Table, &Size, 0 )) ==
               ERROR_INSUFFICIENT_BUFFER ) {
           DH_DbgPrint(MID_TRACE,("Error %d, New Buffer Size: %d\n", Error, Size));
           free( Table );
           Table = (PMIB_IFTABLE) malloc( Size );
       }

       if( Error != NO_ERROR )
       {
           /* HACK: We are waiting until TCP/IP starts */
           Sleep(2000);
           continue;
       }

       DH_DbgPrint(MID_TRACE,("Got Adapter List (%d entries)\n", Table->dwNumEntries));

       for( i = Table->dwNumEntries - 1; i >= 0; i-- ) {
            DH_DbgPrint(MID_TRACE,("Getting adapter %d attributes\n",
                                   Table->table[i].dwIndex));

            ApiLock();

            if ((Adapter = AdapterFindByHardwareAddress(Table->table[i].bPhysAddr, Table->table[i].dwPhysAddrLen)))
            {
                proto = find_protocol_by_adapter(&Adapter->DhclientInfo);

                /* This is an existing adapter */
                if (InterfaceConnected(&Table->table[i])) {
                    /* We're still active so we stay in the list */
                    ifi = &Adapter->DhclientInfo;

                    /* This is a hack because IP helper API sucks */
                    if (IsReconnectHackNeeded(Adapter, &Table->table[i]))
                    {
                        /* This handles a disconnect/reconnect */

                        if (proto)
                            remove_protocol(proto);
                        Adapter->DhclientInfo.client->state = S_INIT;

                        /* These are already invalid since the media state change */
                        Adapter->RouterMib.dwForwardNextHop = 0;
                        Adapter->NteContext = 0;

                        add_protocol(Adapter->DhclientInfo.name,
                                     Adapter->DhclientInfo.rfdesc,
                                     got_one, &Adapter->DhclientInfo);
                        state_init(&Adapter->DhclientInfo);

                        SetEvent(AdapterStateChangedEvent);
                    }

                } else {
                    if (proto)
                        remove_protocol(proto);

                    /* We've lost our link so out we go */
                    RemoveEntryList(&Adapter->ListEntry);
                    free(Adapter);
                }

                ApiUnlock();

                continue;
            }

            ApiUnlock();

            Adapter = (DHCP_ADAPTER*) calloc( sizeof( DHCP_ADAPTER ) + Table->table[i].dwMtu, 1 );

            if( Adapter && Table->table[i].dwType == MIB_IF_TYPE_ETHERNET && InterfaceConnected(&Table->table[i])) {
                memcpy( &Adapter->IfMib, &Table->table[i],
                        sizeof(Adapter->IfMib) );
                Adapter->DhclientInfo.client = &Adapter->DhclientState;
                Adapter->DhclientInfo.rbuf = Adapter->recv_buf;
                Adapter->DhclientInfo.rbuf_max = Table->table[i].dwMtu;
                Adapter->DhclientInfo.rbuf_len =
                    Adapter->DhclientInfo.rbuf_offset = 0;
                memcpy(Adapter->DhclientInfo.hw_address.haddr,
                       Adapter->IfMib.bPhysAddr,
                       Adapter->IfMib.dwPhysAddrLen);
                Adapter->DhclientInfo.hw_address.hlen = Adapter->IfMib.dwPhysAddrLen;

                /* I'm not sure where else to set this, but
                   some DHCP servers won't take a zero.
                   We checked the hardware type earlier in
                   the if statement. */
                Adapter->DhclientInfo.hw_address.htype = HTYPE_ETHER;

                if( DhcpSocket == INVALID_SOCKET ) {
                    DhcpSocket =
                        Adapter->DhclientInfo.rfdesc =
                        Adapter->DhclientInfo.wfdesc =
                        socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );

                    if (DhcpSocket != INVALID_SOCKET) {
						
						/* Allow broadcast on this socket */
						Broadcast = 1;
						setsockopt(DhcpSocket,
								   SOL_SOCKET,
								   SO_BROADCAST,
								   (const char *)&Broadcast,
								   sizeof(Broadcast));
						
                        Adapter->ListenAddr.sin_family = AF_INET;
                        Adapter->ListenAddr.sin_port = htons(LOCAL_PORT);
                        Adapter->BindStatus =
                             (bind( Adapter->DhclientInfo.rfdesc,
                                    (struct sockaddr *)&Adapter->ListenAddr,
                                    sizeof(Adapter->ListenAddr) ) == 0) ?
                             0 : WSAGetLastError();
                    } else {
                        error("socket() failed: %d\n", WSAGetLastError());
                    }
                } else {
                    Adapter->DhclientInfo.rfdesc =
                        Adapter->DhclientInfo.wfdesc = DhcpSocket;
                }

                Adapter->DhclientConfig.timeout = DHCP_PANIC_TIMEOUT;
                Adapter->DhclientConfig.initial_interval = DHCP_DISCOVER_INTERVAL;
                Adapter->DhclientConfig.retry_interval = DHCP_DISCOVER_INTERVAL;
                Adapter->DhclientConfig.select_interval = 1;
                Adapter->DhclientConfig.reboot_timeout = DHCP_REBOOT_TIMEOUT;
                Adapter->DhclientConfig.backoff_cutoff = DHCP_BACKOFF_MAX;
                Adapter->DhclientState.interval =
                    Adapter->DhclientConfig.retry_interval;

                if( PrepareAdapterForService( Adapter ) ) {
                    Adapter->DhclientInfo.next = ifi;
                    ifi = &Adapter->DhclientInfo;

                    read_client_conf(&Adapter->DhclientInfo);

                    if (Adapter->DhclientInfo.client->state == S_INIT)
                    {
                        add_protocol(Adapter->DhclientInfo.name,
                                     Adapter->DhclientInfo.rfdesc,
                                     got_one, &Adapter->DhclientInfo);

                        state_init(&Adapter->DhclientInfo);
                    }

                    ApiLock();
                    InsertTailList( &AdapterList, &Adapter->ListEntry );
                    AdapterCount++;
                    SetEvent(AdapterStateChangedEvent);
                    ApiUnlock();
                } else { free( Adapter ); Adapter = 0; }
            } else { free( Adapter ); Adapter = 0; }

            if( !Adapter )
                DH_DbgPrint(MID_TRACE,("Adapter %d was rejected\n",
                                       Table->table[i].dwIndex));
        }
#if 0
        Error = NotifyAddrChange(NULL, NULL);
        if (Error != NO_ERROR)
            break;
#else
        Sleep(3000);
#endif
    } while (TRUE);

    DbgPrint("DHCPCSVC: Adapter discovery thread is terminating! (Error: %d)\n", Error);

    if( Table ) free( Table );
    return Error;
}
/*
 * Class:     net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
 * Method:    start
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_start
(JNIEnv* jniEnv, jclass clazz, jlong ptr)
{
    /*
        OSVERSIONINFOEX osVersionInfoEx;
        memset( &osVersionInfoEx, 0, sizeof(OSVERSIONINFOEX) );
        osVersionInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
        GetVersionEx((OSVERSIONINFO*) &osVersionInfoEx );

        if( osVersionInfoEx.dwMajorVersion == 5)
        {
    */
    // XP
    while(true)
    {
        HANDLE hand = NULL;
        DWORD ret, bytes;

        hand = NULL;
        ZeroMemory(&overlap, sizeof(overlap));
        overlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
        ret = NotifyAddrChange(&hand, &overlap);

        if(ret != ERROR_IO_PENDING )
        {
            //fprintf(stderr, "NotifyAddrChange returned %d,
            //    expected ERROR_IO_PENDING \n", ret);fflush(stderr);

            // break in case of error.
            break;
        }

        BOOL success = GetOverlappedResult(hand, &overlap, &bytes, TRUE);

        if(!success)
            break;

        notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE);
    }
    /*
        }
        else if( osVersionInfoEx.dwMajorVersion > 5)
        {
            // Vista, 7, ....
            NIpIfaceChange nIpIfaceChange;
            nIpIfaceChange = (NIpIfaceChange)GetProcAddress(
                GetModuleHandle(TEXT("Iphlpapi.dll")),
                "NotifyIpInterfaceChange");

            if(nIpIfaceChange)
            {
                ADDRESS_FAMILY family = AF_UNSPEC;
                HANDLE hNotification;

                nIpIfaceChange(
                    family,
                    (PIPINTERFACE_CHANGE_CALLBACK)InterfaceChangeCallback,
                    NULL,
                    FALSE,
                    &hNotification);
            }
        }
    */
}
コード例 #13
0
ファイル: ipaddrchg.c プロジェクト: maxendpoint/openafs_cvs
void
IpAddrChangeMonitor(void * hWnd)
{
#ifdef USE_OVERLAPPED
    HANDLE Handle = INVALID_HANDLE_VALUE;   /* Do Not Close This Handle */
    OVERLAPPED Ovlap;
#endif /* USE_OVERLAPPED */
    DWORD Result;
    DWORD prevNumOfAddrs = GetNumOfIpAddrs();
    DWORD NumOfAddrs;
    char message[256];

    if ( !hWnd )
        return;

    while ( TRUE ) {
#ifdef USE_OVERLAPPED
        ZeroMemory(&Ovlap, sizeof(OVERLAPPED));

        Result = NotifyAddrChange(&Handle,&Ovlap);
        if (Result != ERROR_IO_PENDING)
        {        
            if ( IsDebuggerPresent() ) {
                sprintf(message, "NotifyAddrChange() failed with error %d \n", Result);
                OutputDebugString(message);
            }
            break;
        }

        if ((Result = WaitForSingleObject(Handle,INFINITE)) != WAIT_OBJECT_0)
        {
            if ( IsDebuggerPresent() ) {
                sprintf(message, "WaitForSingleObject() failed with error %d\n",
                        GetLastError());
                OutputDebugString(message);
            }
            continue;
        }

        if (GetOverlappedResult(Handle, &Ovlap,
                                 &DataTransfered, TRUE) == 0)
        {
            if ( IsDebuggerPresent() ) {
                sprintf(message, "GetOverlapped result failed %d \n",
                        GetLastError());
                OutputDebugString(message);
            }
            break;
        }
#else
        Result = NotifyAddrChange(NULL,NULL);
        if (Result != NO_ERROR)
        {        
            if ( IsDebuggerPresent() ) {
                sprintf(message, "NotifyAddrChange() failed with error %d \n", Result);
                OutputDebugString(message);
            }
            break;
        }
#endif
        
        NumOfAddrs = GetNumOfIpAddrs();

        if ( IsDebuggerPresent() ) {
            sprintf(message,"IPAddrChangeMonitor() NumOfAddrs: now %d was %d\n",
                    NumOfAddrs, prevNumOfAddrs);
            OutputDebugString(message);
        }

        if ( NumOfAddrs != prevNumOfAddrs ) {
            // Give AFS Client Service a chance to notice and die
            // Or for network services to startup
            Sleep(2000);
            // this call should probably be mutex protected
            ObtainTokensFromUserIfNeeded(hWnd);
        }
        prevNumOfAddrs = NumOfAddrs;
    }
}