This is Unofficial EPICS BASE Doxygen Site
osdSock.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /* This is needed for vxWorks 6.8 to prevent an obnoxious compiler warning */
11 #define _VSB_CONFIG_FILE <../lib/h/config/vsbConfig.h>
12 
13 #include <string.h>
14 #include <stdio.h>
15 
16 #ifndef vxWorks
17 #error this is a vxWorks specific source code
18 #endif
19 
20 #include <hostLib.h>
21 #include <inetLib.h>
22 
23 #include "errlog.h"
24 
25 #include "osiSock.h"
26 
28 {
29  return 1;
30 }
31 
33 {
34 }
35 
36 LIBCOM_API SOCKET epicsStdCall epicsSocketCreate (
37  int domain, int type, int protocol )
38 {
39  SOCKET sock = socket ( domain, type, protocol );
40  if ( sock < 0 ) {
41  sock = INVALID_SOCKET;
42  }
43  return sock;
44 }
45 
46 LIBCOM_API int epicsStdCall epicsSocketAccept (
47  int sock, struct sockaddr * pAddr, osiSocklen_t * addrlen )
48 {
49  int newSock = accept ( sock, pAddr, addrlen );
50  if ( newSock < 0 ) {
51  newSock = INVALID_SOCKET;
52  }
53  return newSock;
54 }
55 
56 LIBCOM_API void epicsStdCall epicsSocketDestroy ( SOCKET s )
57 {
58  int status = close ( s );
59  if ( status < 0 ) {
60  char buf [ 64 ];
61  epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
62  errlogPrintf (
63  "epicsSocketDestroy: failed to "
64  "close a socket because \"%s\"\n",
65  buf );
66  }
67 }
68 
69 /*
70  * ipAddrToHostName
71  */
72 LIBCOM_API unsigned epicsStdCall ipAddrToHostName
73  (const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
74 {
75  int status;
76  int errnoCopy = errno;
77  unsigned len;
78 
79  if (bufSize<1) {
80  return 0;
81  }
82 
83  if (bufSize>MAXHOSTNAMELEN) {
84  status = hostGetByAddr ((int)pAddr->s_addr, pBuf);
85  if (status==OK) {
86  pBuf[MAXHOSTNAMELEN] = '\0';
87  len = strlen (pBuf);
88  }
89  else {
90  len = 0;
91  }
92  }
93  else {
94  char name[MAXHOSTNAMELEN+1];
95  status = hostGetByAddr (pAddr->s_addr, name);
96  if (status==OK) {
97  strncpy (pBuf, name, bufSize);
98  pBuf[bufSize-1] = '\0';
99  len = strlen (pBuf);
100  }
101  else {
102  len = 0;
103  }
104  }
105 
106  errno = errnoCopy;
107 
108  return len;
109 }
110 
111 /*
112  * hostToIPAddr ()
113  */
114 LIBCOM_API int epicsStdCall
115 hostToIPAddr(const char *pHostName, struct in_addr *pIPA)
116 {
117  int addr = hostGetByName ( (char *) pHostName );
118  if ( addr == ERROR ) {
119  return -1;
120  }
121  pIPA->s_addr = (unsigned long) addr;
122 
123  /*
124  * success
125  */
126  return 0;
127 }
128 
LIBCOM_API void epicsStdCall epicsSocketDestroy(SOCKET s)
Definition: osdSock.c:117
#define INVALID_SOCKET
Definition: osdSock.h:32
pvd::Status status
int osiSocklen_t
Definition: osdSock.h:36
void osiSockRelease()
Definition: osdSock.c:62
pvd::StructureConstPtr type
LIBCOM_API int epicsStdCall hostToIPAddr(const char *pHostName, struct in_addr *pIPA)
Definition: osdSock.c:162
void epicsSocketConvertErrnoToString(char *pBuf, unsigned bufSize)
LIBCOM_API SOCKET epicsStdCall epicsSocketCreate(int domain, int type, int protocol)
Definition: osdSock.c:71
#define MAXHOSTNAMELEN
Definition: osdSock.h:46
LIBCOM_API int epicsStdCall epicsSocketAccept(int sock, struct sockaddr *pAddr, osiSocklen_t *addrlen)
Definition: osdSock.c:94
int SOCKET
Definition: osdSock.h:31
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
int osiSockAttach()
Definition: osdSock.c:54
LIBCOM_API unsigned epicsStdCall ipAddrToHostName(const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
Definition: osdSock.c:136