int OsDatagramSocket::writeTo(const char* buffer, int bufferLength) { int bytesSent = 0; if (getToSockaddr()) { bytesSent = sendto(socketDescriptor, #ifdef _VXWORKS (char*) #endif buffer, bufferLength, 0, (struct sockaddr*) mpToSockaddr, sizeof(struct sockaddr_in)); #ifdef TEST_PRINT UtlString address(inet_ntoa(mpToSockaddr->sin_addr)); OsSysLog::add(FAC_KERNEL, PRI_DEBUG, "OsDatagramSocket::writeTo bytes: %d to address: %s port: %d", bytesSent, address.data(), (int) ntohs(mpToSockaddr->sin_port)); #endif if(bytesSent != bufferLength) { time_t rightNow; (void) time(&rightNow); mNumRecentWriteErrors++; if (MIN_REPORT_SECONDS <= (rightNow - mLastWriteErrorTime)) { mNumTotalWriteErrors += mNumRecentWriteErrors; if (0 == mNumTotalWriteErrors) { mLastWriteErrorTime = rightNow; } osPrintf("OsDataGramSocket::write:\n" " In last %ld seconds: %d errors; total %d errors;" " last errno=%d\n", (rightNow - mLastWriteErrorTime), mNumRecentWriteErrors, mNumTotalWriteErrors, OsSocketGetERRNO()); mLastWriteErrorTime = rightNow; mNumRecentWriteErrors = 0; } } } return(bytesSent); }
void OsDatagramSocket::getRemoteHostIp(struct in_addr* remoteHostAddress, int* remotePort) { #ifdef __pingtel_on_posix__ socklen_t len; #else int len; #endif struct sockaddr_in remoteAddr; const struct sockaddr_in* pAddr; if (mSimulatedConnect) { getToSockaddr(); pAddr = mpToSockaddr; } else { pAddr = &remoteAddr; len = sizeof(struct sockaddr_in); if (getpeername(socketDescriptor, (struct sockaddr *)pAddr, &len) != 0) { memset(&remoteAddr, 0, sizeof(struct sockaddr_in)); } } memcpy(remoteHostAddress, &(pAddr->sin_addr), sizeof(struct in_addr)); #ifdef TEST_PRINT { int p = ntohs(pAddr->sin_port); UtlString o; inet_ntoa_pt(*remoteHostAddress, o); osPrintf("getRemoteHostIP: Remote name: %s:%d\n" " (pAddr->sin_addr) = 0x%X, sizeof(struct in_addr) = %d\n", o.data(), p, (pAddr->sin_addr), sizeof(struct in_addr)); } #endif if (NULL != remotePort) { *remotePort = ntohs(pAddr->sin_port); } }
int OsDatagramSocket::writeTo(const char* buffer, int bufferLength) { int bytesSent = 0; if (getToSockaddr()) { bytesSent = sendto(socketDescriptor, #ifdef _VXWORKS (char*) #endif buffer, bufferLength, 0, (struct sockaddr*) mpToSockaddr, sizeof(struct sockaddr_in)); if(bytesSent != bufferLength) { time_t rightNow; (void) time(&rightNow); mNumRecentWriteErrors++; if (MIN_REPORT_SECONDS <= (rightNow - mLastWriteErrorTime)) { mNumTotalWriteErrors += mNumRecentWriteErrors; if (0 == mNumTotalWriteErrors) { mLastWriteErrorTime = rightNow; } osPrintf("OsDataGramSocket::write:\n" " In last %ld seconds: %d errors; total %d errors;" " last errno=%d\n", (rightNow - mLastWriteErrorTime), mNumRecentWriteErrors, mNumTotalWriteErrors, OsSocketGetERRNO()); mLastWriteErrorTime = rightNow; mNumRecentWriteErrors = 0; } } } return(bytesSent); }