installed

This commit is contained in:
Jeff Hill
1998-06-16 01:53:00 +00:00
parent b439063760
commit 8968c33bdb
8 changed files with 589 additions and 87 deletions

View File

@@ -0,0 +1,128 @@
/* bsdSockResource.c */
/* share/src/libCom/os/generic/$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
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define epicsExportSharedSymbols
#include "bsdSocketResource.h"
#include "epicsAssert.h"
/*
* NOOP
*/
int bsdSockAttach()
{
return 1;
}
/*
* NOOP
*/
void bsdSockRelease()
{
}
/*
* ipAddrToA()
* (convert IP address to ASCII host name)
*/
void epicsShareAPI ipAddrToA
(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
{
char *pString;
struct hostent *ent;
# define maxPortDigits 5u
if (bufSize<1) {
return;
}
if (paddr->sin_family!=AF_INET) {
strncpy(pBuf, "<Ukn Addr Type>", bufSize-1);
/*
* force null termination
*/
pBuf[bufSize-1] = '\0';
}
else {
ent = gethostbyaddr((char *) &paddr->sin_addr,
sizeof(paddr->sin_addr), AF_INET);
if(ent){
pString = ent->h_name;
}
else{
pString = inet_ntoa (paddr->sin_addr);
}
/*
* allow space for the port number
*/
if (bufSize>maxPortDigits+strlen(pString)) {
sprintf (pBuf, "%.*s:%u", bufSize-maxPortDigits-1,
pString, ntohs(paddr->sin_port));
}
else {
sprintf (pBuf, "%.*s", bufSize-1, pString);
}
}
}
/*
* hostToIPAddr ()
*/
epicsShareFunc int epicsShareAPI hostToIPAddr
(const char *pHostName, struct in_addr *pIPA)
{
struct hostent *phe;
phe = gethostbyname (pHostName);
if (phe && phe->h_addr_list[0]) {
if (phe->h_addrtype==AF_INET && phe->h_length<=sizeof(struct in_addr)) {
struct in_addr *pInAddrIn = (struct in_addr *) phe->h_addr_list[0];
*pIPA = *pInAddrIn;
/*
* success
*/
return 0;
}
}
/*
* return indicating an error
*/
return -1;
}

View File

@@ -0,0 +1,27 @@
#include <stdio.h>
#include <string.h>
#include "osiSock.h"
#define epicsExportSharedSymbols
#include "epicsAssert.h"
#include "osiSleep.h"
/*
* should work correctly on VMS, but there
* is probably a more efficent native call ...
*/
epicsShareFunc void epicsShareAPI osiSleep (unsigned sec, unsigned uSec)
{
int status;
struct timeval tval;
assert (uSec<1000000);
tval.tv_sec = sec;
tval.tv_usec = uSec;
status = select (0, NULL, NILL, NULL, &tval);
if (status<0) {
fprintf (stderr, "error from select in osiDelayMicroSec() was %s\n",
SOCKERRSTR);
}
}

View File

@@ -0,0 +1,200 @@
/*
* bsdSockResource.c
*
* WIN32 specific initialisation for bsd sockets,
* based on Chris Timossi's base/src/ca/windows_depend.c,
* and also further additions by Kay Kasemir when this was in
* dllmain.cc
*
* 7-1-97 -joh-
*
* 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
*
* Lawrence Berkley National Laboratory
*
* Modification Log:
* -----------------
*/
#ifndef _WIN32
#error This source is specific to WIN32
#endif
#include <stdio.h>
#include "epicsVersion.h"
#define epicsExportSharedSymbols
#include "bsdSocketResource.h"
static unsigned nAttached = 0;
static WSADATA WsaData; /* version of winsock */
epicsShareFunc unsigned epicsShareAPI wsaMajorVersion()
{
return (unsigned) LOBYTE( WsaData.wVersion );
}
/*
* bsdSockAttach()
*/
epicsShareFunc int epicsShareAPI bsdSockAttach()
{
int status;
if (nAttached) {
nAttached++;
return TRUE;
}
#if _DEBUG
/* for gui applications, setup console for error messages */
if (AllocConsole())
{
char title[256];
DWORD titleLength = GetConsoleTitle(title, sizeof(title));
if (titleLength) {
titleLength = strlen (title);
strncat (title, " " BASE_VERSION_STRING, sizeof(title));
}
else {
strncpy(title, BASE_VERSION_STRING, sizeof(title));
}
title[sizeof(title)-1]= '\0';
SetConsoleTitle(title);
freopen( "CONOUT$", "a", stderr );
}
#endif
/*
* attach to win sock
*/
status = WSAStartup(MAKEWORD(/*major*/2,/*minor*/2), &WsaData);
if (status != 0) {
fprintf(stderr,
"Unable to attach to windows sockets version 2. error=%d\n", status);
fprintf(stderr,
"A Windows Sockets II update for windows 95 is available at\n");
fprintf(stderr,
"http://www.microsoft.com/windows95/info/ws2.htm");
return FALSE;
}
# if _DEBUG
fprintf(stderr, "EPICS attached to winsock version %s\n", WsaData.szDescription);
# endif
nAttached = 1u;
return TRUE;
}
/*
* bsdSockRelease()
*/
epicsShareFunc void epicsShareAPI bsdSockRelease()
{
if (nAttached) {
if (--nAttached==0u) {
WSACleanup();
# if _DEBUG
fprintf(stderr, "EPICS released winsock version %s\n", WsaData.szDescription);
# endif
memset (&WsaData, '\0', sizeof(WsaData));
}
}
}
/*
* ipAddrToA()
* (convert IP address to ASCII host name)
*/
epicsShareFunc void epicsShareAPI ipAddrToA
(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
{
char *pString;
struct hostent *ent;
# define maxPortDigits 5u
if (bufSize<1) {
return;
}
if (paddr->sin_family!=AF_INET) {
strncpy(pBuf, "<Ukn Addr Type>", bufSize-1);
/*
* force null termination
*/
pBuf[bufSize-1] = '\0';
}
else {
ent = gethostbyaddr((char *) &paddr->sin_addr,
sizeof(paddr->sin_addr), AF_INET);
if(ent){
pString = ent->h_name;
}
else{
pString = inet_ntoa (paddr->sin_addr);
}
/*
* allow space for the port number
*/
if (bufSize>maxPortDigits+strlen(pString)) {
sprintf (pBuf, "%.*s:%u", bufSize-maxPortDigits-1,
pString, ntohs(paddr->sin_port));
}
else {
sprintf (pBuf, "%.*s", bufSize-1, pString);
}
}
}
/*
* hostToIPAddr ()
*/
epicsShareFunc int epicsShareAPI hostToIPAddr
(const char *pHostName, struct in_addr *pIPA)
{
struct hostent *phe;
phe = gethostbyname (pHostName);
if (phe && phe->h_addr_list[0]) {
if (phe->h_addrtype==AF_INET && phe->h_length<=sizeof(struct in_addr)) {
struct in_addr *pInAddrIn = (struct in_addr *) phe->h_addr_list[0];
*pIPA = *pInAddrIn;
/*
* success
*/
return 0;
}
}
/*
* return indicating an error
*/
return -1;
}

View File

@@ -0,0 +1,61 @@
/*
* Author: Jeff Hill
*/
/*
* ANSI C
*/
#include <stdio.h>
/*
* WIN32 specific
*/
#include <winsock2.h>
#include <ws2tcpip.h>
#include <process.h>
#include <mmsystem.h>
/*
* this does specify that winsock should be exported,
* but instead that EPICS winsock specific functions
* should be exported.
*/
#define epicsExportSharedSymbols
#include "bsdSocketResource.h"
/*
* getLastWSAErrorAsString()
*/
epicsShareFunc const char * epicsShareAPI getLastWSAErrorAsString()
{
static char errString[128];
static int init = 0;
/*
* unfortunately, this does not work ...
* and there is no obvious replacement ...
*/
#if 0
DWORD W32status;
W32status = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
WSAGetLastError (),
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
errString,
sizeof(errString)/sizeof(errString[0]),
NULL
);
if (W32status==0) {
sprintf (errString, "WIN32 Socket Library Error %d", WSAGetLastError ());
}
return errString;
#else
sprintf (errString, "WIN32 Socket Library Error %d", WSAGetLastError ());
return errString;
#endif
}

View File

@@ -0,0 +1,19 @@
#include <windows.h>
#define epicsExportSharedSymbols
#include "osiSleep.h"
epicsShareFunc void epicsShareAPI osiSleep (unsigned sec, unsigned uSec)
{
unsigned milliSec;
milliSec = uSec / 1000;
milliSec += sec * 1000;
if (milliSec==0u) {
milliSec = 1;
}
Sleep (milliSec); // time-out interval in milliseconds
}

View File

@@ -0,0 +1,128 @@
/* bsdSockResource.c */
/* share/src/libCom/os/generic/$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
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define epicsExportSharedSymbols
#include "bsdSocketResource.h"
#include "epicsAssert.h"
/*
* NOOP
*/
int bsdSockAttach()
{
return 1;
}
/*
* NOOP
*/
void bsdSockRelease()
{
}
/*
* ipAddrToA()
* (convert IP address to ASCII host name)
*/
void epicsShareAPI ipAddrToA
(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
{
char *pString;
struct hostent *ent;
# define maxPortDigits 5u
if (bufSize<1) {
return;
}
if (paddr->sin_family!=AF_INET) {
strncpy(pBuf, "<Ukn Addr Type>", bufSize-1);
/*
* force null termination
*/
pBuf[bufSize-1] = '\0';
}
else {
ent = gethostbyaddr((char *) &paddr->sin_addr,
sizeof(paddr->sin_addr), AF_INET);
if(ent){
pString = ent->h_name;
}
else{
pString = inet_ntoa (paddr->sin_addr);
}
/*
* allow space for the port number
*/
if (bufSize>maxPortDigits+strlen(pString)) {
sprintf (pBuf, "%.*s:%u", bufSize-maxPortDigits-1,
pString, ntohs(paddr->sin_port));
}
else {
sprintf (pBuf, "%.*s", bufSize-1, pString);
}
}
}
/*
* hostToIPAddr ()
*/
epicsShareFunc int epicsShareAPI hostToIPAddr
(const char *pHostName, struct in_addr *pIPA)
{
struct hostent *phe;
phe = gethostbyname (pHostName);
if (phe && phe->h_addr_list[0]) {
if (phe->h_addrtype==AF_INET && phe->h_length<=sizeof(struct in_addr)) {
struct in_addr *pInAddrIn = (struct in_addr *) phe->h_addr_list[0];
*pIPA = *pInAddrIn;
/*
* success
*/
return 0;
}
}
/*
* return indicating an error
*/
return -1;
}

View File

@@ -1,87 +0,0 @@
/* $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 <ctype.h>
#include <stdio.h>
#include <string.h>
#include "osiSock.h"
#define epicsExportSharedSymbols
#include "ipAddrToA.h"
/*
* ipAddrToA()
* (convert IP address to ASCII host name)
*/
void epicsShareAPI 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;
}

View File

@@ -0,0 +1,26 @@
#include <stdio.h>
#include <string.h>
#include "osiSock.h"
#define epicsExportSharedSymbols
#include "epicsAssert.h"
#include "osiSleep.h"
/*
* should work correctly on UNIX and VMS
*/
epicsShareFunc void epicsShareAPI osiSleep (unsigned sec, unsigned uSec)
{
int status;
struct timeval tval;
assert (uSec<1000000);
tval.tv_sec = sec;
tval.tv_usec = uSec;
status = select (0, NULL, NULL, NULL, &tval);
if (status<0) {
fprintf (stderr, "error from select in osiDelayMicroSec() was %s\n",
SOCKERRSTR);
}
}