This is Unofficial EPICS BASE Doxygen Site
osiSock.h File Reference
#include "libComAPI.h"
#include "osdSock.h"
#include "ellLib.h"
+ Include dependency graph for osiSock.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  osiSockAddr
 
struct  osiSockAddrNode
 

Typedefs

typedef union osiSockAddr osiSockAddr
 
typedef struct osiSockAddrNode osiSockAddrNode
 

Enumerations

enum  epicsSocketSystemCallInterruptMechanismQueryInfo { esscimqi_socketCloseRequired, esscimqi_socketBothShutdownRequired, esscimqi_socketSigAlarmRequired }
 

Functions

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)
 
LIBCOM_API void epicsStdCall epicsSocketEnableAddressReuseDuringTimeWaitState (SOCKET s)
 
LIBCOM_API void epicsStdCall epicsSocketEnableAddressUseForDatagramFanout (SOCKET s)
 
LIBCOM_API enum epicsSocketSystemCallInterruptMechanismQueryInfo epicsSocketSystemCallInterruptMechanismQuery ()
 
LIBCOM_API unsigned epicsStdCall sockAddrToA (const struct sockaddr *paddr, char *pBuf, unsigned bufSize)
 
LIBCOM_API unsigned epicsStdCall ipAddrToA (const struct sockaddr_in *pInetAddr, char *pBuf, unsigned bufSize)
 
LIBCOM_API unsigned epicsStdCall sockAddrToDottedIP (const struct sockaddr *paddr, char *pBuf, unsigned bufSize)
 
LIBCOM_API unsigned epicsStdCall ipAddrToDottedIP (const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
 
LIBCOM_API unsigned epicsStdCall ipAddrToHostName (const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
 
LIBCOM_API int epicsStdCall aToIPAddr (const char *pAddrString, unsigned short defaultPort, struct sockaddr_in *pIP)
 
LIBCOM_API int epicsStdCall hostToIPAddr (const char *pHostName, struct in_addr *pIPA)
 
LIBCOM_API int epicsStdCall osiSockAttach (void)
 
LIBCOM_API void epicsStdCall osiSockRelease (void)
 
LIBCOM_API void epicsSocketConvertErrorToString (char *pBuf, unsigned bufSize, int error)
 
LIBCOM_API void epicsSocketConvertErrnoToString (char *pBuf, unsigned bufSize)
 
LIBCOM_API int epicsStdCall sockAddrAreIdentical (const osiSockAddr *plhs, const osiSockAddr *prhs)
 
LIBCOM_API void epicsStdCall osiSockDiscoverBroadcastAddresses (ELLLIST *pList, SOCKET socket, const osiSockAddr *pMatchAddr)
 
LIBCOM_API osiSockAddr epicsStdCall osiLocalAddr (SOCKET socket)
 

Typedef Documentation

typedef union osiSockAddr osiSockAddr

Enumeration Type Documentation

Enumerator
esscimqi_socketCloseRequired 
esscimqi_socketBothShutdownRequired 
esscimqi_socketSigAlarmRequired 

Definition at line 47 of file osiSock.h.

Function Documentation

LIBCOM_API int epicsStdCall aToIPAddr ( const char *  pAddrString,
unsigned short  defaultPort,
struct sockaddr_in *  pIP 
)

Definition at line 78 of file aToIPAddr.c.

80 {
81  int status;
82  unsigned addr[4];
83  unsigned long rawAddr;
84  /*
85  * !! change n elements here requires change in format below !!
86  */
87  char hostName[512];
88  char dummy[8];
89  unsigned port;
90  struct in_addr ina;
91 
92  /*
93  * dotted ip addresses
94  */
95  status = sscanf ( pAddrString, " %u . %u . %u . %u %7s ",
96  addr, addr+1u, addr+2u, addr+3u, dummy );
97  if ( status == 4 ) {
98  if ( addrArrayToUL ( addr, NELEMENTS ( addr ), & ina ) < 0 ) {
99  return -1;
100  }
101  port = defaultPort;
102  return initIPAddr ( ina, port, pIP );
103  }
104 
105  /*
106  * dotted ip addresses and port
107  */
108  status = sscanf ( pAddrString, " %u . %u . %u . %u : %u %7s",
109  addr, addr+1u, addr+2u, addr+3u, &port, dummy );
110  if ( status >= 5 ) {
111  if ( status > 5 ) {
112  /*
113  * valid at the start but detritus on the end
114  */
115  return -1;
116  }
117  if ( addrArrayToUL ( addr, NELEMENTS ( addr ), &ina ) < 0 ) {
118  return -1;
119  }
120  return initIPAddr ( ina, port, pIP );
121  }
122 
123  /*
124  * IP address as a raw number
125  */
126  status = sscanf ( pAddrString, " %lu %7s ", &rawAddr, dummy );
127  if ( status == 1 ) {
128  if ( rawAddr > 0xffffffff ) {
129  return -1;
130  }
131  port = defaultPort;
132  {
133  epicsUInt32 rawAddr_32 = ( epicsUInt32 ) rawAddr;
134  ina.s_addr = htonl ( rawAddr_32 );
135  return initIPAddr ( ina, port, pIP );
136  }
137  }
138 
139  /*
140  * IP address as a raw number, and port
141  */
142  status = sscanf ( pAddrString, " %lu : %u %7s ", &rawAddr, &port, dummy );
143  if ( status >= 2 ) {
144  if ( status > 2 ) {
145  /*
146  * valid at the start but detritus on the end
147  */
148  return -1;
149  }
150  if ( rawAddr > 0xffffffff ) {
151  return -1;
152  }
153  {
154  epicsUInt32 rawAddr_32 = ( epicsUInt32 ) rawAddr;
155  ina.s_addr = htonl ( rawAddr_32 );
156  return initIPAddr ( ina, port, pIP );
157  }
158  }
159 
160 
161  /*
162  * host name string
163  */
164  status = sscanf ( pAddrString, " %511[^:] %s ", hostName, dummy );
165  if ( status == 1 ) {
166  port = defaultPort;
167  status = hostToIPAddr ( hostName, &ina );
168  if ( status == 0 ) {
169  return initIPAddr ( ina, port, pIP );
170  }
171  }
172 
173  /*
174  * host name string, and port
175  */
176  status = sscanf ( pAddrString, " %511[^:] : %u %s ", hostName,
177  &port, dummy );
178  if ( status >= 2 ) {
179  if ( status > 2 ) {
180  /*
181  * valid at the start but detritus on the end
182  */
183  return -1;
184  }
185  status = hostToIPAddr ( hostName, &ina );
186  if ( status == 0 ) {
187  return initIPAddr ( ina, port, pIP );
188  }
189  }
190 
191  return -1;
192 }
pvd::Status status
LIBCOM_API int epicsStdCall hostToIPAddr(const char *pHostName, struct in_addr *pIPA)
Definition: osdSock.c:162
unsigned int epicsUInt32
Definition: epicsTypes.h:43
#define NELEMENTS(A)
Definition: aToIPAddr.c:21
epics::pvData::PVStructurePtr dummy
Definition: pvAccess.cpp:72
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 void epicsSocketConvertErrnoToString ( char *  pBuf,
unsigned  bufSize 
)

Definition at line 35 of file epicsSocketConvertErrnoToString.cpp.

37 {
38  epicsSocketConvertErrorToString ( pBuf, bufSize, SOCKERRNO );
39 }
#define SOCKERRNO
Definition: osdSock.h:33
void epicsSocketConvertErrorToString(char *pBuf, unsigned bufSize, int theSockError)
LIBCOM_API void epicsSocketConvertErrorToString ( char *  pBuf,
unsigned  bufSize,
int  error 
)

Definition at line 23 of file epicsSocketConvertErrnoToString.cpp.

25 {
26  if ( bufSize ) {
27  strncpy ( pBuf, strerror ( theSockError ), bufSize );
28  pBuf[bufSize-1] = '\0';
29  }
30 }
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  )

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 void epicsStdCall epicsSocketEnableAddressReuseDuringTimeWaitState ( SOCKET  s)

Definition at line 23 of file osdSockAddrReuse.cpp.

24 {
25  int yes = true;
26  int status;
27  status = setsockopt ( s, SOL_SOCKET, SO_REUSEADDR,
28  (char *) & yes, sizeof ( yes ) );
29  if ( status < 0 ) {
30  errlogPrintf (
31  "epicsSocketEnableAddressReuseDuringTimeWaitState: "
32  "unable to set SO_REUSEADDR?\n");
33  }
34 }
pvd::Status status
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API void epicsStdCall epicsSocketEnableAddressUseForDatagramFanout ( SOCKET  s)

Definition at line 50 of file osdSockAddrReuse.cpp.

51 {
52 #define DOIT(sock, opt) setfanout(sock, opt, #opt)
53 #ifdef SO_REUSEPORT
54  DOIT(s, SO_REUSEPORT);
55 #endif
56  DOIT(s, SO_REUSEADDR);
57 #undef DOIT
58 }
#define DOIT(sock, opt)
LIBCOM_API enum epicsSocketSystemCallInterruptMechanismQueryInfo epicsSocketSystemCallInterruptMechanismQuery ( )

Definition at line 18 of file systemCallIntMech.cpp.

19 {
20 #if (CYGWIN_VERSION_DLL_MAJOR == 1007) && (CYGWIN_VERSION_DLL_MINOR < 15)
21  // Behaviour changed in early Cygwin 1.7 releases, reverted later.
23 #else
25 #endif
26 }
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 ipAddrToA ( const struct sockaddr_in *  pInetAddr,
char *  pBuf,
unsigned  bufSize 
)

Definition at line 92 of file osiSock.c.

94 {
95  unsigned len = ipAddrToHostName (
96  & paddr->sin_addr, pBuf, bufSize );
97  if ( len == 0 ) {
98  len = ipAddrToDottedIP ( paddr, pBuf, bufSize );
99  }
100  else {
101  unsigned reducedSize = bufSize - len;
102  int status = epicsSnprintf (
103  &pBuf[len], reducedSize, ":%hu",
104  ntohs (paddr->sin_port) );
105  if ( status > 0 ) {
106  unsigned portSize = (unsigned) status;
107  if ( portSize < reducedSize ) {
108  len += portSize;
109  }
110  }
111  }
112  return len;
113 }
pvd::Status status
LIBCOM_API unsigned epicsStdCall ipAddrToHostName(const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
Definition: osdSock.c:136
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
unsigned epicsStdCall ipAddrToDottedIP(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:144
LIBCOM_API unsigned epicsStdCall ipAddrToDottedIP ( const struct sockaddr_in *  paddr,
char *  pBuf,
unsigned  bufSize 
)

Definition at line 144 of file osiSock.c.

146 {
147  static const char * pErrStr = "<IPA>";
148  unsigned chunk[nDigitsDottedIP];
149  unsigned addr = ntohl ( paddr->sin_addr.s_addr );
150  unsigned strLen;
151  unsigned i;
152  int status;
153 
154  if ( bufSize == 0u ) {
155  return 0u;
156  }
157 
158  for ( i = 0; i < nDigitsDottedIP; i++ ) {
159  chunk[i] = addr & makeMask ( chunkSize );
160  addr >>= chunkSize;
161  }
162 
163  /*
164  * inet_ntoa() isnt used because it isnt thread safe
165  * (and the replacements are not standardized)
166  */
167  status = epicsSnprintf (
168  pBuf, bufSize, "%u.%u.%u.%u:%hu",
169  chunk[3], chunk[2], chunk[1], chunk[0],
170  ntohs ( paddr->sin_port ) );
171  if ( status > 0 ) {
172  strLen = ( unsigned ) status;
173  if ( strLen < bufSize - 1 ) {
174  return strLen;
175  }
176  }
177  strLen = strlen ( pErrStr );
178  if ( strLen < bufSize ) {
179  strcpy ( pBuf, pErrStr );
180  return strLen;
181  }
182  else {
183  strncpy ( pBuf, pErrStr, bufSize );
184  pBuf[bufSize-1] = '\0';
185  return bufSize - 1u;
186  }
187 }
pvd::Status status
int i
Definition: scan.c:967
#define chunkSize
Definition: osiSock.c:26
#define nDigitsDottedIP
Definition: osiSock.c:25
#define makeMask(NBITS)
Definition: osiSock.c:28
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
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 }
LIBCOM_API osiSockAddr epicsStdCall osiLocalAddr ( SOCKET  socket)

Definition at line 347 of file osdNetIntf.c.

348 {
349  epicsThreadOnce(&osiLocalAddrId, osiLocalAddrOnce, &socket);
350  return osiLocalAddrResult;
351 }
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API int epicsStdCall osiSockAttach ( void  )

Definition at line 54 of file osdSock.c.

55 {
56  return 1;
57 }
LIBCOM_API void epicsStdCall osiSockDiscoverBroadcastAddresses ( ELLLIST pList,
SOCKET  socket,
const osiSockAddr pMatchAddr 
)

Definition at line 68 of file osdNetIntf.c.

69 {
70  static const unsigned nelem = 100;
71  int status;
72  struct ifconf ifconf;
73  struct ifreq *pIfreqList;
74  struct ifreq *pIfreqListEnd;
75  struct ifreq *pifreq;
76  struct ifreq *pnextifreq;
77  osiSockAddrNode *pNewNode;
78 
79  if ( pMatchAddr->sa.sa_family == AF_INET ) {
80  if ( pMatchAddr->ia.sin_addr.s_addr == htonl (INADDR_LOOPBACK) ) {
81  pNewNode = (osiSockAddrNode *) calloc (1, sizeof (*pNewNode) );
82  if ( pNewNode == NULL ) {
83  errlogPrintf ( "osiSockDiscoverBroadcastAddresses(): no memory available for configuration\n" );
84  return;
85  }
86  pNewNode->addr.ia.sin_family = AF_INET;
87  pNewNode->addr.ia.sin_port = htons ( 0 );
88  pNewNode->addr.ia.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
89  ellAdd ( pList, &pNewNode->node );
90  return;
91  }
92  }
93 
94  /*
95  * use pool so that we avoid using too much stack space
96  *
97  * nelem is set to the maximum interfaces
98  * on one machine here
99  */
100  pIfreqList = (struct ifreq *) calloc ( nelem, sizeof(*pifreq) );
101  if (!pIfreqList) {
102  errlogPrintf ("osiSockDiscoverBroadcastAddresses(): no memory to complete request\n");
103  return;
104  }
105 
106  ifconf.ifc_len = nelem * sizeof(*pifreq);
107  ifconf.ifc_req = pIfreqList;
108  status = socket_ioctl (socket, SIOCGIFCONF, &ifconf);
109  if (status < 0 || ifconf.ifc_len == 0) {
110  errlogPrintf ("osiSockDiscoverBroadcastAddresses(): unable to fetch network interface configuration (%d)\n", status);
111  free (pIfreqList);
112  return;
113  }
114 
115  pIfreqListEnd = (struct ifreq *) (ifconf.ifc_len + (char *) pIfreqList);
116  pIfreqListEnd--;
117 
118  for ( pifreq = pIfreqList; pifreq <= pIfreqListEnd; pifreq = pnextifreq ) {
119  uint32_t current_ifreqsize;
120 
121  /*
122  * find the next ifreq
123  */
124  pnextifreq = ifreqNext (pifreq);
125 
126  /* determine ifreq size */
127  current_ifreqsize = ifreqSize ( pifreq );
128  /* copy current ifreq to aligned bufferspace (to start of pIfreqList buffer) */
129  memmove(pIfreqList, pifreq, current_ifreqsize);
130 
131  ifDepenDebugPrintf (("osiSockDiscoverBroadcastAddresses(): found IFACE: %s len: 0x%x current_ifreqsize: 0x%x \n",
132  pIfreqList->ifr_name,
133  (unsigned)ifreq_size(pifreq),
134  (unsigned)current_ifreqsize));
135 
136  /*
137  * If its not an internet interface then dont use it
138  */
139  if ( pIfreqList->ifr_addr.sa_family != AF_INET ) {
140  ifDepenDebugPrintf ( ("osiSockDiscoverBroadcastAddresses(): interface \"%s\" was not AF_INET\n", pIfreqList->ifr_name) );
141  continue;
142  }
143 
144  /*
145  * if it isnt a wildcarded interface then look for
146  * an exact match
147  */
148  if ( pMatchAddr->sa.sa_family != AF_UNSPEC ) {
149  if ( pMatchAddr->sa.sa_family != AF_INET ) {
150  continue;
151  }
152  if ( pMatchAddr->ia.sin_addr.s_addr != htonl (INADDR_ANY) ) {
153  struct sockaddr_in *pInetAddr = (struct sockaddr_in *) &pIfreqList->ifr_addr;
154  if ( pInetAddr->sin_addr.s_addr != pMatchAddr->ia.sin_addr.s_addr ) {
155  ifDepenDebugPrintf ( ("osiSockDiscoverBroadcastAddresses(): net intf \"%s\" didnt match\n", pIfreqList->ifr_name) );
156  continue;
157  }
158  }
159  }
160 
161  status = socket_ioctl ( socket, SIOCGIFFLAGS, pIfreqList );
162  if ( status ) {
163  errlogPrintf ("osiSockDiscoverBroadcastAddresses(): net intf flags fetch for \"%s\" failed\n", pIfreqList->ifr_name);
164  continue;
165  }
166  ifDepenDebugPrintf ( ("osiSockDiscoverBroadcastAddresses(): net intf \"%s\" flags: %x\n", pIfreqList->ifr_name, pIfreqList->ifr_flags) );
167 
168  /*
169  * dont bother with interfaces that have been disabled
170  */
171  if ( ! ( pIfreqList->ifr_flags & IFF_UP ) ) {
172  ifDepenDebugPrintf ( ("osiSockDiscoverBroadcastAddresses(): net intf \"%s\" was down\n", pIfreqList->ifr_name) );
173  continue;
174  }
175 
176  /*
177  * dont use the loop back interface
178  */
179  if ( pIfreqList->ifr_flags & IFF_LOOPBACK ) {
180  ifDepenDebugPrintf ( ("osiSockDiscoverBroadcastAddresses(): ignoring loopback interface: \"%s\"\n", pIfreqList->ifr_name) );
181  continue;
182  }
183 
184  pNewNode = (osiSockAddrNode *) calloc (1, sizeof (*pNewNode) );
185  if ( pNewNode == NULL ) {
186  errlogPrintf ( "osiSockDiscoverBroadcastAddresses(): no memory available for configuration\n" );
187  free ( pIfreqList );
188  return;
189  }
190 
191  /*
192  * If this is an interface that supports
193  * broadcast fetch the broadcast address.
194  *
195  * Otherwise if this is a point to point
196  * interface then use the destination address.
197  *
198  * Otherwise CA will not query through the
199  * interface.
200  */
201  if ( pIfreqList->ifr_flags & IFF_BROADCAST ) {
202  osiSockAddr baddr;
203  status = socket_ioctl (socket, SIOCGIFBRDADDR, pIfreqList);
204  if ( status ) {
205  errlogPrintf ("osiSockDiscoverBroadcastAddresses(): net intf \"%s\": bcast addr fetch fail\n", pIfreqList->ifr_name);
206  free ( pNewNode );
207  continue;
208  }
209  baddr.sa = pIfreqList->ifr_broadaddr;
210  if (baddr.ia.sin_family==AF_INET && baddr.ia.sin_addr.s_addr != INADDR_ANY) {
211  pNewNode->addr.sa = pIfreqList->ifr_broadaddr;
212  ifDepenDebugPrintf ( ( "found broadcast addr = %x\n", ntohl ( baddr.ia.sin_addr.s_addr ) ) );
213  } else {
214  ifDepenDebugPrintf ( ( "Ignoring broadcast addr = \n", ntohl ( baddr.ia.sin_addr.s_addr ) ) );
215  free ( pNewNode );
216  continue;
217  }
218  }
219 #if defined (IFF_POINTOPOINT)
220  else if ( pIfreqList->ifr_flags & IFF_POINTOPOINT ) {
221  status = socket_ioctl ( socket, SIOCGIFDSTADDR, pIfreqList);
222  if ( status ) {
223  ifDepenDebugPrintf ( ("osiSockDiscoverBroadcastAddresses(): net intf \"%s\": pt to pt addr fetch fail\n", pIfreqList->ifr_name) );
224  free ( pNewNode );
225  continue;
226  }
227  pNewNode->addr.sa = pIfreqList->ifr_dstaddr;
228  }
229 #endif
230  else {
231  ifDepenDebugPrintf ( ( "osiSockDiscoverBroadcastAddresses(): net intf \"%s\": not point to point or bcast?\n", pIfreqList->ifr_name ) );
232  free ( pNewNode );
233  continue;
234  }
235 
236  ifDepenDebugPrintf ( ("osiSockDiscoverBroadcastAddresses(): net intf \"%s\" found\n", pIfreqList->ifr_name) );
237 
238  /*
239  * LOCK applied externally
240  */
241  ellAdd ( pList, &pNewNode->node );
242  }
243 
244  free ( pIfreqList );
245 }
#define INADDR_LOOPBACK
Definition: osdSock.h:76
osiSockAddr addr
Definition: osiSock.h:163
pvd::Status status
struct sockaddr sa
Definition: osiSock.h:158
struct sockaddr_in ia
Definition: osiSock.h:157
#define NULL
Definition: catime.c:38
#define ifDepenDebugPrintf(argsInParen)
Definition: osdNetIntf.c:29
#define ifreq_size(pifreq)
Definition: osdSock.h:71
#define socket_ioctl(A, B, C)
Definition: osdSock.h:34
void ellAdd(ELLLIST *pList, ELLNODE *pNode)
Adds a node to the end of a list.
Definition: ellLib.c:24
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
ELLNODE node
Definition: osiSock.h:162
if(yy_init)
Definition: scan.c:972
LIBCOM_API void epicsStdCall osiSockRelease ( void  )

Definition at line 62 of file osdSock.c.

63 {
64 }
LIBCOM_API int epicsStdCall sockAddrAreIdentical ( const osiSockAddr plhs,
const osiSockAddr prhs 
)

Definition at line 35 of file osiSock.c.

36 {
37  int match;
38 
39  if ( plhs->sa.sa_family != prhs->sa.sa_family ) {
40  match = 0;
41  }
42  else if ( plhs->sa.sa_family != AF_INET ) {
43  match = 0;
44  }
45  else if ( plhs->ia.sin_addr.s_addr != prhs->ia.sin_addr.s_addr ) {
46  match = 0;
47  }
48  else if ( plhs->ia.sin_port != prhs->ia.sin_port ) {
49  match = 0;
50  }
51  else {
52  match = 1;
53  }
54  return match;
55 }
struct sockaddr sa
Definition: osiSock.h:158
struct sockaddr_in ia
Definition: osiSock.h:157
LIBCOM_API unsigned epicsStdCall sockAddrToA ( const struct sockaddr *  paddr,
char *  pBuf,
unsigned  bufSize 
)

Definition at line 61 of file osiSock.c.

63 {
64  if ( bufSize < 1 ) {
65  return 0;
66  }
67 
68  if ( paddr->sa_family != AF_INET ) {
69  static const char * pErrStr = "<Ukn Addr Type>";
70  unsigned len = strlen ( pErrStr );
71  if ( len < bufSize ) {
72  strcpy ( pBuf, pErrStr );
73  return len;
74  }
75  else {
76  strncpy ( pBuf, "<Ukn Addr Type>", bufSize-1 );
77  pBuf[bufSize-1] = '\0';
78  return bufSize-1;
79  }
80  }
81  else {
82  const struct sockaddr_in * paddr_in =
83  (const struct sockaddr_in *) paddr;
84  return ipAddrToA ( paddr_in, pBuf, bufSize );
85  }
86 }
unsigned epicsStdCall ipAddrToA(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:92
LIBCOM_API unsigned epicsStdCall sockAddrToDottedIP ( const struct sockaddr *  paddr,
char *  pBuf,
unsigned  bufSize 
)

Definition at line 118 of file osiSock.c.

120 {
121  if ( paddr->sa_family != AF_INET ) {
122  const char * pErrStr = "<Ukn Addr Type>";
123  unsigned errStrLen = strlen ( pErrStr );
124  if ( errStrLen < bufSize ) {
125  strcpy ( pBuf, pErrStr );
126  return errStrLen;
127  }
128  else {
129  unsigned reducedSize = bufSize - 1u;
130  strncpy ( pBuf, pErrStr, reducedSize );
131  pBuf[reducedSize] = '\0';
132  return reducedSize;
133  }
134  }
135  else {
136  const struct sockaddr_in *paddr_in = ( const struct sockaddr_in * ) paddr;
137  return ipAddrToDottedIP ( paddr_in, pBuf, bufSize );
138  }
139 }
unsigned epicsStdCall ipAddrToDottedIP(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:144