This is Unofficial EPICS BASE Doxygen Site
osiSock.h
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 /*
11  * socket support library API def
12  *
13  * 7-1-97 -joh-
14  */
15 #ifndef osiSockh
16 #define osiSockh
17 
18 #include "libComAPI.h"
19 #include "osdSock.h"
20 #include "ellLib.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct sockaddr;
27 struct sockaddr_in;
28 struct in_addr;
29 
30 LIBCOM_API SOCKET epicsStdCall epicsSocketCreate (
31  int domain, int type, int protocol );
32 LIBCOM_API int epicsStdCall epicsSocketAccept (
33  int sock, struct sockaddr * pAddr, osiSocklen_t * addrlen );
34 LIBCOM_API void epicsStdCall epicsSocketDestroy (
35  SOCKET );
36 LIBCOM_API void epicsStdCall
38 LIBCOM_API void epicsStdCall
40 
41 /*
42  * Fortunately, on most systems the combination of a shutdown of both
43  * directions and or a signal is sufficent to interrupt a blocking send,
44  * receive, or connect call. For odd ball systems this is stubbed out in the
45  * osi area.
46  */
50  esscimqi_socketSigAlarmRequired /* NO LONGER USED/SUPPORTED */
51 };
54 
55 #ifdef EPICS_PRIVATE_API
56 /*
57  * Some systems (e.g Linux and Windows 10) allow to check the amount
58  * of unsent data in the output queue.
59  * Returns -1 if the information is not available.
60  */
61 LIBCOM_API int epicsSocketUnsentCount(SOCKET sock);
62 #endif
63 
64 /*
65  * convert socket address to ASCII in this order
66  * 1) look for matching host name and typically add trailing IP port
67  * 2) failing that, convert to raw ascii address (typically this is a
68  * dotted IP address with trailing port)
69  * 3) failing that, writes "<Ukn Addr Type>" into pBuf
70  *
71  * returns the number of character elements stored in buffer not
72  * including the null termination, but always writes at least a
73  * null ternminater in the string (if bufSize >= 1)
74  */
75 LIBCOM_API unsigned epicsStdCall sockAddrToA (
76  const struct sockaddr * paddr, char * pBuf, unsigned bufSize );
77 
78 /*
79  * convert IP address to ASCII in this order
80  * 1) look for matching host name and add trailing port
81  * 2) convert to raw dotted IP address with trailing port
82  *
83  * returns the number of character elements stored in buffer not
84  * including the null termination, but always writes at least a
85  * null ternminater in the string (if bufSize >= 1)
86  */
87 LIBCOM_API unsigned epicsStdCall ipAddrToA (
88  const struct sockaddr_in * pInetAddr, char * pBuf, unsigned bufSize );
89 
90 /*
91  * sockAddrToDottedIP ()
92  * typically convert to raw dotted IP address with trailing port
93  *
94  * returns the number of character elements stored in buffer not
95  * including the null termination, but always writes at least a
96  * null ternminater in the string (if bufSize >= 1)
97  */
98 LIBCOM_API unsigned epicsStdCall sockAddrToDottedIP (
99  const struct sockaddr * paddr, char * pBuf, unsigned bufSize );
100 
101 /*
102  * ipAddrToDottedIP ()
103  * convert to raw dotted IP address with trailing port
104  *
105  * returns the number of character elements stored in buffer not
106  * including the null termination, but always writes at least a
107  * null ternminater in the string (if bufSize >= 1)
108  */
109 LIBCOM_API unsigned epicsStdCall ipAddrToDottedIP (
110  const struct sockaddr_in * paddr, char * pBuf, unsigned bufSize );
111 
112 /*
113  * convert inet address to a host name string
114  *
115  * returns the number of character elements stored in buffer not
116  * including the null termination. This will be zero if a matching
117  * host name cant be found.
118  *
119  * there are many OS specific implementation stubs for this routine
120  */
121 LIBCOM_API unsigned epicsStdCall ipAddrToHostName (
122  const struct in_addr * pAddr, char * pBuf, unsigned bufSize );
123 
124 /*
125  * attempt to convert ASCII string to an IP address in this order
126  * 1) look for traditional doted ip with optional port
127  * 2) look for raw number form of ip address with optional port
128  * 3) look for valid host name with optional port
129  */
130 LIBCOM_API int epicsStdCall aToIPAddr
131  ( const char * pAddrString, unsigned short defaultPort, struct sockaddr_in * pIP);
132 
133 /*
134  * attempt to convert ASCII host name string with optional port to an IP address
135  */
136 LIBCOM_API int epicsStdCall hostToIPAddr
137  (const char *pHostName, struct in_addr *pIPA);
138 /*
139  * attach to BSD socket library
140  */
141 LIBCOM_API int epicsStdCall osiSockAttach (void); /* returns T if success, else F */
142 
143 /*
144  * release BSD socket library
145  */
146 LIBCOM_API void epicsStdCall osiSockRelease (void);
147 
148 /*
149  * convert socket error numbers to a string
150  */
151 LIBCOM_API void epicsSocketConvertErrorToString (
152  char * pBuf, unsigned bufSize, int error );
153 LIBCOM_API void epicsSocketConvertErrnoToString (
154  char * pBuf, unsigned bufSize );
155 
156 typedef union osiSockAddr {
157  struct sockaddr_in ia;
158  struct sockaddr sa;
159 } osiSockAddr;
160 
161 typedef struct osiSockAddrNode {
163  osiSockAddr addr;
165 
166 /*
167  * sockAddrAreIdentical()
168  * (returns true if addresses are identical)
169  */
170 LIBCOM_API int epicsStdCall sockAddrAreIdentical
171  ( const osiSockAddr * plhs, const osiSockAddr * prhs );
172 
173 /*
174  * osiSockDiscoverBroadcastAddresses ()
175  * Returns the broadcast addresses of each network interface found.
176  *
177  * This routine is provided with the address of an ELLLIST, a socket,
178  * a destination port number, and a match address. When the
179  * routine returns there will be one additional entry
180  * (an osiSockAddrNode) in the list for each network interface found that
181  * is up and isnt a loop back interface (match addr is INADDR_ANY),
182  * or only the interfaces that match the specified addresses (match addr
183  * is other than INADDR_ANY). If the interface supports broadcasting
184  * then add its broadcast address to the list. If the interface is a
185  * point to point link then add the destination address of the point to
186  * point link to the list.
187  *
188  * Any mutex locking required to protect pList is applied externally.
189  *
190  */
191 LIBCOM_API void epicsStdCall osiSockDiscoverBroadcastAddresses
192  (ELLLIST *pList, SOCKET socket, const osiSockAddr *pMatchAddr);
193 
194 /*
195  * osiLocalAddr ()
196  * Returns the osiSockAddr of the first non-loopback interface found
197  * that is operational (up flag is set). If no valid address can be
198  * located then return an osiSockAddr with the address family set to
199  * unspecified (AF_UNSPEC).
200  *
201  * Unfortunately in EPICS 3.13 beta 11 and before the CA
202  * repeater would not always allow the loopback address
203  * as a local client address so current clients alternate
204  * between the address of the first non-loopback interface
205  * found and the loopback addresss when subscribing with
206  * the CA repeater until all CA repeaters have been updated
207  * to current code. After all CA repeaters have been restarted
208  * this osi interface can be eliminated.
209  */
210 LIBCOM_API osiSockAddr epicsStdCall osiLocalAddr (SOCKET socket);
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif /* ifndef osiSockh */
osiSockAddr addr
Definition: osiSock.h:163
LIBCOM_API osiSockAddr epicsStdCall osiLocalAddr(SOCKET socket)
Definition: osdNetIntf.c:347
int osiSocklen_t
Definition: osdSock.h:36
struct sockaddr sa
Definition: osiSock.h:158
int epicsSocketUnsentCount(SOCKET sock)
struct sockaddr_in ia
Definition: osiSock.h:157
pvd::StructureConstPtr type
LIBCOM_API int epicsStdCall sockAddrAreIdentical(const osiSockAddr *plhs, const osiSockAddr *prhs)
Definition: osiSock.c:35
LIBCOM_API int epicsStdCall aToIPAddr(const char *pAddrString, unsigned short defaultPort, struct sockaddr_in *pIP)
Definition: aToIPAddr.c:78
LIBCOM_API int epicsStdCall osiSockAttach(void)
Definition: osdSock.c:54
LIBCOM_API unsigned epicsStdCall ipAddrToA(const struct sockaddr_in *pInetAddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:92
epicsSocketSystemCallInterruptMechanismQueryInfo
Definition: osiSock.h:47
LIBCOM_API SOCKET epicsStdCall epicsSocketCreate(int domain, int type, int protocol)
Definition: osdSock.c:71
A doubly-linked list library.
LIBCOM_API void epicsSocketConvertErrorToString(char *pBuf, unsigned bufSize, int error)
LIBCOM_API unsigned epicsStdCall ipAddrToDottedIP(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:144
LIBCOM_API unsigned epicsStdCall sockAddrToDottedIP(const struct sockaddr *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:118
bucket ** plhs
Definition: reader.c:37
LIBCOM_API int epicsStdCall hostToIPAddr(const char *pHostName, struct in_addr *pIPA)
Definition: osdSock.c:162
int SOCKET
Definition: osdSock.h:31
List node type.
Definition: ellLib.h:45
LIBCOM_API enum epicsSocketSystemCallInterruptMechanismQueryInfo epicsSocketSystemCallInterruptMechanismQuery()
ELLNODE node
Definition: osiSock.h:162
LIBCOM_API void epicsStdCall epicsSocketEnableAddressUseForDatagramFanout(SOCKET s)
struct osiSockAddrNode osiSockAddrNode
LIBCOM_API unsigned epicsStdCall sockAddrToA(const struct sockaddr *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:61
LIBCOM_API int epicsStdCall epicsSocketAccept(int sock, struct sockaddr *pAddr, osiSocklen_t *addrlen)
Definition: osdSock.c:94
LIBCOM_API void epicsStdCall epicsSocketDestroy(SOCKET)
Definition: osdSock.c:117
List header type.
Definition: ellLib.h:56
LIBCOM_API void epicsSocketConvertErrnoToString(char *pBuf, unsigned bufSize)
LIBCOM_API void epicsStdCall osiSockDiscoverBroadcastAddresses(ELLLIST *pList, SOCKET socket, const osiSockAddr *pMatchAddr)
Definition: osdNetIntf.c:68
LIBCOM_API unsigned epicsStdCall ipAddrToHostName(const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
Definition: osdSock.c:136
LIBCOM_API void epicsStdCall epicsSocketEnableAddressReuseDuringTimeWaitState(SOCKET s)
LIBCOM_API void epicsStdCall osiSockRelease(void)
Definition: osdSock.c:62
union osiSockAddr osiSockAddr