This is Unofficial EPICS BASE Doxygen Site
osdSock.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include "epicsThread.h"
#include "epicsEvent.h"
#include "epicsMutex.h"
#include "osiSock.h"
#include "epicsAssert.h"
#include "errlog.h"
+ Include dependency graph for osdSock.c:

Go to the source code of this file.

Functions

int osiSockAttach ()
 
void 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)
 

Function Documentation

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

Definition at line 94 of file osdSock.c.

96 {
97  int newSock = accept ( sock, pAddr, addrlen );
98  if ( newSock < 0 ) {
99  newSock = INVALID_SOCKET;
100  }
101  else {
102  int status = fcntl ( newSock, F_SETFD, FD_CLOEXEC );
103  if ( status < 0 ) {
104  char buf [ 64 ];
105  epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
106  errlogPrintf (
107  "epicsSocketCreate: failed to "
108  "fcntl FD_CLOEXEC because \"%s\"\n",
109  buf );
110  close ( newSock );
111  newSock = INVALID_SOCKET;
112  }
113  }
114  return newSock;
115 }
#define INVALID_SOCKET
Definition: osdSock.h:32
pvd::Status status
void epicsSocketConvertErrnoToString(char *pBuf, unsigned bufSize)
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API SOCKET epicsStdCall epicsSocketCreate ( int  domain,
int  type,
int  protocol 
)

Definition at line 71 of file osdSock.c.

73 {
74  SOCKET sock = socket ( domain, type, protocol );
75  if ( sock < 0 ) {
76  sock = INVALID_SOCKET;
77  }
78  else {
79  int status = fcntl ( sock, F_SETFD, FD_CLOEXEC );
80  if ( status < 0 ) {
81  char buf [ 64 ];
82  epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
83  errlogPrintf (
84  "epicsSocketCreate: failed to "
85  "fcntl FD_CLOEXEC because \"%s\"\n",
86  buf );
87  close ( sock );
88  sock = INVALID_SOCKET;
89  }
90  }
91  return sock;
92 }
#define INVALID_SOCKET
Definition: osdSock.h:32
pvd::Status status
pvd::StructureConstPtr type
void epicsSocketConvertErrnoToString(char *pBuf, unsigned bufSize)
int SOCKET
Definition: osdSock.h:31
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API void epicsStdCall epicsSocketDestroy ( SOCKET  s)

Definition at line 117 of file osdSock.c.

118 {
119  int status = close ( s );
120  if ( status < 0 ) {
121  char buf [ 64 ];
122  epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
123  errlogPrintf (
124  "epicsSocketDestroy: failed to "
125  "close a socket because \"%s\"\n",
126  buf );
127  }
128 }
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 162 of file osdSock.c.

163 {
164  struct hostent *phe;
165  int ret = -1;
166 
167  lockInfo ();
168  phe = gethostbyname (pHostName);
169  if (phe && phe->h_addr_list[0]) {
170  if (phe->h_addrtype==AF_INET && phe->h_length<=sizeof(struct in_addr)) {
171  struct in_addr *pInAddrIn = (struct in_addr *) phe->h_addr_list[0];
172 
173  *pIPA = *pInAddrIn;
174  ret = 0;
175  }
176  }
177  unlockInfo ();
178  return ret;
179 }
LIBCOM_API unsigned epicsStdCall ipAddrToHostName ( const struct in_addr *  pAddr,
char *  pBuf,
unsigned  bufSize 
)

Definition at line 136 of file osdSock.c.

137 {
138  struct hostent *ent;
139  int ret = 0;
140 
141  if (bufSize<1) {
142  return 0;
143  }
144 
145  lockInfo ();
146  ent = gethostbyaddr((const char *) pAddr, sizeof (*pAddr), AF_INET);
147  if (ent) {
148  strncpy (pBuf, ent->h_name, bufSize);
149  pBuf[bufSize-1] = '\0';
150  ret = strlen (pBuf);
151  }
152  unlockInfo ();
153  return ret;
154 }
int osiSockAttach ( void  )

Definition at line 54 of file osdSock.c.

55 {
56  return 1;
57 }
void osiSockRelease ( void  )

Definition at line 62 of file osdSock.c.

63 {
64 }