This is Unofficial EPICS BASE Doxygen Site
osdSock.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include "osiSock.h"
#include "errlog.h"
#include "epicsVersion.h"
+ Include dependency graph for osdSock.c:

Go to the source code of this file.

Macros

#define VC_EXTRALEAN
 
#define STRICT
 

Functions

LIBCOM_API unsigned epicsStdCall wsaMajorVersion ()
 
LIBCOM_API int epicsStdCall osiSockAttach ()
 
LIBCOM_API void epicsStdCall osiSockRelease ()
 
LIBCOM_API SOCKET epicsStdCall epicsSocketCreate (int domain, int type, int protocol)
 
LIBCOM_API int epicsStdCall epicsSocketAccept (int sock, struct sockaddr *pAddr, osiSocklen_t *addrlen)
 
LIBCOM_API void epicsStdCall epicsSocketDestroy (SOCKET s)
 
LIBCOM_API unsigned epicsStdCall ipAddrToHostName (const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
 
LIBCOM_API int epicsStdCall hostToIPAddr (const char *pHostName, struct in_addr *pIPA)
 

Macro Definition Documentation

#define STRICT

Definition at line 31 of file osdSock.c.

#define VC_EXTRALEAN

Definition at line 30 of file osdSock.c.

Function Documentation

LIBCOM_API int epicsStdCall epicsSocketAccept ( int  sock,
struct sockaddr *  pAddr,
osiSocklen_t addrlen 
)

Definition at line 122 of file osdSock.c.

124 {
125  return accept ( sock, pAddr, addrlen );
126 }
LIBCOM_API SOCKET epicsStdCall epicsSocketCreate ( int  domain,
int  type,
int  protocol 
)

Definition at line 116 of file osdSock.c.

118 {
119  return socket ( domain, type, protocol );
120 }
pvd::StructureConstPtr type
LIBCOM_API void epicsStdCall epicsSocketDestroy ( SOCKET  s)

Definition at line 128 of file osdSock.c.

129 {
130  int status = closesocket ( s );
131  if ( status < 0 ) {
132  char buf [ 64 ];
133  epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
134  errlogPrintf (
135  "epicsSocketDestroy: failed to "
136  "close a socket because \"%s\"\n", buf );
137  }
138 }
pvd::Status status
void epicsSocketConvertErrnoToString(char *pBuf, unsigned bufSize)
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API int epicsStdCall hostToIPAddr ( const char *  pHostName,
struct in_addr *  pIPA 
)

Definition at line 165 of file osdSock.c.

166 {
167  struct hostent *phe;
168 
169  phe = gethostbyname (pHostName);
170  if (phe && phe->h_addr_list[0]) {
171  if (phe->h_addrtype==AF_INET && phe->h_length<=sizeof(struct in_addr)) {
172  struct in_addr *pInAddrIn = (struct in_addr *) phe->h_addr_list[0];
173 
174  *pIPA = *pInAddrIn;
175 
176  /*
177  * success
178  */
179  return 0;
180  }
181  }
182 
183  /*
184  * return indicating an error
185  */
186  return -1;
187 }
LIBCOM_API unsigned epicsStdCall ipAddrToHostName ( const struct in_addr *  pAddr,
char *  pBuf,
unsigned  bufSize 
)

Definition at line 144 of file osdSock.c.

145 {
146  struct hostent *ent;
147 
148  if (bufSize<1) {
149  return 0;
150  }
151 
152  ent = gethostbyaddr((char *) pAddr, sizeof (*pAddr), AF_INET);
153  if (ent) {
154  strncpy (pBuf, ent->h_name, bufSize);
155  pBuf[bufSize-1] = '\0';
156  return strlen (pBuf);
157  }
158  return 0;
159 }
LIBCOM_API int epicsStdCall osiSockAttach ( void  )

Definition at line 49 of file osdSock.c.

50 {
51  int status;
52 
53  if (nAttached) {
54  nAttached++;
55  return TRUE;
56  }
57 
58 #if _DEBUG
59  /* for gui applications, setup console for error messages */
60  if (AllocConsole())
61  {
62  char title[256];
63  DWORD titleLength = GetConsoleTitle(title, sizeof(title));
64  if (titleLength) {
65  titleLength = strlen (title);
66  strncat (title, " " EPICS_VERSION_STRING, sizeof(title));
67  }
68  else {
69  strncpy(title, EPICS_VERSION_STRING, sizeof(title));
70  }
71  title[sizeof(title)-1]= '\0';
72  SetConsoleTitle(title);
73  freopen( "CONOUT$", "a", stderr );
74  }
75 #endif
76 
77  /*
78  * attach to win sock
79  */
80  status = WSAStartup(MAKEWORD(/*major*/2,/*minor*/2), &WsaData);
81  if (status != 0) {
82  fprintf(stderr,
83  "Unable to attach to windows sockets version 2. error=%d\n", status);
84  fprintf(stderr,
85  "A Windows Sockets II update for windows 95 is available at\n");
86  fprintf(stderr,
87  "http://www.microsoft.com/windows95/info/ws2.htm");
88  return FALSE;
89  }
90 
91 # if defined ( _DEBUG ) && 0
92  fprintf(stderr, "EPICS attached to winsock version %s\n", WsaData.szDescription);
93 # endif
94 
95  nAttached = 1u;
96 
97  return TRUE;
98 }
#define FALSE
Definition: dbDefs.h:32
pvd::Status status
#define TRUE
Definition: dbDefs.h:27
#define stderr
Definition: epicsStdio.h:32
LIBCOM_API void epicsStdCall osiSockRelease ( void  )

Definition at line 103 of file osdSock.c.

104 {
105  if (nAttached) {
106  if (--nAttached==0u) {
107  WSACleanup();
108 # if defined ( _DEBUG ) && 0
109  fprintf(stderr, "EPICS released winsock version %s\n", WsaData.szDescription);
110 # endif
111  memset (&WsaData, '\0', sizeof(WsaData));
112  }
113  }
114 }
#define stderr
Definition: epicsStdio.h:32
LIBCOM_API unsigned epicsStdCall wsaMajorVersion ( )

Definition at line 41 of file osdSock.c.

42 {
43  return (unsigned) LOBYTE( WsaData.wVersion );
44 }