// testADC() void testADC(int value) { int tmp; if ((regA ^ value) & N_FLAG) { CLV(); } else { setOverflow(); } if (decimalMode()) { tmp = (regA & 0xf) + (value & 0xf) + carrySet(); if (tmp >= 10) { tmp = 0x10 | ((tmp + 6) & 0xf); } tmp += (regA & 0xf0) + (value & 0xf0); if (tmp >= 160) { SEC(); if (overflowSet() && tmp >= 0x180) { CLV(); } tmp += 0x60; } else { CLC(); if (overflowSet() && tmp < 0x80) { CLV(); } } } else { tmp = regA + value + carrySet(); if (tmp >= 2*N_FLAG) { SEC(); if (overflowSet() && tmp >= 3*N_FLAG) { CLV(); } } else { CLC(); if (overflowSet() && tmp < N_FLAG) { CLV(); } } } regA = tmp & UMASK; setNVflagsForRegA(); }
static int SetBaudSender( void ) { int data; /* storing sync string data to other machine */ int i; /* loop index */ int wait_time; if( !SenderHandshake() ) return( FAIL ); /* sync byte received ... send string */ StartBlockTrans(); for( i = data = 0; i < SYNC_LEN; i++, data = (data + SYNC_INC) & 0xff ) { SendByte( data ); /* send sync string bytes */ } StopBlockTrans(); wait_time = WaitCount() + SYNC_TIME_OUT; /* limit for time out */ /* If MaxBaud == MIN_BAUD, we're talking over a modem and it might have buffered characters that haven't been transmitted yet. */ if( MaxBaud == MIN_BAUD ) wait_time += SEC(2); for( ;; ) { if( WaitByte( 1 ) == SDATA_TAK ) { SendByte( SDATA_ACK ); if( WaitByte( SEC(1)/2 ) == SDATA_TAK ) { return( SUCCESS ); } else { return( FAIL ); } } else if( WaitCount() >= wait_time ) { /* break not found; other end have not acknowledged string */ return( FAIL ); } } }
void CDPLoginClient::OnPreJoin( CAr & ar ) { CNetwork::GetInstance().OnEvent( LOGIN_ACK_PREJOIN ); // ata2k - (1)시간 해제 g_Neuz.m_dwTimeOutDis = 0xffffffff; // Open world here. #ifdef __RT_1025 g_DPlay.SendJoin( (BYTE)m_nSlot, g_Neuz.m_adwWorldID[m_nSlot], g_Neuz.m_apPlayer[m_nSlot], &g_Neuz.m_aRTMessenger[m_nSlot], g_Neuz.m_uIdofMulti ); #else // __RT_1025 g_DPlay.SendJoin( (BYTE)m_nSlot, g_Neuz.m_adwWorldID[m_nSlot], g_Neuz.m_apPlayer[m_nSlot], &g_Neuz.m_Messenger[m_nSlot], g_Neuz.m_uIdofMulti ); #endif // __RT_1025 // ata2k - (2)시간 저장 #ifdef __NO_SUB_LANG if(::GetLanguage() == LANG_USA ) #else // __NO_SUB_LANG if( ::GetLanguage() == LANG_USA && ::GetSubLanguage() == LANG_SUB_USA ) #endif // __NO_SUB_LANG g_Neuz.m_dwTimeOutDis = GetTickCount() + SEC( 50 ); else g_Neuz.m_dwTimeOutDis = GetTickCount() + SEC( 25 ); }
void CAccountTimeLimitDBCtrl::Handler( LPDB_OVERLAPPED_PLUS pov, DWORD dwCompletionKey ) { CAr ar( pov->lpBuf, pov->uBufSize ); switch( pov->nQueryMode ) { case QUERY_TIMELIMIT_LOAD: { DWORD dwPlayerId; int nPlayTime = -1; char szAccount[MAX_ACCOUNT]; ar >> dwPlayerId; ar.ReadString( szAccount, MAX_ACCOUNT ); CQuery* pQuery = GetQueryObject(); if( pQuery->Execute( "USP_AccountPlay_Select '%s'", szAccount ) ) { if( pQuery->Fetch() ) { nPlayTime = pQuery->GetInt( "PlayTime" ) * SEC( 1 ); // 초단위를 ms단위로 변환 DWORD dwLastPlayDate = static_cast<DWORD>( pQuery->GetInt( "PlayDate" ) ); int nYear = dwLastPlayDate/10000; dwLastPlayDate%=10000; int nMonth = dwLastPlayDate/100; dwLastPlayDate%=100; int nDay = dwLastPlayDate; CTime time( nYear, nMonth, nDay+1, 0, 0, 0 ); // 하루를 더한 값이 더 작으면 초기화.. if( time < CTime::GetCurrentTime() ) nPlayTime = 0; if( !prj.m_EventLua.IsTimeLimit() ) // 루아이벤트 스크립트에 베트남 제한 여부 설정 nPlayTime = 0; } } if( nPlayTime < 0 ) Error( "PlayTime is wrong - PlayerId : %d, PlayTime : %d", dwPlayerId, nPlayTime ); CDPTrans::GetInstance()->SendTimeLimitAck( dwPlayerId, nPlayTime, dwCompletionKey ); } break; case QUERY_TIMELIMIT_UPDATE: { char szAccount[MAX_ACCOUNT]; int nPlayTime; ar.ReadString( szAccount, MAX_ACCOUNT ); ar >> nPlayTime; nPlayTime /= SEC( 1 ); // ms 단위를 초단위로 변환 CTime time = CTime::GetCurrentTime(); DWORD dwLastDate = (time.GetYear()*10000) + (time.GetMonth()*100) + time.GetDay(); GetQueryObject()->Execute( "USP_AccountPlay_Update '%s', %d, %d", szAccount, dwLastDate, nPlayTime ); } break; } }
int calculatesunlongitude30(int year, int degreeGMToffset, int *ichinesemonths) { int m, d, h; double dec; double curL, prevL; int *pichinesemonths, *monthdays, *cumdays, i; int firstmonth330 = -1; cumdays = cumdaytab[isleap(year)]; monthdays = mondaytab[isleap(year)]; pichinesemonths = ichinesemonths; h = 0; sunpos(year - 1, 12, 31, -24 * (degreeGMToffset / 360.0), HOUR(h), MIN(h), SEC(h), 0.0, 0.0, &prevL, &dec); for (m = 1; m <= 12; m++) { for (d = 1; d <= monthdays[m]; d++) { for (h = 0; h < 4 * HOURSPERDAY; h++) { sunpos(year, m, d, -24 * (degreeGMToffset / 360.0), HOUR(h), MIN(h), SEC(h), 0.0, 0.0, &curL, &dec); if (curL < 180 && prevL > 180) { *pichinesemonths = cumdays[m] + d; #ifdef DEBUG printf("%04d-%02d-%02d %02d:%02d - %d %g\n", year, m, d, HOUR(h), MIN(h), *pichinesemonths, curL); #endif pichinesemonths++; } else { for (i = 0; i <= 360; i += 30) if (curL > i && prevL < i) { *pichinesemonths = cumdays[m] + d; #ifdef DEBUG printf("%04d-%02d-%02d %02d:%02d - %d %g\n", year, m, d, HOUR(h), MIN(h), *pichinesemonths, curL); #endif if (i == 330) firstmonth330 = *pichinesemonths; pichinesemonths++; } } prevL = curL; } } } *pichinesemonths = -1; return (firstmonth330); }
bool RemoteConnect( void ) { int baud_limit; /* maximum baud that BOTH sides can achieve */ byte dummy; /* hold values that we don't need here */ byte MaxBaud2; /* MaxBaud at the other machine */ SendBlkNo = ReceiveBlkNo = 0; LastResponse = SDATA_NAK; if( !SetSyncTime() ) return( FALSE ); /* establish baud limit */ #ifdef SERVER if( !WaitReceive( &dummy, 1, &MaxBaud2, SEC( 2 ) ) ) { return( FALSE ); } if( !BlockSend( 1, (byte *)&MaxBaud, SEC( 2 ) ) ) { return( FALSE ); } #else if( !BlockSend( 1, (byte *)&MaxBaud, SEC( 2 ) ) ) { return( FALSE ); } if( !WaitReceive( &dummy, 1, &MaxBaud2, SEC( 2 ) ) ) { return( FALSE ); } #endif /* MaxBaud2 now contains the other side's baud rate limit */ if( MaxBaud > MaxBaud2 ) { baud_limit = MaxBaud; } else { baud_limit = MaxBaud2; } BaudCounter = baud_limit; if( !Speed() ) return( FALSE ); #ifdef SERVER { char buff[128]; if( BaudCounter == MIN_BAUD ) { strcpy( buff, "pre-set" ); } else { strcpy( buff, BaudTable[BaudCounter].name ); } strcat( buff, " baud" ); ServMessage( buff ); } #endif return( TRUE ); }
void CProfileInfo::SetProfileInfo() { CProfileIterator* it = CProfileManager::Get_Iterator(); float fTotal = 0.0f; while( !it->Is_Done() ) { fTotal += it->Get_Current_Total_Time(); it->Next(); } it->First(); Clear(); m_vecstrProfileInfo.push_back( "Root" ); char szTab[64], szTemp[4096]; while( !it->Is_Done() ) { memset( szTab, 0, sizeof(szTab) ); for( DWORD i=0; i<it->GetPreOrderDepth(); i++ ) strcat( szTab, PROFILE_TAB_STR ); sprintf( szTemp, "%s---> %.2f%% %s, <%.3f ms>, <%d calls>, <%f ms/call>", szTab, (it->Get_Current_Total_Time() / fTotal) * 100, it->Get_Current_Name(), it->Get_Current_Total_Time() * 1000, it->Get_Current_Total_Calls(), (it->Get_Current_Total_Time() * 1000) / (it->Get_Current_Total_Calls() ? it->Get_Current_Total_Calls() : 1)); m_vecstrProfileInfo.push_back( szTemp ); it->NextPreOrder(); } CProfileManager::Release_Iterator( it ); Reset(); if( fTotal * 1000 > SEC( 1 ) ) // 1초이상 지연되면 로그 남김 FileOut( "..\\profile.txt" ); }
static int CheckSyncString( void ) { int syn_c; /* correct sync string bytes value */ int i; /* loop index */ unsigned wait; if( CheckPendingError() ) return( FAIL ); wait = (MaxBaud == MIN_BAUD) ? SEC(2) : (SEC(1)/4); for( syn_c = i = 0; i < SYNC_LEN; ++i, syn_c = (syn_c + SYNC_INC) & 0xff ) { if( WaitByte( wait ) != syn_c ) { /* error -- timeout or incorrect data */ return( FAIL ); } wait = SEC(1)/4; } return( SUCCESS ); }
//--------------------------------------------------------------------------- void CShowTVNumber(BYTE ucNumber, BYTE ucOption) { BYTE PosX = 0; bChangeChannel = 0; COsdFxDisableOsd(); g_ucPageIndex = _P_MENU_NONE; g_ucMenuItemIndex = _MENU_NONE; SetOSDDouble(0x03); SetOsdMap(tUserMenuOsdMap); // Init OSD Ram OSDClear(0, GET_OSD_MAP_ROWCOUNT(), 0, 30, 0x8C, BYTE_ATTRIB); OSDClear(0, GET_OSD_MAP_ROWCOUNT(), 0, 30, 0x00, BYTE_DISPLAY); OSDLine(0, 0, 30, 0x40, BYTE_COLOR); OSDClear(1, GET_OSD_MAP_ROWCOUNT() - 1, 0, 30, 0x60, BYTE_COLOR); COsdFxCodeWrite(ucCloseAllWindow); OSDPosition(_MAINMENU_WIDTH * 12,_MAINMENU_HEIGHT * 18,50,1,0x03); // OSDPosition(10 * 12, 3 * 18, 90, 4, 0x03); if (ucOption & _SHOW_CH_TV_NUMBER) CShowNumber(0, 0, ucNumber); if (_SHOW_CH_TV_TYPE & ucOption) CTextOutEx(sTVType[ucTVType], 0, 1); COsdFxEnableOsd(); CTimerReactiveTimerEvent(SEC(5), COsdDispOsdTimerEvent); bOSDTimeOut = 0; #if(_SLEEP_FUNC) bOSDOnScreen = 1; #endif }
CDPLoginClient::CDPLoginClient() { m_timer.Set( SEC( 10 ) ); m_fConn = FALSE; m_nSlot = -1; m_bShowDisconnectMsg = TRUE; m_lError = 0; #if __VER >= 15 // __2ND_PASSWORD_SYSTEM m_idNumberPad = 0; #endif // __2ND_PASSWORD_SYSTEM BEGIN_MSG; ON_MSG( PACKETTYPE_ERROR, OnError ); ON_MSG( PACKETTYPE_PLAYER_LIST, OnPlayerList ); ON_MSG( PACKETTYPE_CACHE_ADDR, OnCacheAddr ); ON_MSG( PACKETTYPE_QUERYTICKCOUNT, OnQueryTickCount ); ON_MSG( PACKETTYPE_PRE_JOIN, OnPreJoin ); ON_MSG( PACKETTYPE_ONE_HOUR_NOTIFY, OnOneHourNotify ); ON_MSG( PACKETTYPE_PING, OnPing ); ON_MSG( PACKETTYPE_AUTHQUERY, OnAuthQuery ); #if __VER >= 15 // __2ND_PASSWORD_SYSTEM ON_MSG( PACKETTYPE_LOGIN_PROTECT_NUMPAD, OnLoginNumPad ); ON_MSG( PACKETTYPE_LOGIN_PROTECT_CERT, OnLoginProtect ); #endif // __2ND_PASSWORD_SYSTEM }
CNpcProperty::CNpcProperty() { m_dwTick = ::GetTickCount() + MIN( 1 ) + xRandom( SEC( 30 ) ); #if defined(__REMOVE_SCIRPT_060712) m_szName[0] = '\0'; #endif }
void CWndDialog::RunScript( const char* szKey, DWORD dwParam, DWORD dwQuest ) { CMover* pMover = prj.GetMover( m_idMover ); if( pMover ) g_DPlay.SendScriptDialogReq( pMover->GetId(), szKey, dwParam, dwQuest, pMover->GetId(), g_pPlayer->GetId() ); m_timer.Set( SEC( 1 ) ); }
//----------------------------------------------------------------------------- BOOL CWndMailRequestingBox::OnChildNotify( UINT message, UINT nID, LRESULT* pLResult ) { switch( nID ) { case WIDC_BUTTON_REQUEST: { ++m_nDestroyCounter; CWndButton* pWndButton = ( CWndButton* )GetDlgItem( WIDC_BUTTON_REQUEST ); if( pWndButton == NULL ) { break; } if( pWndButton->IsWindowEnabled() == FALSE ) { break; } g_DPlay.SendQueryMailBox(); m_timeWaitingRequest = g_tmCurrent + SEC( REQUEST_BUTTON_WAITING_TIME ); pWndButton->EnableWindow( FALSE ); break; } } return CWndNeuz::OnChildNotify( message, nID, pLResult ); }
void CUserMng::ClearDum( CDPMng* pdp ) { BEFORESEND( ar, PACKETTYPE_KEEP_ALIVE ); CUser* pUsertmp; DWORD dwTick = GetTickCount() - SEC( 10 ); CMclAutoLock Lock( m_AddRemoveLock ); for( map<DPID, CUser*>::iterator i = begin(); i != end(); ++i ) { pUsertmp = i->second; if( pUsertmp->m_dwTick < dwTick ) { pdp->DestroyPlayer( pUsertmp->m_dpid ); } else if( pUsertmp->m_bValid == FALSE ) { pUsertmp->m_bValid = TRUE; pdp->DestroyPlayer( pUsertmp->m_dpid ); } else { pUsertmp->m_bValid = FALSE; SEND( ar, pdp, pUsertmp->m_dpid ); } } }
const char *timestr(int t) { static char s[80]; if (DAY(t) > 0) (void) sprintf(s, "%dd+%02dhrs", DAY(t), HOUR(t)); else if (HOUR(t) > 0) (void) sprintf(s, "%d:%02d:%02d", HOUR(t), MIN(t), SEC(t)); else if (MIN(t) > 0) (void) sprintf(s, "%d:%02d", MIN(t), SEC(t)); else if (SEC(t) > 0) (void) sprintf(s, ":%02d", SEC(t)); else *s = '\0'; return s; }
// doCompare() - Do a comparison void doCompare(int reg,int val ) { if (reg >= val) {SEC();} else {CLC();} val = (reg - val); setNVflags(val); }
// 2006.03 MSG_VER를 보내는 부분이 5차 국내에는 없음 void CDPCertified::SendCertify() { if( ::GetLanguage() == LANG_ENG && ::GetSubLanguage() == LANG_SUB_USA ) g_Neuz.m_dwTimeOutDis = GetTickCount() + SEC( 40 ); else g_Neuz.m_dwTimeOutDis = GetTickCount() + SEC( 20 ); BEFORESEND( ar, PACKETTYPE_CERTIFY ); ar.WriteString( ::GetProtocolVersion() ); // MSG_VER #ifdef __SECURITY_0628 ar.WriteString( CResFile::m_szResVer ); #endif // __SECURITY_0628 ar.WriteString( g_Neuz.m_szAccount ); ////////////////////////////////////////////////////////////////////////// // mulcom BEGIN100218 패스워드 암호화 #ifdef __ENCRYPT_PASSWORD char szPlain[ 16 * MAX_PASSWORD ] = {0, }; char szEnc[ 16 * MAX_PASSWORD ] = {0, }; ::memcpy( szPlain, g_Neuz.m_szPassword, sizeof(g_Neuz.m_szPassword) ); g_xRijndael->ResetChain(); g_xRijndael->Encrypt( szPlain, szEnc, 16 * MAX_PASSWORD, CRijndael::CBC ); ar.Write( szEnc, 16 * MAX_PASSWORD ); #else ar.WriteString( g_Neuz.m_szPassword ); #endif // mulcom END100218 패스워드 암호화 #ifdef __TWN_LOGIN0816 if( GetLanguage() == LANG_TWN ) { ar.WriteString( g_Neuz.m_szSessionPwd ); // char lpOutputString[256] = { 0,}; // sprintf( lpOutputString, "account = %s, pwd = %s, session = %s", g_Neuz.m_szAccount, g_Neuz.m_szPassword, g_Neuz.m_szSessionPwd ); // OutputDebugString( lpOutputString ); } #endif // __TWN_LOGIN0816 SEND( ar, this, DPID_SERVERPLAYER ); }
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hMainWnd = hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) return FALSE; SetTimer( hMainWnd, 3, SEC( 60 ), NULL ); // 10(s) int x = 480, y = 606; SetWindowPos( hWnd, NULL, x, y, 400, 416, SWP_SHOWWINDOW ); g_MyTrace.Initialize( hWnd, "SquireD", RGB( 0x00, 0x00, 0x00 ), RGB( 0xff, 0xff, 0xff ) ); CTime time = CTime::GetCurrentTime(); g_MyTrace.Add( 0, FALSE, "%s", time.Format( "%Y/%m/%d %H:%M:%S" ) ); g_MyTrace.AddLine( '\0' ); #ifndef _DEBUG // InitEH(); #endif // _DEBUG if( !Script( "CacheServer.ini" ) ) return FALSE; if( InitializeNetLib() == FALSE ) return FALSE; if( !g_DPCoreClient.ConnectToServer( g_szCoreAddr, PN_CORESRVR + 1 ) ) return FALSE; #ifdef __CRC if( !g_DPCacheSrvr.StartServer( g_uPort, FALSE, CSock::crcRead ) ) #else // __CRC if( !g_DPCacheSrvr.StartServer( g_uPort ) ) #endif // __CRC return FALSE; g_MyTrace.AddLine( '-' ); char lpszIpAddr[16]; g_DPCoreClient.GetPlayerAddr( DPID_SERVERPLAYER, lpszIpAddr ); g_MyTrace.Add( CMyTrace::Key( "main" ), FALSE, "%s", lpszIpAddr ); g_MyTrace.AddLine( '-' ); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; }
void Create_Attacker_List(char *router_ip, char *attacker_ip, char * victim_ip) { struct attacker_list *p; struct router_list *p_routerlist, *new_routerlist; if(routerAttackerHead == NULL) { routerAttackerHead = create_attackerlist_node(router_ip, attacker_ip, victim_ip); } else { p = routerAttackerHead; while(p != NULL) { if(strncmp(p->attacker_ip_addr, attacker_ip, MAXIPADDRLEN) == 0) { p_routerlist = p->routerhead; while(p_routerlist != NULL) { if(strncmp(p_routerlist->router_ip, router_ip, MAXIPADDRLEN) == 0) { p_routerlist->frequency++; goto end; } p_routerlist = p_routerlist->next; } if(p_routerlist == NULL) { new_routerlist = (struct router_list *)malloc(sizeof(struct router_list)); memset(new_routerlist, '\0', sizeof(struct router_list)); strncpy(new_routerlist->router_ip, router_ip, strlen(router_ip)); new_routerlist->frequency = 1; new_routerlist->next = p->routerhead; p->routerhead = new_routerlist; p->no_of_routers++; struct timeval curtime; gettimeofday(&curtime, NULL); LOG(fp_log, LOGL, "%f %s distance", SEC(TIME_IN_USEC(curtime)), router_ip); goto end; } } p = p->next; } end: if(p == NULL) { p = create_attackerlist_node(router_ip, attacker_ip, victim_ip); p->next = routerAttackerHead; routerAttackerHead = p; } } }
// testSBC() void testSBC(int value ) { int tmp,w; if ((regA ^ value) & N_FLAG) {setOverflow();} else {CLV();} if (decimalMode()) { tmp = 0xf + (regA & 0xf) - (value & 0xf) + carrySet(); if (tmp < 0x10) { w = 0; tmp -= 6; } else { w = 0x10; tmp -= 0x10; } w += 0xf0 + (regA & 0xf0) - (value & 0xf0); if (w < 0x100) { CLC(); if (overflowSet() && w < 0x80) { CLV(); } w -= 0x60; } else { SEC(); if (overflowSet() && w >= 0x180) { CLV(); } } w += tmp; } else { w = UMASK + regA - value + carrySet(); if (w < 1+UMASK) { CLC(); if (overflowSet() && w < N_FLAG) { CLV(); } } else { SEC(); if (overflowSet() && w >= (3*N_FLAG)) { CLV(); } } } regA = w & UMASK; setNVflagsForRegA(); }
static int SetBaudReceiver( void ) { unsigned wait; if( !ReceiverHandshake() ) return( FAIL ); /* sync string should have been received; and in receive buffer now CheckSyncString() checks if sync string is received successfully */ if( CheckSyncString() ) { SendByte( SDATA_TAK ); wait = (MaxBaud == MIN_BAUD) ? SEC(2) : SEC(1)/2; if( WaitByte( wait ) == SDATA_ACK ) { SendByte( SDATA_TAK ); return( SUCCESS ); } else { return( FAIL ); } } else { return( FAIL ); } }
bool MarchToTheSameDrummer( void ) { int got; #ifdef SERVER SendByte( SDATA_LOK ); #else if( ( got = WaitByte( SEC( 2 ) ) ) != SDATA_LOK ) { return( FAIL ); } #endif #ifndef SERVER SendByte( SDATA_ACK ); #else if( ( got = WaitByte( SEC(1)/2 ) ) != SDATA_ACK ) { return( FAIL ); } #endif Wait( 1 ); /* don't go till the timer hits exactly on the tick */ ZeroWaitCount(); return( SUCCESS ); }
bool SetSyncTime( void ) { if( MaxBaud != MIN_BAUD ) { if( !Baud( LOW_BAUD ) ) return( FAIL ); } #ifdef SERVER if( WaitByte( SEC(1)/10 ) != SDATA_HI ) { return( FAIL ); } #else SendByte( SDATA_HI ); #endif return( MarchToTheSameDrummer() ); }
void CDbControllerTimer::Tick( void ) { while( WaitForSingleObject( m_hCloseTick, SEC( 1 ) ) != WAIT_OBJECT_0 ) { DWORD dwTick = GetTickCount(); CMclAutoLock Lock( m_csLock ); for( VPDD::iterator i = m_vDbController.begin(); i != m_vDbController.end(); i++ ) { if( dwTick > ( *i ).second ) { ( *i ).first->PostRequest( CDbController::eTimer, NULL, 0, 0 ); ( *i ).second += ( *i ).first->GetTimer(); } } } }
trap_retval RemotePut( byte *send, trap_elen len ) { unsigned timeout; /* time limit for getting the data */ int result; /* result of BlockSend() operation */ timeout = SEC( 10 ); /* Sending data block */ result = BlockSend( len, send, timeout ); if( !result ) return( REQUEST_FAILED ); /* ReSync if necessary */ if( PrevErrors > MAX_ERRORS ) { ReSync(); } return( len ); }
void send_start_marking_msg(char *router_ip, int tcpport) { int fd; struct sockaddr_in router_addr; struct hostent *router_ip_addr; struct in_addr * address; struct timeval curtime; socklen_t alen = sizeof(struct sockaddr_in); char my_message[BUFSIZE]; memset(my_message, 0, BUFSIZE); if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { LOG(stderr, ERROR, "cannot create socket"); } memset((char*)&router_addr, 0, sizeof(struct sockaddr_in)); router_addr.sin_family = AF_INET; router_addr.sin_port = htons(tcpport); router_ip_addr = gethostbyname(router_ip); address = (struct in_addr *)router_ip_addr->h_addr; router_addr.sin_addr.s_addr = inet_addr(inet_ntoa(*address)); if (connect(fd, (struct sockaddr *)&router_addr, alen) == -1) { close(fd); perror("TCP connection error"); exit(0); } snprintf(my_message,BUFSIZE,"startMarking %s",router_ip); if(write(fd, my_message, BUFSIZE) < 0) { close(fd); perror("Endhost: Error in write() for victim client"); exit(0); } LOG(stdout, LOGL, "EndHost: StartMarking message is sent to Router(IP: %s, TCP: %d)",router_ip, tcpport); gettimeofday(&curtime, NULL); LOG(fp_log, LOGL, "%f startMarking %s \'%s\'", SEC(TIME_IN_USEC(curtime)), router_ip, my_message); close(fd); }
static int SenderHandshake( void ) { unsigned wait_time; /* used to test for time-out */ int reply; /* storing data received from other machine */ wait_time = WaitCount() + SYNC_TIME_OUT; /* limit for time out */ if( MaxBaud == MIN_BAUD ) wait_time += SEC(1); SendByte( SYNC_BYTE ); /* send SYNC_BYTE */ for( ;; ) { /* loop until ACK received or time out */ reply = WaitByte( 1 ); /* get reply */ if( reply == SDATA_ACK ) break; /* ACK received; go to next operation */ if( reply == SDATA_HI ) { /* return HI received */ SendByte( SDATA_HI ); } else if( WaitCount() > wait_time ) { /* time out */ return( FAIL ); } /* not yet time out; loop */ } SendByte( SYNC_END ); return( SUCCESS ); }
static int ReceiverHandshake( void ) { int reply; /* storing data received from other machine */ int wait_time; wait_time = WaitCount() + SYNC_TIME_OUT; if( MaxBaud == MIN_BAUD ) wait_time += SEC(1); for( ;; ) { /* loop until SYNC_END received or time out */ reply = WaitByte( 1 ); /* get character */ if( reply == SYNC_END ) break; /* SYNC_END received; continue */ if( reply == SYNC_BYTE ) { /* SYNC_BYTE received; send ACK */ SendByte( SDATA_ACK ); } else if( reply == SDATA_HI ) { /* return HI received */ SendByte( SDATA_HI ); } else if( WaitCount() >= wait_time ) { /* 2 sec time out */ return( FAIL ); } /* not yet time out; loop */ } return( SUCCESS ); }
struct attacker_list *create_attackerlist_node(char *router_ip_addr, char *attacker_ip_addr, char *victim_ip_addr) { struct attacker_list *newNode = (struct attacker_list *)malloc(sizeof(struct attacker_list)); memset(newNode->attacker_ip_addr,'\0',MAXIPADDRLEN); memset(newNode->victim_ip_addr,'\0',MAXIPADDRLEN); strncpy(newNode->attacker_ip_addr, attacker_ip_addr, strlen(attacker_ip_addr)); strncpy(newNode->victim_ip_addr, victim_ip_addr, strlen(victim_ip_addr)); newNode->routerhead = (struct router_list *)malloc(sizeof(struct router_list)); memset(newNode->routerhead,'\0',sizeof(struct router_list)); strncpy(newNode->routerhead->router_ip, router_ip_addr, strlen(router_ip_addr)); struct timeval curtime; gettimeofday(&curtime, NULL); LOG(fp_log, LOGL, "%f %s distance", SEC(TIME_IN_USEC(curtime)), router_ip_addr); newNode->routerhead->frequency = 1; newNode->routerhead->next = NULL; newNode->no_of_routers = 1; newNode->next = NULL; return newNode; }
//----------------------------------------------------------------------- void CDrawMuteState(void) { COsdFxDisableOsd(); SetOSDDouble(0x03); SetOsdMap(tUserMenuOsdMap); // Init OSD Ram OSDClear(0,_MAINMENU_HEIGHT, 0, 31, 0x8C, BYTE_ATTRIB); OSDClear(0,_MAINMENU_HEIGHT, 0, 31, 0x00, BYTE_DISPLAY); OSDClear(0,_MAINMENU_HEIGHT, 0, 31, 0x40, BYTE_COLOR); COsdFxCodeWrite(ucCloseAllWindow); OSDPosition(4 * 12, 2 * 18, 40, 1, 0x03); if (GET_AUDIO_MUTE()) // Mute on COsdLoad1BitFont(FntMute, 0x10, 6, tFntVolumeCharWidth); else COsdLoad1BitFont(FntVolume, 0x10, 6, tFntVolumeCharWidth); // Display Volume/Mute icon Gotoxy(0, 0, BYTE_DISPLAY); OutputChar(0x10); OutputChar(0x11); OutputChar(0x12); Gotoxy(0, 1, BYTE_DISPLAY); OutputChar(0x13); OutputChar(0x14); OutputChar(0x15); COsdFxEnableOsd(); bOSDTimeOut = 0; // ucAudioState = 1; if (GET_AUDIO_MUTE()) // Mute on { CTimerCancelTimerEvent(COsdDispOsdTimerEvent); } else { CTimerReactiveTimerEvent(SEC(5), COsdDispOsdTimerEvent); } }