diff --git a/src/libCom/os/README b/src/libCom/os/README new file mode 100644 index 000000000..94aadb25f --- /dev/null +++ b/src/libCom/os/README @@ -0,0 +1,3 @@ + +The source files here are OS dependent + diff --git a/src/libCom/os/generic/README b/src/libCom/os/generic/README new file mode 100644 index 000000000..05cf23614 --- /dev/null +++ b/src/libCom/os/generic/README @@ -0,0 +1,5 @@ + +The source files here are OS dependent. The implementation +is generic enough that it can be used on several OS and therefore is the +default implementation. + diff --git a/src/libCom/os/generic/ipAddrToA.c b/src/libCom/os/generic/ipAddrToA.c new file mode 100644 index 000000000..d9341bc88 --- /dev/null +++ b/src/libCom/os/generic/ipAddrToA.c @@ -0,0 +1,83 @@ +/* $Id$ */ +/* + * This provides a generic way to convert an IP address into a + * host name. + * + * Author: Jeff Hill + * Date: 04-05-94 + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * Modification Log: + * ----------------- + * .00 mm-dd-yy iii Comment + * + */ + +#include +#include +#include + +#include + +/* + * inetAddrToHostName() + */ +void ipAddrToA (const struct sockaddr_in *pInetAddr, char *pBuf, + const unsigned bufSize) +{ + struct hostent *ent; + char *pName; +# define maxPortDigits 16u + char tmp[maxPortDigits+1u]; + + if (pInetAddr->sin_family != AF_INET) { + pName = "UKN ADDR FAMILY"; + tmp[0u] = '\0'; + } + else { + int port = ntohs(pInetAddr->sin_port); + + ent = gethostbyaddr( + (char *) &pInetAddr->sin_addr, + sizeof(pInetAddr->sin_addr), + AF_INET); + if(ent){ + pName = ent->h_name; + } + else{ + pName = inet_ntoa(pInetAddr->sin_addr); + } + + sprintf (tmp, "(%d)", port); + } + + /* + * force null termination + */ + strncpy(pBuf, pName, bufSize-1); + strncat(pBuf, tmp, bufSize-1); + pBuf[bufSize-1u] = '\0'; + + return; +} + diff --git a/src/libCom/os/generic/osdTime.cc b/src/libCom/os/generic/osdTime.cc new file mode 100644 index 000000000..e894408cf --- /dev/null +++ b/src/libCom/os/generic/osdTime.cc @@ -0,0 +1,29 @@ + +#include +#include + +// +// for sunos4 +// +extern "C" { +int gettimeofday (struct timeval *tp, struct timezone *tzp); +} + +#define epicsExportSharedSymbols +#include "osiTime.h" + + +// +// osiTime::getCurrent () +// +osiTime osiTime::getCurrent () +{ + int status; + struct timeval tv; + + status = gettimeofday (&tv, NULL); + assert (status==0); + + return osiTime(tv.tv_sec, tv.tv_usec * nSecPerUSec); +} + diff --git a/src/libCom/os/vxWorks/README b/src/libCom/os/vxWorks/README new file mode 100644 index 000000000..bbc0046b3 --- /dev/null +++ b/src/libCom/os/vxWorks/README @@ -0,0 +1,3 @@ + +The source files here are vxWorks dependent. + diff --git a/src/libCom/os/vxWorks/ipAddrToA.c b/src/libCom/os/vxWorks/ipAddrToA.c new file mode 100644 index 000000000..50b48243b --- /dev/null +++ b/src/libCom/os/vxWorks/ipAddrToA.c @@ -0,0 +1,78 @@ +/* $Id$ */ +/* + * Author: Jeff Hill + * Date: 04-05-94 + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * Modification Log: + * ----------------- + * .00 mm-dd-yy iii Comment + */ + +/* + * NOTES: + * 1) vxWorks so far does not have DNS support + * (and also has a non-standard host table interface) + * so we dont attempt to find the ascii host name equiv + * 2) We use inet_ntoa_b() here because inet_ntoa() isnt reentrant + */ +#include +#include +#include + +#include + +#include + +/* + * ipAddrToA () + */ +void ipAddrToA (const struct sockaddr_in *pInetAddr, + char *pBuf, const unsigned bufSize) +{ + char pName[INET_ADDR_LEN]; + const unsigned maxPortDigits = 16u; + char tmp[maxPortDigits+1]; + + + if (pInetAddr->sin_family != AF_INET) { + strncpy(pName, "UKN ADDR FAMILY", sizeof(pName)-1); + pName[sizeof(pName)-1u]='\0'; + tmp[0u] = '\0'; + } + else { + int port = ntohs(pInetAddr->sin_port); + inet_ntoa_b (pInetAddr->sin_addr, pName); + sprintf (tmp, "(%d)", port); + } + + /* + * force null termination + */ + strncpy(pBuf, pName, bufSize-1); + strncat(pBuf, tmp, bufSize-1); + pBuf[bufSize-1u] = '\0'; + + return; +} + diff --git a/src/libCom/os/vxWorks/osdTime.cc b/src/libCom/os/vxWorks/osdTime.cc new file mode 100644 index 000000000..8ade4fd85 --- /dev/null +++ b/src/libCom/os/vxWorks/osdTime.cc @@ -0,0 +1,26 @@ + + +#define epicsExportSharedSymbols +#include + + +#include +#include + +// +// osiTime::getCurrent () +// +osiTime osiTime::getCurrent () +{ + ULONG ticks; + ULONG sec; + ULONG nsec; + ULONG rate = sysClkRateGet(); + + ticks = tickGet(); + sec = ticks/rate; + nsec = (ticks%rate)*(nSecPerSec/rate); + + return osiTime(sec, nsec); +} +