/** dSend_CAPD_Data function. * * dSend_CAPD_Data Function : we collect the nodes for sending to the next process effectively. * Compare the time and packet count. * if the packets are received more than old , we increae the collection #. * if the packets are received less than old , we decreae the collection #. * * @param *pstMEMSINFO : New Interface 관리 구조체 * @param *pNode : 전송하고자 하는 Node * @param dSndMsgQ : send the msg to the next process * @param sec : the time for comparing * * @return S32 SUCCESS: 0, FAIL: -1(NIFO NODE 생성 실패) -2(TLV NODE 생성 실패) -3(메시지 전송 실패) * @see capd_msgq.c * **/ int dSend_CAPD_Data(stMEMSINFO *pstMEMSINFO, S32 dSndMsgQ, U8 *pNode, U32 sec) { #ifdef MEM_TEST nifo_node_delete(pstMEMSINFO, pNode); #else /* * SIGTERM, SIGUSR1 시그널을 받은 경우에는 * 버퍼링하고 있는 패킷을 모두 전송 한 후에 종료 한다. */ if(pNode == NULL) { Collection_Cnt = 0; } else { if(Send_Node_Head) { nifo_node_link_nont_prev(pstMEMSINFO, Send_Node_Head, pNode); } else { Send_Node_Head = pNode; } Send_Node_Cnt++; check_pkt++; } if(Send_Node_Cnt > Collection_Cnt) { UINT dRet; if((dRet = nifo_msg_write(pstMEMSINFO, dSndMsgQ, Send_Node_Head)) < 0) { dAppLog(LOG_CRI, "[%s][%s.%d] nifo_msg_write dRet[%d][%s]", __FILE__, __FUNCTION__, __LINE__, dRet, strerror(-dRet)); return -1; } else { if(pNode == NULL) dAppLog(LOG_CRI, "### Send Buffered Packet[%d]", Send_Node_Cnt); Send_Node_Cnt = 0; Send_Node_Head = NULL; } } /* * 패킷이 들어오는 속도에 따라 버퍼링의 개수를 조절한다. */ #ifdef BUFFERING if( (old_time + COLLECTION_TIME) < sec) { if( (check_pkt / COLLECTION_TIME) > (Collection_Cnt * COLLECTION_MULTIPLY) ) { Collection_Cnt *= COLLECTION_MULTIPLY; if(Collection_Cnt > COLLECTION_MAX) { Collection_Cnt = COLLECTION_MAX; } } else if( (check_pkt / COLLECTION_TIME) < (Collection_Cnt / COLLECTION_MULTIPLY) ) { Collection_Cnt /= COLLECTION_MULTIPLY; if(Collection_Cnt < COLLECTION_MIN) { Collection_Cnt = COLLECTION_MIN; } } dAppLog(LOG_INFO, "CHECK_PKT:%d COLLECTION_CNT:%d", check_pkt, Collection_Cnt); check_pkt = 0; old_time = sec; } #endif /* BUFFERING */ #endif return 0; }
void print_pktbuf(int level, st_pktbuf_array pktbuf[]) { dAppLog(level, "---------- ARRAY0 [%d] ----------", pktbuf[0].used_count); print_pktbuf_array(level, &pktbuf[0]); dAppLog(level, "---------- ARRAY1 [%d] ----------", pktbuf[1].used_count); print_pktbuf_array(level, &pktbuf[1]); }
int Send_AlmMsg( char loctype, char invtype, short invno, char almstatus, char oldalm ) { dAppLog(LOG_CRI,"Send_AlmMSg"); dAppLog(LOG_CRI,"LOCTYPE[%d] INVTYPE[%d] invno[%d] almstatus[%d] oldalm[%d]", (int)loctype, (int)invtype, (int)invno, (int)almstatus, (int)oldalm); return 1; }
void do_action(int port, int len, char *data, struct timeval *tmv) { int ret; T_CAPHDR *pstCAPHead; if(len > 1518) { /* ethernet packet size */ dAppLog(LOG_CRI, "Ethernet Packet Size Error, input length =%d", len); } /* ADD BY YOON 2008.10.14 */ if( (pstNode = nifo_node_alloc(pstMEMSINFO)) == NULL) { dAppLog(LOG_CRI, "[%s.%d] nifo_node_alloc NULL", __FUNCTION__, __LINE__); exit(0); } if( (pstCAPHead = (T_CAPHDR *)nifo_tlv_alloc(pstMEMSINFO, pstNode, CAP_HEADER_NUM, CAP_HDR_SIZE, DEF_MEMSET_OFF)) == NULL ) { dAppLog(LOG_CRI, "[%s.%d] nifo_tlv_alloc [%d] NULL", __FUNCTION__, __LINE__, CAP_HEADER_NUM); exit(0); } if( (pstBuffer = nifo_tlv_alloc(pstMEMSINFO, pstNode, ETH_DATA_NUM, len, DEF_MEMSET_OFF)) == NULL ) { dAppLog(LOG_CRI, "[%s.%d] nifo_tlv_alloc [%d] NULL", __FUNCTION__, __LINE__, ETH_DATA_NUM); exit(0); } pstCAPHead->bRtxType = port; pstCAPHead->curtime = tmv->tv_sec; pstCAPHead->ucurtime = tmv->tv_usec; pstCAPHead->datalen = len; memcpy(pstBuffer, data, pstCAPHead->datalen); if((ret = dSend_CAPD_Data(pstMEMSINFO, dANAQid, pstNode, pstCAPHead->curtime)) < 0) { dAppLog(LOG_CRI, "[%s.%d] dSend_CAPD_Data [%d][%s]", __FUNCTION__, __LINE__, ret, strerror(-ret)); exit(111); } } /**** end of do_action ******/
void Trace_BLKMSG (SMS_INFO *rcvBlkMsg) { int trcIdx; if (gpCurTrc->dTCount <= 0) return; if (rcvBlkMsg->subsID == NULL) { dAppLog(LOG_WARN, "[TRACE] BLOCK INFO : IMSI is NULL"); return; } if (rcvBlkMsg->smsMsg == NULL) { dAppLog(LOG_WARN, "[TRACE] BLOCK INFO : SMS-MSG is NULL"); return; } for( trcIdx = 0; trcIdx < gpCurTrc->dTCount; trcIdx++ ) { switch (gpCurTrc->stTrc[trcIdx].dType) { case TRACE_METHOD_IMSI: if(!strcmp(gpCurTrc->stTrc[trcIdx].szImsi, rcvBlkMsg->subsID)) { Send_TrcMsg_BlkMsg_SMPP2COND(rcvBlkMsg, TRACE_METHOD_IMSI); } break; case TRACE_METHOD_IP: if(!strcmp(gpCurTrc->stTrc[trcIdx].szImsi, rcvBlkMsg->subsIP)) { Send_TrcMsg_BlkMsg_SMPP2COND(rcvBlkMsg, TRACE_METHOD_IP); } break; default: dAppLog(LOG_CRI, "[TRACE] trace type is wrong(%d:%d)", trcIdx, gpCurTrc->stTrc[trcIdx].dType); break; } } /* end of for */ }
int dSend_Message( pst_MsgQ pstMsgQ, int qid ) { int isize, dRet; isize = sizeof(st_MsgQ) - MAX_MSGBODY_SIZE + pstMsgQ->usBodyLen - sizeof(long int); dRet = msgsnd(qid, pstMsgQ, isize, 0); if ( dRet < 0) { dAppLog( LOG_CRI, "[Qid = %d] ERROR SEND : %d[%s]", qid, errno, strerror(errno)); return -1; } #ifdef DEBUG else dAppLog(LOG_INFO, "MESSAGE SEND SUCCESS"); num++; if (old != time(0)) { fprintf(stderr, "SEND NUM %d\n", num); num = 0; old = time(0); } #endif return 0; }
int dInit_FIDB() { int dShm; if( (dShm = shmget( S_SSHM_FIDB, sizeof(st_NTAF), 0666|IPC_CREAT|IPC_EXCL )) < 0 ) { if( errno == EEXIST ) { if( (dShm = shmget( S_SSHM_FIDB, sizeof(st_NTAF), 0666|IPC_CREAT )) < 0 ) { dAppLog( LOGN_CRI, "ERROR SHMGET %s.%d dShm:%d", __FUNCTION__, __LINE__, dShm ); return -1; } if( (fidb = (st_NTAF *)shmat( dShm, (char *)0, 0 )) == (st_NTAF *)-1 ) { dAppLog( LOGN_CRI, "ERROR SHMAT %s.%d", __FUNCTION__, __LINE__ ); return -2; } } else return -3; } else { if( (fidb = (st_NTAF *)shmat( dShm, (char *)0, 0 )) == (st_NTAF *)-1 ) { dAppLog( LOGN_CRI, "ERROR SHMAT %s.%d", __FUNCTION__, __LINE__ ); return -4; } } return 0; }
void Trace_DELIVER_MSG (SMS_HIS *sms_his, SMPP_DELIVER *deliver) { int trcIdx; if (gpCurTrc->dTCount <= 0) return; if (sms_his->info.subsID == NULL) { dAppLog(LOG_WARN, "[TRACE] DELIVER MSG : IMSI is NULL"); return; } if (sms_his->info.subsIP == NULL) { dAppLog(LOG_WARN, "[TRACE] DELIVER MSG : IP is NULL"); return; } for( trcIdx = 0; trcIdx < gpCurTrc->dTCount; trcIdx++ ) { switch (gpCurTrc->stTrc[trcIdx].dType) { case TRACE_METHOD_IMSI: if(!strcmp(gpCurTrc->stTrc[trcIdx].szImsi, sms_his->info.subsID)) { Send_TrcMsg_DelivMsg_SMPP2COND (sms_his, deliver, TRACE_METHOD_IMSI); } break; case TRACE_METHOD_IP: if(!strcmp(gpCurTrc->stTrc[trcIdx].szImsi, sms_his->info.subsIP)) { Send_TrcMsg_DelivMsg_SMPP2COND (sms_his, deliver, TRACE_METHOD_IP); } break; default: dAppLog(LOG_CRI, "[TRACE] trace type is wrong(%d:%d)", trcIdx, gpCurTrc->stTrc[trcIdx].dType); break; } } /* end of for */ }
int create_tcp_sock () { int flag; int sockfd; int dBufSize; socklen_t slen; if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) { dAppLog (LOG_DEBUG, "Can't open tcp socket! errno=%d[%s]\n", errno, strerror(errno)); return -1; } if ((flag = fcntl (sockfd, F_GETFL, 0)) < 0) { dAppLog (LOG_DEBUG, "Fail in get socket option! errno=%d[%s]\n", errno, strerror(errno)); close (sockfd); return -1; } flag |= O_NONBLOCK; if (fcntl (sockfd, F_SETFL, flag) < 0) { dAppLog (LOG_DEBUG, "Fail in Change Nonblcok option! errno=%d[%s]\n", errno, strerror(errno)); close (sockfd); return -1; } return sockfd; }
int start_connect (hs_key *pksid, hs_body *pbsid) { int n, dret; struct sockaddr_in stServerAddr; stServerAddr.sin_family = AF_INET; stServerAddr.sin_addr.s_addr = pbsid->dest_ipaddr; stServerAddr.sin_port = pbsid->dest_port; if ( (n = connect (pbsid->cfd, (struct sockaddr *)&stServerAddr, sizeof(stServerAddr))) < 0) { if (errno != EINPROGRESS) { dAppLog (LOG_DEBUG, "Nonblocking connect error! %d.%s-%s", errno, strerror(errno), __FUNCTION__); return -1; } #if 0 epollOne_cli_add (pbsid->tcpsock.sockfd); dAppLog(LOG_DEBUG, "--->] Nonblocking connect succss!! Dst:%d.%d.%d.%d : %d", NIPADDR(pbsid->dest_ipaddr), ntohs(pbsid->dest_port)); #endif } return 0; }
void period_smbuf_clear (int k, void *d) { time_t cur_time; struct tm* pcur_tm; SMNB_HANDLE *pgSCE_nbapi=NULL; int rst=0; cur_time = time ((time_t *)0); pcur_tm = (struct tm*)localtime((time_t*)&cur_time); if (gMySmBuf.dUsed != CMD_USE_ON) return; if (loc_sadb->loc_system_dup.myLocalDupStatus == SYS_STATE_ACTIVE) { pgSCE_nbapi = &gSMConn.hdl_nbSceApi; if (pgSCE_nbapi==NULL) { dAppLog(LOG_CRI, "[period_smbuf_clear] Connection is disconnected"); } rst = SMNB_clearClientBuffer(*pgSCE_nbapi); dAppLog(LOG_CRI, "[period_smbuf_clear] SM Buffer is Cleared(RST=%d)", rst); } if (gMySmBuf.uiClrPeriod>0) { set_cb_timeout(period_smbuf_clear, 4, NULL, gMySmBuf.uiClrPeriod); } else { dAppLog(LOG_CRI, "[period_smbuf_clear] SM Buffer Clear Period is invalid(period=%u)", gMySmBuf.uiClrPeriod); } }
void dump_sm_sub_clr (SM_BUF_CLR *pSmBuf) { dAppLog(LOG_INFO, "[SM_BUF_CLR] dUsed=%d", gMyIdx, pSmBuf->dUsed); dAppLog(LOG_INFO, "[SM_BUF_CLR] dPeriod=%d", gMyIdx, pSmBuf->dPeriod); dAppLog(LOG_INFO, "[SM_BUF_CLR] dHour=%d", gMyIdx, pSmBuf->dHour); dAppLog(LOG_INFO, "[SM_BUF_CLR] uiClrPeriod=%d", gMyIdx, pSmBuf->uiClrPeriod); }
int comm_txMMLResult ( int SendQid, // 보내고자 하는 Message Q id IxpcQMsgType *rxIxpcMsg, char *resBuf, char resCode, char contFlag, unsigned short extendTime, char segFlag, char seqNo ) { GeneralQMsgType txGenQMsg; IxpcQMsgType *txIxpcMsg; MMLResMsgType *txResMsg; int txLen; char cmdName[32]; MMLReqMsgType *rxReqMsg; txIxpcMsg = (IxpcQMsgType*)txGenQMsg.body; memset ((void*)&txIxpcMsg->head, 0, sizeof(txIxpcMsg->head)); rxReqMsg = (MMLReqMsgType*)rxIxpcMsg->body; txResMsg = (MMLResMsgType*)txIxpcMsg->body; txGenQMsg.mtype = MTYPE_MMC_RESPONSE; strcpy (cmdName, rxReqMsg->head.cmdName); strcpy (txIxpcMsg->head.srcSysName, rxIxpcMsg->head.dstSysName); strcpy (txIxpcMsg->head.srcAppName, rxIxpcMsg->head.dstAppName); strcpy (txIxpcMsg->head.dstSysName, rxIxpcMsg->head.srcSysName); strcpy (txIxpcMsg->head.dstAppName, rxIxpcMsg->head.srcAppName); txIxpcMsg->head.segFlag = segFlag; txIxpcMsg->head.seqNo = seqNo; txResMsg->head.mmcdJobNo = rxReqMsg->head.mmcdJobNo; txResMsg->head.extendTime = extendTime; txResMsg->head.resCode = resCode; txResMsg->head.contFlag = contFlag; strcpy(txResMsg->head.cmdName, cmdName); strcpy(txResMsg->body, resBuf); txIxpcMsg->head.bodyLen = sizeof(txResMsg->head) + strlen(txResMsg->body); txLen = sizeof(txIxpcMsg->head) + txIxpcMsg->head.bodyLen; dAppLog(LOG_DEBUG, "[comm_txMMLResult] SRC(SYS:%s, APP:%s) DST(SYS:%s, APP:%s)", txIxpcMsg->head.srcSysName, txIxpcMsg->head.srcAppName, txIxpcMsg->head.dstSysName, txIxpcMsg->head.dstAppName); if (msgsnd(SendQid, (void*)&txGenQMsg, txLen, IPC_NOWAIT) < 0) { dAppLog(LOG_CRI, "[comm_txMMLResult] msgsnd error=%s, cmd=%s, len=%d" , strerror(errno), txResMsg->head.cmdName, txLen); return -1; } return 1; }
int Send_TrcMsg_BlkMsg_SMPP2COND (SMS_INFO *rcvBlkMsg, int trace_type) { GeneralQMsgType txGenQMsg; IxpcQMsgType *txIxpcMsg = NULL; char szTrcMsg[4096]; int dMsgLen= 0, dTxLen; struct timeval stTmval; char sztimebuf[128]; char szTypeStr[512]; memset(&stTmval, 0x00, sizeof(struct timeval)); memset(&sztimebuf, 0x00, sizeof(sztimebuf)); memset(&txGenQMsg, 0x00, sizeof(txGenQMsg)); memset(szTrcMsg, 0x00, 4096); txGenQMsg.mtype = MTYPE_TRC_CONSOLE; txIxpcMsg = (IxpcQMsgType*)txGenQMsg.body; memset((void*)&txIxpcMsg->head, 0x00, sizeof(txIxpcMsg->head)); strcpy(txIxpcMsg->head.srcSysName, mySysName); strcpy(txIxpcMsg->head.srcAppName, myAppName); strcpy(txIxpcMsg->head.dstSysName, "DSCM"); strcpy(txIxpcMsg->head.dstAppName, "COND"); gettimeofday(&stTmval, NULL ); sprintf( sztimebuf,"[%s.%06ld]", str_time(stTmval.tv_sec), stTmval.tv_usec); sprintf (szTypeStr, "SMS : block info Message\nblock time:%d\nP/H:%02d %02d\nsms msg:%s " , rcvBlkMsg->blkTm, rcvBlkMsg->sPBit, rcvBlkMsg->sHBit, rcvBlkMsg->smsMsg); if (trace_type == TRACE_METHOD_IMSI) { dMsgLen += snprintf(szTrcMsg + dMsgLen, sizeof(szTrcMsg), "IMSI:%s S7000 CALL TRACE INFORMATION (SMPP)\n", rcvBlkMsg->subsID); } else if (trace_type == TRACE_METHOD_IP) { dMsgLen += snprintf(szTrcMsg + dMsgLen, sizeof(szTrcMsg), "IP:%s: S7000 CALL TRACE INFORMATION (SMPP)\n", rcvBlkMsg->subsIP); } else { dAppLog(LOG_CRI, "trace type is wrong(%d)", trace_type); } dMsgLen += snprintf(szTrcMsg + dMsgLen, sizeof(szTrcMsg), "%s\t%s \n", mySysName, sztimebuf); dMsgLen += snprintf(szTrcMsg + dMsgLen, sizeof(szTrcMsg), "------------------------------------------------------------\n"); dMsgLen += snprintf(szTrcMsg + dMsgLen, sizeof(szTrcMsg), "Trace Log] %s \n", szTypeStr); txIxpcMsg->head.bodyLen = dMsgLen; memcpy(txIxpcMsg->body, szTrcMsg, dMsgLen); dTxLen = sizeof(txIxpcMsg->head) + txIxpcMsg->head.bodyLen; if( msgsnd(ixpcQid, (void*)&txGenQMsg, dTxLen, IPC_NOWAIT) < 0 ) { dAppLog(LOG_CRI, "[FAIL] SEND TO TRACE ERROR %d(%s)\n", errno, strerror(errno)); return -1; } else { dAppLog(LOG_CRI, "[SUCC] SEND TO BLK-INFO TRACE, SUCCESS(%d)", dTxLen); } return 0; }
int send_packet(UCHAR *pNode, T_CAPHDR *pHead, UCHAR *pBuffer) { int ret; struct timeval cap_t; cap_t.tv_sec = 0; cap_t.tv_usec = 0; gettimeofday (&cap_t, NULL); pHead->bRtxType = 1; //port; pHead->curtime = cap_t.tv_sec; pHead->ucurtime = cap_t.tv_usec; if(pHead->datalen > 1518) { /* ethernet packet size */ dAppLog(LOG_CRI, "eth packet size ERR(len=%d)", pHead->datalen); } /* ADD : BY JUNE, 2011-05-09 * DESC: STANDBY 상태에서는 DLPI BUFFER 에서 Packet을 빼내기 위해 읽은 후 버리고 * ACTIVE 상태에서는 DLPI BUFFER 에서 Packet을 읽은 후 Next Block으로 전송. */ if (loc_sadb->loc_system_dup.myLocalDupStatus != SYS_STATE_ACTIVE /** NOT ACTIVE **/) { dAppLog(LOG_DEBUG, "SYSTEM MODE : %d", loc_sadb->loc_system_dup.myLocalDupStatus); nifo_node_delete(pstMEMSINFO, pNode); return 0; } /* ADD : BY JUNE, 2010-05-10 * DESC : BUFFERING 시에 (Send_Node_Cnt <= Collection_Cnt) 의 경우 처리. */ #ifdef BUFFERING #if 0 nowTime = time(0); if (oldTime + COLLECTION_TIME < nowTime) { if (Send_Node_Cnt && Send_Node_Cnt == Diff_Node_Cnt) { // Send Buffring Packet if((ret = dSend_CAPD_Data(pstMEMSINFO, dANAQid, NULL, 0)) < 0) { dAppLog(LOG_CRI, "dSend_CAPD_Data[%d] ERR[%s", ret, strerror(-ret)); } Collection_Cnt = COLLECTION_MIN; } Diff_Node_Cnt = Send_Node_Cnt; oldTime = nowTime; } #endif #endif /* BUFFERING */ if((ret = dSend_CAPD_Data(pstMEMSINFO, dANAQid, pNode, pHead->curtime)) < 0) { dAppLog(LOG_CRI, "dSend_CAPD_Data[%d] ERR[%s]", ret, strerror(-ret)); nifo_node_delete(pstMEMSINFO, pNode); return -1; } return 0; }
int dCheck_SocketEvent() { int i, nfds, iRet, dIndex; pst_ServerInfo pstSI; pst_ServerSock pstSSock; nfds = epoll_wait( g_epoll_fd, g_events, MAX_EVENTS, 0 ); if( nfds == 0 ) { return 0; /* no events */ } else if( nfds < 0 ) { dAppLog( LOG_CRI, "EPOLL WATI ERROR OCCURED [%d:%s]", errno, strerror(errno) ); return -1; } else { for( i = 0 ; i < nfds ; i++ ) { if( g_events[i].events & (EPOLLERR | EPOLLHUP) ) { dAppLog(LOG_CRI, "EPOLL ERROR EVENT OCCURED!!"); pstSSock = g_events[i].data.ptr; dAppLog( LOG_CRI, "CLOSE SOCKET [%s]", CVT_IPADDR(pstSSock->uiServerIPAddr) ); close( pstSSock->dSocket ); iRet = Get_hashed_shm( &stServerHandle, pstSSock->ullKey, (void **)&pstSI ); if (iRet < 0) { dAppLog( LOG_CRI, "Get_hashed_shm KEY:%llx RET: %d", pstSSock->ullKey, iRet ); } else { pstSI->dSendLen = 0; pstSI->dRecvLen = 0; pstSI->dConnFlag = DEF_DISCONNECT; } return -2; } /* if not server socket , this socket is for client socket, so we read it */ if( g_events[i].events & EPOLLIN ) { pstSSock = g_events[i].data.ptr; iRet = dProc_ReadEvent( pstSSock ); } if( g_events[i].events & EPOLLOUT ) { pstSSock = g_events[i].data.ptr; iRet = dProc_WriteEvent( pstSSock ); } } } return 0; }
void CatchSignal(int sig) { int ret; dAppLog(LOG_CRI, "%s: SIGNAL[%d] CATCH. FINISH PROGRAM", __FUNCTION__, sig); loop_continue = 0; if((ret = dSend_CAPD_Data(pstMEMSINFO, dANAQid, NULL, 0)) < 0) { dAppLog(LOG_CRI, "[%s.%d] dSend_CAPD_Data [%d][%s]", __FUNCTION__, __LINE__, ret, strerror(-ret)); exit(111); } exit(0); }
void IgnoreSignal(int sig) { int ret; if( sig != SIGALRM ) dAppLog(LOG_INFO, "SIGNAL[%d] RECEIVED.", sig); signal(SIGALRM, IgnoreSignal); if( sig == SIGUSR1 ) { if((ret = dSend_CAPD_Data(pstMEMSINFO, dANAQid, NULL, 0)) < 0) { dAppLog(LOG_CRI, "[%s.%d] dSend_CAPD_Data [%d][%s]", __FUNCTION__, __LINE__, ret, strerror(-ret)); } } }
int main (int argc, char *argv[]) { int ret; char logbuffer[4096]; Init_logdebug( getpid(), "CAPD", "/DSC/APPLOG" ); ret = INIT_CAPD_IPCS(); if(ret < 0) { sprintf(logbuffer, "FAIL[init_ipc] [%s] %d.", strerror(errno), ret); dAppWrite(LOG_CRI, logbuffer); exit(0); } if( gen_info->DebugLevel == 0 ) gen_info->DebugLevel = LOG_INFO; /* temporary code (without CHSMD) */ if((ret=set_version(SEQ_PROC_CAPD, vERSION)) < 0 ) { dAppLog( LOG_CRI, "SET_VERSION ERROR(RET=%d,IDX=%d,VER=%s)\n", ret,SEQ_PROC_CAPD,vERSION); } if( check_my_run_status("CAPD") < 0) exit(0); if( keepalivelib_init("CAPD") < 0 ) exit(1); #if 0 if( argc==3 ) { test_func(argv[1], atoi(argv[2])); } #endif if( argc == 3 ) { test_func2(argv[1], atoi(argv[2])); exit(0); } else if( argc!=1 ) { exit(0); } SetupSignal(); dAppLog(LOG_CRI, "CAPD %s %d] [PROCESS INIT SUCCESS", vERSION, getpid()); dAppLog(LOG_CRI, "CAPD %s %d] [PROCESS STARTED", vERSION, getpid()); open_device_dlpi(DEV_PATH); return 0; } /***** end of main *****/
/******************************************************************************* dSendMsg *******************************************************************************/ void dSendMsg(int qid, pst_MsgQ pstMsgQ) { int isize, dRet; pstMsgQ->dMsgQID = dMyQid; isize = sizeof(st_MsgQ) - MAX_MSGBODY_SIZE + pstMsgQ->usBodyLen - sizeof(long int); if ((dRet = msgsnd(qid, pstMsgQ, isize, 0)) < 0) { dAppLog( LOG_CRI, "[Qid = %d] ERROR SEND : %d[%s]", qid, errno, strerror(errno)); return; } else dAppLog( LOG_INFO, "SEND TO MSGQ=%d LEN[%u]", qid, pstMsgQ->usBodyLen ); }
void RealTimeTrace(void *arg) { int ret; GeneralQMsgType rxGenQMsg; memset(&rxGenQMsg, 0, sizeof(GeneralQMsgType)); while(1) { keepalivelib_increase(); while ((ret = msgrcv(dMyQid, &rxGenQMsg, sizeof(GeneralQMsgType), 0, IPC_NOWAIT)) > 0 ) { switch (rxGenQMsg.mtype) { case MTYPE_TRACE_INFO: // TODO TrcInfo.conf ¨¡AAI reloading. memset(&g_stTrcInfo, 0x00, sizeof(st_SESSInfo)); dGetTraceData(&g_stTrcInfo); dAppLog(LOG_CRI, "MMCR Msg Get...."); break; default: break; } keepalivelib_increase(); memset(&rxGenQMsg, 0, sizeof(GeneralQMsgType)); } commlib_microSleep(1000); } }
int test(char *ab) { int arg_len, pn; arg_len = strlen(ab); dAppLog(LOG_INFO,"ARG?[%s:%d]", ab, arg_len); LOGLN; if( !isdigit(ab[arg_len-1]) ){ pn = 0; }else{ pn = atoi(&ab[arg_len-1]); } dAppLog(LOG_INFO,"ARGS>>[%d]", pn); LOGLN; dAppLog(LOG_INFO,"STRING=%s", ab); LOGLN; dAppLog(LOG_INFO,"LEN=%d", strlen(ab)); LOGLN; return 0; }
int dUdpSockInit(unsigned short usPort, int *pdSock) { int dRet; int dSockfd; struct sockaddr_in stServAddr; int bufsize; dSockfd = socket(AF_INET, SOCK_DGRAM, 0); if(dSockfd < 0) { dAppLog(LOG_CRI, "socket Error :%s", strerror(errno)); return -1; } dRet = fcntl(dSockfd, F_SETFD, O_NONBLOCK); if(dRet < 0) { dAppLog(LOG_CRI, "fcntl Error :%s", strerror(errno)); return -2; } bufsize = 1000000; dRet = setsockopt(dSockfd, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize)); if( dRet < 0 ) { dAppLog(LOG_CRI, "setsockopt() RCV BUFFER set error :%s", strerror(errno)); return -3; } memset(&stServAddr, 0x00, sizeof(struct sockaddr)); stServAddr.sin_family = AF_INET; stServAddr.sin_addr.s_addr = htonl(guiMyIP); stServAddr.sin_port = htons(usPort); dRet = bind(dSockfd, (struct sockaddr *)&stServAddr, sizeof(stServAddr)); if(dRet < 0) { dAppLog(LOG_CRI, "Bind Error :%s", strerror(errno)); return -3; } dAppLog(LOG_DEBUG, "SUCC SOCK PORT[%hu]", usPort); *pdSock = dSockfd; return 0; }
void sigtest(int sig) { #ifdef MEM_TEST dAppLog(LOG_CRI, "CREATE CNT[%llu] DELETE CNT[%llu]", nifo_create, nifo_del); #endif close(gdSockfd); exit(0); }
void print_pktbuf_array(int level, st_pktbuf_array *pktbuf) { int idx = pktbuf->head; Capture_Header_Msg *p_hdr; while( idx >= 0 && idx < MAX_NODE ) { p_hdr = (Capture_Header_Msg *)pktbuf->node[idx].buffer; dAppLog(level, "INDEX[%d] CAPTIME[%ld.%06ld] NEXT[%d]", idx, p_hdr->curtime, p_hdr->ucurtime, pktbuf->node[idx].next); idx = pktbuf->node[idx].next; } if( idx < -1 || idx >= MAX_NODE ) { // Broken linked list. dAppLog(LOG_CRI, "LINKED LIST to be initialized."); } }
int dProc_WriteEvent(pst_ServerSock pstSSock) { struct epoll_event event; int dRet; pst_ServerInfo pstINFO; dRet = Get_hashed_shm( &stServerHandle, pstSSock->ullKey, (void **)&pstINFO ); if( dRet < 0 ) { dAppLog( LOG_CRI, "%s --> KEY:%llx RET:%d msg:%s", __func__, pstSSock->ullKey, dRet, Msg_hashed_shm(dRet) ); return -1; } if( !pstINFO->dConnFlag ) { //NOT CONNECTED dAppLog(LOG_CRI, "%s --> CONNECTION CLOSED!!", __func__); pstINFO->dSendLen = 0; return -1; } EPOLL_IN_FILL_PTR(pstSSock, event); EPOLL_MODIFY( &event, &g_epoll_fd, &pstSSock->dSocket ); dRet = dWrite_Packet( pstINFO->stSSock.dSocket, (CHAR*)pstINFO->szSendBuf, pstINFO->dSendLen ); if( dRet < 0 ) { if( dRet != ERR_SOCK_EAGAIN ) { pstINFO->dSendLen = 0; dAppLog( LOG_CRI, "Failed In dWrite_Message LEN:%d RET:%d", pstINFO->dSendLen, dRet ); } } else if ( dRet > 0 ) { memmove( pstINFO->szSendBuf, pstINFO->szSendBuf + (pstINFO->dSendLen - dRet), dRet ); pstINFO->dSendLen = dRet; event.events = EPOLL_OUT_EVENT; EPOLL_MODIFY( &event, &g_epoll_fd, &pstSSock->dSocket ); } else { pstINFO->dSendLen = 0; } return 0; }
void FinishProgram() { /* * SHM에 WRITE하는 부분에서 고려하지 않기 위해 */ //shm_cap->ReadPos[MRG_READER_ANA] = -2; dAppLog( LOG_CRI, "PROGRAM IS NORMALLY TERMINATED, Cause = %d", FinishFlag); exit(0); }
void test_func(char *ip, unsigned short usPort) { dAppLog(LOG_CRI, "CAPD TEST START"); signal(SIGINT, sigtest); guiMyIP = ntohl(inet_addr(ip)); if(dUdpSockInit(usPort, &gdSockfd) < 0) { dAppLog(LOG_CRI, "[%s.%d] dUdpSockInit", __FUNCTION__, __LINE__); exit(0); } gdMaxfd = gdSockfd; while(1) { if(dIsRcvedPacket() < 0) exit(0); } }
int main(int ac, char **av) { int i, PROCNO; if( ac != 2 ){ dAppLog(LOG_CRI,LP"need to parameter block index",LT); LOGLN; return 0; } test(av[0]); /* for( i = 0; i < strlen(av[1]); i++ ){ if( !isdigit(av[1][0]) ){ dAppLog(LOG_WARN,LP"INVALID ARG=%s, Only Number Support",LT, av[1]); LOGLN; return 0; } } */ PROCNO = atoi(av[1]); uiSeqProcKey = SEQ_PROC_NO + PROCNO; dAppLog(LOG_INFO,LP" @@@ ARG=%s", LT, av[1]);LOGLN; dAppLog(LOG_INFO,LP" @@@ PROCNO=%d", LT, PROCNO);LOGLN; dAppLog(LOG_INFO,LP" @@@ SEQ_NO=%d", LT, uiSeqProcKey);LOGLN; dAppLog(LOG_INFO,LP" @@@ MOD1=%d", LT, PROCNO%MAX_RANGE_CNT);LOGLN; dAppLog(LOG_INFO,LP" @@@ MOD2=%d", LT, (PROCNO%MAX_RANGE_CNT)%3);LOGLN; return 0; }
/******************************************************************************* dIsRcvedMessage *******************************************************************************/ int dIsRcvedMessage(pst_MsgQ pstMsgQ) { int dRet; dRet = msgrcv(dMyQid, pstMsgQ, sizeof(st_MsgQ) - sizeof(long int), 0, IPC_NOWAIT | MSG_NOERROR); if(dRet < 0) { if(errno != EINTR && errno != ENOMSG) { dAppLog( LOG_CRI, "[FAIL:%d] MSGRCV MYQ : [%s]", errno, strerror(errno)); return -1; /* Error */ } return 0; /* Do Nothing */ } else { #ifdef _PATCH_MESSAGE_QUEUE /*************************************************************************************** msgrcv() 의 반환값은 처음 long int 형 만큼의 사이즈는 제외하고 가져온 바이트 수가 됨. 자세한 항목은 man -S2 msgrcv 참고 Writer: Han-jin Park Date: 2008.08.13 ***************************************************************************************/ if(dRet != pstMsgQ->usBodyLen + DEF_MSGHEAD_LEN - sizeof(long int)) #else /* ELSE: #ifdef _PATCH_MESSAGE_QUEUE */ if(dRet != pstMsgQ->usBodyLen + DEF_MSGHEAD_LEN) #endif /* END: #ifdef _PATCH_MESSAGE_QUEUE */ { dAppLog( LOG_CRI, "PROID[%d] MESSAGE SIZE ERROR RCV[%d]BODY[%d]HEAD[%d]", pstMsgQ->ucProID, dRet, pstMsgQ->usBodyLen, DEF_MSGHEAD_LEN ); return 10; } else { pstMsgQ->szBody[pstMsgQ->usBodyLen] = 0x00; dAppLog( LOG_INFO, "[MESSAGE RECEIVED] RCV[%d]BODY[%d]HEAD[%d]", dRet, pstMsgQ->usBodyLen, DEF_MSGHEAD_LEN ); } } return dRet; /* Good */ }