61 epicsTime programBeginTime = epicsTime::getCurrent();
62 bool validCommandLine =
false;
63 unsigned interest = 0u;
75 validCommandLine =
true;
77 else if ( argc == 2 ) {
78 status = sscanf ( argv[1],
" -i%u ", & interest );
80 validCommandLine =
true;
83 else if ( argc == 3 ) {
84 if ( strcmp ( argv[1],
"-i" ) == 0 ) {
85 status = sscanf ( argv[2],
" %u ", & interest );
87 validCommandLine =
true;
92 if ( ! validCommandLine ) {
93 printf (
"usage: casw <-i interestLevel>\n" );
111 sockErrBuf,
sizeof ( sockErrBuf ) );
112 errlogPrintf (
"casw: unable to create datagram socket because = \"%s\"\n",
117 memset ( (
char *) &addr, 0 ,
sizeof (addr) );
118 addr.
ia.sin_family = AF_INET;
119 addr.
ia.sin_addr.s_addr = htonl ( INADDR_ANY );
120 addr.
ia.sin_port = htons ( 0 );
121 status = bind ( sock, &addr.
sa, sizeof (addr) );
125 sockErrBuf,
sizeof ( sockErrBuf ) );
127 errlogPrintf (
"casw: unable to bind to an unconstrained address because = \"%s\"\n",
137 sockErrBuf,
sizeof ( sockErrBuf ) );
139 errlogPrintf (
"casw: unable to set socket to nonblocking state because \"%s\"\n",
144 unsigned attemptNumber = 0u;
149 status = recvfrom ( sock, buf,
sizeof ( buf ), 0,
150 &addr.
sa, &addrSize );
151 if ( status >= static_cast <int> (
sizeof ( *pCurMsg ) ) ) {
152 pCurMsg = reinterpret_cast <
caHdr * > ( buf );
160 if ( attemptNumber > 100 ) {
162 errlogPrintf (
"casw: unable to register with the CA repeater\n" );
172 sockErrBuf,
sizeof ( sockErrBuf ) );
174 errlogPrintf (
"casw: unable to set socket to blocking state because \"%s\"\n",
183 status = recvfrom ( sock, buf,
sizeof ( buf ), 0,
184 &addr.
sa, &addrSize );
188 sockErrBuf,
sizeof ( sockErrBuf ) );
195 if ( addr.
sa.sa_family != AF_INET ) {
199 unsigned byteCount = static_cast <
unsigned> (
status );
200 pCurMsg = reinterpret_cast <
const caHdr * > ( ( pCurBuf = buf ) );
201 while ( byteCount ) {
203 size_t msgSize = pstSize +
sizeof ( *pCurMsg ) ;
204 if ( msgSize > byteCount ) {
205 errlogPrintf (
"CASW: udp input protocol violation\n" );
211 bool anomaly =
false;
212 epicsTime previousTime;
213 struct sockaddr_in ina;
229 ina.sin_family = AF_INET;
233 ina.sin_port = pCurMsg->
m_count;
240 ina.sin_port = htons ( serverPort );
244 unsigned protocolRevision = ntohs ( pCurMsg->
m_dataType );
255 guard, programBeginTime,
256 currentTime, beaconNumber, protocolRevision );
266 pBHE =
new ( bheFreeList )
267 bhe ( mutex, currentTime, beaconNumber, ina );
269 if ( beaconTable.
add ( *pBHE ) < 0 ) {
275 if ( anomaly || interest > 1 ) {
277 currentTime.strftime ( date,
sizeof ( date ),
278 "%Y-%m-%d %H:%M:%S.%09f");
280 ipAddrToA ( &ina, host,
sizeof ( host ) );
281 const char * pPrefix =
"";
282 if ( interest > 1 ) {
291 pPrefix, host, date );
292 if ( anomaly && interest > 0 ) {
293 printf (
"\testimate=%f current=%f\n",
295 currentTime - previousTime );
301 pCurMsg = reinterpret_cast <
const caHdr * > ( pCurBuf );
302 byteCount -= msgSize;
LIBCOM_API void epicsStdCall epicsSocketDestroy(SOCKET s)
unsigned short epicsUInt16
LIBCA_API bool updatePeriod(epicsGuard< epicsMutex > &, const epicsTime &programBeginTime, const epicsTime ¤tTime, ca_uint32_t beaconNumber, unsigned protocolRevision)
unsigned short ca_uint16_t
T * lookup(const ID &idIn) const
void epicsSocketConvertErrnoToString(char *pBuf, unsigned bufSize)
LIBCA_API epicsTime updateTime(epicsGuard< epicsMutex > &) const
#define socket_ioctl(A, B, C)
LIBCOM_API SOCKET epicsStdCall epicsSocketCreate(int domain, int type, int protocol)
LIBCOM_API const ENV_PARAM EPICS_CA_SERVER_PORT
void epicsStdCall caStartRepeaterIfNotInstalled(unsigned repeaterPort)
LIBCOM_API const ENV_PARAM EPICS_CA_REPEATER_PORT
LIBCOM_API unsigned short epicsStdCall envGetInetPortConfigParam(const ENV_PARAM *pEnv, unsigned short defaultPort)
Get value of a port number configuration parameter.
int errlogPrintf(const char *pFormat,...)
void date(const char *format)
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
unsigned epicsStdCall ipAddrToA(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
LIBCA_API double period(epicsGuard< epicsMutex > &) const
void epicsStdCall caRepeaterRegistrationMessage(SOCKET sock, unsigned repeaterPort, unsigned attemptNumber)
#define CA_PROTO_RSRV_IS_UP