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