diff --git a/modules/ca/src/client/iocinf.cpp b/modules/ca/src/client/iocinf.cpp index c760a0d34..8bd42f108 100644 --- a/modules/ca/src/client/iocinf.cpp +++ b/modules/ca/src/client/iocinf.cpp @@ -21,6 +21,9 @@ #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" +#include +#include + #include #include #include @@ -28,6 +31,7 @@ #include "envDefs.h" #include "epicsAssert.h" +#include "epicsString.h" #include "epicsStdioRedirect.h" #include "errlog.h" #include "osiWireFormat.h" @@ -35,39 +39,6 @@ #include "addrList.h" #include "iocinf.h" -/* - * getToken() - */ -static char *getToken ( const char **ppString, char *pBuf, unsigned bufSIze ) -{ - bool tokenFound = false; - const char *pToken; - unsigned i; - - pToken = *ppString; - while ( isspace (*pToken) && *pToken ){ - pToken++; - } - - for ( i=0u; iname); - fprintf ( stderr, "\tBad internet address or host name: '%s'\n", pToken); - continue; + try { + std::vector scratch(pStr, pStr+strlen(pStr)+1); // copy chars and trailing nil + + char *save = NULL; + for(const char *pToken = epicsStrtok_r(&scratch[0], " \t\n\r", &save); + pToken; + pToken = epicsStrtok_r(NULL, " \t\n\r", &save)) + { + if(!pToken[0]) { + continue; + } + + status = aToIPAddr ( pToken, port, &addr ); + if (status<0) { + fprintf ( stderr, "%s: Parsing '%s'\n", __FILE__, pEnv->name); + fprintf ( stderr, "\tBad internet address or host name: '%s'\n", pToken); + continue; + } + + if ( ignoreNonDefaultPort && ntohs ( addr.sin_port ) != port ) { + continue; + } + + pNewNode = (osiSockAddrNode *) calloc (1, sizeof(*pNewNode)); + if (pNewNode==NULL) { + fprintf ( stderr, "addAddrToChannelAccessAddressList(): no memory available for configuration\n"); + break; + } + + pNewNode->addr.ia = addr; + + /* + * LOCK applied externally + */ + ellAdd (pList, &pNewNode->node); + ret = 0; /* success if anything is added to the list */ } - - if ( ignoreNonDefaultPort && ntohs ( addr.sin_port ) != port ) { - continue; - } - - pNewNode = (osiSockAddrNode *) calloc (1, sizeof(*pNewNode)); - if (pNewNode==NULL) { - fprintf ( stderr, "addAddrToChannelAccessAddressList(): no memory available for configuration\n"); - break; - } - - pNewNode->addr.ia = addr; - - /* - * LOCK applied externally - */ - ellAdd (pList, &pNewNode->node); - ret = 0; /* success if anything is added to the list */ + } catch(std::exception&) { // only bad_alloc currently possible + ret = -1; } return ret;