1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
20 /********************************************************************20**
22 Name: common Internet socket library
26 Desc: common library for Internet sockets,
27 always link this library with following libraries:
33 *********************************************************************21*/
37 * This software may be combined with the following TRILLIUM
40 * part no. description
41 * -------- ----------------------------------------------
42 * 1000151 TCAP over TCP/IP
46 /* header include files (.h) */
48 #include "envopt.h" /* environment options */
49 #include "envdep.h" /* environment dependent */
50 #include "envind.h" /* environment independent */
52 #include "gen.h" /* general */
53 #include "ssi.h" /* system services interface */
54 #include "cm_inet.h" /* socket library file */
56 /*cm_inet_c_001.main_35 : Updated for C++ compilation */
59 #endif /* __cplusplus */
61 /* environment dependent include files */
73 #if (!defined(SS_VW) && !defined(SS_PS))
80 #include <sys/types.h>
84 #include <sys/socket.h>
85 #include <sys/ioctl.h>
88 #include <sys/times.h>
91 #include <selectLib.h>
94 #if (!defined (SS_PS) && !defined(HPOS))
95 #include <sys/select.h>
100 #include <sys/filio.h>
101 #endif /* SS_LINUX */
102 #endif /* SS_PS && HPOS */
104 #include <sys/time.h>
108 #include <netinet/in.h>
109 #include <arpa/inet.h>
110 #include <netinet/tcp.h>
111 #ifdef IPV6_SUPPORTED
113 /* cm_inet_c_001.main_54: Fix for vxworks 6.7 adding the new header includes */
114 #if (defined(SS_VW) && defined(SS_VW6_7))
115 #include <ipcom_inet.h>
116 #include <ipcom_sock6.h>
117 #include <netinet/icmp6.h>
119 #include <netinet/icmp6.h>
122 #endif /* IPV6_SUPPORTED */
126 /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
128 #include <netinet/sctp.h>
131 /* cm_inet_c_001.main_58: Added new header files to support filteration
132 * of ICMP messages */
134 #ifdef CM_ICMP_FILTER_SUPPORT
135 #include <asm/types.h>
136 #include <linux/icmp.h>
139 /* cm_inet_c_001.main_62:Warning fix */
140 #if (!defined(SS_VW) && !defined(SS_PS) && !defined(WIN32))
145 #endif /* __cplusplus */
146 /* header/extern include files (.x) */
148 #include "gen.x" /* general */
149 #include "ssi.x" /* system services interface */
150 #include "cm_inet.x" /* socket library file */
151 #include "cm_lib.x" /* lib library file */
160 /* BSD and Winsock error handling is different */
162 #define INET_ERR SOCKET_ERROR
163 #define INET_ERR_CODE WSAGetLastError()
164 #define ERR_INPROGRESS WSAEINPROGRESS
165 #define ERR_ISCONN WSAEISCONN
166 #define ERR_WOULDBLOCK WSAEWOULDBLOCK
167 #define ERR_INADDRNONE INADDR_NONE
168 #define ERR_NOTCONN WSAENOTCONN
169 #define ERR_ALREADY WSAEALREADY
170 #define ERR_AGAIN WSAEWOULDBLOCK
171 #define ERR_INVAL WSAEINVAL
172 #define ERR_CONNREFUSED WSAECONNREFUSED
173 #define ERR_PIPE WSAENOTCONN
174 /* Changed ERR_TIMEOUT for pSos compilation */
175 #define ERR_TIMEDOUT WSAETIMEDOUT
176 #define ERR_CONNRESET WSAECONNRESET
177 #define ERR_CONNABORTED WSAECONNABORTED
178 /* cm_inet_c_001.main_36 Do select again in case of interrupt */
179 #define ERR_EINTR WSAEINTR
180 /* cm_inet_c_001.main_37 network unreacheble error is added */
181 #define ERR_NETUNREACH WSAENETUNREACH
182 /* cm_inet_c_001.main_61: host unreachable is added */
183 #define ERR_HOSTUNREACH WSAEHOSTUNREACH
186 #define INET_ERR_CODE errno
187 #define ERR_INPROGRESS EINPROGRESS
188 #define ERR_ISCONN EISCONN
189 #define ERR_WOULDBLOCK EWOULDBLOCK
190 #define ERR_INADDRNONE -1
191 #define ERR_NOTCONN ENOTCONN
192 #define ERR_ALREADY EALREADY
193 #define ERR_AGAIN EAGAIN
194 /* cm_inet_c_001.main_36 Do select again in case of interrupt */
195 #define ERR_EINTR EINTR
196 /* EINVAL is not mapped because it is a valid error code here */
198 #define ERR_CONNREFUSED ECONNREFUSED
199 #define ERR_PIPE EPIPE
200 /* Changed ERR_TIMEOUT for pSos compilation */
201 #define ERR_TIMEDOUT ETIMEDOUT
202 #define ERR_CONNRESET ECONNRESET
203 #define ERR_CONNABORTED ECONNABORTED
204 /* cm_inet_c_001.main_37 network unreacheble error is added */
205 #define ERR_NETUNREACH ENETUNREACH
206 /* cm_inet_c_001.main_61: host unreachable is added */
207 #define ERR_HOSTUNREACH EHOSTUNREACH
211 #define MIN_BACK_LOG 0
213 /* added a win2k specific defines in. */
216 #ifndef SIO_UDP_CONNRESET
217 #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR, 12)
220 #define MAX_BACK_LOG 1
222 #define MAX_BACK_LOG 5
225 #ifdef IPV6_OPTS_SUPPORTED
226 #ifndef IPV6_SUPPORTED
227 #error "Enable IPV6_SUPPORTED flag if IPV6_OPTS_SUPPORTED is defined."
229 #if (!defined(SS_LINUX) && !defined(_XPG4_2))
230 #error "Enable _XPG4_2 or SS_LINUX if IPV6_OPTS_SUPPORTED is defined."
231 #endif /* SS_LINUX || _XPG4_2 */
232 #endif /* IPV6_OPTS_SUPPORTED */
235 #if (!defined(SS_LINUX) && !defined(_XPG4_2))
236 #error "Enable _XPG4_2 or SS_LINUX if LOCAL_INTF is defined."
237 #endif /* SS_LINUX || _XPG4_2 */
238 #endif /* LOCAL_INTF */
244 /* forward references */
246 /* added !(defined(CMINETFLATBUF) */
247 #if (!(defined(WIN32)) && !(defined(CMINETFLATBUF)))
248 /* Added another function parameter */
249 PRIVATE S16 buildRecvBuf ARGS((CmInetMemInfo *info, MsgLen len,
250 CmInetIovec rxArr[], Buffer *dBuf[], U16 maxSize,
251 struct msghdr *msg, Bool isStrmMsg));
252 PRIVATE S16 buildRecvMsg ARGS((CmInetMemInfo *info, CmInetIovec rxArr[],
253 S16 numBduf, MsgLen msgLen, Buffer *dBufs[],
255 /* cm_inet_c_001.main_50 - Added parameter to get length of dbufs packed for partial
258 PRIVATE S16 buildSendIovec ARGS((Buffer *mBuf, MsgLen msgLen,
259 CmInetIovec txArr[], S16 numDBuf,
260 S16 *numIovElems, U32 *strtEndDBufNum,
262 #endif /* (defined(WIN32)) && !(defined(CMINETFLATBUF)) */
264 /* prototypes of new functions needed to send and
265 * process after receiving the extension headers through ancillary data */
267 #ifdef IPV6_SUPPORTED
268 #ifdef IPV6_OPTS_SUPPORTED
269 PRIVATE S16 cmInet6BuildSendHBHOpts ARGS((CmInetIpv6HBHHdrArr *hbhOptsArr,
270 U8 *cmsgBuf, U32 *curMsgIdx,
272 PRIVATE S16 cmInet6BuildSendRouteOpts ARGS((CmInetIpv6RtHdr *rtOptsArr,
273 U8 *cmsgBuf, U32 *curMsgIdx));
275 PRIVATE S16 cmInet6BuildRecvRtHdr ARGS((U8 *cmsgData, U32 rtDataLen,
276 CmInetIpv6RtHdr0 *rtHdr0,
277 CmInetIpv6RtHdr *rtOptsArr,
278 CmInetMemInfo *info));
279 PRIVATE S16 cmInet6BuildRecvHopOptsArr ARGS((U8 *cmsgData, U32 hbhDataLen,
280 CmInetIpv6HBHHdrArr *hbhOptsArr,
281 U8 hdrId, CmInetMemInfo *info));
282 PRIVATE S16 cmInet6GetHopLimitValue ARGS((U8 *cmsgData, U32 hopLimitDataLen,
283 CmInetIpv6HdrParm *ipv6HdrParam));
286 PRIVATE S16 cmInetBuildSendHoplimit ARGS((U32 hoplimit, U8 *cmsgBuf,
288 #endif /* SS_LINUX */
290 PRIVATE S16 cmInet6BuildSendPktinfo ARGS((CmInetIpAddr6 *srcAddr,
291 U8 *cmsgBuf, U32 *curMsgIdx,
293 #endif /* LOCAL_INTF */
294 #endif /* IPV6_OPTS_SUPPORTED */
295 #endif /* IPV6_SUPPORTED */
297 /* public variable declarations */
299 /* private variable declarations */
302 /* Global buffer for debug prints */
303 /*cm_inet_c_001.main_62:Warning fix*/
304 Txt prntBuf[CMINET_PRNT_BUF_SIZE];
305 #endif /* CMINETDBG */
307 /* cm_inet_c_001.main_60 POLL Specific Functions defined */
313 * Desc: Poll on pollfdarr
315 * Ret: Number of File Descriptor Selected
326 CmInetPollFd *pollFdArr, /* poll FD Array */
327 U32 numFds, /* Number of Fds to be monitored */
328 S16 *numRdyFds, /* number of ready descriptors */
329 U32 timeout /* timeout value for Poll */
332 S16 cmInetPoll(pollFdArr,numFds,numRdyFds,timeout)
333 CmInetPollFd *pollFdArr; /* poll FD Array */
334 U32 numFds; /* Number of Fds to be monitored */
335 S16 *numRdyFds; /* number of ready descriptors */
336 U32 timeout; /* timeout value for Poll */
344 if(numFds > CM_INET_POLL_MAXFDSUPP)
347 /* cm_inet_c_001.main_62:Warning fix */
349 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPoll() : number of file descriptor (%lu) invalid \n",numFds);
351 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPoll() : number of file descriptor (%u) invalid \n",numFds);
353 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
354 #endif /* CMINETDBG */
358 #if (ERRCLASS & ERRCLS_INT_PAR)
359 /* error check on parameters */
360 if (pollFdArr == NULLP)
363 /* cm_inet_c_001.main_62:Warning fix */
364 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPoll() : Invalid Parameter (pollFdArr is NULL)");
365 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
366 #endif /* CMINETDBG */
369 #endif /* ERRCLASS & ERRCLS_INT_PAR */
371 ret = poll(pollFdArr,numFds,timeout);
378 switch(INET_ERR_CODE)
385 /* cm_inet_c_001.main_62:Warning fix */
386 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "File: %s, cmInetPoll() failed on line: %d \n\
387 error(%d)\n", __FILE__, __LINE__, INET_ERR_CODE);
389 #endif /* CMINETDBG */
392 } /* end of switch */
395 *numRdyFds = (S16)ret;
403 * Fun: cmInetPollSetFd
405 * Desc: Set the selected fd in pollFdArr with event eventMask
407 * Ret: RFAILED : if file descriptor is out of range
408 * ROK : if pollFdArr is set.
419 CmInetFd *sockFd, /* socket file descriptor */
420 CmInetPollFd *pollFdArr, /* poll FD Array */
421 S16 idx, /* poll Fd Array Index */
422 U16 eventMask /* Event Mask to be set */
425 S16 cmInetPollSetFd(sockFd,pollFdArr,idx,eventMask)
426 CmInetFd *sockFd; /* socket file descriptor */
427 CmInetPollFd *pollFdArr; /* poll FD Array */
428 S16 idx; /* poll Fd Array Index */
429 U16 eventMask; /* Event Mask to be set */
434 if ((idx) >= CM_INET_POLL_MAXFDSUPP || (idx) < 0)
437 /* cm_inet_c_001.main_62:Warning fix */
438 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollSetFd() : Invalid idx(%d) \n",idx);
439 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
440 #endif /* CMINETDBG */
445 #if (ERRCLASS & ERRCLS_INT_PAR)
446 /* error check on parameters */
447 if (pollFdArr == NULLP)
450 /* cm_inet_c_001.main_62:Warning fix */
451 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollSetFd() : Invalid Parameter (pollFdArr is NULL)");
452 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
453 #endif /* CMINETDBG */
456 #endif /* ERRCLASS & ERRCLS_INT_PAR */
460 /* cm_inet_c_001.main_62:Warning fix */
461 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,
462 "cmInetPollSetFd() Before Setting fd : sockFd->fd(%d) Index(%d) Event(%d) \n Fd and event to be set fd(%ld) event(%d) \n",
463 pollFdArr[idx].fd,idx, pollFdArr[idx].events,sockFd->fd,eventMask);
464 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
466 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,
467 "cmInetPollSetFd() Before Setting fd: sockFd->fd(%d) Index(%d) Event(%d) \n Fd and event to be set fd(%d) event(%d) \n",
468 pollFdArr[idx].fd,idx, pollFdArr[idx].events,sockFd->fd,eventMask);
469 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
470 #endif /*ALIGN_64BIT */
471 #endif /* CMINETDBG */
473 /* Setting fd and events with eventMask */
474 pollFdArr[idx].fd = sockFd->fd;
475 pollFdArr[idx].events |= eventMask;
480 /* cm_inet_c_001.main_62:Warning fix */
481 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollSetFd() After Setting fd: sockFd->fd(%d) Index(%d) Event(%d) \n",
482 pollFdArr[idx].fd,idx, pollFdArr[idx].events);
483 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
485 /* cm_inet_c_001.main_62:Warning fix */
486 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollSetFd() After Setting fd: sockFd->fd(%d) Index(%d) Event(%d) \n",
487 pollFdArr[idx].fd,idx, pollFdArr[idx].events);
488 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
489 #endif /*ALIGN_64BIT */
490 #endif /* CMINETDBG */
499 * Fun: cmInetPollFdIsSet
501 * Desc: Checks whether fd is selected
503 * Ret: TRUE : If Fd is Selected
504 * FALSE: If Fd is not Selected
513 S16 cmInetPollFdIsSet
515 CmInetPollFd *pollFdArr, /* poll FD Array */
516 S16 idx, /* poll Fd Array Index */
517 U16 eventMask /* Event Mask to be set */
520 S16 cmInetPollFdIsSet(pollFdArr,idx,eventMask)
521 CmInetPollFd *pollFdArr; /* poll FD Array */
522 S16 idx; /* poll Fd Array Index */
523 U16 eventMask; /* Event Mask to be set */
529 if((idx < 0) || (idx > CM_INET_POLL_MAXFDSUPP))
532 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollFdIsSet() : Invalid Index (%d) \n",idx);
533 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
534 #endif /* CMINETDBG */
538 #if (ERRCLASS & ERRCLS_INT_PAR)
539 /* error check on parameters */
540 if (pollFdArr == NULLP)
543 /* cm_inet_c_001.main_62:Warning fix */
544 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollFdIsSet() : Invalid Parameter (pollFdArr is NULL)");
545 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
546 #endif /* CMINETDBG */
549 #endif /* ERRCLASS & ERRCLS_INT_PAR */
551 ret = (pollFdArr[idx].revents & eventMask);
558 * Fun: cmInetPollClearFdREvent
560 * Desc: clears the reventMask in revent of the givent FD.
572 S16 cmInetPollClearFdREvent
574 CmInetPollFd *pollFdArr, /* poll FD Array */
575 S16 idx, /* poll Fd Array Index */
576 U16 eventMask /* Event Mask to be set */
579 S16 cmInetPollClearFdREvent(sockFd,pollFdArr,eventMask)
580 CmInetPollFd *pollFdArr; /* poll FD Array */
581 S16 idx; /* poll Fd Array Index */
582 U16 eventMask; /* Event Mask to be set */
588 if((idx < 0) || (idx > CM_INET_POLL_MAXFDSUPP))
591 /* cm_inet_c_001.main_62:Warning fix */
592 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() : Invalid Index (%d) \n",idx);
593 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
594 #endif /* CMINETDBG */
598 #if (ERRCLASS & ERRCLS_INT_PAR)
599 /* error check on parameters */
600 if (pollFdArr == NULLP)
603 /* cm_inet_c_001.main_62:Warning fix */
604 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() : Invalid Parameter (pollFdArr is NULL)");
605 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
606 #endif /* CMINETDBG */
609 #endif /* ERRCLASS & ERRCLS_INT_PAR */
613 /* cm_inet_c_001.main_62:Warning fix */
614 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() Before clearing fd revents with eventMask: \n sockFd->fd(%d) Index(%d) REvent(%d) EventMask(%d) \n",
615 pollFdArr[idx].fd,idx, pollFdArr[idx].revents,eventMask);
616 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
618 /* cm_inet_c_001.main_62:Warning fix */
619 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() Before clearing fd revents with eventMask: \n sockFd->fd(%d) Index(%d) REvent(%d) EventMask(%d) \n",
620 pollFdArr[idx].fd,idx, pollFdArr[idx].revents,eventMask);
621 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
622 #endif /*ALIGN_64BIT */
623 #endif /* CMINETDBG */
625 /* Clearing the events with eventMask */
626 pollFdArr[idx].revents = (pollFdArr[idx].revents & (~(eventMask)));
630 /* cm_inet_c_001.main_62:Warning fix */
631 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() After clearing fd revents with eventMask: \n sockFd->fd(%d) Index(%d) REvent(%d) EventMask(%d) \n",
632 pollFdArr[idx].fd,idx, pollFdArr[idx].revents,eventMask);
633 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
635 /* cm_inet_c_001.main_62:Warning fix */
636 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() After clearing fd revents with eventMask: \n sockFd->fd(%d) Index(%d) REvent(%d) EventMask(%d) \n",
637 pollFdArr[idx].fd,idx, pollFdArr[idx].revents,eventMask);
638 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
639 #endif /*ALIGN_64BIT */
640 #endif /* CMINETDBG */
649 * Fun: cmInetPollClearFdEvent
651 * Desc: clears the eventMask in event of the givent FD.
663 S16 cmInetPollClearFdEvent
665 CmInetPollFd *pollFdArr, /* poll FD Array */
666 S16 idx, /* poll Fd Array Index */
667 U16 eventMask /* Event Mask to be set */
670 S16 cmInetPollClearFdEvent(sockFd,pollFdArr,eventMask)
671 CmInetPollFd *pollFdArr; /* poll FD Array */
672 S16 idx; /* poll Fd Array Index */
673 U16 eventMask; /* Event Mask to be set */
679 if((idx < 0) || (idx > CM_INET_POLL_MAXFDSUPP))
682 /* cm_inet_c_001.main_62:Warning fix */
683 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() : Invalid Index (%d) \n",idx);
684 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
685 #endif /* CMINETDBG */
689 #if (ERRCLASS & ERRCLS_INT_PAR)
690 /* error check on parameters */
691 if (pollFdArr == NULLP)
694 /* cm_inet_c_001.main_62:Warning fix */
695 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() : Invalid Parameter (pollFdArr is NULL)");
696 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
697 #endif /* CMINETDBG */
700 #endif /* ERRCLASS & ERRCLS_INT_PAR */
704 /* cm_inet_c_001.main_62:Warning fix */
705 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() Before clearing fd events with eventMask: \n sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
706 pollFdArr[idx].fd,idx, pollFdArr[idx].events,eventMask);
707 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
709 /* cm_inet_c_001.main_62:Warning fix */
710 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() Before clearing fd events with eventMask:\n sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
711 pollFdArr[idx].fd,idx, pollFdArr[idx].events,eventMask);
712 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
713 #endif /*ALIGN_64BIT */
714 #endif /* CMINETDBG */
716 /* Clearing events with eventMask */
717 pollFdArr[idx].events = (pollFdArr[idx].events & (~(eventMask)));
721 /* cm_inet_c_001.main_62:Warning fix */
722 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() After clearing fd events with eventMask: sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
723 pollFdArr[idx].fd,idx, pollFdArr[idx].events,eventMask);
724 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
726 /* cm_inet_c_001.main_62:Warning fix */
727 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() After clearing fd events with eventMask: sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
728 pollFdArr[idx].fd,idx, pollFdArr[idx].events,eventMask);
729 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
730 #endif /*ALIGN_64BIT */
731 #endif /* CMINETDBG */
740 * Fun: cmInetPollDelFd
742 * Desc: Delete the given FD from the pollFdArray
743 * delIdx : Poll Fd Array Index at which fd has to be deleted.
744 * lastIdx: Last index of poll fd array.
746 * It deletes fd from array by swapping lastIdx pollFd
747 * values to index to be deleted and deinitializes the
753 * Notes: It does not decrement the lastIdx and it has to be
754 * decremented by the caller of this function.
763 CmInetPollFd *pollFdArr, /* poll FD Array */
764 S16 delIdx, /* poll Fd Array Index for which fd has to be deleted*/
765 S16 lastIdx /* Last index of poll Fd Array */
768 S16 cmInetPollDelFd(pollFdArr, delIdx, lastIdx)
769 CmInetPollFd *pollFdArr; /* poll FD Array */
770 S16 delIdx; /* poll Fd Array Index for which fd has to be deleted*/
771 S16 lastIdx; /* Last index of poll Fd Array */
776 if(lastIdx < delIdx || lastIdx < 0 || delIdx < 0)
779 /* cm_inet_c_001.main_62:Warning fix */
780 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollDelFd() : Invalid Index \n Current Index (%d) Delete Index (%d) \n",lastIdx,delIdx);
781 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
782 #endif /* CMINETDBG */
787 #if (ERRCLASS & ERRCLS_INT_PAR)
788 /* error check on parameters */
789 if (pollFdArr == NULLP)
792 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollDelFd() : Invalid Parameter (pollFdArr is NULL)");
793 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
794 #endif /* CMINETDBG */
797 #endif /* ERRCLASS & ERRCLS_INT_PAR */
801 /* cm_inet_c_001.main_62:Warning fix */
802 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollDelFd() Deleting the sockFd->fd(%d) Index(%d) Event(%d) revent(%d) \n",
803 pollFdArr[delIdx].fd,delIdx, pollFdArr[delIdx].events,pollFdArr[delIdx].revents);
804 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
806 /* cm_inet_c_001.main_62:Warning fix */
807 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollDelFd() After clearing fd events with eventMask: sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
808 pollFdArr[delIdx].fd,delIdx, pollFdArr[delIdx].events,pollFdArr[delIdx].revents);
809 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
810 #endif /*ALIGN_64BIT */
811 #endif /* CMINETDBG */
813 pollFdArr[delIdx].fd = pollFdArr[lastIdx].fd;
814 pollFdArr[delIdx].events = pollFdArr[lastIdx].events;
815 pollFdArr[delIdx].revents = pollFdArr[lastIdx].revents;
817 pollFdArr[lastIdx].fd = -1;
818 pollFdArr[lastIdx].events = 0;
819 pollFdArr[lastIdx].revents = 0;
827 * Fun: cmInetPollInitFdArr
829 * Desc: Cleans all elements of fd array.
834 * Notes: It does not allocates/deallocates memory for Poll Fd Array.
835 * Caller of function has to allocate/deallocate memory for
843 S16 cmInetPollInitFdArr
845 CmInetPollFd *pollFdArr /* poll FD Array */
848 S16 cmInetPollInitFdArr(pollFdArr)
849 CmInetPollFd *pollFdArr; /* poll FD Array */
854 /* Sets each element of pollFdArr to initial value
859 #if (ERRCLASS & ERRCLS_INT_PAR)
860 /* error check on parameters */
861 if (pollFdArr == NULLP)
864 /* cm_inet_c_001.main_62:Warning fix */
865 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollInitFdArr() : Invalid Parameter (pollFdArr is NULL)");
866 CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
867 #endif /* CMINETDBG */
870 #endif /* ERRCLASS & ERRCLS_INT_PAR */
872 for(idx=0; idx < CM_INET_POLL_MAXFDSUPP; idx++)
874 pollFdArr[idx].fd = -1;
875 pollFdArr[idx].events = 0;
876 pollFdArr[idx].revents = 0;
881 #if (!(defined(WIN32)) && !(defined(CMINETFLATBUF)))
886 * Desc: Allocates dBufs to receive an entire message.
888 * Ret: ROK - successful
890 * ROUTRES - failed, out of resources
899 PRIVATE S16 buildRecvBuf
901 CmInetMemInfo *info, /* buffer allocation info */
902 MsgLen len, /* message length */
903 CmInetIovec rxArr[], /* gather array */
904 Buffer *dBuf[], /* allocated dBufs */
905 U16 maxSize, /* size of rxArr/dBuf array */
906 struct msghdr *msg, /* message header for recvmsg() */
907 Bool isStrmMsg /* Is a TCP message */
910 PRIVATE S16 buildRecvBuf(info, len, rxArr, dBuf, maxSize, msg, isStrmMsg)
911 CmInetMemInfo *info; /* buffer allocation info */
912 MsgLen len; /* message length */
913 CmInetIovec rxArr[]; /* gather array */
914 Buffer *dBuf[]; /* allocated dBufs */
915 U16 maxSize; /* size of rxArr/dBuf array */
916 struct msghdr *msg; /* message header for recvmsg() */
917 Bool isStrmMsg; /* Is a TCP message */
920 S16 ret; /* temporary return value */
921 U16 numBuf; /* number of dBufs */
922 U16 i; /* dBuf index counter */
923 Data *dPtr; /* data pointer */
924 /* cm_inet_c_001.main_47: 102069 Changed from S32 to MsgLen for bufLen*/
925 MsgLen bufLen; /* entire receive buffer length, if S16
926 could wrap to negative number */
927 MsgLen dLen; /* buffer length */
932 /* Initialise ret and part of msg here */
935 /* added defined(_XPG4_2) */
936 /* Moved initialisation of msg here. */
938 #if (defined(SS_LINUX) || defined(_XPG4_2))
939 msg->msg_control = NULLP;
940 msg->msg_controllen = 0;
942 msg->msg_accrights = NULLP;
943 msg->msg_accrightslen = 0;
944 #endif /* SS_LINUX */
946 /* Check if maxSize if enough to hold the entire message length before
947 * going into the loop. If the boolean isStrmMsg is TRUE then the recv
948 * buf is built even if the whole message cannot be accomodated. */
950 #ifdef T2K_MEM_LEAK_DBG
951 char * file = __FILE__;
953 ret = SGetDBuf(info->region, info->pool, &dBuf[numBuf]);
955 ret = SGetDBuf(info->region, info->pool, &dBuf[numBuf]);
960 /* Get the data part */
961 ret = SGetDataRx(dBuf[numBuf], 0, &dPtr, &dLen);
964 numBuf++; /* because of cleanup */
970 /* The assumption here is that all dBuf's from a given region and
971 * pool have a constance size */
972 if (len > (maxSize * dLen))
975 numBuf++; /* because of cleanup */
981 rxArr[numBuf].iov_base = (Void*)dPtr;
982 rxArr[numBuf].iov_len = (U32)dLen;
984 rxArr[numBuf].iov_base = (S8*)dPtr;
985 rxArr[numBuf].iov_len = dLen;
986 #endif /* SS_LINUX */
991 /* allocate buffer space for entire message length */
994 if (numBuf >= maxSize)
996 /* to big to fit in gather vector array */
1000 ret = SGetDBuf(info->region, info->pool, &dBuf[numBuf]);
1005 ret = SGetDataRx(dBuf[numBuf], 0, &dPtr, &dLen);
1008 numBuf++; /* because of cleanup */
1012 rxArr[numBuf].iov_base = (Void*)dPtr;
1013 rxArr[numBuf].iov_len = (U32)dLen;
1015 rxArr[numBuf].iov_base = (S8*)dPtr;
1016 rxArr[numBuf].iov_len = dLen;
1017 #endif /* SS_LINUX */
1022 /* adjust last buffer length */
1023 /* check if we broke out because numBuf >= maxSize */
1025 rxArr[numBuf - 1].iov_len = dLen;
1027 rxArr[numBuf - 1].iov_len = dLen - (bufLen - len);
1029 /* setup recvmsg() message header */
1030 msg->msg_iov = rxArr;
1031 msg->msg_iovlen = numBuf;
1037 for (i = 0; i < numBuf; i++)
1038 SPutDBuf(info->region, info->pool, dBuf[i]);
1040 msg->msg_iovlen = 0;
1043 } /* end of buildRecvBuf */
1049 * Desc: Builds a message out of the received dBufs.
1051 * Ret: ROK - successful
1053 * ROUTRES - failed, out of resources
1062 PRIVATE S16 buildRecvMsg
1064 CmInetMemInfo *info, /* buffer allocation info */
1065 CmInetIovec rxArr[], /* scatter array */
1066 S16 numBuf, /* number of allocated dBufs */
1067 MsgLen msgLen, /* message length */
1068 Buffer *dBufs[], /* dBufs */
1069 Buffer **mPtr /* message built from dBufs */
1072 PRIVATE S16 buildRecvMsg(info, rxArr, numBuf, msgLen, dBufs, mPtr)
1073 CmInetMemInfo *info; /* buffer allocation info */
1074 CmInetIovec rxArr[]; /* scatter array */
1075 S16 numBuf; /* number of allocated dBufs */
1076 MsgLen msgLen; /* length of one particular dBuf */
1077 Buffer *dBufs[]; /* dBufs */
1078 Buffer **mPtr; /* message built from dBufs */
1081 S16 ret; /* return value */
1082 S16 i; /* dBuf index counter */
1083 MsgLen bufLen; /* length of one particular dBuf */
1084 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
1085 Buffer *mBuf = NULLP; /* allocated message */
1091 ret = SGetMsg(info->region, info->pool, &mBuf);
1097 /* link buffers to message */
1100 /* cm_inet_c_001.main_58: fix for klockwork issue */
1101 bufLen = (MsgLen)rxArr[i].iov_len;
1102 if (msgLen < bufLen)
1106 ret = SUpdMsg(mBuf, dBufs[i], bufLen);
1124 /* cleanup unused buffers */
1127 #ifdef T2K_MEM_LEAK_DBG
1128 char * file = __FILE__;
1129 U32 line = __LINE__;
1130 SPutDBuf(info->region, info->pool, dBufs[i]);
1132 SPutDBuf(info->region, info->pool, dBufs[i]);
1138 } /* end of buildRecvMsg */
1144 * Fun: buildSendIovec
1146 * Desc: Builds a io vector to send a message.
1148 * Ret: ROK - successful
1150 * ROUTRES - failed, out of resources
1151 * RNA - failed, not available, indicates that the
1152 * maximum number of dBufs are not sufficient
1153 * to hold the entire message.
1161 PRIVATE S16 buildSendIovec
1163 Buffer *mBuf, /* Message buffer */
1164 MsgLen msgLen, /* Length of mBuf */
1165 CmInetIovec txArr[], /* transmit scatter vector array */
1166 S16 numDBufs, /* Maximum number of dBufs to use */
1167 S16 *numIovElems, /* Number of iov elements in array */
1168 U32 *strtEndDBufNum, /* dBuf number to start and end */
1169 MsgLen *ioLen /* cm_inet_c_001.main_50 - Len of dbuf packed into IO-vector */
1172 PRIVATE S16 buildSendIovec(mBuf, msgLen, txArr, numDBufs, numIovElems,
1173 strtEndDBufNum,ioLen)
1174 Buffer *mBuf; /* Message buffer */
1175 MsgLen msgLen; /* Length of mBuf */
1176 CmInetIovec txArr[]; /* transmit scatter vector array */
1177 S16 numDBufs; /* Maximum number of dBufs to use */
1178 S16 *numIovElems; /* Number of iov elements in array */
1179 U32 *strtEndDBufNum; /* dBuf number to start and end */
1180 MsgLen *ioLen; /* cm_inet_c_001.main_50 - Len of dbuf packed into IO-vector */
1191 /* Initialisations */
1196 /* cm_inet_c_001.main_50 - Intialize the newly added parameter */
1199 /* Set up vector for gathering send */
1200 ret = SInitNxtDBuf(mBuf);
1207 txArr[iovIdx].iov_len = 0;
1209 if ((*strtEndDBufNum != 0))
1211 /* Skip through the required number of dBufs */
1212 dBufsToSkip = *strtEndDBufNum;
1216 ret = SGetNxtDBuf(mBuf, &dBuf);
1225 ret = SGetNxtDBuf(mBuf, &dBuf);
1228 ret = SGetDataTx(dBuf, &dPtr, &dLen);
1235 txArr[iovIdx].iov_base = (S8 *)dPtr;
1236 txArr[iovIdx].iov_len = dLen;
1240 else if (ret == ROKDNA)
1253 if (iovIdx >= numDBufs)
1255 if (allocLen >= msgLen)
1263 (*numIovElems) = iovIdx;
1264 (*strtEndDBufNum) += iovIdx;
1266 /* cm_inet_c_001.main_50 - Assign the value of dbufs packed in IO-vector */
1271 } /* end of buildSendIovec */
1272 #endif /* (defined(WIN32)) && !(defined(CMINETFLATBUF)) */
1279 * Desc: Creates an Internet socket descriptor.
1280 * On default the socket is non-blocking ( can be changed
1281 * with the function cmInetSetOpt()).
1284 * CM_INET_STREAM (TCP)
1285 * CM_INET_DGRAM (UDP)
1287 * Ret: ROK - successful
1297 #ifdef IPV6_SUPPORTED
1300 U8 type, /* socket type */
1301 CmInetFd *sockFd, /* socket file descriptor */
1302 U8 protocol, /* protocol value */
1303 U8 domain /* domain */
1308 U8 type, /* socket type */
1309 CmInetFd *sockFd, /* socket file descriptor */
1310 U8 protocol /* protocol value */
1312 #endif /* IPV6_SUPPORTED */
1313 #else /* CM_INET2 */
1316 U8 type, /* socket type */
1317 CmInetFd *sockFd /* socket file descriptor */
1319 #endif /* CM_INET2 */
1322 #ifdef IPV6_SUPPORTED
1323 S16 cmInetSocket(type, sockFd, protocol, domain)
1324 U8 type; /* socket type */
1325 CmInetFd *sockFd; /* socket file descriptor */
1326 U8 protocol; /* protocol value */
1327 U8 domain; /* domain */
1329 S16 cmInetSocket(type, sockFd, protocol)
1330 U8 type; /* socket type */
1331 CmInetFd *sockFd; /* socket file descriptor */
1332 U8 protocol; /* protocol value */
1333 #endif /* IPV6_SUPPORTED */
1334 #else /* CM_INET2 */
1335 S16 cmInetSocket(type, sockFd)
1336 U8 type; /* socket type */
1337 CmInetFd *sockFd; /* socket file descriptor */
1338 #endif /* CM_INET2 */
1341 S32 ret; /* temporary return value */
1345 #if (defined(WIN32) && defined(WIN2K))
1348 #endif /* WIN2K && WIN32 */
1351 #if (defined(WIN32) && defined(WIN2K))
1353 bNewBehavior = FALSE;
1354 #endif /* WIN32 && WIN2K */
1358 #ifdef IPV6_SUPPORTED
1359 sockFd->fd = socket(domain, type, protocol);
1361 sockFd->fd = socket(AF_INET, type, protocol);
1362 #endif /* IPV6_SUPPORTED */
1363 #else /* CM_INET2 */
1364 sockFd->fd = socket(AF_INET, type, 0);
1365 #endif /* CM_INET2 */
1366 if (CM_INET_INV_SOCK_FD(sockFd))
1370 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1371 /* cm_inet_c_001.main_62:Warning fix */
1372 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSocket() Failed : errno(%d), sockFd->fd(%ld)\n",
1373 INET_ERR_CODE, sockFd->fd);
1374 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET001, 0, prntBuf);
1376 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSocket() Failed : errno(%d), sockFd->fd(%d)\n",
1377 INET_ERR_CODE, sockFd->fd);
1378 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET001, 0, prntBuf);
1379 #endif /*ALIGN_64BIT */
1380 #endif /* CMINETDBG */
1381 /* Set sockFd->fd to invalid socket */
1382 sockFd->fd = CM_INET_INV_SOCKFD;
1386 /* set socket type */
1387 sockFd->type = type;
1389 /* set socket protocol type (IPv4/IPv6) */
1390 #ifdef IPV6_SUPPORTED
1391 sockFd->protType = domain;
1392 #endif /* IPV6_SUPPORTED */
1394 /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
1396 if (protocol != IPPROTO_SCTP)
1399 /* set default options */
1400 optVal = CM_INET_OPT_DISABLE;
1401 ret = cmInetSetOpt(sockFd, SOL_SOCKET, CM_INET_OPT_BLOCK, (Ptr)&optVal);
1404 ret = cmInetClose(sockFd);
1409 #ifndef CMINET_BSDCOMPAT
1410 optVal = CM_INET_OPT_ENABLE;
1411 ret = cmInetSetOpt(sockFd, SOL_SOCKET, CM_INET_OPT_BSD_COMPAT, (Ptr)&optVal);
1414 ret = cmInetClose(sockFd);
1417 #endif /* CMINET_BSDCOMPAT */
1418 #endif /* SS_LINUX */
1420 #if (defined(WIN32) && defined(WIN2K))
1421 if(type == CM_INET_DGRAM)
1423 ret = WSAIoctl(sockFd->fd, SIO_UDP_CONNRESET, &bNewBehavior,
1424 sizeof(bNewBehavior), NULLP, 0, &bytesReturned,
1430 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
1431 /* cm_inet_c_001.main_62:Warning fix */
1432 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "WSAIoctl() Failed : error(%d), sockFd->fd(%ld)\n",
1433 INET_ERR_CODE, sockFd->fd);
1434 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET002, 0, prntBuf);
1436 /* cm_inet_c_001.main_62:Warning fix */
1437 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "WSAIoctl() Failed : error(%d), sockFd->fd(%d)\n",
1438 INET_ERR_CODE, sockFd->fd);
1439 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET002, 0, prntBuf);
1440 #endif /*ALIGN_64BIT*/
1441 #endif /* CMINETDBG */
1442 ret = cmInetClose(sockFd);
1446 #endif /* WIN2K && WIN32 */
1447 /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
1450 #ifdef CM_LKSCTP_NONBLOCK
1453 /* cm_inet_c_001.main_47:if non-blocking SCTP socket compile time
1454 * * flag is set then even for kernel SCTP make the socket
1457 optVal = CM_INET_OPT_DISABLE;
1458 ret = cmInetSetOpt(sockFd, SOL_SOCKET, CM_INET_OPT_BLOCK, (Ptr)&optVal);
1461 ret = cmInetClose(sockFd);
1465 #endif /* CM_LKSCTP_NONBLOCK ends */
1468 } /* end of cmInetSocket */
1475 * Desc: Binds a socket file descriptor to a local Internet
1478 * Ret: ROK - successful
1490 CmInetFd *sockFd, /* socket file descriptor */
1491 CmInetAddr *myAddr /* locale Internet address/port */
1494 S16 cmInetBind(sockFd, myAddr)
1495 CmInetFd *sockFd; /* socket file descriptor */
1496 CmInetAddr *myAddr; /* locale Internet address/port */
1499 S32 ret; /* temporary return value */
1500 struct sockaddr_in srcAddr; /* local Internet address/port */
1501 #ifdef IPV6_SUPPORTED
1502 struct sockaddr_in6 srcAddr6; /* local IPV6 address/port */
1505 #endif /* CMINETDBG */
1506 #endif /* IPV6_SUPPORTED */
1507 U32 sizeOfAddr; /* sizeof address passed to the bind call */
1508 CmInetSockAddr *sockAddrPtr;
1511 #if (ERRCLASS & ERRCLS_INT_PAR)
1512 /* error check on parameters */
1513 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
1518 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1520 #ifdef IPV6_SUPPORTED
1521 if (myAddr->type == CM_INET_IPV6ADDR_TYPE)
1523 memset(&srcAddr6, 0, sizeof(srcAddr6));
1524 srcAddr6.sin6_family = AF_INET6;
1525 srcAddr6.sin6_port = CM_INET_HTON_U16(myAddr->u.ipv6Addr.port);
1526 CM_INET_COPY_IPV6ADDR(&srcAddr6.sin6_addr,
1527 &myAddr->u.ipv6Addr.ipv6NetAddr);
1528 sizeOfAddr = sizeof(struct sockaddr_in6);
1529 sockAddrPtr = (CmInetSockAddr *)&srcAddr6;
1533 memset(&srcAddr, 0, sizeof(srcAddr));
1534 srcAddr.sin_family = AF_INET;
1535 srcAddr.sin_port = CM_INET_HTON_U16(myAddr->u.ipv4Addr.port);
1536 srcAddr.sin_addr.s_addr = CM_INET_HTON_U32(myAddr->u.ipv4Addr.address);
1537 sizeOfAddr = sizeof(struct sockaddr_in);
1538 sockAddrPtr = (CmInetSockAddr *)&srcAddr;
1541 memset(&srcAddr, 0, sizeof(srcAddr));
1542 srcAddr.sin_family = AF_INET;
1543 srcAddr.sin_port = CM_INET_HTON_U16(myAddr->port);
1544 srcAddr.sin_addr.s_addr = CM_INET_HTON_U32(myAddr->address);
1545 sizeOfAddr = sizeof(struct sockaddr_in);
1546 sockAddrPtr = (CmInetSockAddr *)&srcAddr;
1547 #endif /* IPV6_SUPPORTED */
1549 ret = bind(sockFd->fd, sockAddrPtr, sizeOfAddr);
1550 if (ret == INET_ERR)
1553 #ifdef IPV6_SUPPORTED
1554 if (myAddr->type == CM_INET_IPV6ADDR_TYPE)
1555 port = myAddr->u.ipv6Addr.port;
1557 port = myAddr->u.ipv4Addr.port;
1559 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1560 /* cm_inet_c_001.main_62:Warning fix */
1561 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetBind() Failed : error(%d), addrType(%d),"
1562 " port(%d), sockFd->fd(%ld)\n",
1563 INET_ERR_CODE , myAddr->type, port, sockFd->fd);
1564 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET003, 0, prntBuf);
1566 /* cm_inet_c_001.main_62:Warning fix */
1567 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetBind() Failed : error(%d), addrType(%d),"
1568 " port(%d), sockFd->fd(%d)\n ",
1569 INET_ERR_CODE , myAddr->type, port, sockFd->fd);
1570 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET003, 0, prntBuf);
1571 #endif /*ALIGN_64BIT*/
1574 /* cm_inet_c_001.main_62:Warning fix */
1575 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetBind() Failed : error(%d), addr(0x%lx), port(%d),"
1576 "sockFd->fd(%ld)\n",
1577 INET_ERR_CODE , myAddr->address, myAddr->port, sockFd->fd);
1578 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET004, 0, prntBuf);
1580 /* cm_inet_c_001.main_62:Warning fix */
1581 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetBind() Failed : error(%d), addr(0x%x), port(%d),"
1582 " sockFd->fd(%d)\n",
1583 INET_ERR_CODE , myAddr->address, myAddr->port, sockFd->fd);
1584 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET004, 0, prntBuf);
1585 #endif /*ALIGN_64BIT*/
1586 #endif /* IPV6_SUPPORTED */
1587 #endif /* CMINETDBG */
1592 } /* end of cmInetBind */
1594 /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
1595 /* cm_inet_c_001.main_51 Added Ipv6 support to KSCtP implementation */
1599 * Fun: cmInetSctpBindx
1601 * Desc: Binds a SCTP socket file descriptor to local Internet
1604 * Ret: ROK - successful
1615 CmInetFd *sockFd, /* socket file descriptor */
1616 CmInetNetAddrLst *addrLst, /* local Internet address list */
1617 U16 port /* port number */
1620 S16 cmInetSctpBindx(sockFd, addrLst, port)
1621 CmInetFd *sockFd; /* socket file descriptor */
1622 CmInetNetAddrLst *addrLst; /* locale Internet address list */
1623 U16 port; /* port number */
1626 S32 ret; /* temporary return value */
1629 U32 ipv4_array_size = 0;
1630 struct sockaddr_in addrs[CM_INET_NUM_NET_ADDR];
1631 #ifndef IPV6_SUPPORTED
1632 Data address_array[(CM_INET_NUM_NET_ADDR * sizeof(struct sockaddr_in))];
1634 Data address_array[(CM_INET_NUM_NET_ADDR * sizeof(struct sockaddr_in6))];
1635 #endif /* IPV6_SUPPORTED */
1638 Data *tempAddrPtr = NULLP;
1640 U32 addresses_array_size = 0;
1641 #ifdef IPV6_SUPPORTED
1643 S8 *addrString = NULLP;
1645 S8 ipv4Format[23] = "::ffff:";
1646 #endif /* SUN_KSCTP */
1648 U32 ipv6_array_size = 0;
1649 struct sockaddr_in6 addrs6[CM_INET_NUM_NET_ADDR];
1650 #endif /* IPV6_SUPPORTED */
1651 struct sockaddr *sockAddrPtr = NULLP;
1652 U32 sockAddrLen = 0;
1654 #if (ERRCLASS & ERRCLS_INT_PAR)
1655 /* error check on parameters */
1656 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
1662 if(addrLst->count > CM_INET_NUM_NET_ADDR)
1666 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1667 /* cm_inet_c_001.main_62:Warning fix */
1668 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "No of address(%d) is greater than Max(%d),"
1669 " sockFd->fd(%ld)\n",
1670 addrLst->count, CM_INET_NUM_NET_ADDR, sockFd->fd);
1671 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET005, 0, prntBuf);
1673 /* cm_inet_c_001.main_62:Warning fix */
1674 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "No of address(%d) is greater than Max(%d),"
1675 " sockFd->fd(%d)\n",
1676 addrLst->count, CM_INET_NUM_NET_ADDR, sockFd->fd);
1677 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET005, 0, prntBuf);
1678 #endif /*ALIGN_64BIT*/
1679 #endif /* CMINETDBG */
1682 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1684 memset(&addrs, 0, (sizeof(struct sockaddr_in) * CM_INET_NUM_NET_ADDR));
1685 #ifdef IPV6_SUPPORTED
1686 memset(&addrs6, 0, (sizeof(struct sockaddr_in6) * CM_INET_NUM_NET_ADDR));
1687 #endif /* IPV6_SUPPORTED */
1689 for (idx = 0; idx < addrLst->count; idx++)
1691 #ifdef IPV6_SUPPORTED
1692 if (addrLst->addrs[idx].type == CM_INET_IPV6ADDR_TYPE)
1694 ipv6_array_size += sizeof(struct sockaddr_in6);
1695 addresses_array_size += sizeof(struct sockaddr_in6);
1696 if (sockFd->protType == AF_INET)
1700 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1701 /* cm_inet_c_001.main_62:Warning fix */
1702 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't bind IPV6 address on IPV4 socket,"
1703 " sockFd->fd(%ld)\n", sockFd->fd);
1704 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET057, 0, prntBuf);
1706 /* cm_inet_c_001.main_62:Warning fix */
1707 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't bind IPV6 address on IPV4 socket,"
1708 " sockFd->fd(%d)\n", sockFd->fd);
1709 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET057, 0, prntBuf);
1710 #endif /*ALIGN_64BIT*/
1711 #endif /* CMINETDBG */
1715 addrs6[idx6].sin6_family = AF_INET6;
1716 addrs6[idx6].sin6_port = CM_INET_HTON_U16(port);
1717 CM_INET_COPY_IPV6ADDR((addrs6[idx6].sin6_addr.s6_addr), &(addrLst->addrs[idx].u.ipv6NetAddr));
1724 ipv6_array_size += sizeof(struct sockaddr_in6);
1725 addresses_array_size += sizeof(struct sockaddr_in6);
1726 if (sockFd->protType == AF_INET)
1730 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1731 /* cm_inet_c_001.main_62:Warning fix */
1732 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't bind IPV6 address on IPV4 socket,"
1733 " sockFd->fd(%ld)\n", sockFd->fd);
1734 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET058, 0, prntBuf);
1736 /* cm_inet_c_001.main_62:Warning fix */
1737 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't bind IPV6 address on IPV4 socket,"
1738 " sockFd->fd(%d)\n", sockFd->fd);
1739 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET058, 0, prntBuf);
1740 #endif /*ALIGN_64BIT*/
1741 #endif /* CMINETDBG */
1745 addrs6[idx6].sin6_family = AF_INET6;
1746 addrs6[idx6].sin6_port = CM_INET_HTON_U16(port);
1747 addrLst->addrs[idx].u.ipv4NetAddr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
1748 cmInetNtoa(addrLst->addrs[idx].u.ipv4NetAddr, &addrString);
1749 addrLen = cmStrlen((U8*)addrString);
1750 memcpy((ipv4Format+7), addrString, addrLen);
1751 ipv4Format[7+addrLen] = '\0';
1752 cmInetPton6((CmInetIpAddr6*)(addrs6[idx6].sin6_addr.s6_addr), ipv4Format);
1755 ipv4_array_size += sizeof(struct sockaddr_in);
1756 addresses_array_size += sizeof(struct sockaddr_in);
1757 addrs[idx4].sin_family = AF_INET;
1758 addrs[idx4].sin_port = CM_INET_HTON_U16(port);
1759 addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
1761 #endif /* SUN_KSCTP */
1764 ipv4_array_size += sizeof(struct sockaddr_in);
1765 addresses_array_size += sizeof(struct sockaddr_in);
1766 addrs[idx4].sin_family = AF_INET;
1767 addrs[idx4].sin_port = CM_INET_HTON_U16(port);
1768 addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
1770 #endif /* IPV6_SUPPORTED */
1774 if(ipv4_array_size > 0)
1776 sockAddrPtr = (struct sockaddr*)address_array;
1777 sockAddrLen = sizeof(struct sockaddr_in);
1778 memcpy(address_array, addrs, ipv4_array_size);
1780 #ifdef IPV6_SUPPORTED
1783 sockAddrPtr = (struct sockaddr*)address_array;
1784 sockAddrLen = sizeof(struct sockaddr_in6);
1787 if(ipv6_array_size > 0)
1789 memcpy((address_array + ipv4_array_size), addrs6, ipv6_array_size);
1791 #endif /* IPV6_SUPPORTED */
1795 ret = bind(sockFd->fd, sockAddrPtr, sockAddrLen);
1796 if (ret == INET_ERR)
1801 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1802 /* cm_inet_c_001.main_62:Warning fix */
1803 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx() Failed : error(%d), port(%d),"
1804 " sockFd->fd(%ld)\n",INET_ERR_CODE, port, sockFd->fd);
1805 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET006, 0, prntBuf);
1807 /* cm_inet_c_001.main_62:Warning fix */
1808 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx() Failed : error(%d), port(%d),"
1809 " sockFd->fd(%d)\n",INET_ERR_CODE, port, sockFd->fd);
1810 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET006, 0, prntBuf);
1811 #endif /*ALIGN_64BIT*/
1812 #endif /* CMINETDBG */
1816 if (addrLst->count > 1)
1818 if(((struct sockaddr*)address_array)->sa_family == AF_INET)
1820 tempAddrPtr = address_array + (sizeof(struct sockaddr_in));
1822 else if(((struct sockaddr*)address_array)->sa_family == AF_INET6)
1824 tempAddrPtr = address_array + (sizeof(struct sockaddr_in6));
1830 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1831 /* cm_inet_c_001.main_62:Warning fix */
1832 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx(Invalid address Type) failed:"
1833 " sockFd->fd(%ld), error(%d), port(%d)\n ",
1834 INET_ERR_CODE, port, sockFd->fd);
1835 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET059, 0, prntBuf);
1837 /* cm_inet_c_001.main_62:Warning fix */
1838 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx(Invalid address Type) failed:"
1839 " sockFd->fd(%d), error(%d), port(%d)\n ",
1840 INET_ERR_CODE, port, sockFd->fd);
1841 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET059, 0, prntBuf);
1842 #endif /*ALIGN_64BIT*/
1843 #endif /* CMINETDBG */
1847 ret = sctp_bindx(sockFd->fd, (Void*)tempAddrPtr, addrLst->count - 1, SCTP_BINDX_ADD_ADDR);
1851 ret = sctp_bindx(sockFd->fd, (struct sockaddr*)address_array, addrLst->count, SCTP_BINDX_ADD_ADDR);
1852 UNUSED(sockAddrPtr);
1853 UNUSED(sockAddrLen);
1855 if (ret == INET_ERR)
1859 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
1860 /* cm_inet_c_001.main_62:Warning fix */
1861 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx() Failed : error(%d), port(%d),"
1862 " sockFd->fd(%ld)\n",INET_ERR_CODE, port, sockFd->fd);
1863 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET007, 0, prntBuf);
1865 /* cm_inet_c_001.main_62:Warning fix */
1866 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx() Failed : error(%d), port(%d),"
1867 " sockFd->fd(%d)\n",INET_ERR_CODE, port, sockFd->fd);
1868 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET007, 0, prntBuf);
1869 #endif /*ALIGN_64BIT*/
1870 #endif /* CMINETDBG */
1879 * Fun: cmInetSctpConnectx
1881 * Desc: Establishes a sctp connection with remote addresses
1883 * Ret: ROK - successful
1892 S16 cmInetSctpConnectx
1894 CmInetFd *sockFd, /* socket file descriptor */
1895 CmInetNetAddr *primAddr, /* primary destination Internet address */
1896 CmInetNetAddrLst *addrLst, /* destination Internet address list */
1897 U16 port /* port number */
1900 S16 cmInetSctpConnectx(sockFd, primAddr, addrLst, port)
1901 CmInetFd *sockFd; /* socket file descriptor */
1902 CmInetNetAddr *primAddr; /* primary destination Internet address */
1903 CmInetNetAddrLst *addrLst; /* destination Internet address list */
1904 U16 port; /* port number */
1909 /* cm_inet_c_001.main_46: Removed SS_LINUX flag */
1912 /* cm_inet_c_001.main_64: New variable used as an argument for sctp_connectx */
1913 #ifdef SCTP_CONNECTX_NEW
1916 U32 addresses_array_size = 0;
1918 struct sockaddr_in addrs[CM_INET_NUM_NET_ADDR];
1919 U32 ipv4_array_size = 0;
1921 #ifndef IPV6_SUPPORTED
1922 Data address_array[(CM_INET_NUM_NET_ADDR * sizeof(struct sockaddr_in))];
1924 Data address_array[(CM_INET_NUM_NET_ADDR * sizeof(struct sockaddr_in6))];
1925 #endif /* IPV6_SUPPORTED */
1927 #ifdef IPV6_SUPPORTED
1929 S8 *addrString = NULLP;
1931 S8 ipv4Format[23] = "::ffff:";
1932 CmInetIpAddr ipv4NetAddr;
1933 #endif /* SUN_KSCTP */
1935 struct sockaddr_in6 addrs6[CM_INET_NUM_NET_ADDR];
1936 U32 ipv6_array_size = 0;
1937 #endif /* IPV6_SUPPORTED */
1939 U32 sockAddrLen = 0;
1940 #endif /* sockAddrLen */
1943 CmInetSockAddr *sockAddrPtr = NULLP;
1944 #endif /* SS_LINUX */
1945 #if (ERRCLASS & ERRCLS_INT_PAR)
1946 /* error check on parameters */
1947 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
1948 (primAddr == NULLP))
1952 /* cm_inet_c_001.main_58 : Added check for addrLst to fix klockwork issue */
1953 if (addrLst == NULLP)
1957 /* cm_inet_c_001.main_46: Included check for no of address aginst max */
1958 if( addrLst->count > CM_INET_NUM_NET_ADDR )
1962 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1963 /* cm_inet_c_001.main_62:Warning fix */
1964 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "No of address(%d) is greater than Max(%d),"
1965 " sockFd->fd(%ld)\n",
1966 addrLst->count, CM_INET_NUM_NET_ADDR, sockFd->fd);
1967 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET060, 0, prntBuf);
1969 /* cm_inet_c_001.main_62:Warning fix */
1970 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "No of address(%d) is greater than Max(%d),"
1971 " sockFd->fd(%d)\n",
1972 addrLst->count, CM_INET_NUM_NET_ADDR, sockFd->fd);
1973 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET060, 0, prntBuf);
1974 #endif /*ALIGN_64BIT*/
1975 #endif /* CMINETDBG */
1978 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1981 memset(&addrs, 0, (sizeof(struct sockaddr_in) * CM_INET_NUM_NET_ADDR));
1982 #ifdef IPV6_SUPPORTED
1983 memset(&addrs6, 0, (sizeof(struct sockaddr_in6) * CM_INET_NUM_NET_ADDR));
1984 #endif /* IPV6_SUPPORTED */
1988 #ifdef IPV6_SUPPORTED
1989 if (primAddr->type == CM_INET_IPV6ADDR_TYPE)
1991 if (sockFd->protType == AF_INET)
1995 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
1996 /* cm_inet_c_001.main_62:Warning fix */
1997 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't connect to IPV6 address through IPV4 socket,"
1998 " sockFd->fd(%ld)\n", sockFd->fd);
1999 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET008, 0, prntBuf);
2001 /* cm_inet_c_001.main_62:Warning fix */
2002 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't connect to IPV6 address through IPV4 socket,"
2003 " sockFd->fd(%d)\n", sockFd->fd);
2004 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET008, 0, prntBuf);
2005 #endif /*ALIGN_64BIT*/
2006 #endif /* CMINETDBG */
2010 addrs6[idx6].sin6_family = AF_INET6;
2011 addrs6[idx6].sin6_port = CM_INET_HTON_U16(port);
2012 CM_INET_COPY_IPV6ADDR(&(addrs6[idx6].sin6_addr.s6_addr), &(primAddr->u.ipv6NetAddr));
2013 addresses_array_size += sizeof(struct sockaddr_in6);
2014 ipv6_array_size += sizeof(struct sockaddr_in6);
2020 if (sockFd->protType == AF_INET)
2024 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2025 /* cm_inet_c_001.main_62:Warning fix */
2026 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4 socket,"
2027 " sockFd->fd(%ld)\n", sockFd->fd);
2028 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET061, 0, prntBuf);
2030 /* cm_inet_c_001.main_62:Warning fix */
2031 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4 socket,"
2032 " sockFd->fd(%d)\n", sockFd->fd);
2033 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET061, 0, prntBuf);
2034 #endif /*ALIGN_64BIT*/
2035 #endif /* CMINETDBG */
2038 addrs6[idx6].sin6_family = AF_INET6;
2039 addrs6[idx6].sin6_port = CM_INET_HTON_U16(port);
2040 ipv4NetAddr = CM_INET_HTON_U32(primAddr->u.ipv4NetAddr);
2041 cmInetNtoa(ipv4NetAddr, &addrString);
2042 addrLen = cmStrlen((U8*)addrString);
2043 memcpy((ipv4Format+7), addrString, addrLen);
2044 ipv4Format[7+addrLen] = '\0';
2045 cmInetPton6((CmInetIpAddr6*)&(addrs6[idx6].sin6_addr), ipv4Format);
2046 addresses_array_size += sizeof(struct sockaddr_in6);
2047 ipv6_array_size += sizeof(struct sockaddr_in6);
2050 addrs[idx4].sin_family = AF_INET;
2051 addrs[idx4].sin_port = CM_INET_HTON_U16(port);
2052 addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(primAddr->u.ipv4NetAddr);
2053 addresses_array_size += sizeof(struct sockaddr_in);
2054 ipv4_array_size += sizeof(struct sockaddr_in);
2059 addrs[idx4].sin_family = AF_INET;
2060 addrs[idx4].sin_port = CM_INET_HTON_U16(port);
2061 addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(primAddr->u.ipv4NetAddr);
2062 addresses_array_size += sizeof(struct sockaddr_in);
2063 ipv4_array_size += sizeof(struct sockaddr_in);
2065 #endif /* IPV6_SUPPORTED */
2069 /* cm_inet_c_001.main_46: Moved the SS_LINUX flag down,
2070 * copy addresses in Solaris also */
2071 if (addrLst != NULLP)
2073 for (idx = 0; idx < addrLst->count; idx++)
2076 /* cm_inet_c_001.main_46: Don't include the primary address
2077 * if its prersent in list */
2078 if ( addrLst->addrs[idx].type == CM_INET_IPV4ADDR_TYPE )
2080 if ( addrLst->addrs[idx].u.ipv4NetAddr == primAddr->u.ipv4NetAddr )
2085 #ifdef IPV6_SUPPORTED
2086 else if ( addrLst->addrs[idx].type == CM_INET_IPV6ADDR_TYPE )
2088 if (( cmMemcmp(addrLst->addrs[idx].u.ipv6NetAddr,
2089 primAddr->u.ipv6NetAddr, sizeof(CmInetIpAddr6) )) == 0 )
2095 if (addrLst->addrs[idx].type == CM_INET_IPV6ADDR_TYPE)
2097 if (sockFd->protType == AF_INET)
2101 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2102 /* cm_inet_c_001.main_62:Warning fix */
2103 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't connect to IPV6 address through IPV4 socket,"
2104 " sockFd->fd(%ld)\n", sockFd->fd);
2105 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET009, 0, prntBuf);
2107 /* cm_inet_c_001.main_62:Warning fix */
2108 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't connect to IPV6 address through IPV4 socket,"
2109 " sockFd->fd(%d)\n", sockFd->fd);
2110 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET009, 0, prntBuf);
2111 #endif /*ALIGN_64BIT*/
2112 #endif /* CMINETDBG */
2116 addrs6[idx6].sin6_family = AF_INET6;
2117 addrs6[idx6].sin6_port = CM_INET_HTON_U16(port);
2118 CM_INET_COPY_IPV6ADDR(&(addrs6[idx6].sin6_addr.s6_addr),
2119 &(addrLst->addrs[idx].u.ipv6NetAddr));
2120 addresses_array_size += sizeof(struct sockaddr_in6);
2121 ipv6_array_size += sizeof(struct sockaddr_in6);
2127 if (sockFd->protType == AF_INET)
2131 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2132 /* cm_inet_c_001.main_62:Warning fix */
2133 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4 socket,"
2134 " sockFd->fd(%ld)\n", sockFd->fd);
2135 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET062, 0, prntBuf);
2137 /* cm_inet_c_001.main_62:Warning fix */
2138 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4 socket,"
2139 " sockFd->fd(%d)\n", sockFd->fd);
2140 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET062, 0, prntBuf);
2141 #endif /*ALIGN_64BIT*/
2142 #endif /* CMINETDBG */
2145 addrs6[idx6].sin6_family = AF_INET6;
2146 addrs6[idx6].sin6_port = CM_INET_HTON_U16(port);
2147 ipv4NetAddr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
2148 cmInetNtoa(ipv4NetAddr, &addrString);
2149 addrLen = cmStrlen((U8*)addrString);
2150 memcpy((ipv4Format+7), addrString, addrLen);
2151 ipv4Format[7+addrLen] = '\0';
2152 cmInetPton6((CmInetIpAddr6*)(addrs6[idx6].sin6_addr.s6_addr), ipv4Format);
2153 addresses_array_size += sizeof(struct sockaddr_in6);
2154 ipv6_array_size += sizeof(struct sockaddr_in6);
2157 addrs[idx4].sin_family = AF_INET;
2158 addrs[idx4].sin_port = CM_INET_HTON_U16(port);
2159 addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
2160 addresses_array_size += sizeof(struct sockaddr_in);
2161 ipv4_array_size += sizeof(struct sockaddr_in);
2163 #endif /* SUN_KSCTP */
2166 addrs[idx4].sin_family = AF_INET;
2167 addrs[idx4].sin_port = CM_INET_HTON_U16(port);
2168 addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
2169 addresses_array_size += sizeof(struct sockaddr_in);
2170 ipv4_array_size += sizeof(struct sockaddr_in);
2172 #endif /* IPV6_SUPPORTED */
2173 /*cm_inet_c_001.main_39 */
2178 /* cm_inet_c_001.main_46: Moved SS_LINUX flag to here */
2180 /*cm_inet_c_001.main_58 : Added check array_size to fix klockwork issue */
2181 if((ipv4_array_size > 0) && (ipv4_array_size <= (CM_INET_NUM_NET_ADDR * \
2182 sizeof(struct sockaddr_in))))
2184 memcpy(address_array, &addrs[0], ipv4_array_size);
2191 #ifdef IPV6_SUPPORTED
2192 if((ipv6_array_size > 0) && (ipv6_array_size <= (CM_INET_NUM_NET_ADDR * \
2193 sizeof(struct sockaddr_in))))
2195 memcpy((address_array + ipv4_array_size), addrs6, ipv6_array_size);
2201 #endif /* IPV6_SUPPORTED */
2203 /* cm_inet_c_001.main_64: Support for new definition of sctp_connectx */
2204 #ifndef SCTP_CONNECTX_NEW
2205 ret = sctp_connectx(sockFd->fd, (struct sockaddr*)address_array, cnt);
2207 ret = sctp_connectx(sockFd->fd, (struct sockaddr*)address_array, cnt, (sctp_assoc_t *)&assocId);
2212 /* cm_inet_c_001.main_46: Use next provided address to connect if
2213 * first one fails */
2215 #ifdef CMINET_SUN_CONNECTX
2217 #ifdef IPV6_SUPPORTED
2219 #endif /* IPV6_SUPPORTED */
2220 for (idx = 0; idx < cnt; idx++)
2222 if( addrs[idx4].sin_family == AF_INET)
2224 sockAddrPtr = (CmInetSockAddr *)&addrs[idx4];
2225 sockAddrLen = sizeof(struct sockaddr_in);
2228 #ifdef IPV6_SUPPORTED
2231 sockAddrPtr = (CmInetSockAddr *)&addrs6[idx6];
2232 sockAddrLen = sizeof(struct sockaddr_in6);
2235 #endif/* IPV6_SUPPORTED */
2237 ret = connect(sockFd->fd, sockAddrPtr, sockAddrLen);
2239 if ( ret != INET_ERR )
2245 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2246 /* cm_inet_c_001.main_62:Warning fix */
2247 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpConnectx() failed:error(%d), port(0x%1x),"
2248 " sockFd->fd(%ld)\n", INET_ERR_CODE, port, sockFd->fd);
2249 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET063, 0, prntBuf);
2251 /* cm_inet_c_001.main_62:Warning fix */
2252 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpConnectx() failed:error(%d), port(0x%1x),"
2253 " sockFd->fd(%d)\n", INET_ERR_CODE, port, sockFd->fd);
2254 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET063, 0, prntBuf);
2255 #endif /*ALIGN_64BIT*/
2256 #endif /* CMINETDBG */
2261 if( addrs[0].sin_family == AF_INET)
2263 sockAddrPtr = (CmInetSockAddr*)&addrs[0];
2264 sockAddrLen = sizeof(struct sockaddr_in);
2267 #ifdef IPV6_SUPPORTED
2270 sockAddrPtr = (CmInetSockAddr*)&addrs6[0];
2271 sockAddrLen = sizeof(struct sockaddr_in6);
2274 #endif/* IPV6_SUPPORTED */
2276 ret = connect(sockFd->fd, sockAddrPtr, sockAddrLen);
2278 #endif /* CMINET_SUN_CONNECTX */
2279 #endif /* SS_LINUX */
2281 if (ret == INET_ERR)
2285 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2286 /* cm_inet_c_001.main_62:Warning fix */
2287 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "CmInetSctpConnectx() Failed : error(%d), port(0x%1x),"
2288 " sockFd->fd(%ld)\n", INET_ERR_CODE, port, sockFd->fd);
2289 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET010, 0, prntBuf);
2291 DU_LOG("\nCmInetSctpConnectx() Failed : error(%d), port(0x%1x),\
2292 sockFd->fd(%d)\n", INET_ERR_CODE, port, sockFd->fd);
2293 #endif /*ALIGN_64BIT*/
2294 #endif /* CMINETDBG */
2296 switch (INET_ERR_CODE)
2298 /* non-blocking: connection is in progress */
2299 case ERR_INPROGRESS:
2300 return (RINPROGRESS);
2304 * non-blocking: connection is established
2305 * blocking : connection is already established
2311 /* resource temporarily unavailable */
2312 case ERR_WOULDBLOCK:
2316 /* non-blocking: connection is in progress */
2318 return (RINPROGRESS);
2322 return (RINPROGRESS);
2325 /* Check for connection refused and timeout errors */
2326 case ERR_CONNREFUSED:
2331 /* it is a real error */
2343 * Fun: cmInetSctpPeelOff
2345 * Desc: Branches an existing sctp association off to a seperate socket
2347 * Ret: ROK - successful
2356 S16 cmInetSctpPeelOff
2358 CmInetFd *sockFd, /* socket file descriptor */
2359 U32 assocId, /* association id */
2360 CmInetFdType *assocFd /* association fd */
2363 S16 cmInetSctpPeelOff(sockFd, assocId, assocFd)
2364 CmInetFd *sockFd; /* socket file descriptor */
2365 U32 assocId; /* association id */
2366 CmInetFdType *assocFd; /* association fd */
2371 #if (ERRCLASS & ERRCLS_INT_PAR)
2372 /* error check on parameters */
2373 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) || (assocFd == NULLP))
2377 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2380 ret = sctp_peeloff(sockFd->fd, assocId);
2381 if (ret == INET_ERR)
2385 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2386 /* cm_inet_c_001.main_62:Warning fix */
2387 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpPeelOff() Failed : error(%d) assocId(%ld),"
2388 " sockFd->fd(%ld)\n", INET_ERR_CODE, assocId, sockFd->fd);
2389 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET011, 0, prntBuf);
2391 /* cm_inet_c_001.main_55: Fix for compilation warning */
2392 /* cm_inet_c_001.main_62:Warning fix */
2393 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpPeelOff() Failed : error(%d) assocId(%d),"
2394 " sockFd->fd(%d)\n", INET_ERR_CODE, assocId, sockFd->fd);
2395 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET011, 0, prntBuf);
2396 #endif /*ALIGN_64BIT*/
2397 #endif /* CMINETDBG */
2409 * Fun: cmInetSctpSendMsg
2411 * Desc: invokes sctp socket API to send message to the remote addresses
2413 * Ret: ROK - successful
2422 S16 cmInetSctpSendMsg
2424 CmInetFd *sockFd, /* socket file descriptor */
2425 CmInetNetAddr *dstAddr, /* destination Internet address/port */
2426 U16 port, /* destination port no. */
2427 CmInetMemInfo *info, /* buffer allocation info */
2428 Buffer *mBuf, /* buffer structure to send */
2429 MsgLen *len, /* number of actually sent octets */
2430 U16 strmId, /* sctp stream identifier */
2431 Bool unorderFlg, /* flag to enable the unordered delivery */
2432 U16 ttl, /* time to live */
2433 U32 ppId, /* opaque value passed along with the message */
2434 U32 context /* value to be passed back, if error occurs */
2437 S16 cmInetSctpSendMsg(sockFd, dstAddr, port, info, mBuf, len, strmId,
2438 unorderFlg, ttl, ppId, context)
2439 CmInetFd *sockFd; /* socket file descriptor */
2440 CmInetNetAddr *dstAddr; /* destination Internet address/port */
2441 U16 port; /* destination port no. */
2442 CmInetMemInfo *info; /* buffer allocation info */
2443 Buffer *mBuf; /* buffer structure to send */
2444 MsgLen *len; /* number of actually sent octets */
2445 U16 strmId; /* sctp stream identifier */
2446 Bool unorderFlg; /* flag to enable the unordered delivery */
2447 U16 ttl; /* time to live */
2448 U32 ppId; /* opaque value passed along with the message */
2449 U32 context; /* value to be passed back, if error occurs */
2453 /* cm_inet_c_001.main_58 : Fix for klockwork issue */
2454 MsgLen msgLen = 0; /* message length */
2455 MsgLen bufLen = 0; /* send buffer length */
2456 Data *sendBuf = NULLP; /* plain send buffer */
2458 CmInetSockAddr *sockAddrPtr = NULLP;
2459 /* cm_inet_c_001.main_58 : Fix for klockwork issue */
2460 MsgLen sockAddrLen = 0;
2461 struct sockaddr_in addr;
2462 #ifdef IPV6_SUPPORTED
2464 S8 *addrString = NULLP;
2466 S8 ipv4Format[23] = "::ffff:";
2467 CmInetIpAddr ipv4NetAddr;
2468 #endif /* SUN_KSCTP */
2469 struct sockaddr_in6 addr6;
2470 #endif /* IPV6_SUPPORTED */
2472 #if (ERRCLASS & ERRCLS_INT_PAR)
2473 /* error check on parameters */
2474 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd)
2475 || (info == NULLP) || (mBuf == NULLP) || (len == NULLP))
2479 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2482 memset(&addr, 0, sizeof(struct sockaddr_in));
2483 #ifdef IPV6_SUPPORTED
2484 memset(&addr6, 0, sizeof(struct sockaddr_in6));
2485 #endif /* IPV6_SUPPORTED */
2487 /* copy message to a flat buffer */
2488 ret = SFndLenMsg(mBuf, &bufLen);
2493 /* max message length is limited to control the memory usage */
2494 /* casting bufLen to avoid warnings */
2495 if ((bufLen > 0) && ((U32)bufLen > CM_INET_MAX_MSG_LEN))
2499 ret = SGetSBuf(info->region, info->pool, &sendBuf, bufLen);
2504 ret = SCpyMsgFix(mBuf, 0, bufLen, sendBuf, &msgLen);
2505 if ((ret != ROK) || (msgLen != bufLen))
2507 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
2511 if ( dstAddr != NULLP)
2513 #ifdef IPV6_SUPPORTED
2514 if (dstAddr->type == CM_INET_IPV6ADDR_TYPE)
2516 if (sockFd->protType == AF_INET)
2518 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
2521 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2522 /* cm_inet_c_001.main_62:Warning fix */
2523 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't send message to IPV6 address through"
2524 " IPV4 socket, sockFd->fd(%ld)\n", sockFd->fd);
2525 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET012, 0, prntBuf);
2527 /* cm_inet_c_001.main_62:Warning fix */
2528 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't send message to IPV6 address through"
2529 " IPV4 socket, sockFd->fd(%d)\n", sockFd->fd);
2530 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET012, 0, prntBuf);
2531 #endif /*ALIGN_64BIT*/
2532 #endif /* CMINETDBG */
2536 addr6.sin6_family = AF_INET6;
2537 addr6.sin6_port = CM_INET_HTON_U16(port);
2538 CM_INET_COPY_IPV6ADDR(&addr6.sin6_addr.s6_addr, &dstAddr->u.ipv6NetAddr);
2539 sockAddrLen = sizeof(struct sockaddr_in6);
2540 sockAddrPtr = (CmInetSockAddr*)&addr6;
2546 if (sockFd->protType == AF_INET)
2550 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2551 /* cm_inet_c_001.main_62:Warning fix */
2552 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4"
2553 " socket, sockFd->fd(%ld)\n", sockFd->fd);
2554 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET064, 0, prntBuf);
2556 /* cm_inet_c_001.main_62:Warning fix */
2557 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4"
2558 " socket, sockFd->fd(%d)\n", sockFd->fd);
2559 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET064, 0, prntBuf);
2560 #endif /*ALIGN_64BIT*/
2561 #endif /* CMINETDBG */
2564 addr6.sin6_family = AF_INET6;
2565 addr6.sin6_port = CM_INET_HTON_U16(port);
2566 ipv4NetAddr = CM_INET_HTON_U32(dstAddr->u.ipv4NetAddr);
2567 cmInetNtoa(ipv4NetAddr, &addrString);
2568 addrLen = cmStrlen((U8*)addrString);
2569 memcpy((ipv4Format+7), addrString, addrLen);
2570 ipv4Format[7+addrLen] = '\0';
2571 cmInetPton6((CmInetIpAddr6*)(addr6.sin6_addr.s6_addr), ipv4Format);
2572 sockAddrLen = sizeof(struct sockaddr_in6);
2573 sockAddrPtr = (CmInetSockAddr*)&addr6;
2575 addr.sin_family = AF_INET;
2576 addr.sin_port = CM_INET_HTON_U16(port);
2577 addr.sin_addr.s_addr = CM_INET_HTON_U32(dstAddr->u.ipv4NetAddr);
2578 sockAddrLen = sizeof(struct sockaddr_in);
2579 sockAddrPtr = (CmInetSockAddr*)&addr;
2580 #endif /* SUN_KSCTP */
2583 addr.sin_family = AF_INET;
2584 addr.sin_port = CM_INET_HTON_U16(port);
2585 addr.sin_addr.s_addr = CM_INET_HTON_U32(dstAddr->u.ipv4NetAddr);
2586 /* cm_inet_c_001.main_58 : Fix for Klockwork issue */
2587 sockAddrLen = (MsgLen)sizeof(struct sockaddr_in);
2588 sockAddrPtr = (CmInetSockAddr*)&addr;
2589 #endif /* IPV6_SUPPORTED */
2596 sockAddrPtr = (CmInetSockAddr*)&addr;
2598 /* cm_inet_c_001.main_58 : initialized sockAddrLen properly */
2599 #ifdef IPV6_SUPPORTED
2600 sockAddrLen = sizeof(struct sockaddr_in6);
2602 sockAddrLen = sizeof(struct sockaddr_in);
2606 /* Not validating the address, whether addr is a valid address or not */
2611 if (unorderFlg == TRUE)
2614 flags |= MSG_UNORDERED;
2617 flags |= SCTP_UNORDERED;
2620 /*cm_inet_c_001.main_54: converting ppid to network*/
2621 ppId = CM_INET_HTON_U32(ppId);
2622 ret = sctp_sendmsg(sockFd->fd, (Void*)sendBuf, bufLen,
2623 (struct sockaddr*)sockAddrPtr, (size_t)sockAddrLen,
2624 ppId, flags, strmId, ttl, context);
2625 if (ret == INET_ERR)
2627 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
2630 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2631 /* cm_inet_c_001.main_62:Warning fix */
2632 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpSendMsg() Failed : error(%d) ppId(%ld),"
2633 " strmId(%u),sockFd->fd(%ld)\n",
2634 INET_ERR_CODE, ppId, strmId, sockFd->fd);
2635 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET013, 0, prntBuf);
2637 /* cm_inet_c_001.main_55: Fix for compilation warning */
2638 /* cm_inet_c_001.main_62:Warning fix */
2639 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpSendMsg() Failed : error(%d) ppId(%d),"
2640 " strmId(%u),sockFd->fd(%d)\n",
2641 INET_ERR_CODE, ppId, strmId, sockFd->fd);
2642 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET013, 0, prntBuf);
2643 #endif /*ALIGN_64BIT*/
2644 #endif /* CMINETDBG */
2646 if ((INET_ERR_CODE == ERR_AGAIN) || (INET_ERR_CODE == ERR_WOULDBLOCK))
2647 return (RWOULDBLOCK);
2648 else if (INET_ERR_CODE == ERR_PIPE)
2654 /* cm_inet_c_001.main_58 : Fix for klockwork issue */
2658 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
2665 * Fun: cmInetSctpRecvMsg
2667 * Desc: invokes sctp API to get the message received at sctp socket
2669 * Ret: ROK - successful
2678 S16 cmInetSctpRecvMsg
2680 CmInetFd *sockFd, /* socket file descriptor */
2681 CmInetNetAddr *srcAddr, /* source Internet address/port */
2682 U16 *port, /* source port no. */
2683 CmInetMemInfo *meminfo, /* buffer allocation info */
2684 Buffer **mBuf, /* buffer structure received */
2685 MsgLen *len, /* number of octets received */
2686 CmInetSctpSndRcvInfo *sinfo, /* sctp send-receive info */
2687 U32 *flag, /* flags */
2688 CmInetSctpNotification *ntfy /* notification parameters */
2691 S16 cmInetSctpRecvMsg(sockFd, srcAddr, port, meminfo, mBuf, len,
2693 CmInetFd *sockFd; /* socket file descriptor */
2694 CmInetNetAddr *srcAddr; /* source Internet address/port */
2695 U16 *port; /* source port no. */
2696 CmInetMemInfo *meminfo; /* buffer allocation info */
2697 Buffer **mBuf; /* buffer structure received */
2698 MsgLen *len; /* number of octets received */
2699 CmInetSctpSndRcvInfo *sinfo; /* sctp send-receive info */
2700 U32 *flag; /* flags */
2701 CmInetSctpNotification *ntfy; /* notification parameters */
2706 struct sctp_sndrcvinfo info;
2707 struct sockaddr_storage addr;
2708 struct sockaddr_in *pAddr = NULLP;
2709 #ifdef IPV6_SUPPORTED
2710 struct sockaddr_in6 *pAddr6 = NULLP;
2713 Data *recvbuf = NULLP;
2715 union sctp_notification *sctpNtfy = NULLP;
2716 /* cm_inet_c_001.main_46: Defined new variable to store length of data */
2719 #endif /* SS_LINUX */
2721 #if (ERRCLASS & ERRCLS_INT_PAR)
2722 /* error check on parameters */
2723 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
2724 (srcAddr == NULLP) || (port == NULLP) || (meminfo == NULLP) ||
2725 (mBuf == NULLP) || (len == NULLP) || (sinfo == NULLP) || (flag == NULLP))
2729 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2734 memset(ntfy, 0, sizeof(CmInetSctpNotification));
2736 buflen = CM_INET_MAX_MSG_LEN;
2738 /* allocate flat receive buffer */
2739 ret = SGetSBuf(meminfo->region, meminfo->pool, &recvbuf, buflen);
2743 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2744 /* cm_inet_c_001.main_62:Warning fix */
2745 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SGetSBuf failed to allocate memory\n");
2746 CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET065, 0, prntBuf);
2747 #endif /* CMINETDBG */
2751 addrlen = sizeof(struct sockaddr_storage);
2753 memset(&addr, 0, sizeof(struct sockaddr_storage));
2754 memset(&info, 0, sizeof(struct sctp_sndrcvinfo));
2756 ret = sctp_recvmsg(sockFd->fd, (Void *)recvbuf, (size_t)buflen,
2757 (struct sockaddr*)&addr, &addrlen, &info,
2759 if (ret == INET_ERR)
2762 SPutSBuf(meminfo->region, meminfo->pool, recvbuf, buflen);
2765 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2766 /* cm_inet_c_001.main_62:Warning fix */
2767 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpRecvMsg() Failed : error(%d),"
2768 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
2769 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET014, 0, prntBuf);
2771 DU_LOG("\ncmInetSctpRecvMsg() Failed : error(%d), sockFd->fd(%d)", \
2772 INET_ERR_CODE, sockFd->fd);
2773 #endif /*ALIGN_64BIT*/
2774 #endif /* CMINETDBG */
2779 /* save the length of the received message */
2780 /* cm_inet_c_001.main_58 : Fix for klockwork issue */
2783 #ifdef IPV6_SUPPORTED
2784 if (addr.ss_family == AF_INET6)
2786 U8 ipv4Format[12] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff};
2787 pAddr6 = (struct sockaddr_in6*)&addr;
2788 *port = CM_INET_NTOH_U16(pAddr6->sin6_port);
2790 if((cmMemcmp(ipv4Format, pAddr6->sin6_addr.s6_addr, 12)) == 0)
2792 srcAddr->type = CM_INET_IPV4ADDR_TYPE;
2793 memcpy(&srcAddr->u.ipv4NetAddr, ((pAddr6->sin6_addr.s6_addr) + 12), sizeof(U32));
2794 srcAddr->u.ipv4NetAddr = CM_INET_HTON_U32(srcAddr->u.ipv4NetAddr);
2799 srcAddr->type = CM_INET_IPV6ADDR_TYPE;
2800 CM_INET_COPY_IPV6ADDR(&srcAddr->u.ipv6NetAddr, &pAddr6->sin6_addr.s6_addr);
2805 pAddr = (struct sockaddr_in*)&addr;
2806 *port = CM_INET_NTOH_U16(pAddr->sin_port);
2807 srcAddr->type = CM_INET_IPV4ADDR_TYPE;
2808 srcAddr->u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
2811 pAddr = (struct sockaddr_in*)&addr;
2812 *port = CM_INET_NTOH_U16(pAddr->sin_port);
2813 srcAddr->type = CM_INET_IPV4ADDR_TYPE;
2814 srcAddr->u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
2815 #endif /* IPV6_SUPPORTED */
2817 /* fill sndrcv info */
2818 sinfo->stream = info.sinfo_stream;
2819 sinfo->ssn = info.sinfo_ssn;
2820 sinfo->flags = info.sinfo_flags;
2821 /*cm_inet_c_001.main_54: converting ppid to host*/
2822 sinfo->ppid = CM_INET_NTOH_U32(info.sinfo_ppid);
2823 sinfo->context = info.sinfo_context;
2824 sinfo->timetolive = info.sinfo_timetolive;
2825 sinfo->tsn = info.sinfo_tsn;
2826 sinfo->cumtsn = info.sinfo_cumtsn;
2827 sinfo->assocId = info.sinfo_assoc_id;
2829 /* fill message flags */
2831 if ((msgFlags & MSG_EOR) != 0)
2832 *flag |= CM_INET_SCTP_MSG_EOR;
2834 if ((msgFlags & MSG_NOTIFICATION) != 0)
2836 *flag |= CM_INET_SCTP_MSG_NOTIFICATION;
2839 sctpNtfy = (union sctp_notification*)recvbuf;
2841 ntfy->header.nFlags = sctpNtfy->sn_header.sn_flags;
2842 ntfy->header.nLen = sctpNtfy->sn_header.sn_length;
2844 switch(sctpNtfy->sn_header.sn_type)
2846 case SCTP_ASSOC_CHANGE:
2847 ntfy->header.nType = CM_INET_SCTP_ASSOC_CHANGE;
2848 switch(sctpNtfy->sn_assoc_change.sac_state)
2851 ntfy->u.assocChange.state = CM_INET_SCTP_COMM_UP;
2853 case SCTP_COMM_LOST:
2854 ntfy->u.assocChange.state = CM_INET_SCTP_COMM_LOST;
2857 ntfy->u.assocChange.state = CM_INET_SCTP_RESTART;
2859 case SCTP_SHUTDOWN_COMP:
2860 ntfy->u.assocChange.state = CM_INET_SCTP_SHUTDOWN_COMP;
2862 case SCTP_CANT_STR_ASSOC:
2863 ntfy->u.assocChange.state = CM_INET_SCTP_CANT_STR_ASSOC;
2868 ntfy->u.assocChange.error = sctpNtfy->sn_assoc_change.sac_error;
2869 ntfy->u.assocChange.outStreams = sctpNtfy->sn_assoc_change.sac_outbound_streams;
2870 ntfy->u.assocChange.inStreams = sctpNtfy->sn_assoc_change.sac_inbound_streams;
2871 ntfy->u.assocChange.assocId = sctpNtfy->sn_assoc_change.sac_assoc_id;
2873 ntfy->u.assocChange.info = sctpNtfy->sn_assoc_change.sac_info;
2876 case SCTP_PEER_ADDR_CHANGE:
2877 ntfy->header.nType = CM_INET_SCTP_PEER_ADDR_CHANGE;
2878 switch(sctpNtfy->sn_paddr_change.spc_state)
2880 case SCTP_ADDR_AVAILABLE:
2881 ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_AVAILABLE;
2883 case SCTP_ADDR_UNREACHABLE:
2884 ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_UNREACHABLE;
2886 case SCTP_ADDR_REMOVED:
2887 ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_REMOVED;
2889 case SCTP_ADDR_ADDED:
2890 ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_ADDED;
2892 case SCTP_ADDR_MADE_PRIM:
2893 ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_MADE_PRIM;
2896 case SCTP_ADDR_CONFIRMED:
2897 ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_CONFIRMED;
2904 #ifdef IPV6_SUPPORTED
2905 if (sctpNtfy->sn_paddr_change.spc_aaddr.ss_family == AF_INET6)
2907 pAddr6 = (struct sockaddr_in6*)&(sctpNtfy->sn_paddr_change.spc_aaddr);
2908 ntfy->u.paddrChange.addr.type = CM_INET_IPV6ADDR_TYPE;
2909 CM_INET_COPY_IPV6ADDR(&ntfy->u.paddrChange.addr.u.ipv6NetAddr,
2910 &pAddr6->sin6_addr.s6_addr);
2914 pAddr = (struct sockaddr_in*)&(sctpNtfy->sn_paddr_change.spc_aaddr);
2915 ntfy->u.paddrChange.addr.type = CM_INET_IPV4ADDR_TYPE;
2916 ntfy->u.paddrChange.addr.u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
2919 pAddr = (struct sockaddr_in*)&(sctpNtfy->sn_paddr_change.spc_aaddr);
2920 ntfy->u.paddrChange.addr.type = CM_INET_IPV4ADDR_TYPE;
2921 ntfy->u.paddrChange.addr.u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
2922 #endif /* IPV6_SUPPORTED */
2924 ntfy->u.paddrChange.error = sctpNtfy->sn_paddr_change.spc_error;
2925 ntfy->u.paddrChange.assocId = sctpNtfy->sn_paddr_change.spc_assoc_id;
2927 case SCTP_REMOTE_ERROR:
2928 ntfy->header.nType = CM_INET_SCTP_REMOTE_ERROR;
2930 ntfy->u.remoteErr.error = sctpNtfy->sn_remote_error.sre_error;
2931 ntfy->u.remoteErr.assocId = sctpNtfy->sn_remote_error.sre_assoc_id;
2933 /* cm_inet_c_001.main_46: Allocate memory for data before copying */
2934 datlen = cmStrlen(sctpNtfy->sn_remote_error.sre_data) + 1;
2936 ret = SGetSBuf( meminfo->region, meminfo->pool, \
2937 &ntfy->u.remoteErr.data, datlen );
2940 ntfy->u.remoteErr.data = NULLP;
2943 memcpy(ntfy->u.remoteErr.data,\
2944 sctpNtfy->sn_remote_error.sre_data, datlen);
2947 case SCTP_SEND_FAILED:
2948 ntfy->header.nType = CM_INET_SCTP_SEND_FAILED;
2950 ntfy->u.sndFailed.error = sctpNtfy->sn_send_failed.ssf_error;
2951 ntfy->u.sndFailed.assocId = sctpNtfy->sn_send_failed.ssf_assoc_id;
2953 /* cm_inet_c_001.main_46: Allocate memory for data before copying */
2954 datlen = cmStrlen(sctpNtfy->sn_send_failed.ssf_data) + 1;
2956 ret = SGetSBuf( meminfo->region, meminfo->pool, \
2957 &ntfy->u.sndFailed.data, datlen );
2960 ntfy->u.sndFailed.data = NULLP;
2963 memcpy(ntfy->u.sndFailed.data,\
2964 sctpNtfy->sn_send_failed.ssf_data, datlen );
2966 ntfy->u.sndFailed.info.stream = sctpNtfy->sn_send_failed.ssf_info.sinfo_stream;
2967 ntfy->u.sndFailed.info.ssn = sctpNtfy->sn_send_failed.ssf_info.sinfo_ssn;
2968 ntfy->u.sndFailed.info.flags = sctpNtfy->sn_send_failed.ssf_info.sinfo_flags;
2969 ntfy->u.sndFailed.info.ppid = sctpNtfy->sn_send_failed.ssf_info.sinfo_ppid;
2970 ntfy->u.sndFailed.info.context = sctpNtfy->sn_send_failed.ssf_info.sinfo_context;
2971 ntfy->u.sndFailed.info.timetolive = sctpNtfy->sn_send_failed.ssf_info.sinfo_timetolive;
2972 ntfy->u.sndFailed.info.tsn = sctpNtfy->sn_send_failed.ssf_info.sinfo_tsn;
2973 ntfy->u.sndFailed.info.cumtsn = sctpNtfy->sn_send_failed.ssf_info.sinfo_cumtsn;
2974 ntfy->u.sndFailed.info.assocId = sctpNtfy->sn_send_failed.ssf_info.sinfo_assoc_id;
2976 case SCTP_SHUTDOWN_EVENT:
2977 ntfy->header.nType = CM_INET_SCTP_SHUTDOWN_EVENT;
2979 ntfy->u.shutdownEvt.assocId = sctpNtfy->sn_shutdown_event.sse_assoc_id;
2982 case SCTP_ADAPTION_INDICATION :
2985 case SCTP_ADAPTATION_INDICATION :
2987 ntfy->header.nType = CM_INET_SCTP_ADAPTATION_INDICATION;
2990 ntfy->u.adaptationEvt.adaptationInd = sctpNtfy->sn_adaption_event.sai_adaption_ind;
2991 ntfy->u.adaptationEvt.assocId = sctpNtfy->sn_adaption_event.sai_assoc_id;
2994 ntfy->u.adaptationEvt.adaptationInd = sctpNtfy->sn_adaptation_event.sai_adaptation_ind;
2995 ntfy->u.adaptationEvt.assocId = sctpNtfy->sn_adaptation_event.sai_assoc_id;
2998 case SCTP_PARTIAL_DELIVERY_EVENT:
2999 ntfy->header.nType = CM_INET_SCTP_PARTIAL_DELIVERY_EVENT;
3001 ntfy->u.pdapiEvt.indication = sctpNtfy->sn_pdapi_event.pdapi_indication;
3002 ntfy->u.pdapiEvt.assocId = sctpNtfy->sn_pdapi_event.pdapi_assoc_id;
3010 /* get a message buffer */
3011 ret = SGetMsg(meminfo->region, meminfo->pool, mBuf);
3014 SPutSBuf(meminfo->region, meminfo->pool, recvbuf, buflen);
3018 ret = SAddPstMsgMult(recvbuf, *len, *mBuf);
3022 SPutSBuf(meminfo->region, meminfo->pool, recvbuf, buflen);
3028 SPutSBuf(meminfo->region, meminfo->pool, recvbuf, buflen);
3035 * Fun: cmInetSctpGetPAddrs
3037 * Desc: returns the list of peer addresses
3039 * Ret: ROK - successful
3048 S16 cmInetSctpGetPAddrs
3050 CmInetFd *sockFd, /* socket file descriptor */
3051 U32 assocId, /* association id */
3052 CmInetNetAddrLst *addrlst /* peer address list */
3055 S16 cmInetSctpGetPAddrs(sockFd, assocId, addrlst)
3056 CmInetFd *sockFd; /* socket file descriptor */
3057 U32 assocId; /* association id */
3058 CmInetNetAddrLst *addrlst; /* peer address list */
3061 /* cm_inet_c_001.main_58 : Fix for Klockwork issue */
3065 struct sockaddr *peerAddrList;
3066 struct sockaddr_in *pAddr;
3067 #ifdef IPV6_SUPPORTED
3068 struct sockaddr_in6 *pAddr6;
3069 #endif /* IPV6_SUPPORTED */
3072 if((cnt = sctp_getpaddrs(sockFd->fd, assocId, (Void**)&peerAddrList)) == -1)
3074 if((cnt = sctp_getpaddrs(sockFd->fd, assocId, &peerAddrList)) == -1)
3079 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
3080 /* cm_inet_c_001.main_62:Warning fix */
3081 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpGetPAddrs() Failed : error(%d),"
3082 " sockFd->fd(%ld), assocId(%ld)\n",
3083 INET_ERR_CODE, sockFd->fd, assocId);
3084 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET015, 0, prntBuf);
3086 /* cm_inet_c_001.main_55: Fix for compilation warning */
3087 /* cm_inet_c_001.main_62:Warning fix */
3088 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpGetPAddrs() Failed : error(%d),"
3089 " sockFd->fd(%d),assocId(%d)\n",
3090 INET_ERR_CODE, sockFd->fd, assocId);
3091 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET015, 0, prntBuf);
3092 #endif /*ALIGN_64BIT*/
3093 #endif /* CMINETDBG */
3098 byteAddress = (U8*)peerAddrList;
3099 for (idx = 0; idx < cnt; idx++)
3101 #ifdef IPV6_SUPPORTED
3103 if (((struct sockaddr*)byteAddress)->sa_family == AF_INET6)
3105 if (sockFd->protType == AF_INET)
3109 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
3110 sprintf(prntBuf, "cmInetSctpGetPAddrs() Failed : Invalid address"
3111 " sockFd->fd(%ld)", sockFd->fd);
3112 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET016, 0, prntBuf);
3114 sprintf(prntBuf, "cmInetSctpGetPAddrs() Failed : Invalid address"
3115 " sockFd->fd(%d)", sockFd->fd);
3116 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET016, 0, prntBuf);
3117 #endif /*ALIGN_64BIT*/
3118 #endif /* CMINETDBG */
3120 sctp_freepaddrs(peerAddrList);
3124 pAddr6 = (struct sockaddr_in6*)byteAddress;
3126 addrlst->addrs[idx].type = CM_INET_IPV6ADDR_TYPE;
3127 CM_INET_COPY_IPV6ADDR(&(addrlst->addrs[idx].u.ipv6NetAddr), &(pAddr6->sin6_addr.s6_addr));
3128 byteAddress += sizeof(struct sockaddr_in6);
3132 pAddr = (struct sockaddr_in*)byteAddress;
3133 addrlst->addrs[idx].type = CM_INET_IPV4ADDR_TYPE;
3134 addrlst->addrs[idx].u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
3135 byteAddress += sizeof(struct sockaddr_in);
3138 pAddr = (struct sockaddr_in*)byteAddress;
3139 addrlst->addrs[idx].type = CM_INET_IPV4ADDR_TYPE;
3140 addrlst->addrs[idx].u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
3141 byteAddress += sizeof(struct sockaddr_in);
3142 #endif /* IPV6_SUPPORTED */
3145 /* cm_inet_c_001.main_58 : Fix for klockwork issue */
3146 addrlst->count = (U8)cnt;
3148 sctp_freepaddrs(peerAddrList);
3157 * Desc: invokes socket API to retrive specified socket options
3159 * Ret: ROK - successful
3170 CmInetFd *sockFd, /* socket file descriptor */
3171 U32 level, /* option level */
3172 U32 type, /* option type */
3173 Ptr value /* option value */
3176 S16 cmInetGetOpt(sockFd, level, type, value)
3177 CmInetFd *sockFd; /* socket file descriptor */
3178 U32 level; /* option level */
3179 U32 type; /* option type */
3180 Ptr value; /* option value */
3184 struct sctp_status status;
3185 struct sctp_paddrinfo addrInfo;
3186 struct sockaddr_in *pAddr;
3187 #ifdef IPV6_SUPPORTED
3188 struct sockaddr_in6 *pAddr6;
3189 #endif /* IPV6_SUPPORTED */
3190 struct sctp_assocparams assocParams;
3191 /*cm_inet_c_001.main_40 Updated for the support of configurable RTO parameters,
3192 HBeat value Max retransmissions (Init, Path, Association)*/
3193 struct sctp_initmsg initMsg;
3194 struct sctp_rtoinfo rtoInfo;
3195 struct sctp_paddrparams addrParams;
3196 CmInetSctpStatus *pSctpStatus;
3197 CmInetSctpPeerAddrInfo *pPeerAddrInfo;
3198 CmInetSctpInitMsg *pInitMsg;
3199 CmInetSctpAssocParams *pAssocParams;
3200 CmInetSctpRtoInfo *pRtoInfo;
3201 CmInetSctpPeerAddrParams *pPeerAddrParams;
3202 /*cm_inet_c_001.main_58 : fix for klockwork issue */
3206 #if (ERRCLASS & ERRCLS_INT_PAR)
3207 /* error check on parameters */
3208 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
3212 #endif /* ERRCLASS & ERRCLS_INT_PAR */
3216 case CM_INET_OPT_SCTP_GET_ASSOC_STA:
3217 pSctpStatus = (CmInetSctpStatus*)value;
3218 memset(&status, 0, sizeof(struct sctp_status));
3219 len = sizeof(status);
3220 status.sstat_assoc_id = pSctpStatus->assocId;
3222 ret = getsockopt(sockFd->fd, level, SCTP_STATUS, &status, &len);
3224 pSctpStatus->rwnd = status.sstat_rwnd;
3225 pSctpStatus->unackdata = status.sstat_unackdata;
3226 pSctpStatus->penddata = status.sstat_penddata;
3227 pSctpStatus->instrms = status.sstat_instrms;
3228 pSctpStatus->outstrms = status.sstat_outstrms;
3229 pSctpStatus->fragPoint = status.sstat_fragmentation_point;
3231 switch (status.sstat_state)
3241 pSctpStatus->state = CM_INET_SCTP_STA_EMPTY;
3248 pSctpStatus->state = CM_INET_SCTP_STA_CLOSED;
3254 case SCTPS_COOKIE_WAIT:
3256 case SCTP_COOKIE_WAIT:
3259 pSctpStatus->state = CM_INET_SCTP_STA_COOKIE_WAIT;
3264 case SCTPS_COOKIE_ECHOED:
3266 case SCTP_COOKIE_ECHOED:
3269 pSctpStatus->state = CM_INET_SCTP_STA_COOKIE_ECHOED;
3274 case SCTPS_ESTABLISHED:
3276 case SCTP_ESTABLISHED:
3279 pSctpStatus->state = CM_INET_SCTP_STA_ESTABLISHED;
3284 case SCTPS_SHUTDOWN_PENDING:
3286 case SCTP_SHUTDOWN_PENDING:
3289 pSctpStatus->state = CM_INET_SCTP_STA_SHUTDOWN_PENDING;
3294 case SCTPS_SHUTDOWN_SENT:
3296 case SCTP_SHUTDOWN_SENT:
3299 pSctpStatus->state = CM_INET_SCTP_STA_SHUTDOWN_SENT;
3304 case SCTPS_SHUTDOWN_RECEIVED:
3306 case SCTP_SHUTDOWN_RECEIVED:
3309 pSctpStatus->state = CM_INET_SCTP_STA_SHUTDOWN_RECEIVED;
3314 case SCTPS_SHUTDOWN_ACK_SENT:
3316 case SCTP_SHUTDOWN_ACK_SENT:
3319 pSctpStatus->state = CM_INET_SCTP_STA_SHUTDOWN_ACK_SENT;
3330 #ifdef IPV6_SUPPORTED
3331 if (status.sstat_primary.spinfo_address.ss_family == AF_INET6)
3333 pAddr6 = (struct sockaddr_in6*)&(status.sstat_primary.spinfo_address);
3334 pSctpStatus->primary.port = CM_INET_NTOH_U16(pAddr6->sin6_port);
3336 pSctpStatus->primary.addr.type = CM_INET_IPV6ADDR_TYPE;
3337 CM_INET_COPY_IPV6ADDR(&pSctpStatus->primary.addr.u.ipv6NetAddr,
3338 &pAddr6->sin6_addr.s6_addr);
3342 pAddr = (struct sockaddr_in*)&(status.sstat_primary.spinfo_address);
3343 pSctpStatus->primary.port = CM_INET_NTOH_U16(pAddr->sin_port);
3344 pSctpStatus->primary.addr.type = CM_INET_IPV4ADDR_TYPE;
3345 pSctpStatus->primary.addr.u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
3348 pAddr = (struct sockaddr_in*)&(status.sstat_primary.spinfo_address);
3349 pSctpStatus->primary.port = CM_INET_NTOH_U16(pAddr->sin_port);
3350 pSctpStatus->primary.addr.type = CM_INET_IPV4ADDR_TYPE;
3351 pSctpStatus->primary.addr.u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
3352 #endif /* IPV6_SUPPORTED */
3354 pSctpStatus->primary.assocId = status.sstat_primary.spinfo_assoc_id;
3355 if (status.sstat_primary.spinfo_state == SCTP_ACTIVE)
3356 pSctpStatus->primary.isActive = TRUE;
3359 pSctpStatus->primary.isActive = FALSE;
3360 pSctpStatus->primary.cwnd = status.sstat_primary.spinfo_cwnd;
3361 pSctpStatus->primary.srtt = status.sstat_primary.spinfo_srtt;
3362 pSctpStatus->primary.rto = status.sstat_primary.spinfo_rto;
3363 pSctpStatus->primary.mtu = status.sstat_primary.spinfo_mtu;
3367 case CM_INET_OPT_SCTP_GET_PADDR_INFO:
3368 pPeerAddrInfo = (CmInetSctpPeerAddrInfo*)value;
3369 memset(&addrInfo, 0, sizeof(struct sctp_paddrinfo));
3370 len = sizeof(addrInfo);
3371 addrInfo.spinfo_assoc_id = pPeerAddrInfo->assocId;
3373 #ifdef IPV6_SUPPORTED
3374 if (pPeerAddrInfo->addr.type == CM_INET_IPV6ADDR_TYPE)
3376 if (sockFd->protType == AF_INET)
3380 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
3381 /* cm_inet_c_001.main_62:Warning fix */
3382 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetOpt() Failed : Invalid address,"
3383 " sockFd->fd(%ld)\n", sockFd->fd);
3384 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET017, 0, prntBuf);
3386 /* cm_inet_c_001.main_62:Warning fix */
3387 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetOpt() Failed : Invalid address,"
3388 " sockFd->fd(%d)\n", sockFd->fd);
3389 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET017, 0, prntBuf);
3390 #endif /*ALIGN_64BIT*/
3391 #endif /* CMINETDBG */
3395 pAddr6 = (struct sockaddr_in6*)&(addrInfo.spinfo_address);
3396 pAddr6->sin6_family = AF_INET6;
3397 pAddr6->sin6_port = CM_INET_HTON_U16(pPeerAddrInfo->port);
3398 CM_INET_COPY_IPV6ADDR(&pAddr6->sin6_addr.s6_addr, &pPeerAddrInfo->addr.u.ipv6NetAddr);
3402 pAddr = (struct sockaddr_in*)&(addrInfo.spinfo_address);
3403 pAddr->sin_family = AF_INET;
3404 pAddr->sin_port = CM_INET_HTON_U16(pPeerAddrInfo->port);
3405 pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pPeerAddrInfo->addr.u.ipv4NetAddr);
3408 pAddr = (struct sockaddr_in*)&(addrInfo.spinfo_address);
3409 pAddr->sin_family = AF_INET;
3410 pAddr->sin_port = CM_INET_HTON_U16(pPeerAddrInfo->port);
3411 pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pPeerAddrInfo->addr.u.ipv4NetAddr);
3412 #endif /* IPV6_SUPPORTED */
3414 /* Not validating the address, whether Addr is a valid address or not */
3416 ret = getsockopt(sockFd->fd, level, SCTP_GET_PEER_ADDR_INFO, &addrInfo, &len);
3418 if (addrInfo.spinfo_state == SCTP_ACTIVE)
3419 pPeerAddrInfo->isActive = TRUE;
3421 pPeerAddrInfo->isActive = FALSE;
3422 pPeerAddrInfo->cwnd = addrInfo.spinfo_cwnd;
3423 pPeerAddrInfo->srtt = addrInfo.spinfo_srtt;
3424 pPeerAddrInfo->rto = addrInfo.spinfo_rto;
3425 pPeerAddrInfo->mtu = addrInfo.spinfo_mtu;
3428 case CM_INET_OPT_SCTP_PEERADDR_PARAMS:
3430 pPeerAddrParams = (CmInetSctpPeerAddrParams *)value;
3432 memset(&addrParams, 0, sizeof(struct sctp_paddrparams));
3434 addrParams.spp_assoc_id = pPeerAddrParams->assocId;
3436 if (pPeerAddrParams->s.addrPres == TRUE)
3438 #ifdef IPV6_SUPPORTED
3439 if (pPeerAddrParams->s.addr.type == CM_INET_IPV6ADDR_TYPE)
3441 if (sockFd->protType == AF_INET)
3445 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
3446 /* cm_inet_c_001.main_62:Warning fix */
3447 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "invalid address line:sockFd->fd(%ld)\n",
3449 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET066, 0, prntBuf);
3451 /* cm_inet_c_001.main_62:Warning fix */
3452 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "invalid address line:sockFd->fd(%d)\n",
3454 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET066, 0, prntBuf);
3455 #endif /*ALIGN_64BIT*/
3456 #endif /* CMINETDBG */
3460 pAddr6 = (struct sockaddr_in6*)&(addrParams.spp_address);
3461 pAddr6->sin6_family = AF_INET6;
3462 pAddr6->sin6_port = CM_INET_HTON_U16(pPeerAddrParams->s.port);
3463 CM_INET_COPY_IPV6ADDR(&pAddr6->sin6_addr.s6_addr, &pPeerAddrParams->s.addr.u.ipv6NetAddr);
3467 pAddr = (struct sockaddr_in*)&(addrParams.spp_address);
3468 pAddr->sin_family = AF_INET;
3469 pAddr->sin_port = CM_INET_HTON_U16(pPeerAddrParams->s.port);
3470 pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pPeerAddrParams->s.addr.u.ipv4NetAddr);
3473 pAddr = (struct sockaddr_in*)&(addrParams.spp_address);
3474 pAddr->sin_family = AF_INET;
3475 pAddr->sin_port = CM_INET_HTON_U16(pPeerAddrParams->s.port);
3476 pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pPeerAddrParams->s.addr.u.ipv4NetAddr);
3477 #endif /* IPV6_SUPPORTED */
3481 #ifdef IPV6_SUPPORTED
3482 if (sockFd->protType == AF_INET6)
3483 addrParams.spp_address.ss_family = AF_INET6;
3485 addrParams.spp_address.ss_family = AF_INET;
3487 addrParams.spp_address.ss_family = AF_INET;
3491 len = sizeof(addrParams);
3493 ret = getsockopt(sockFd->fd, level, SCTP_PEER_ADDR_PARAMS, &addrParams, &len);
3494 /* cm_inet_c_001.main_41 : Fixed the Solaris compilation problem */
3497 pPeerAddrParams->hbInterval = addrParams.spp_hbinterval;
3498 pPeerAddrParams->pathMaxRxt = addrParams.spp_pathmaxrxt;
3499 pPeerAddrParams->assocId = addrParams.spp_assoc_id;
3500 pPeerAddrParams->pathMtu = addrParams.spp_pathmtu;
3501 pPeerAddrParams->sackDelay = addrParams.spp_sackdelay;
3503 if (addrParams.spp_flags & SPP_HB_ENABLE)
3504 pPeerAddrParams->hbEnblFlag = CM_INET_OPT_ENABLE;
3506 pPeerAddrParams->hbEnblFlag = CM_INET_OPT_DISABLE;
3508 if (addrParams.spp_flags & SPP_PMTUD_ENABLE)
3509 pPeerAddrParams->pmtudFlag = CM_INET_OPT_ENABLE;
3511 pPeerAddrParams->pmtudFlag = CM_INET_OPT_DISABLE;
3513 if (addrParams.spp_flags & SPP_SACKDELAY_ENABLE)
3514 pPeerAddrParams->sackDelayFlag = CM_INET_OPT_ENABLE;
3516 pPeerAddrParams->sackDelayFlag = CM_INET_OPT_DISABLE;
3521 case CM_INET_OPT_SCTP_ASSOC_PARAMS:
3523 pAssocParams = (CmInetSctpAssocParams *)value;
3525 memset(&assocParams, 0, sizeof(struct sctp_assocparams));
3527 assocParams.sasoc_assoc_id = pAssocParams->assocId;
3529 len = sizeof(assocParams);
3531 ret = getsockopt(sockFd->fd, level, SCTP_ASSOCINFO, &assocParams, &len);
3533 pAssocParams->assocMaxReTx = assocParams.sasoc_asocmaxrxt;
3534 pAssocParams->cookieLife = assocParams.sasoc_cookie_life;
3535 pAssocParams->assocId = assocParams.sasoc_assoc_id;
3536 pAssocParams->numberOfPeerDest = assocParams.sasoc_number_peer_destinations;
3537 pAssocParams->peerRwnd = assocParams.sasoc_peer_rwnd;
3538 pAssocParams->localRwnd = assocParams.sasoc_local_rwnd;
3542 case CM_INET_OPT_SCTP_RTO_INFO:
3544 pRtoInfo = (CmInetSctpRtoInfo *)value;
3546 memset(&rtoInfo, 0, sizeof(struct sctp_rtoinfo));
3548 len = sizeof(rtoInfo);
3550 ret = getsockopt(sockFd->fd, level, SCTP_RTOINFO, &rtoInfo, &len);
3552 pRtoInfo->assocId = rtoInfo.srto_assoc_id;
3553 pRtoInfo->rtoInitial = rtoInfo.srto_initial;
3554 pRtoInfo->rtoMax = rtoInfo.srto_max;
3555 pRtoInfo->rtoMin = rtoInfo.srto_min;
3559 case CM_INET_OPT_SCTP_INIT_MSG:
3561 pInitMsg = (CmInetSctpInitMsg *)value;
3563 memset(&initMsg, 0, sizeof(struct sctp_initmsg));
3565 len = sizeof(initMsg);
3567 ret = getsockopt(sockFd->fd, level, SCTP_INITMSG, &initMsg, &len);
3569 pInitMsg->maxInitReTx = initMsg.sinit_max_attempts;
3570 pInitMsg->maxInitTimeout = initMsg.sinit_max_init_timeo;
3571 pInitMsg->numOstreams = initMsg.sinit_num_ostreams;
3572 pInitMsg->maxInstreams = initMsg.sinit_max_instreams;
3580 if (ret == INET_ERR)
3584 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
3585 /* cm_inet_c_001.main_62:Warning fix */
3586 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetOpt() failed on line:"
3587 " error(%d), sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
3588 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET067, 0, prntBuf);
3590 /* cm_inet_c_001.main_62:Warning fix */
3591 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetOpt() failed on line:"
3592 " error(%d), sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
3593 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET067, 0, prntBuf);
3594 #endif /*ALIGN_64BIT*/
3595 #endif /* CMINETDBG */
3602 /* cm_inet_c_001.main_54: Added new function cmInetShutDownSctp()*/
3605 * Fun: cmInetShutDownSctp
3607 * Desc: Shutdown the SCTP association gracefully.
3609 * Ret: ROK - successful
3618 S16 cmInetShutDownSctp
3620 CmInetFd *sockFd /* socket file descriptor */
3623 S16 cmInetShutDownSctp(sockFd)
3624 CmInetFd *sockFd; /* socket file descriptor */
3627 /*cm_inet_c_001.main_58 : fix for klockwork issue */
3629 struct sctp_sndrcvinfo sndRcvInfo;
3632 memset(&sndRcvInfo, 0, sizeof(sndRcvInfo));
3635 sndRcvInfo.sinfo_flags = MSG_EOF;
3637 sndRcvInfo.sinfo_flags = SCTP_EOF;
3640 /* Call the sctp_send with flag set to termiante the association */
3642 ret = sctp_send(sockFd->fd, NULLP, 0, &sndRcvInfo, sndRcvInfo.sinfo_flags);
3648 /* cm_inet_c_001.main_62:Warning fix */
3649 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetShutDownSctp() Failed : error(%d), sockFd->fd(%ld)\n",
3650 INET_ERR_CODE, sockFd->fd);
3651 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET018, 0, prntBuf);
3653 /* cm_inet_c_001.main_62:Warning fix */
3654 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetShutDownSctp() Failed : error(%d), sockFd->fd(%d)\n",
3655 INET_ERR_CODE, sockFd->fd);
3656 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET018, 0, prntBuf);
3657 #endif /*ALIGN_64BIT*/
3658 #endif /* CMINETDBG */
3666 /* cm_inet_c_001.main_61: Added new function cmInetAbortSctpAssoc()*/
3669 * Fun: cmInetAbortSctpAssoc
3671 * Desc: ABORT the association.
3673 * Ret: ROK - successful
3682 S16 cmInetAbortSctpAssoc
3684 CmInetFd *sockFd, /* socket file descriptor */
3685 UConnId assocId /* Association ID */
3688 S16 cmInetAbortSctpAssoc(sockFd, assocId)
3689 CmInetFd *sockFd; /* socket file descriptor */
3690 UConnId assocId; /* Association ID */
3694 struct sctp_sndrcvinfo sndRcvInfo;
3697 memset(&sndRcvInfo, 0, sizeof(sndRcvInfo));
3700 sndRcvInfo.sinfo_flags = MSG_ABORT;
3702 sndRcvInfo.sinfo_flags = SCTP_ABORT;
3705 sndRcvInfo.sinfo_assoc_id = assocId;
3707 /* Call the sctp_send with flag set to termiante the association */
3709 ret = sctp_send(sockFd->fd, NULLP, 0, &sndRcvInfo, sndRcvInfo.sinfo_flags);
3715 /* cm_inet_c_001.main_62:Warning fix */
3716 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAbortSctpAssoc() Failed : error(%d), sockFd->fd(%ld)\n",
3717 INET_ERR_CODE, sockFd->fd);
3718 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET018, 0, prntBuf);
3720 /* cm_inet_c_001.main_62:Warning fix */
3721 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAbortSctpAssoc() Failed : error(%d), sockFd->fd(%d)\n",
3722 INET_ERR_CODE, sockFd->fd);
3723 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET018, 0, prntBuf);
3724 #endif /*ALIGN_64BIT*/
3725 #endif /* CMINETDBG */
3738 * Fun: cmInetConnect
3740 * Desc: Establishs a connection to a foreign address (TCP) or associates
3741 * a UDP socket to a foreign address.
3743 * Ret: ROK - successful
3744 * ROKDNA - resource temporarily unavaiable
3745 * RINPROGRESS - connection is in progress (only non-blocking)
3746 * RISCONN - connection is established (only non-blocking)
3758 CmInetFd *sockFd, /* socket file descriptor */
3759 CmInetAddr *servAddr /* foreign Internet address/port */
3762 S16 cmInetConnect(sockFd, servAddr)
3763 CmInetFd *sockFd; /* socket file descriptor */
3764 CmInetAddr *servAddr; /* foreign Internet address/port */
3767 S32 ret; /* temporary return value */
3768 struct sockaddr_in dstAddr; /* foreign Internet address/port */
3769 #ifdef IPV6_SUPPORTED
3770 struct sockaddr_in6 dstAddr6; /* foreign Internet IPV6 address/port */
3773 #endif /* CMINETDBG */
3774 #endif /* IPV6_SUPPORTED */
3776 CmInetSockAddr *sockAddrPtr;
3779 #if (ERRCLASS & ERRCLS_INT_PAR)
3780 /* error check on parameters */
3781 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
3782 (servAddr == NULLP))
3786 #endif /* ERRCLASS & ERRCLS_INT_PAR */
3788 #ifdef IPV6_SUPPORTED
3789 if (servAddr->type == CM_INET_IPV6ADDR_TYPE)
3791 memset(&dstAddr6, 0, sizeof(dstAddr6));
3792 dstAddr6.sin6_family = AF_INET6;
3793 dstAddr6.sin6_port = CM_INET_HTON_U16(servAddr->u.ipv6Addr.port);
3794 CM_INET_COPY_IPV6ADDR(&dstAddr6.sin6_addr,
3795 &servAddr->u.ipv6Addr.ipv6NetAddr);
3796 sizeOfAddr = sizeof(struct sockaddr_in6);
3797 sockAddrPtr = (CmInetSockAddr *)&dstAddr6;
3801 memset(&dstAddr, 0, sizeof(dstAddr));
3802 dstAddr.sin_family = AF_INET;
3803 dstAddr.sin_port = CM_INET_HTON_U16(servAddr->u.ipv4Addr.port);
3804 dstAddr.sin_addr.s_addr = CM_INET_HTON_U32(servAddr->u.ipv4Addr.address);
3805 sizeOfAddr = sizeof(struct sockaddr_in);
3806 sockAddrPtr = (CmInetSockAddr *)&dstAddr;
3809 memset(&dstAddr, 0, sizeof(dstAddr));
3810 dstAddr.sin_family = AF_INET;
3811 dstAddr.sin_port = CM_INET_HTON_U16(servAddr->port);
3812 dstAddr.sin_addr.s_addr = CM_INET_HTON_U32(servAddr->address);
3813 sizeOfAddr = sizeof(struct sockaddr_in);
3814 sockAddrPtr = (CmInetSockAddr *)&dstAddr;
3815 #endif /* IPV6_SUPPORTED */
3817 ret = connect(sockFd->fd, sockAddrPtr, sizeOfAddr);
3818 if (ret == INET_ERR)
3820 switch (INET_ERR_CODE)
3822 /* non-blocking: connection is in progress */
3823 case ERR_INPROGRESS:
3824 return (RINPROGRESS);
3828 * non-blocking: connection is established
3829 * blocking : connection is already established
3835 /* resource temporarily unavailable */
3836 case ERR_WOULDBLOCK:
3840 /* non-blocking: connection is in progress */
3842 return (RINPROGRESS);
3846 return (RINPROGRESS);
3849 /* Check for connection refused and timeout errors */
3850 case ERR_CONNREFUSED:
3855 /* it is a real error */
3858 #ifdef IPV6_SUPPORTED
3859 if (servAddr->type == CM_INET_IPV6ADDR_TYPE)
3860 port = servAddr->u.ipv6Addr.port;
3862 port = servAddr->u.ipv4Addr.port;
3864 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
3866 /* cm_inet_c_001.main_62:Warning fix */
3867 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetConnect() Failed : error(%d),"
3868 " addrtype(0x%x), port(0x%1x), sockFd->fd(%ld)\n",
3869 INET_ERR_CODE, servAddr->type, port, sockFd->fd);
3870 CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET019, 0, prntBuf);
3872 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetConnect() Failed : error(%d),"
3873 " addrtype(0x%x), port(0x%1x), sockFd->fd(%d)\n",
3874 INET_ERR_CODE, servAddr->type, port, sockFd->fd);
3875 CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET019, 0, prntBuf);
3876 #endif /*ALIGN_64BIT*/
3879 /* cm_inet_c_001.main_62:Warning fix */
3880 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetConnect() Failed : error(%d), addr(0x%lx),"
3881 "port(0x%1x), sockFd->fd(%ld)\n", INET_ERR_CODE ,
3882 servAddr->address, servAddr->port, sockFd->fd);
3883 CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET020, 0, prntBuf);
3885 /* cm_inet_c_001.main_62:Warning fix */
3886 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetConnect() Failed : error(%d), addr(0x%x),"
3887 "port(0x%x), sockFd->fd(%d)\n", INET_ERR_CODE ,
3888 servAddr->address, servAddr->port, sockFd->fd);
3889 CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET020, 0, prntBuf);
3890 #endif /*ALIGN_64BIT*/
3891 #endif /* IPV6_SUPPORTED */
3892 #endif /* CMINETDBG */
3899 } /* end of cmInetConnect */
3906 * Desc: Indicates the willingness of a socket to listen for incomming
3907 * connection requests.
3909 * Ret: ROK - successful
3912 * Notes: The backLog value has to be within 0..5
3921 CmInetFd *sockFd, /* socket file descriptor */
3922 S16 backLog /* max. number of outstandig connections 0..5 */
3925 S16 cmInetListen(sockFd, backLog)
3926 CmInetFd *sockFd; /* socket file descriptor */
3927 S16 backLog; /* max. number of outstandig connections 0..5 */
3930 S32 ret; /* temporary return value */
3933 #if (ERRCLASS & ERRCLS_INT_PAR)
3934 /* error check on parameters */
3935 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
3936 (backLog < MIN_BACK_LOG) || (backLog > MAX_BACK_LOG))
3940 #endif /* ERRCLASS & ERRCLS_INT_PAR */
3942 ret = listen(sockFd->fd, backLog);
3943 if (ret == INET_ERR)
3947 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
3948 /* cm_inet_c_001.main_62:Warning fix */
3949 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetListen() Failed : error(%d), backLog(%d),"
3950 " sockFd->fd(%ld)\n", INET_ERR_CODE, backLog, sockFd->fd);
3951 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET021, 0, prntBuf);
3953 /* cm_inet_c_001.main_62:Warning fix */
3954 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetListen() Failed : error(%d), backLog(%d),"
3955 " sockFd->fd(%d)\n", INET_ERR_CODE, backLog, sockFd->fd);
3956 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET021, 0, prntBuf);
3957 #endif /*ALIGN_64BIT*/
3958 #endif /* CMINETDBG */
3963 } /* end of cmInetListen */
3970 * Desc: Accepts an incoming connection.
3971 * On default the new socket is non-blocking. The options can be
3972 * changed with the function cmInetSetOpt().
3974 * Ret: ROK - successful
3975 * ROKDNA - there is no connection present to accept (only
3988 CmInetFd *sockFd, /* socket file descriptor */
3989 CmInetAddr *fromAddr, /* calling Internet address/port */
3990 CmInetFd *newSockFd /* socket file descriptor for new connection*/
3993 S16 cmInetAccept(sockFd, fromAddr, newSockFd)
3994 CmInetFd *sockFd; /* socket file descriptor */
3995 CmInetAddr *fromAddr; /* calling Internet address/port */
3996 CmInetFd *newSockFd; /* socket file descriptor for new connection*/
3999 S32 ret; /* temporary return value */
4000 S32 addrLen; /* address structure length */
4001 struct sockaddr_in *peerAddr; /* calling Internet address/port */
4002 #ifdef IPV6_SUPPORTED
4003 struct sockaddr_in6 *peerAddr6; /* calling Internet address/port */
4004 struct sockaddr_in6 sockAddr;
4006 CmInetSockAddr sockAddr;
4007 #endif /* IPV6_SUPPORTED */
4013 #if (ERRCLASS & ERRCLS_INT_PAR)
4014 /* error check on parameters */
4015 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
4019 #endif /* ERRCLASS & ERRCLS_INT_PAR */
4021 /* change CmInetSockAddr to sockAddr */
4022 addrLen = sizeof(sockAddr);
4025 #if ( defined(SUNOS) || defined(SS_LINUX))
4026 newSockFd->fd = accept(sockFd->fd, (CmInetSockAddr*)&sockAddr,
4027 (socklen_t *)&addrLen);
4029 newSockFd->fd = accept(sockFd->fd, (CmInetSockAddr*)&sockAddr,
4031 #endif /* SUNOS || SS_LINUX */
4033 /* cm_inet_c_001.main_58: Moved setting of protType below */
4035 if (CM_INET_INV_SOCK_FD(newSockFd))
4037 if (INET_ERR_CODE == ERR_WOULDBLOCK)
4039 /* no connection present to accept */
4046 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
4047 /* cm_inet_c_001.main_62:Warning fix */
4048 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAccept() Failed : error(%d),"
4049 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
4050 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET022, 0, prntBuf);
4052 /* cm_inet_c_001.main_62:Warning fix */
4053 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAccept() Failed : error(%d),"
4054 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
4055 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET022, 0, prntBuf);
4056 #endif /*ALIGN_64BIT*/
4057 #endif /* CMINETDBG */
4063 /* cm_inet_c_001.main_58: Fix for g++ compilation warning */
4064 /* added for IPv6/IPv4 socket distinguishing */
4065 #ifdef IPV6_SUPPORTED
4066 if (addrLen == sizeof(struct sockaddr_in))
4067 newSockFd->protType = AF_INET;
4068 else if(addrLen == sizeof(struct sockaddr_in6))
4069 newSockFd->protType = AF_INET6;
4074 /* cm_inet_c_001.main_62:Warning fix */
4075 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAccept() Failed : sockFd->fd(%ld)\n", sockFd->fd);
4076 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET071, 0, prntBuf);
4078 /* cm_inet_c_001.main_62:Warning fix */
4079 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAccept() Failed : sockFd->fd(%d)\n", sockFd->fd);
4080 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET071, 0, prntBuf);
4081 #endif /*ALIGN_64BIT*/
4082 #endif /* CMINETDBG */
4085 #endif /* IPV6_SUPPORTED */
4087 /* set the new socket file descriptor type */
4088 newSockFd->type = CM_INET_STREAM;
4090 /* set default options for new socket file descriptor */
4091 optVal = CM_INET_OPT_DISABLE;
4092 ret = cmInetSetOpt(newSockFd, SOL_SOCKET, CM_INET_OPT_BLOCK, &optVal);
4095 ret = cmInetClose(newSockFd);
4099 #ifdef IPV6_SUPPORTED
4100 memset(fromAddr, 0, sizeof(fromAddr));
4101 if (addrLen == sizeof(struct sockaddr_in))
4103 peerAddr = (struct sockaddr_in *)&sockAddr;
4104 fromAddr->type = CM_INET_IPV4ADDR_TYPE;
4105 fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(peerAddr->sin_port);
4106 fromAddr->u.ipv4Addr.address =
4107 CM_INET_NTOH_U32(peerAddr->sin_addr.s_addr);
4109 else if (addrLen == sizeof(struct sockaddr_in6))
4111 peerAddr6 = (struct sockaddr_in6 *)&sockAddr;
4112 fromAddr->type = CM_INET_IPV6ADDR_TYPE;
4113 fromAddr->u.ipv6Addr.port = CM_INET_NTOH_U16(peerAddr6->sin6_port);
4114 CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr,
4115 &peerAddr6->sin6_addr);
4118 peerAddr = (struct sockaddr_in *)&sockAddr;
4119 fromAddr->port = CM_INET_NTOH_U16(peerAddr->sin_port);
4120 fromAddr->address = CM_INET_NTOH_U32(peerAddr->sin_addr.s_addr);
4121 #endif /* IPV6_SUPPORTED */
4123 } /* end of cmInetAccept */
4128 * Fun: cmInet4FillTos
4130 * Desc: This function inserts tos (into ancillary data) which
4131 * will be used to fill tos value in ip header in outgoing IP packet
4132 * when sending that packet using sendmsg()function.
4143 PRIVATE S16 cmInet4FillTos
4145 U8 tos, /* tos value to be filled in ipheader */
4146 U8 *cmsgBuf, /* flat buffer where to build ext hdrs */
4147 U32 *curMsgIdx /* idx in cmsgBuf where HBH/Dest ext hdr ends */
4150 PRIVATE S16 cmInet4FillTos(tos, cmsgBuf, curMsgIdx, protType)
4151 U8 tos; /* tos value to be filled in ipheader */
4152 U8 *cmsgBuf; /* flat buffer where to build ext hdrs */
4153 U32 *curMsgIdx; /* idx in cmsgBuf where HBH/Dest ext hdr ends */
4156 struct cmsghdr *tempHdr;
4163 /* cmsghdr struc will appear before data in the ancillary data object.
4164 * So put cmsghdr struc in flat buffer first. */
4166 /* cmsghdr struc points to flat buffer's starting address */
4167 tempHdr = (struct cmsghdr *)cmsgBuf;
4169 /* fill up level & type of cmsghdr structure */
4170 tempHdr->cmsg_level = IPPROTO_IPV6;
4171 tempHdr->cmsg_type = IP_TOS;
4172 (*(U8*)CMSG_DATA(tempHdr)) = tos;
4173 len = CMSG_SPACE(sizeof tos);
4176 /* fill up the length of cmsghdr structure */
4177 tempHdr->cmsg_len = len;
4182 }/* end of cmInet4FillTos */
4185 * Fun: cmInetSendDscpMsg
4187 * Desc: Sends the message data hold by mBuf.
4188 * The len paramter gives the actual written octets. If the socket
4189 * is non-blocking this value can be differ from the mBuf length
4190 * because there was not enough transmit buffer space available. If
4191 * this occurs, RWOULDBLOCK is returned and only a part of the mBuf
4193 * Values for flag parameter:
4195 * CM_INET_NO_FLAG - no additional control flag
4197 * Ret: ROK - successful
4198 * RWOULDBLOCK - no or not entire mBuf sent because would block
4199 * ROUTRES - failed, out of resources
4200 * RCLOSED - connection was closed by the peer
4203 * Notes: The successful completion of a send call does not indicate that
4204 * the data has been successfully delivered!
4206 * This function does not free any sent buffers.
4214 S16 cmInetSendDscpMsg
4216 CmInetFd *sockFd, /* socket file descriptor */
4217 CmInetAddr *dstAddr, /* destination Internet address/port */
4218 CmInetMemInfo *info, /* buffer allocation info */
4219 Buffer *mBuf, /* buffer structure to send */
4220 MsgLen *len, /* number of actually sent octets */
4221 /* added for IPv6 ext hdr */
4222 CmInetIpHdrParm *ipHdrParams, /* IPv6 extensions headers */
4223 S16 flags /* additional control flags, unused */
4226 /* added for IPv6 ext hdr */
4227 S16 cmInetSendDscpMsg(sockFd, dstAddr, info, mBuf, len, ipHdrParams, flags)
4228 CmInetFd *sockFd; /* socket file descriptor */
4229 CmInetAddr *dstAddr; /* destination Internet address/port */
4230 CmInetMemInfo *info; /* buffer allocation info */
4231 Buffer *mBuf; /* buffer structure to send */
4232 MsgLen *len; /* number of actually sent octets */
4233 CmInetIpHdrParm *ipHdrParams; /* IPv6 extensions headers */
4234 S16 flags; /* additional control flags, unused */
4237 #if (defined(WIN32) || defined(CMINETFLATBUF))
4238 S32 ret; /* temporary return value */
4239 MsgLen msgLen; /* message length */
4240 MsgLen bufLen; /* send buffer length */
4241 Data *sendBuf; /* plain send buffer */
4243 S32 ret; /* temporary return value */
4244 S32 retVal; /* temporary return value */
4245 S16 i; /* loop index */
4246 CmInetIovec txArr[CM_INET_MAX_DBUF]; /* scatter vector */
4247 S16 numDBufs; /* number of dBufs in message */
4248 struct msghdr msg; /* sendmsg() message header */
4249 MsgLen msgLen; /* message length */
4250 U32 strtEndDBufNum; /* starting/ending DBuf number */
4251 MsgLen unSentLen; /* sent len */
4252 #ifdef IPV6_SUPPORTED
4253 U32 curMsgIdx; /* indx in cmsgData where to write an ext hdr */
4254 /* added for IPv6 ext hdr */
4255 #if (defined(SS_LINUX) || defined(_XPG4_2))
4256 /* alloc from stack for IPv6 ancill data */
4257 U8 cmsgData[CM_INET_IPV6_ANCIL_DATA];
4258 #endif /* SS_LINUX || _XPG4_2 */
4260 U32 curMsgIdx; /* indx in cmsgData where to write an ext hdr */
4261 #if (defined(SS_LINUX) || defined(_XPG4_2))
4262 /* alloc from stack for IPv4 ancill data */
4263 U8 cmsgData[CM_INET_IPV4_ANCIL_DATA];
4264 #endif /* SS_LINUX || _XPG4_2 */
4265 #endif /* IPV6_SUPPORTED */
4266 #endif /* WIN32 | CMINETFLATBUF */
4268 struct sockaddr_in remAddr; /* remote Internet address */
4269 #ifdef IPV6_SUPPORTED
4270 struct sockaddr_in6 remAddr6; /* remote Internet address */
4271 #endif /* IPV8_SUPPORTED */
4272 CmInetSockAddr *sockAddrPtr;
4273 /* cm_inet_c_001.main_58 : Fix for klockwork issue */
4276 /* cm_inet_c_001.main_50 - Added for partial send handling */
4277 /* cm_inet_c_001.main_59: Protected under if not defined WIN32*/
4278 #if (!defined(WIN32))
4285 #if (ERRCLASS & ERRCLS_INT_PAR)
4286 /* error check on parameters */
4287 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
4288 (info == NULLP) || (len == NULLP))
4292 #endif /* ERRCLASS & ERRCLS_INT_PAR */
4294 /* added for IPv6 ext hdr */
4295 #if !(defined(WIN32) || defined(CMINETFLATBUF))
4296 #if (defined(SS_LINUX) || defined(_XPG4_2))
4297 /* memset(cmsgData, 0, sizeof(cmsgData)); */
4298 #endif /* SS_LINUX || _XPG4_2 */
4300 #endif /* WIN32 | CMINETFLATBUF */
4302 msgLen = 0; /* need by CC to pass without warning */
4303 sockAddrPtr = NULLP;
4306 /* setup remote address */
4307 if (dstAddr != NULLP)
4309 #ifdef IPV6_SUPPORTED
4310 if (dstAddr->type == CM_INET_IPV6ADDR_TYPE)
4312 memset(&remAddr6, 0, sizeof(remAddr6));
4313 remAddr6.sin6_family = AF_INET6;
4314 remAddr6.sin6_port = CM_INET_HTON_U16(dstAddr->u.ipv6Addr.port);
4315 CM_INET_COPY_IPV6ADDR(&remAddr6.sin6_addr,
4316 &dstAddr->u.ipv6Addr.ipv6NetAddr);
4317 sizeOfAddr = sizeof(remAddr6);
4318 sockAddrPtr = (CmInetSockAddr *)&remAddr6;
4322 memset(&remAddr, 0, sizeof(remAddr));
4323 remAddr.sin_family = AF_INET;
4324 remAddr.sin_port = CM_INET_HTON_U16(dstAddr->u.ipv4Addr.port);
4325 remAddr.sin_addr.s_addr =
4326 CM_INET_HTON_U32(dstAddr->u.ipv4Addr.address);
4327 sizeOfAddr = sizeof(remAddr);
4328 sockAddrPtr = (CmInetSockAddr *)&remAddr;
4331 /* memset(&remAddr, 0, sizeof(remAddr)); */
4332 remAddr.sin_family = AF_INET;
4333 remAddr.sin_port = CM_INET_HTON_U16(dstAddr->port);
4334 remAddr.sin_addr.s_addr = CM_INET_HTON_U32(dstAddr->address);
4335 sizeOfAddr = sizeof(remAddr);
4336 sockAddrPtr = (CmInetSockAddr *)&remAddr;
4337 #endif /* IPV6_SUPPORTED */
4340 #if (defined(WIN32) || defined(CMINETFLATBUF))
4341 /* copy message to a flat buffer */
4342 ret = SFndLenMsg(mBuf, &bufLen);
4347 /* max message length is limited to control the memory usage */
4348 /* casting bufLen to avoid warnings */
4349 if ((bufLen > 0) && ((U32)bufLen > CM_INET_MAX_MSG_LEN))
4353 ret = SGetSBuf(info->region, info->pool, &sendBuf, bufLen);
4358 ret = SCpyMsgFix(mBuf, 0, bufLen, sendBuf, &msgLen);
4359 if ((ret != ROK) || (msgLen != bufLen))
4362 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
4366 if (dstAddr == NULLP)
4368 /* VxWorks sendto has some problem
4369 * with connected UDP socket, use send */
4371 ret = sendto(sockFd->fd, (S8 *)sendBuf, bufLen, 0,
4374 ret = send(sockFd->fd, (S8 *)sendBuf, bufLen, 0);
4375 #endif /* end of SS_VW */
4378 /* cm_inet_c_001.main_54: Fix for vxworks 6.7 sending data on TCP sockets */
4380 #if (defined(SS_VW) && defined(SS_VW6_7))
4381 if ((sockFd->type == CM_INET_STREAM) || (sockFd->type == SOCK_RDM) )
4383 ret = send(sockFd->fd, (S8 *)sendBuf, bufLen, 0);
4386 #endif /* end of SS_VW6_7 and SS_VW */
4388 ret = sendto(sockFd->fd, (S8 *)sendBuf, bufLen, 0,
4389 sockAddrPtr, sizeOfAddr);
4392 if (ret == INET_ERR)
4395 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
4397 if(INET_ERR_CODE == ERR_AGAIN)
4400 return (RWOULDBLOCK);
4403 /* Check for ERR_WOULDBLOCK */
4404 if(INET_ERR_CODE == ERR_WOULDBLOCK)
4407 return (RWOULDBLOCK);
4412 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
4413 /* cm_inet_c_001.main_62:Warning fix */
4414 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendDscpMsg() Failed : error(%d), msgLen(%d),"
4415 " sockFd->fd(%ld)\n", INET_ERR_CODE, bufLen, sockFd->fd);
4416 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET023, 0, prntBuf);
4418 /* cm_inet_c_001.main_62:Warning fix */
4419 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendDscpMsg() Failed : error(%d), msgLen(%d),"
4420 " sockFd->fd(%d)\n", INET_ERR_CODE, bufLen, sockFd->fd);
4421 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET023, 0, prntBuf);
4422 #endif /*ALIGN_64BIT*/
4423 #endif /* CMINETDBG */
4425 /* cm_inet_c_001.main_37 network unreacheble error is added */
4426 /* check if network is reacheble*/
4427 if ((INET_ERR_CODE == ERR_NETUNREACH))
4429 return (RNETFAILED);
4433 /* Check if connection was closed */
4434 if ((INET_ERR_CODE == ERR_PIPE) ||
4435 (INET_ERR_CODE == ERR_CONNABORTED) ||
4436 (INET_ERR_CODE == ERR_CONNRESET))
4447 /* check if entire message could be sent */
4452 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
4453 return (RWOULDBLOCK);
4457 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
4459 #else /* end of Win NT/flat buffer specific part */
4460 ret = SFndLenMsg(mBuf, &msgLen);
4467 /* memset(&msg, 0, sizeof(msg)); */
4470 if (dstAddr != NULLP)
4473 msg.msg_name = (Void*)sockAddrPtr;
4476 msg.msg_name = (char *)sockAddrPtr;
4478 msg.msg_name = (caddr_t)sockAddrPtr;
4480 #endif /* SS_LINUX */
4481 msg.msg_namelen = sizeOfAddr;
4485 msg.msg_name = NULLP;
4486 msg.msg_namelen = 0;
4488 /* added defined(_XPG4_2) */
4489 #if (defined(SS_LINUX) || defined(_XPG4_2))
4490 msg.msg_control = NULLP;
4491 msg.msg_controllen = 0;
4493 msg.msg_accrights = 0;
4494 msg.msg_accrightslen = NULLP;
4495 #endif /* SS_LINUX */
4497 /* allocate scatter vector */
4498 numDBufs = CM_INET_MAX_DBUF;
4504 if (ipHdrParams != NULLP && (ipHdrParams->type == CM_INET_IPV4ADDR_TYPE))
4505 if((ipHdrParams->u.hdrParmIpv4.tos.pres == TRUE)&& \
4506 (ipHdrParams->u.hdrParmIpv4.tos.val != 0))
4508 cmInet4FillTos(ipHdrParams->u.hdrParmIpv4.tos.val,
4509 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);
4510 msg.msg_control = cmsgData; /* pointer to Ancillary Data */
4511 msg.msg_controllen = curMsgIdx; /* total length of ancillary Data */
4513 /* if the sender wants to send Ipv6 exten. headers */
4514 #ifdef IPV6_OPTS_SUPPORTED
4515 if (ipHdrParams != NULLP && (ipHdrParams->type == CM_INET_IPV6ADDR_TYPE))
4518 if(ipHdrParams->u.ipv6HdrParm.ttl.pres == TRUE)
4520 cmInetBuildSendHoplimit((U32)ipHdrParams->u.ipv6HdrParm.ttl.val,
4521 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);
4523 #endif /* SS_LINUX */
4526 /* have to decide how to get the src addr to add in in6_pktinfo */
4527 if(ipHdrParams->u.ipv6HdrParm.srcAddr6.type == 6)
4529 cmInet6BuildSendPktinfo(
4530 &ipHdrParams->u.ipv6HdrParm.srcAddr6.u.ipv6NetAddr,
4531 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx,
4534 #endif /* LOCAL_INTF */
4536 /* copy each ipv6 ext header from ipHdrParams to the flat buffer
4537 * cmsgData one by one. */
4539 if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhHdrPrsnt == TRUE)
4540 /* build HBH ext header in cmsgData starting at indx 0 */
4541 cmInet6BuildSendHBHOpts(
4542 &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhOptsArr,
4543 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx, 0);
4545 /* now copy the elements from the Destination Option array one by
4546 * one to the Flat Buffer cmsgData. Start filling at indx curMsgIdx
4547 * which is the end of HBH hdr. */
4548 if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsPrsnt == TRUE)
4549 /* build Dest opt hdr starting at (cmsgData + curMsgIdx) */
4550 cmInet6BuildSendDestOpts(
4551 &(ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsArr),
4552 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx, 1);
4554 /* copy Route header to to the Flat Buffer cmsgData */
4555 if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsPrsnt == TRUE)
4556 /* curMsgIdx will be the indx where Dest opt ends in cmsgData */
4557 cmInet6BuildSendRouteOpts(
4558 &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsArr,
4559 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);
4561 /* msghrd struc's msg_control will point cmsgData and msg_controllen
4562 * will be the curMsgIdx */
4563 msg.msg_control = cmsgData; /* pointer to Ancillary Data */
4564 msg.msg_controllen = curMsgIdx; /* total length of ancillary Data */
4567 #endif /* IPV6_OPTS_SUPPORTED */
4569 /* Loop till all the data is sent or till the sendmsg call cannot send
4573 /* build the send vector */
4574 /* cm_inet_c_001.main_50 - Partial send handling. Added variable to hold
4575 total length of the packed dbufs */
4576 retVal = buildSendIovec(mBuf, unSentLen, txArr, numDBufs, &i,
4577 &strtEndDBufNum, &ioLen);
4582 /* Incase of UDP/RAW messages call SCompressMsg. */
4583 if (sockFd->type != CM_INET_STREAM)
4585 /* Compress the message into a single dBuf */
4586 ret = SCompressMsg(mBuf);
4591 /* Rebuild the send vector */
4592 /* cm_inet_c_001.main_50 - Partial send handling. Added variable to hold
4593 total length of the packed dbuf */
4594 ret = buildSendIovec(mBuf, unSentLen, txArr, numDBufs, &i,
4595 &strtEndDBufNum, &ioLen);
4605 msg.msg_iov = txArr;
4611 extern int ntl_hLib;
4612 if ( sockFd->fd >= 0xD001)
4613 ret = ntl_sendmsg(ntl_hLib, sockFd->fd, &msg, 0);
4615 ret = sendmsg(sockFd->fd, &msg, 0);
4618 ret = sendmsg(sockFd->fd, &msg, 0);
4620 /* cm_inet_c_001.main_50 - Update the length only in successful cases */
4621 if (ret == INET_ERR)
4623 if((INET_ERR_CODE == ERR_AGAIN) ||
4624 (INET_ERR_CODE == ERR_WOULDBLOCK))
4626 /* cm_inet_c_001.main_50 - Return without making length 0, if in case the partial
4627 message was sent earlier */
4628 return (RWOULDBLOCK);
4632 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
4633 /* cm_inet_c_001.main_62:Warning fix */
4634 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendDscpMsg() Failed : error(%d),"
4635 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
4636 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET024, 0, prntBuf);
4638 /* cm_inet_c_001.main_62:Warning fix */
4639 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendDscpMsg() Failed : error(%d),"
4640 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
4641 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET024, 0, prntBuf);
4642 #endif /*ALIGN_64BIT*/
4643 #endif /* CMINETDBG */
4645 /* cm_inet_c_001.main_37 network unreacheble error is added */
4646 /* check if network is reacheble or not */
4647 if ((INET_ERR_CODE == ERR_NETUNREACH))
4649 return (RNETFAILED);
4652 /* Check if connection was closed by the peer */
4653 if ((INET_ERR_CODE == ERR_PIPE) ||
4654 (INET_ERR_CODE == ERR_CONNREFUSED) ||
4655 (INET_ERR_CODE == ERR_CONNABORTED))
4663 /* cm_inet_c_001.main_50 - Update the length only in successful cases */
4666 /* cm_inet_c_001.main_50 - if what is actually sent is less than what is attemped
4667 * to be sent, then return WOULDBLOCK
4670 return (RWOULDBLOCK);
4674 } while (*len < msgLen);
4675 #endif /* WIN32 | CMINETFLATBUF */
4679 } /* end of cmInetSendDscpMsg */
4683 * Fun: cmInetSendMsg
4685 * Desc: Sends the message data hold by mBuf.
4686 * The len paramter gives the actual written octets. If the socket
4687 * is non-blocking this value can be differ from the mBuf length
4688 * because there was not enough transmit buffer space available. If
4689 * this occurs, RWOULDBLOCK is returned and only a part of the mBuf
4691 * Values for flag parameter:
4693 * CM_INET_NO_FLAG - no additional control flag
4695 * Ret: ROK - successful
4696 * RWOULDBLOCK - no or not entire mBuf sent because would block
4697 * ROUTRES - failed, out of resources
4698 * RCLOSED - connection was closed by the peer
4701 * Notes: The successful completion of a send call does not indicate that
4702 * the data has been successfully delivered!
4704 * This function does not free any sent buffers.
4714 CmInetFd *sockFd, /* socket file descriptor */
4715 CmInetAddr *dstAddr, /* destination Internet address/port */
4716 CmInetMemInfo *info, /* buffer allocation info */
4717 Buffer *mBuf, /* buffer structure to send */
4718 MsgLen *len, /* number of actually sent octets */
4719 /* added for IPv6 ext hdr */
4720 #ifdef IPV6_OPTS_SUPPORTED
4721 CmInetIpHdrParm *ipHdrParams, /* IPv6 extensions headers */
4722 #endif /* IPV6_OPTS_SUPPORTED */
4723 S16 flags /* additional control flags, unused */
4726 /* added for IPv6 ext hdr */
4727 #ifdef IPV6_OPTS_SUPPORTED
4728 S16 cmInetSendMsg(sockFd, dstAddr, info, mBuf, len, ipHdrParams, flags)
4729 CmInetFd *sockFd; /* socket file descriptor */
4730 CmInetAddr *dstAddr; /* destination Internet address/port */
4731 CmInetMemInfo *info; /* buffer allocation info */
4732 Buffer *mBuf; /* buffer structure to send */
4733 MsgLen *len; /* number of actually sent octets */
4734 CmInetIpHdrParm *ipHdrParams; /* IPv6 extensions headers */
4735 S16 flags; /* additional control flags, unused */
4737 S16 cmInetSendMsg(sockFd, dstAddr, info, mBuf, len, flags)
4738 CmInetFd *sockFd; /* socket file descriptor */
4739 CmInetAddr *dstAddr; /* destination Internet address/port */
4740 CmInetMemInfo *info; /* buffer allocation info */
4741 Buffer *mBuf; /* buffer structure to send */
4742 MsgLen *len; /* number of actually sent octets */
4743 S16 flags; /* additional control flags, unused */
4744 #endif /* IPV6_OPTS_SUPPORTED */
4747 #if (defined(WIN32) || defined(CMINETFLATBUF))
4748 S32 ret; /* temporary return value */
4749 MsgLen msgLen; /* message length */
4750 MsgLen bufLen; /* send buffer length */
4751 Data *sendBuf; /* plain send buffer */
4753 S32 ret; /* temporary return value */
4754 S32 retVal; /* temporary return value */
4755 S16 i; /* loop index */
4756 CmInetIovec txArr[CM_INET_MAX_DBUF]; /* scatter vector */
4757 S16 numDBufs; /* number of dBufs in message */
4758 struct msghdr msg; /* sendmsg() message header */
4759 MsgLen msgLen; /* message length */
4760 U32 strtEndDBufNum; /* starting/ending DBuf number */
4761 MsgLen unSentLen; /* sent len */
4762 #ifdef IPV6_SUPPORTED
4763 /* added for IPv6 ext hdr */
4764 #ifdef IPV6_OPTS_SUPPORTED
4765 U32 curMsgIdx; /* indx in cmsgData where to write an ext hdr */
4766 #if (defined(SS_LINUX) || defined(_XPG4_2))
4767 /* alloc from stack for IPv6 ancill data */
4768 U8 cmsgData[CM_INET_IPV6_ANCIL_DATA];
4769 #endif /* SS_LINUX || _XPG4_2 */
4770 #endif /* IPV6_OPTS_SUPPORTED */
4772 #if (defined(SS_LINUX) || defined(_XPG4_2))
4773 /* alloc from stack for IPv4 ancill data */
4774 /* U8 cmsgData[CM_INET_IPV4_ANCIL_DATA];*/
4775 #endif /* SS_LINUX || _XPG4_2 */
4776 #endif /* IPV6_SUPPORTED */
4777 #endif /* WIN32 | CMINETFLATBUF */
4779 struct sockaddr_in remAddr; /* remote Internet address */
4780 #ifdef IPV6_SUPPORTED
4781 struct sockaddr_in6 remAddr6; /* remote Internet address */
4782 #endif /* IPV8_SUPPORTED */
4783 CmInetSockAddr *sockAddrPtr;
4784 /* cm_inet_c_001.main_58 : Fix for klockwork issue */
4787 /* cm_inet_c_001.main_50 - Added for partial send handling */
4788 /* cm_inet_c_001.main_59: Protected under if not defined WIN32*/
4789 #if (!defined(WIN32))
4796 #if (ERRCLASS & ERRCLS_INT_PAR)
4797 /* error check on parameters */
4798 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
4799 (info == NULLP) || (len == NULLP))
4803 #endif /* ERRCLASS & ERRCLS_INT_PAR */
4805 /* added for IPv6 ext hdr */
4806 #if !(defined(WIN32) || defined(CMINETFLATBUF))
4807 #if (defined(SS_LINUX) || defined(_XPG4_2))
4808 /* memset(cmsgData, 0, sizeof(cmsgData)); */
4809 #endif /* SS_LINUX || _XPG4_2 */
4810 #ifdef IPV6_OPTS_SUPPORTED
4812 #endif /* IPV6_SUPPORTED */
4813 #endif /* WIN32 | CMINETFLATBUF */
4815 msgLen = 0; /* need by CC to pass without warning */
4816 sockAddrPtr = NULLP;
4819 /* setup remote address */
4820 if (dstAddr != NULLP)
4822 #ifdef IPV6_SUPPORTED
4823 if (dstAddr->type == CM_INET_IPV6ADDR_TYPE)
4825 memset(&remAddr6, 0, sizeof(remAddr6));
4826 remAddr6.sin6_family = AF_INET6;
4827 remAddr6.sin6_port = CM_INET_HTON_U16(dstAddr->u.ipv6Addr.port);
4828 CM_INET_COPY_IPV6ADDR(&remAddr6.sin6_addr,
4829 &dstAddr->u.ipv6Addr.ipv6NetAddr);
4830 sizeOfAddr = sizeof(remAddr6);
4831 sockAddrPtr = (CmInetSockAddr *)&remAddr6;
4835 memset(&remAddr, 0, sizeof(remAddr));
4836 remAddr.sin_family = AF_INET;
4837 remAddr.sin_port = CM_INET_HTON_U16(dstAddr->u.ipv4Addr.port);
4838 remAddr.sin_addr.s_addr =
4839 CM_INET_HTON_U32(dstAddr->u.ipv4Addr.address);
4840 sizeOfAddr = sizeof(remAddr);
4841 sockAddrPtr = (CmInetSockAddr *)&remAddr;
4844 /* memset(&remAddr, 0, sizeof(remAddr)); */
4845 remAddr.sin_family = AF_INET;
4846 remAddr.sin_port = CM_INET_HTON_U16(dstAddr->port);
4847 remAddr.sin_addr.s_addr = CM_INET_HTON_U32(dstAddr->address);
4848 sizeOfAddr = sizeof(remAddr);
4849 sockAddrPtr = (CmInetSockAddr *)&remAddr;
4850 #endif /* IPV6_SUPPORTED */
4853 #if (defined(WIN32) || defined(CMINETFLATBUF))
4854 /* copy message to a flat buffer */
4855 ret = SFndLenMsg(mBuf, &bufLen);
4860 /* max message length is limited to control the memory usage */
4861 /* casting bufLen to avoid warnings */
4862 if ((bufLen > 0) && ((U32)bufLen > CM_INET_MAX_MSG_LEN))
4866 ret = SGetSBuf(info->region, info->pool, &sendBuf, bufLen);
4871 ret = SCpyMsgFix(mBuf, 0, bufLen, sendBuf, &msgLen);
4872 if ((ret != ROK) || (msgLen != bufLen))
4875 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
4879 if (dstAddr == NULLP)
4881 /* VxWorks sendto has some problem
4882 * with connected UDP socket, use send */
4884 ret = sendto(sockFd->fd, (S8 *)sendBuf, bufLen, 0,
4887 ret = send(sockFd->fd, (S8 *)sendBuf, bufLen, 0);
4888 #endif /* end of SS_VW */
4891 /* cm_inet_c_001.main_54: Fix for vxworks 6.7 sending data on TCP sockets */
4893 #if (defined(SS_VW) && defined(SS_VW6_7))
4894 if ((sockFd->type == CM_INET_STREAM) || (sockFd->type == SOCK_RDM) )
4896 ret = send(sockFd->fd, (S8 *)sendBuf, bufLen, 0);
4899 #endif /* end of SS_VW6_7 and SS_VW */
4901 ret = sendto(sockFd->fd, (S8 *)sendBuf, bufLen, 0,
4902 sockAddrPtr, sizeOfAddr);
4905 if (ret == INET_ERR)
4908 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
4910 if(INET_ERR_CODE == ERR_AGAIN)
4913 return (RWOULDBLOCK);
4916 /* Check for ERR_WOULDBLOCK */
4917 if(INET_ERR_CODE == ERR_WOULDBLOCK)
4920 return (RWOULDBLOCK);
4925 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
4926 /* cm_inet_c_001.main_62:Warning fix */
4927 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendMsg() Failed : error(%d), msgLen(%d),"
4928 " sockFd->fd(%ld)\n", INET_ERR_CODE, bufLen, sockFd->fd);
4929 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET023, 0, prntBuf);
4931 /* cm_inet_c_001.main_62:Warning fix */
4932 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendMsg() Failed : error(%d), msgLen(%d),"
4933 " sockFd->fd(%d)\n", INET_ERR_CODE, bufLen, sockFd->fd);
4934 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET023, 0, prntBuf);
4935 #endif /*ALIGN_64BIT*/
4936 #endif /* CMINETDBG */
4938 /* cm_inet_c_001.main_37 network unreacheble error is added */
4939 /* check if network is reacheble*/
4940 if ((INET_ERR_CODE == ERR_NETUNREACH))
4942 return (RNETFAILED);
4946 /* Check if connection was closed */
4947 if ((INET_ERR_CODE == ERR_PIPE) ||
4948 (INET_ERR_CODE == ERR_CONNABORTED) ||
4949 (INET_ERR_CODE == ERR_CONNRESET))
4960 /* check if entire message could be sent */
4965 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
4966 return (RWOULDBLOCK);
4970 SPutSBuf(info->region, info->pool, sendBuf, bufLen);
4972 #else /* end of Win NT/flat buffer specific part */
4973 ret = SFndLenMsg(mBuf, &msgLen);
4980 /* memset(&msg, 0, sizeof(msg)); */
4983 if (dstAddr != NULLP)
4986 msg.msg_name = (Void*)sockAddrPtr;
4989 msg.msg_name = (char *)sockAddrPtr;
4991 msg.msg_name = (caddr_t)sockAddrPtr;
4993 #endif /* SS_LINUX */
4994 msg.msg_namelen = sizeOfAddr;
4998 msg.msg_name = NULLP;
4999 msg.msg_namelen = 0;
5001 /* added defined(_XPG4_2) */
5002 #if (defined(SS_LINUX) || defined(_XPG4_2))
5003 msg.msg_control = NULLP;
5004 msg.msg_controllen = 0;
5006 msg.msg_accrights = 0;
5007 msg.msg_accrightslen = NULLP;
5008 #endif /* SS_LINUX */
5010 /* allocate scatter vector */
5011 numDBufs = CM_INET_MAX_DBUF;
5018 /* if the sender wants to send Ipv6 exten. headers */
5019 #ifdef IPV6_OPTS_SUPPORTED
5020 if (ipHdrParams != NULLP && (ipHdrParams->type == CM_INET_IPV6ADDR_TYPE))
5023 if(ipHdrParams->u.ipv6HdrParm.ttl.pres == TRUE)
5025 cmInetBuildSendHoplimit((U32)ipHdrParams->u.ipv6HdrParm.ttl.val,
5026 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);
5028 #endif /* SS_LINUX */
5031 /* have to decide how to get the src addr to add in in6_pktinfo */
5032 if(ipHdrParams->u.ipv6HdrParm.srcAddr6.type == 6)
5034 cmInet6BuildSendPktinfo(
5035 &ipHdrParams->u.ipv6HdrParm.srcAddr6.u.ipv6NetAddr,
5036 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx,
5039 #endif /* LOCAL_INTF */
5041 /* copy each ipv6 ext header from ipHdrParams to the flat buffer
5042 * cmsgData one by one. */
5044 if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhHdrPrsnt == TRUE)
5045 /* build HBH ext header in cmsgData starting at indx 0 */
5046 cmInet6BuildSendHBHOpts(
5047 &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhOptsArr,
5048 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx, 0);
5050 /* now copy the elements from the Destination Option array one by
5051 * one to the Flat Buffer cmsgData. Start filling at indx curMsgIdx
5052 * which is the end of HBH hdr. */
5053 if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsPrsnt == TRUE)
5054 /* build Dest opt hdr starting at (cmsgData + curMsgIdx) */
5055 cmInet6BuildSendDestOpts(
5056 &(ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsArr),
5057 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx, 1);
5059 /* copy Route header to to the Flat Buffer cmsgData */
5060 if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsPrsnt == TRUE)
5061 /* curMsgIdx will be the indx where Dest opt ends in cmsgData */
5062 cmInet6BuildSendRouteOpts(
5063 &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsArr,
5064 (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);
5066 /* msghrd struc's msg_control will point cmsgData and msg_controllen
5067 * will be the curMsgIdx */
5068 msg.msg_control = cmsgData; /* pointer to Ancillary Data */
5069 msg.msg_controllen = curMsgIdx; /* total length of ancillary Data */
5072 #endif /* IPV6_OPTS_SUPPORTED */
5074 /* Loop till all the data is sent or till the sendmsg call cannot send
5078 /* build the send vector */
5079 /* cm_inet_c_001.main_50 - Partial send handling. Added variable to hold
5080 total length of the packed dbufs */
5081 retVal = buildSendIovec(mBuf, unSentLen, txArr, numDBufs, &i,
5082 &strtEndDBufNum, &ioLen);
5087 /* Incase of UDP/RAW messages call SCompressMsg. */
5088 if (sockFd->type != CM_INET_STREAM)
5090 /* Compress the message into a single dBuf */
5091 ret = SCompressMsg(mBuf);
5096 /* Rebuild the send vector */
5097 /* cm_inet_c_001.main_50 - Partial send handling. Added variable to hold
5098 total length of the packed dbuf */
5099 ret = buildSendIovec(mBuf, unSentLen, txArr, numDBufs, &i,
5100 &strtEndDBufNum, &ioLen);
5110 msg.msg_iov = txArr;
5116 extern int ntl_hLib;
5117 if ( sockFd->fd >= 0xD001)
5118 ret = ntl_sendmsg(ntl_hLib, sockFd->fd, &msg, 0);
5120 ret = sendmsg(sockFd->fd, &msg, 0);
5123 ret = sendmsg(sockFd->fd, &msg, 0);
5125 /* cm_inet_c_001.main_50 - Update the length only in successful cases */
5126 if (ret == INET_ERR)
5128 if((INET_ERR_CODE == ERR_AGAIN) ||
5129 (INET_ERR_CODE == ERR_WOULDBLOCK))
5131 /* cm_inet_c_001.main_50 - Return without making length 0, if in case the partial
5132 message was sent earlier */
5133 return (RWOULDBLOCK);
5137 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5138 /* cm_inet_c_001.main_62:Warning fix */
5139 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendMsg() Failed : error(%d),"
5140 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
5141 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET024, 0, prntBuf);
5143 /* cm_inet_c_001.main_62:Warning fix */
5144 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendMsg() Failed : error(%d),"
5145 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
5146 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET024, 0, prntBuf);
5147 #endif /*ALIGN_64BIT*/
5148 #endif /* CMINETDBG */
5150 /* cm_inet_c_001.main_37 network unreacheble error is added */
5151 /* check if network is reacheble or not */
5152 if ((INET_ERR_CODE == ERR_NETUNREACH))
5154 return (RNETFAILED);
5157 /* Check if connection was closed by the peer */
5158 if ((INET_ERR_CODE == ERR_PIPE) ||
5159 (INET_ERR_CODE == ERR_CONNREFUSED) ||
5160 (INET_ERR_CODE == ERR_CONNABORTED))
5168 /* cm_inet_c_001.main_50 - Update the length only in successful cases */
5171 /* cm_inet_c_001.main_50 - if what is actually sent is less than what is attemped
5172 * to be sent, then return WOULDBLOCK
5175 return (RWOULDBLOCK);
5179 } while (*len < msgLen);
5180 #endif /* WIN32 | CMINETFLATBUF */
5184 } /* end of cmInetSendMsg */
5187 /* added new functions for IPv6 extension headers */
5188 #ifdef IPV6_OPTS_SUPPORTED
5192 * Fun: cmInet6BuildSendPktinfo
5194 * Desc: This function inserts src address (into ancillary data) which
5195 * will be used as the src addr in outgoing IP packet when sending
5196 * that packet using sendmsg()function.
5207 PRIVATE S16 cmInet6BuildSendPktinfo
5209 CmInetIpAddr6 *srcAddr, /* src ip addr to set on outgoing packet */
5210 U8 *cmsgBuf, /* flat buffer where to build ext hdrs */
5211 U32 *curMsgIdx, /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5212 U8 protType /* whether IPv4/IPv6 socket */
5215 PRIVATE S16 cmInet6BuildSendPktinfo(srcAddr, cmsgBuf, curMsgIdx, protType)
5216 CmInetIpAddr6 *srcAddr; /* src ip addr to set on outgoing packet */
5217 U8 *cmsgBuf; /* flat buffer where to build ext hdrs */
5218 U32 *curMsgIdx; /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5219 U8 protType; /* whether IPv4/IPv6 socket */
5222 struct cmsghdr *tempHdr;
5223 struct in6_pktinfo *ipv6Pktinfo;
5224 struct in6_addr lpBkAddr;
5230 lpBkAddr = in6addr_loopback;
5232 /* cmsghdr struc will appear before data in the ancillary data object.
5233 * So put cmsghdr struc in flat buffer first. */
5235 /* cmsghdr struc points to flat buffer's starting address */
5236 tempHdr = (struct cmsghdr *)cmsgBuf;
5238 /* fill up level & type of cmsghdr structure */
5239 if (protType == AF_INET6)
5241 tempHdr->cmsg_level = IPPROTO_IPV6;
5242 tempHdr->cmsg_type = IPV6_PKTINFO;
5245 else if(protType == AF_INET)
5247 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5248 /* cm_inet_c_001.main_62:Warning fix */
5249 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid socket type in cmInet6BuildPktinfo(),"
5250 "protType(%d)\n", protType);
5251 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET025, 0, prntBuf);
5255 /* skip length of cmsghdr structure - 12 bytes */
5256 len += sizeof(struct cmsghdr);
5258 if(protType == AF_INET6)
5259 ipv6Pktinfo = (struct in6_pktinfo *)(cmsgBuf + len);
5263 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5264 /* cm_inet_c_001.main_62:Warning fix */
5265 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid socket type in cmInet6BuildPktinfo(),"
5266 "protType(%d)\n", protType);
5267 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET026, 0, prntBuf);
5271 /* insert the hoplimit. This will override the kernel's
5272 * default hoplimit value */
5273 if(protType == AF_INET6)
5275 /* store ipv6 src addr */
5276 memcpy(&(ipv6Pktinfo->ipi6_addr), srcAddr, 16);
5279 /* store interface index */
5280 /* 0 is invalid intf indx it tells kernel to chose any intf it likes to
5281 * send this pkt. if we use nozero intf indx then kernel will send this
5282 * pkt only through that intf */
5283 ipv6Pktinfo->ipi6_ifindex = 0;
5287 else if(protType == AF_INET)
5289 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5290 /* cm_inet_c_001.main_62:Warning fix */
5291 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid socket type in cmInet6BuildPktinfo(),"
5292 "protType(%d)\n", protType);
5293 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET027, 0, prntBuf);
5297 /* fill up the length of cmsghdr structure */
5298 tempHdr->cmsg_len = len;
5303 }/* end of cmInet6BuildSendPktinfo */
5304 #endif /* LOCAL_INTF */
5310 * Fun: cmInetBuildSendHoplimit
5312 * Desc: This function inserts hoplimit value to be sent out by ancillary
5313 * data by calling sendmsg()function.
5324 PRIVATE S16 cmInetBuildSendHoplimit
5326 U32 hoplimit, /* the hoplimit value to be set on outgoing packet */
5327 U8 *cmsgBuf, /* flat buffer where to build ext hdrs */
5328 U32 *curMsgIdx /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5331 PRIVATE S16 cmInetBuildSendHoplimit(hoplimit, cmsgBuf, curMsgIdx)
5332 U32 hoplimit; /* the hoplimit value to be sent on outgoing packet */
5333 U8 *cmsgBuf; /* flat buffer where to build ext hdrs */
5334 U32 *curMsgIdx; /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5337 struct cmsghdr *tempHdr;
5343 /* cmsghdr struc will appear before data in the ancillary data object.
5344 * So put cmsghdr struc in flat buffer first. */
5346 /* cmsghdr struc points to flat buffer's starting address */
5347 tempHdr = (struct cmsghdr *)cmsgBuf;
5349 /* fill up level & type of cmsghdr structure */
5350 tempHdr->cmsg_level = IPPROTO_IPV6;
5351 tempHdr->cmsg_type = IPV6_HOPLIMIT;
5353 /* skip cmsghdr struc (length of cmsghdr structure) */
5354 len += sizeof(struct cmsghdr);
5356 /* insert the hoplimit. This will override the kernel's
5357 * default hoplimit value */
5358 *(cmsgBuf + len) = hoplimit;
5359 len += sizeof(hoplimit);
5361 /* fill up the length of cmsghdr structure */
5362 tempHdr->cmsg_len = len;
5366 } /* end of cmInetBuildSendHoplimit */
5367 #endif /* SS_LINUX */
5372 * Fun: cmInet6BuildSendHBHOpts
5374 * Desc: This function builds the HopByHop option which will be put
5375 * in the data portion of the ancillary data object. To build
5376 * the HopByHop option this function takes an array of
5377 * individual HopByHop option and fill them in a flat buffer.
5378 * cmsghdr struc always appear before HopBYHop Options, Dest
5379 * Options and Route header option.
5381 * The address of the flat Buffer *cmsgBuf is passed to this
5382 * function from cmInetSendMsg. This buffer will have all extension
5383 * headers. This buffer is passed as ancillary data by sendmsg()
5387 * Notes: This function will also be used for Destination options
5394 PRIVATE S16 cmInet6BuildSendHBHOpts
5396 CmInetIpv6HBHHdrArr *hbhOptsArr,/* IPv6 extensions headers HBH/Dest opts */
5397 U8 *cmsgBuf, /* flat buffer where to build ext hdrs */
5398 U32 *curMsgIdx, /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5399 U8 hdrId /* 0: HBH hdr, 1:Dest Hdr */
5402 PRIVATE S16 cmInet6BuildSendHBHOpts(hbhOptsArr, cmsgBuf, curMsgIdx, hdrId)
5403 CmInetIpv6HBHHdrArr *hbhOptsArr;/* IPv6 extensions headers HBH/Dest opts */
5404 U8 *cmsgBuf; /* flat buffer where to build ext hdrs */
5405 U32 *curMsgIdx; /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5406 U8 hdrId; /* 0: HBH hdr, 1:Dest Hdr */
5409 struct cmsghdr *tempHdr;
5417 /* cmsghdr struc will appear before data in the ancillary data object.
5418 * So put cmsghdr struc in flat buffer first. */
5420 /* cmsghdr struc points to flat buffer's starting address */
5421 tempHdr = (struct cmsghdr *)cmsgBuf;
5423 /* fill up level & type of cmsghdr structure */
5426 tempHdr->cmsg_level = IPPROTO_IPV6;
5427 tempHdr->cmsg_type = IPV6_HOPOPTS;
5429 else if (hdrId == 1)
5431 tempHdr->cmsg_level = IPPROTO_IPV6;
5432 tempHdr->cmsg_type = IPV6_DSTOPTS;
5435 /* skip cmsghdr struc (length of cmsghdr structure) */
5436 len += (sizeof(tempHdr->cmsg_level) + sizeof(tempHdr->cmsg_len) +
5437 sizeof(tempHdr->cmsg_type));
5439 /* Next Hdr: will be fill up accordingly by Kernel */
5440 *(cmsgBuf + len) = 0x00;
5443 /* Header Ext Length: will be fill up by us. In units of 8-byte excluding
5444 * first 8 bytes starting from Next Header field. */
5445 *(cmsgBuf + len) = 0x00;
5448 /* fillup all HBH/dest options' TLV. Here, we assume that all the HBH/dest
5449 * options are packed inside 1 HBH option header. */
5450 for (optsIdx = 0; optsIdx < hbhOptsArr->numHBHOpts;
5453 /* Copy the TLV into cmsgBuf data portion */
5454 /* copy type field of every HBH/dest option */
5455 *(cmsgBuf + len) = hbhOptsArr->hbhOpts[optsIdx].type;
5456 len += sizeof(hbhOptsArr->hbhOpts[optsIdx].type);
5458 /* copy length field of every HBH/dest option */
5459 *(cmsgBuf + len) = hbhOptsArr->hbhOpts[optsIdx].length;
5460 len += sizeof(hbhOptsArr->hbhOpts[optsIdx].length);
5462 /* copy all value bytes of current HBH/dest option to the flat buffer */
5463 memcpy((cmsgBuf + len),
5464 (hbhOptsArr->hbhOpts[optsIdx].value),
5465 hbhOptsArr->hbhOpts[optsIdx].length);
5466 len += hbhOptsArr->hbhOpts[optsIdx].length;
5469 /* cuMsgIdx will have the total length of HBH options array */
5470 /* add this length to the length of cmsgHdr struc */
5472 /* Padding: Different header has different padding requirement(xn+y). For
5473 * HBH Router Alert we need 2 bytes of padding. As this same function is
5474 * used for Destination option also and there is no option for it is yet
5475 * proposed, we are passing padN options - 6 bytes to make the Dest Option
5476 * hdr a multiple of 8 bytes. */
5478 /* HBH: padN of 2 bytes needed for Router Alert */
5479 /* This logic is present currently to support router alert which is the
5480 * only supported HBH option today. For other, generic method needed */
5483 *(cmsgBuf + len) = 0x01;
5485 *(cmsgBuf + len) = 0x00;
5489 /* fill up the length of cmsghdr structure */
5490 tempHdr->cmsg_len = len;
5494 } /* end of cmInet6BuildSendHBHOpts */
5499 * Fun: cmInet6BuildSendRouteOpts
5501 * Desc: This function transfers bytes from the Route hdr array to the
5502 * flat buffer. First the top cmsghdr structure will be filled in
5503 * the flat buffer, then route hdr type 0 will be added after
5504 * cmsghdr struc in the flat buffer. Then all IPV6 addresses will
5516 PRIVATE S16 cmInet6BuildSendRouteOpts
5518 CmInetIpv6RtHdr *rtOptsArr, /* IPv6 destination options array */
5519 U8 *cmsgBuf, /* flat buffer where to build ext hdrs */
5520 U32 *curMsgIdx /* idx in cmsgBuf where to start building RT hdr */
5523 PRIVATE S16 cmInet6BuildSendRouteOpts(rtOptsArr, cmsgBuf, curMsgIdx)
5524 CmInetIpv6RtHdr *rtOptsArr; /* IPv6 destination options array */
5525 U8 *cmsgBuf; /* flat buffer where to build ext hdrs */
5526 U32 *curMsgIdx; /* idx in cmsgBuf where to start building RT hd */
5529 struct cmsghdr *tempHdr;
5530 CmInetIpv6RtHdr0 *tempRtHdr;
5538 /* cmsghdr struc will appear before data in the ancillary data object.
5539 * So put cmsghdr struc in flat buffer first */
5541 /* cmsghdr struc points to flat buffer */
5542 tempHdr = (struct cmsghdr *)(cmsgBuf);
5544 tempHdr->cmsg_level = IPPROTO_IPV6;
5545 tempHdr->cmsg_type = IPV6_RTHDR;
5547 /* skip cmsghdr structure */
5548 len += sizeof(struct cmsghdr);
5550 /* we know the total size of Route hdr if we know the num of ipv6 addrs */
5551 tempHdr->cmsg_len = len + sizeof(CmInetIpv6RtHdr0)
5552 + rtOptsArr->numAddrs * sizeof(CmInetIpAddr6);
5554 /* attach route hdr type 0 after cmsghdr structure */
5555 tempRtHdr = (CmInetIpv6RtHdr0 *)(cmsgBuf + len);
5557 /* fill up fields of route hdr type 0 */
5559 /* will be filled up by Kernel */
5560 tempRtHdr->ip6r0_nextHdr = 0x00;
5562 tempRtHdr->ip6r0_hdrExtLen = (2 * rtOptsArr->numAddrs);
5564 /* only type supported today */
5565 tempRtHdr->ip6r0_type = 0x00;
5567 tempRtHdr->ip6r0_segLeft = rtOptsArr->numAddrs;
5569 /* Note: rfc 2292(1998) mentions 1 reserve byte & 3 strict/loose bytes
5570 * restricting total 23 ipv6 addresses can be added to the route header.
5571 * But rfc 2292(2002) mentions all 4 bytes are reserved which allows
5572 * as many ipv6 addresses as wishes to be added to the route header */
5574 tempRtHdr->ip6r0_resrvAndSLmap = rtOptsArr->slMap;
5576 /* move pointer in the flat buffer to the end of this structure */
5577 len += sizeof(CmInetIpv6RtHdr0);
5579 /* fill up all IPV6 addresses from rtOptsArr in the flat buffer */
5580 for (addrIdx = 0; addrIdx < rtOptsArr->numAddrs; addrIdx++)
5582 memcpy((cmsgBuf + len),
5583 (rtOptsArr->ipv6Addrs[addrIdx]), 16);
5589 } /* end of cmInet6BuildSendRouteOpts */
5594 * Fun: cmInet6BuildRecvHopOptsArr
5596 * Desc: This function fills up the HopByHop Array of ipHdrParam from
5597 * the ancillary data received through recvmsg() call. The memory
5598 * to hold the extension headers is allocated here. All received
5599 * ext hdr info will be passed to upper user as ipHdrParam.
5601 * Ret: ROK - successful
5611 PRIVATE S16 cmInet6BuildRecvHopOptsArr
5613 U8 *cmsgData, /* flat buffer where to build ext hdrs */
5614 U32 hbhDataLen, /* byte len of cmsghdr + hbh ancil data */
5615 CmInetIpv6HBHHdrArr *hbhOptsArr, /* IPv6 extensions headers */
5616 U8 hdrId, /* 0: HBH, 1: DEST */
5617 CmInetMemInfo *info /* Memory information */
5620 PRIVATE S16 cmInet6BuildRecvHopOptsArr(cmsgData, hbhDataLen, hbhOptsArr, hdrId,
5622 U8 *cmsgData; /* flat buffer where to build ext hdrs */
5623 U32 hbhDataLen; /* byte len of cmsghdr + hbh ancil data */
5624 CmInetIpv6HBHHdrArr *hbhOptsArr; /* IPv6 extensions headers */
5625 U8 hdrId; /* 0: HBH, 1: DEST */
5626 CmInetMemInfo *info; /* Memory information */
5629 U32 curDataIdx; /* to keep track where we are in the hbh Data */
5630 U8 optsIdx; /* how many hbh opts present in data */
5631 U8 numOpts; /* number of hbh opts present in data */
5637 /* get length of actual hbh ancillary data */
5638 hbhDataLen -= sizeof(struct cmsghdr);
5644 /* skip Next Hdr byte & Hdr Ext Length byte */
5647 /* First find out how many hop-by-hop headers we need to allocate */
5650 /* break when all HBH data is copied to hbhOptsArr */
5651 if (curDataIdx >= hbhDataLen)
5657 tempType = *(U8 *)(cmsgData + curDataIdx);
5660 /* take care of pad1 option */
5663 /* not considering the pad1 as valid option */
5669 tempLen = *(U8 *)(cmsgData + curDataIdx);
5671 /* 1 is to skip length. tempLen to skip the value field */
5672 curDataIdx += (1 + tempLen);
5674 /* considering the padN as valid option for Dest Opt Hdr!!! As this is
5675 * the "only" valid option today. Ignore for HBH hdr */
5681 /* allocate mem needed to hold all HBH/Dest options */
5682 ret = SGetSBuf(info->region, info->pool,
5683 (Data **)&hbhOptsArr->hbhOpts,
5684 (Size)((sizeof(CmInetIpv6HBHHdr)) * numOpts));
5688 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5689 /* cm_inet_c_001.main_62:Warning fix */
5690 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SGetSBuf failure 1 in cmInet6BuildRecvHopOptsArr\n");
5691 CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET028, 0, prntBuf);
5692 #endif /* CMINETDBG */
5699 /* skip Next Hdr byte & Hdr Ext Length byte */
5702 hbhOptsArr->numHBHOpts = numOpts;
5704 /* fill up HBH/dest opt array from recvd ancillary data */
5707 /* break when all HBH data is copied to hbhOptsArr */
5708 if (curDataIdx >= hbhDataLen)
5711 /* only copy Router Alert HBH option part which has type 5. Otherwise,
5712 * skip it when it is a PAD1, PADN or Jumbogram option for HBH. But
5713 * consider padN as valid option for dest opt hdr. */
5715 /* get the type of current HBH/dest option */
5716 tempType = *(cmsgData + curDataIdx);
5719 /* ignore PAD1 for both HBH/dest by skipping to next option */
5723 /* calculate how much to skip for padN in case of HBH */
5728 /* get the length field of padN option */
5729 tempLen = *(cmsgData + curDataIdx);
5732 /* move pointer forward to skip value field */
5733 curDataIdx += tempLen;
5737 hbhOptsArr->hbhOpts[optsIdx].type = tempType;
5739 /* copy the length */
5740 hbhOptsArr->hbhOpts[optsIdx].length = *(cmsgData + curDataIdx);
5743 /* take care of PADN = 2 when value field empty. We also don't need
5744 * to allocate memory for empty value field */
5745 if (hbhOptsArr->hbhOpts[optsIdx].length == 0)
5746 hbhOptsArr->hbhOpts[optsIdx].value = NULLP;
5749 /* take care of all other options having valid value field
5750 * such as Router Alert, PADN >= 3 bytes and Jumbo */
5751 ret = SGetSBuf(info->region, info->pool,
5752 (Data **)&hbhOptsArr->hbhOpts[optsIdx].value,
5753 (Size)hbhOptsArr->hbhOpts[optsIdx].length);
5757 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5758 /* cm_inet_c_001.main_62:Warning fix */
5759 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SGetSBuf failure 2 cmInet6BuildRecvHopOptsArr\n");
5760 CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET029, 0, prntBuf);
5761 #endif /* CMINETDBG */
5762 /* now go inside every separate HBH option and free the memory
5763 * allocated for its value field */
5764 for (; optsIdx > 0; optsIdx --)
5766 if (hbhOptsArr->hbhOpts[optsIdx - 1].value != NULLP)
5769 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5770 /* cm_inet_c_001.main_62:Warning fix */
5771 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SPutSBuf call 1 in BuildRecvHopOptsArr\n");
5772 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET030, 0, prntBuf);
5773 #endif /* CMINETDBG */
5774 SPutSBuf(info->region, info->pool,
5775 (Data *)hbhOptsArr->hbhOpts[optsIdx - 1].value,
5776 (Size)hbhOptsArr->hbhOpts[optsIdx - 1].length);
5779 /* clean up all CmInetIpv6HBHHdr structures allocated for all
5780 * arrived HBH options OR numOpts CmInetIpv6HBHHdr structures
5781 * allocated after counting numOpts */
5783 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5784 /* cm_inet_c_001.main_62:Warning fix */
5785 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SPutSBuf call 2 in BuildRecvHopOptsArr\n");
5786 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET031, 0, prntBuf);
5787 #endif /* CMINETDBG */
5788 SPutSBuf(info->region, info->pool,
5789 (Data *)hbhOptsArr->hbhOpts, numOpts * sizeof(CmInetIpv6HBHHdr));
5790 hbhOptsArr->numHBHOpts = 0;
5791 hbhOptsArr->hbhOpts = NULLP;
5794 /* copy the value bytes */
5795 memcpy(hbhOptsArr->hbhOpts[optsIdx].value,
5796 (cmsgData + curDataIdx),
5797 hbhOptsArr->hbhOpts[optsIdx].length);
5798 curDataIdx += hbhOptsArr->hbhOpts[optsIdx].length;
5801 /* get next option */
5805 } /* end of cmInet6BuildRecvHopOptsArr() */
5810 * Fun: cmInet6BuildRecvRtHdr
5812 * Desc: This function fills up the Route Header in the cmInetIpv6HdrParm
5813 * from the recvd ancillary data from recvmsg system call.
5815 * Ret: ROK - successful
5825 PRIVATE S16 cmInet6BuildRecvRtHdr
5827 U8 *cmsgData, /* flat buffer where to build Route hdr */
5828 U32 rtDataLen, /* byte len of cmsghdr struc+rtHdr ancil data */
5829 CmInetIpv6RtHdr0 *rtHdr0, /* rtHeader0 struct that precedes IPV6 addrss */
5830 CmInetIpv6RtHdr *rtOptsArr,/* IPv6 extensions headers */
5831 CmInetMemInfo *info /* Memory information */
5834 PRIVATE S16 cmInet6BuildRecvRtHdr(cmsgData, rtDataLen, rtHdr0, rtOptsArr, info)
5835 U8 *cmsgData; /* flat buffer where to build Route hdr */
5836 U32 rtDataLen; /* byte len of cmsghdr struc+rtHdr ancil data */
5837 CmInetIpv6RtHdr0 *rtHdr0; /* rtHeader0 struct that precedes IPV6 addrss */
5838 CmInetIpv6RtHdr *rtOptsArr;/* IPv6 extensions headers */
5839 CmInetMemInfo *info; /* Memory information */
5842 U32 curDataIdx; /* to keep track where we are in hbh Data */
5843 U8 i; /* loop counter */
5844 S16 ret; /* temporary return value */
5847 /* byte len of actual rtHdr ancil data */
5848 rtDataLen -= sizeof(struct cmsghdr);
5850 /* start from beginning */
5853 /* copy next header byte */
5854 rtHdr0->ip6r0_nextHdr = *(cmsgData + curDataIdx);
5857 /* copy header extension length byte */
5858 rtHdr0->ip6r0_hdrExtLen = *(cmsgData + curDataIdx);
5861 /* copy type byte (always 0) */
5862 rtHdr0->ip6r0_type = 0x00;
5865 /* copy segment left byte */
5866 rtHdr0->ip6r0_segLeft = *(cmsgData + curDataIdx);
5869 /* copy 1 reserve byte + 3 strict/loose bytes */
5870 memcpy((&rtOptsArr->slMap),
5871 (cmsgData + curDataIdx), 4);
5874 /* also save reserv byte + 3 sl bytes to rtHdro struc */
5875 rtHdr0->ip6r0_resrvAndSLmap = rtOptsArr->slMap;
5877 /* subtract 8 bytes for Next Hdr, Hdr Ext Len, .... + SL bit map */
5878 rtOptsArr->numAddrs = (rtDataLen - 8)/16;
5880 ret = SGetSBuf(info->region, info->pool,
5881 (Data **)&rtOptsArr->ipv6Addrs,
5882 (Size)rtOptsArr->numAddrs * 16);
5886 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5887 /* cm_inet_c_001.main_62:Warning fix */
5888 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SGetSBuf failure 1 in cmInet6BuildRecvRtHdr\n");
5889 CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET032, 0, prntBuf);
5890 #endif /* CMINETDBG */
5894 /* copy all the ipv6 addresses */
5895 for(i=0; i < rtOptsArr->numAddrs; i++)
5897 memcpy((rtOptsArr->ipv6Addrs[i]),
5898 (cmsgData + curDataIdx), 16);
5903 } /* end of cmInet6BuildRecvRtHdr() */
5908 * Fun: cmInet6GetHopLimitValue
5910 * Desc: This function extracts the hop limit value(ttl) of from the
5911 * ancillary data received through recvmsg() call. Then this
5912 * hoplimit value will be passed to upper user as ipHdrParam.
5914 * Ret: ROK - successful
5923 PRIVATE S16 cmInet6GetHopLimitValue
5925 U8 *cmsgData, /* flat buffer where to build ext hdrs */
5926 U32 hopLimitDataLen, /* byte len of cmsghdr + hbh ancil data */
5927 CmInetIpv6HdrParm *ipv6HdrParam /* ipv6 header parameters */
5930 PRIVATE S16 cmInet6GetHopLimitValue(cmsgData, hopLimitDataLen, ipv6HdrParam)
5931 U8 *cmsgData; /* flat buffer where to build ext hdrs */
5932 U32 hopLimitDataLen; /* byte len of cmsghdr + hbh ancil data */
5933 CmInetIpv6HdrParm *ipv6HdrParam; /* ipv6 header parameters */
5936 U16 curDataIdx; /* to keep track where we are in the ancillary Data */
5937 U32 *hopLimitValue; /* ttl/hoplimit value */
5939 hopLimitValue = NULL;
5942 /* get length of actual hbh ancillary data */
5943 hopLimitDataLen -= sizeof(struct cmsghdr);
5945 /* go to the first byte of hop limit which present after cmsghdr struc */
5946 curDataIdx += sizeof(struct cmsghdr);
5948 /* mark that hoplimit(ttl) is present */
5949 ipv6HdrParam->ttl.pres = TRUE;
5951 /* the first byte will be the HopLimit value */
5952 hopLimitValue = (U32 *)(cmsgData);
5953 ipv6HdrParam->ttl.val = (U8)(*hopLimitValue);
5957 #endif /* IPV6_OPTS_SUPPORTED */
5962 * Fun: cmInetRecvMsg
5964 * Desc: Reads data from a socket into a message.
5965 * The buffers for the message are allocated within the
5966 * cmInetRead() function from the pool and region Id set in the
5968 * If the number of octets given by the paramter len is not
5969 * available the function immediately returns with RKDNA.
5970 * If the len parameter is set to CM_INET_READ_ANY, the currently
5971 * available data is read.
5972 * Values for flag parameter:
5974 * CM_INET_NO_FLAG - no additional control flag
5975 * CM_INET_MSG_PEEK - do not destroy data on receive buffer
5977 * Ret: ROK - successful
5978 * ROKDNA - ok, data not available
5979 * RCLOSED - connection closed by peer
5980 * ROUTRES - failed, out of resources
5991 CmInetFd *sockFd, /* socket file descriptor */
5992 CmInetAddr *fromAddr, /* sender Internet address/port */
5993 CmInetMemInfo *info, /* buffer allocation info */
5994 Buffer **mPtr, /* received buffer structure */
5995 MsgLen *len, /* number of octets to read */
5996 /* added for IPv6 */
5997 #ifdef IPV6_OPTS_SUPPORTED
5998 CmInetIpHdrParm *ipHdrParams, /* IPv6 extensions headers */
5999 #endif /* IPV6_OPTS_SUPPORTED */
6001 CmInetLocalInf *localIf, /* local interface on which pkt was recvd */
6002 #endif /* LOCAL_INTF */
6003 S32 flags /* additional control flags */
6006 /* added for IPv6 */
6007 #ifdef IPV6_OPTS_SUPPORTED
6009 S16 cmInetRecvMsg(sockFd, fromAddr, info, mPtr, len,
6010 ipHdrParams, localIf, flags)
6011 CmInetFd *sockFd; /* socket file descriptor */
6012 CmInetAddr *fromAddr; /* sender Internet address/port */
6013 CmInetMemInfo *info; /* buffer allocation info */
6014 Buffer **mPtr; /* received buffer structure */
6015 MsgLen *len; /* number of octets to read */
6016 CmInetIpHdrParm *ipHdrParams; /* IPv6 extensions headers */
6017 CmInetLocalInf *localIf; /* local interface on which pkt was recvd */
6018 S32 flags; /* additional control flags */
6020 S16 cmInetRecvMsg(sockFd, fromAddr, info, mPtr, len, ipHdrParams, flags)
6021 CmInetFd *sockFd; /* socket file descriptor */
6022 CmInetAddr *fromAddr; /* sender Internet address/port */
6023 CmInetMemInfo *info; /* buffer allocation info */
6024 Buffer **mPtr; /* received buffer structure */
6025 MsgLen *len; /* number of octets to read */
6026 CmInetIpHdrParm *ipHdrParams; /* IPv6 extensions headers */
6027 S32 flags; /* additional control flags */
6028 #endif /* LOCAL_INTF */
6031 S16 cmInetRecvMsg(sockFd, fromAddr, info, mPtr, len, localIf, flags)
6032 CmInetFd *sockFd; /* socket file descriptor */
6033 CmInetAddr *fromAddr; /* sender Internet address/port */
6034 CmInetMemInfo *info; /* buffer allocation info */
6035 Buffer **mPtr; /* received buffer structure */
6036 MsgLen *len; /* number of octets to read */
6037 CmInetLocalInf *localIf; /* local interface on which pkt was recvd */
6038 S32 flags; /* additional control flags */
6040 S16 cmInetRecvMsg(sockFd, fromAddr, info, mPtr, len, flags)
6041 CmInetFd *sockFd; /* socket file descriptor */
6042 CmInetAddr *fromAddr; /* sender Internet address/port */
6043 CmInetMemInfo *info; /* buffer allocation info */
6044 Buffer **mPtr; /* received buffer structure */
6045 MsgLen *len; /* number of octets to read */
6046 S32 flags; /* additional control flags */
6047 #endif /* LOCAL_INTF */
6048 #endif /* IPV6_OPTS_SUPPORTED */
6051 #if (defined(WIN32) || defined(CMINETFLATBUF))
6052 S32 ret; /* temporary return value */
6053 U32 pendLen; /* pending data length */
6054 S32 recvLen; /* number of received octets by recvmsg() */
6055 MsgLen bufLen; /* entire number of received octets */
6056 MsgLen curLen; /* current number of octets in buffer */
6057 Data *recvBuf; /* receive buffer */
6058 Data *bufPtr; /* current buffer position */
6059 Buffer *mBuf; /* received message */
6060 U32 remAddrLen; /* length of remote address */
6061 struct sockaddr_in *remAddr; /* remote Internet address */
6062 #ifdef IPV6_SUPPORTED
6063 struct sockaddr_in6 *remAddr6; /* remote Internet address */
6064 struct sockaddr_in6 remSockAddr; /* to get packet's source IP address */
6066 CmInetSockAddr remSockAddr; /* to get packet's source IP address */
6067 #endif /* IPV6_SUPPORTED */
6069 S32 ret; /* temporary return value */
6070 /* cm_inet_c_001.main_58: Fix for g++ compilation warning */
6072 U32 pendLen; /* pending data length */
6073 S32 numBuf; /* number of allocated dBufs */
6074 S32 recvLen; /* number of received octets by recvmsg() */
6075 MsgLen bufLen; /* entire number of received octets */
6076 struct msghdr msg; /* message header */
6077 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6078 Buffer *tempMsg = NULLP; /* temporary message */
6079 CmInetIovec rxArr[CM_INET_MAX_DBUF]; /* dynamic gather array */
6080 Buffer **dBufs = NULLP; /* dynamic array with allocated dBufs */
6081 S16 numDBufs; /* number of allocated dBufs */
6083 /* cm_inet_c_001.main_55: As remAddrLen is only being used when
6084 * WIN32 or CMINETFLATBUF is defined, then Removed variable
6086 struct sockaddr_in *remAddr; /* remote Internet address */
6087 #ifdef IPV6_SUPPORTED
6088 struct sockaddr_in6 *remAddr6; /* remote Internet address */
6089 struct sockaddr_in6 remSockAddr;/* to get packet's source IP address */
6090 /* added for IPv6 ext headers support */
6091 #ifdef IPV6_OPTS_SUPPORTED
6092 CmInetIpv6RtHdr0 rtHdr0; /* type 0 route header */
6093 #endif /* IPV6_OPTS_SUPPORTED */
6096 struct in6_pktinfo *pkt6Info; /* IPv6 IP_PKTINFO */
6097 #endif /* LOCAL_INTF */
6099 #if (defined(SS_LINUX) || defined(_XPG4_2))
6100 U8 ancillData[CM_INET_IPV6_ANCIL_DATA];
6101 /* from stack for IPv6 ancill data */
6104 CmInetSockAddr remSockAddr; /* to get packet's src IP address */
6105 #if (defined(SS_LINUX) || defined(_XPG4_2))
6106 U8 ancillData[CM_INET_IPV4_ANCIL_DATA];
6107 /* from stack for IPv4 ancill data */
6109 #endif /* IPV6_SUPPORTED */
6110 /* added new definitions */
6111 Bool allocFlatBuf; /* allocate a flat buffer */
6112 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6113 Data *recvBuf = NULLP; /* receive buffer */
6116 struct in_pktinfo *pkt4Info; /* IPv4 IP_PKTINFO */
6118 #endif /* SS_LINUX */
6119 #if (defined(IPV6_OPTS_SUPPORTED) || defined(LOCAL_INTF))
6120 struct cmsghdr *cmsgptr;/* pointer to struct cmsghdr */
6122 #endif /* WIN32 | CMINETFLATBUF */
6123 /* used by getsockopt */
6125 /* cm_inet_c_001.main_55:Removed unused variables errValue and optLen */
6128 #if (ERRCLASS & ERRCLS_INT_PAR)
6129 /* error check on parameters */
6130 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
6131 (info == NULLP) || (mPtr == NULLP) || (len == NULLP))
6135 #endif /* ERRCLASS & ERRCLS_INT_PAR */
6139 /*cm_inet_c_001.main_48 variables declaration */
6140 #if !((defined(WIN32) || defined(CMINETFLATBUF)))
6145 #if (defined(WIN32) || defined(CMINETFLATBUF))
6147 #ifdef IPV6_SUPPORTED
6149 #endif /* IPV6_SUPPORTED */
6151 #ifdef IPV6_SUPPORTED
6154 #endif /* IPV6_SUPPORTED */
6156 #if (defined(SS_LINUX) || defined(_XPG4_2))
6157 memset(ancillData, 0, sizeof(ancillData));
6158 #endif /* SS_LINUX || _XPG4_2 */
6160 #endif /* (WIN32 | CMINETFLATBUF) */
6162 /* clear the structure */
6163 memset(&remSockAddr, 0, sizeof(remSockAddr));
6165 /* get number of pending data */
6166 /* removed 3rd arg memInfo. MemInfo is no longer
6167 needed as we call ioctl for all sockets */
6169 /* cm_inet_c_001.main_48 : call ioctl only for STREAM
6170 * sockets now. For Non-Stream sockets(Raw & UDP), fix
6171 * pending length to CM_INET_MAX_UDPRAW_MSGSIZE
6173 if(sockFd->type == CM_INET_STREAM)
6175 ret = cmInetGetNumRead(sockFd, &pendLen);
6178 /* ret may be RFAILED or ROUTRES */
6184 /* cm_inet_c_001.main_48 : pendLen is set 1 greater
6185 * than the #defined value. If recvFrom/recvMsg
6186 * returns the len == pendLen, we would drop the
6187 * message as the msg len is larger than the largest
6188 * msg we are willing to accept.
6190 pendLen = CM_INET_MAX_UDPRAW_MSGSIZE+1;
6194 /* check if connection got closed */
6197 if (sockFd->type == CM_INET_STREAM)
6199 /* cm_inet_c_001.main_50:
6200 * cm_inet_c_001.main_56: Removed comment for cm_inet_c_001.main_50 as
6201 * the current patch changes its functionality */
6202 U8 readBuf[1]; /* declaration of variable for Peek */
6205 * cm_inet_c_001.main_56:
6206 * We are peeking the socket buffer again with peek as on some machines
6207 * like solaris, there is a latency observed in ioctl. In such cases,
6208 * ioctl may return 0, even though there are bytes available to read.
6209 * We reconfirm through peek whether 0 means EOF or its ioctl latency
6212 ret = cmInetPeekNew(sockFd, NULLP, info, 0, 1, readBuf);
6217 /* cm_inet_c_001.main_56:
6218 * Returning ROKDNA even cmInetPeekNew returns ROK. Because currently
6219 * we are not sure about pending length. Anyway socket FD already set,
6220 * we do another iteration to get exact pendLen value. We cannot call
6221 * cmInetGetNumRead at this point because of latency between the ioctl
6222 * call and recvfrom call issues on some machines ioctl call may
6223 * return ZERO even their a data to read. */
6227 /* cm_inet_c_001.main_52: Support for partial reception */
6228 /* cm_inet_c_001.main_59: Fix for compilation warning */
6229 if ((sockFd->type == CM_INET_STREAM) && (*len > (MsgLen)pendLen))
6231 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6232 *len = (MsgLen)pendLen;
6235 /* check if there are enough pending data to read */
6236 if ((*len == CM_INET_READ_ANY) || ((U32)*len <= pendLen))
6238 if (*len == CM_INET_READ_ANY)
6240 /* added check for TCP socket. Pending data length in
6241 the socket recv buffer is determined by ioctl call in
6243 For TCP it can't be > CM_INET_MAX_MSG_LEN. */
6244 if (sockFd->type == CM_INET_STREAM)
6246 /* max message length is limited to control the memory usage */
6247 if (pendLen > CM_INET_MAX_MSG_LEN)
6248 pendLen = CM_INET_MAX_MSG_LEN;
6250 /* cm_inet_c_001.main_48 : removed the check for
6251 * Non Stream sockets (pendLen < MAX_UDPRAW_MSGSIZE)
6252 * as we are hardcoding pendLen for Non-Stream sockets.
6255 /* read all pending data */
6256 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6257 bufLen = (MsgLen)pendLen;
6258 *len = (MsgLen)pendLen;
6262 /* cm_inet_c_001.main_45- Returning CM_INET_MAX_MSG_LEN when input is larger than
6265 /* max message length is limited to control the memory usage */
6266 if ((*len) > CM_INET_MAX_MSG_LEN)
6268 (*len) = CM_INET_MAX_MSG_LEN;
6271 /* read data length given by user */
6275 #if (defined(WIN32) || defined(CMINETFLATBUF))
6277 /* set destination Internet address structure */
6278 if (fromAddr != NULLP)
6280 remAddrLen = sizeof(remSockAddr);
6287 /* allocate flat receive buffer */
6288 ret = SGetSBuf(info->region, info->pool, &recvBuf, bufLen);
6297 * maybe needs more than one recvfrom() call to read an entire
6298 * message from a stream socket (TCP)
6302 /* added separate recvfrom calls different OS */
6304 /*cm_inet_c_001.main_42 1. In Vx-Works the 5th and 6th parameter of recvfrom
6305 system call are either NULL or should be valid pointer.*/
6306 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
6308 recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0,
6309 (struct sockaddr *)&remSockAddr, (int *)&remAddrLen);
6311 recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0,
6312 NULLP, (int *)&remAddrLen);
6314 #if ( defined(SUNOS) || defined(SS_LINUX))
6316 recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0,
6317 (struct sockaddr *)&remSockAddr, (socklen_t *)&remAddrLen);
6319 recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0,
6320 NULLP, (socklen_t *)&remAddrLen);
6323 recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0,
6324 &remSockAddr, (S32 *)&remAddrLen);
6326 recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0,
6327 NULLP, (S32 *)&remAddrLen);
6329 #endif /* defined(SUNOS) || defined(SS_LINUX) */
6330 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */
6332 if (recvLen == INET_ERR)
6335 /* moved cleanup here */
6336 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6338 /* added check ERR_WOULDBLOCK */
6339 if ((INET_ERR_CODE == ERR_AGAIN) ||
6340 (INET_ERR_CODE == ERR_WOULDBLOCK))
6347 /* In Windows the recvfrom function fails
6348 * with error code which maps to either WSAECONNABORTED. If
6349 * this happens then cmInetRecvMsg must return RCLOSED */
6350 if ((INET_ERR_CODE == ERR_CONNABORTED) ||
6351 (INET_ERR_CODE == ERR_CONNRESET))
6359 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
6360 /* cm_inet_c_001.main_62:Warning fix */
6361 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() Failed : error(%d),"
6362 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
6363 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET034, 0, prntBuf);
6365 /* cm_inet_c_001.main_62:Warning fix */
6366 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() Failed : error(%d),"
6367 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
6368 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET034, 0, prntBuf);
6369 #endif /*ALIGN_64BIT*/
6370 #endif /* CMINETDBG */
6378 * a message is always read atomically on a datagram socket,
6379 * therefore it's ok to read less than pending data!
6382 if ((sockFd->type == CM_INET_RAW) ||
6383 (sockFd->type == CM_INET_DGRAM))
6388 #else /* CM_INET2 */
6389 if (sockFd->type == CM_INET_DGRAM)
6394 #endif /* CM_INET2 */
6395 } /* while (curLen > 0) (only for stream sockets) */
6397 /* For UDP, it is possible to receive
6398 * a 0 byte datagram, in this case just return ROKDNA.
6401 if ((sockFd->type == CM_INET_DGRAM || sockFd->type == CM_INET_RAW)
6404 if ((sockFd->type == CM_INET_DGRAM) && (*len == 0))
6407 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6411 /* cm_inet_c_001.main_48 : If Received
6412 * len == CM_INET_MAX_UDPRAW_MSGSIZE+1
6416 if ((sockFd->type == CM_INET_DGRAM || sockFd->type == CM_INET_RAW)
6417 && (*len == (CM_INET_MAX_UDPRAW_MSGSIZE+1)))
6419 if ((sockFd->type == CM_INET_DGRAM)
6420 && (*len == (CM_INET_MAX_UDPRAW_MSGSIZE+1)))
6425 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
6426 /* cm_inet_c_001.main_62:Warning fix */
6427 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg(),recevied a message"
6428 " > than allowed(%lu), sockFd->fd(%ld) \n",
6429 CM_INET_MAX_UDPRAW_MSGSIZE, sockFd->fd);
6430 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET068, 0, prntBuf);
6432 /* cm_inet_c_001.main_62:Warning fix */
6433 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg(),recevied a message"
6434 " > than allowed(%lu), sockFd->fd(%d) \n",
6435 CM_INET_MAX_UDPRAW_MSGSIZE, sockFd->fd);
6436 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET068, 0, prntBuf);
6437 #endif /*ALIGN_64BIT*/
6439 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6443 /* cm_inet_c_001.main_48 : copy data to a message structure */
6444 ret = SGetMsg(info->region, info->pool, &mBuf);
6448 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6453 if ((sockFd->type == CM_INET_DGRAM) ||
6454 (sockFd->type == CM_INET_RAW))
6456 ret = SAddPstMsgMult(recvBuf, *len, mBuf);
6460 ret = SAddPstMsgMult(recvBuf, bufLen, mBuf);
6463 #else /* CM_INET2 */
6464 if (sockFd->type == CM_INET_DGRAM)
6466 ret = SAddPstMsgMult(recvBuf, *len, mBuf);
6470 ret = SAddPstMsgMult(recvBuf, bufLen, mBuf);
6472 #endif /* CM_INET2 */
6476 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6482 /* setup return destination Internet address */
6483 /* added the check of (remAddrLen > 0) */
6484 if ((fromAddr != NULLP) && (remAddrLen > 0))
6486 #ifdef IPV6_SUPPORTED
6487 if (remAddrLen == sizeof(struct sockaddr_in6))
6489 remAddr6 = (struct sockaddr_in6 *)&remSockAddr;
6490 fromAddr->type = CM_INET_IPV6ADDR_TYPE;
6491 fromAddr->u.ipv6Addr.port = CM_INET_NTOH_U16(remAddr6->sin6_port);
6492 CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr,
6493 &remAddr6->sin6_addr);
6497 remAddr = (struct sockaddr_in *)&remSockAddr;
6498 fromAddr->type = CM_INET_IPV4ADDR_TYPE;
6499 fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(remAddr->sin_port);
6500 fromAddr->u.ipv4Addr.address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
6503 remAddr = (struct sockaddr_in *)&remSockAddr;
6504 fromAddr->port = CM_INET_NTOH_U16(remAddr->sin_port);
6505 fromAddr->address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
6506 #endif /* IPV6_SUPPORTED */
6510 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6512 #else /* end of Win NT/flat buffer specific part */
6514 /* Initialise variable */
6515 allocFlatBuf = FALSE;
6518 * maybe needs more than one recvmsg() call to read entire message
6519 * on a stream socket
6523 /* allocate gather vector, it's a dynamic array */
6524 numDBufs = CM_INET_MAX_DBUF;
6526 ret = SGetSBuf(info->region, info->pool, (Data**)&dBufs,
6527 numDBufs*sizeof(Buffer*));
6533 /* Allocate dBufs for gather read */
6534 /* allocate dBufs for gathering read */
6535 if (sockFd->type == CM_INET_STREAM)
6536 ret = buildRecvBuf(info, bufLen, rxArr, dBufs, numDBufs, &msg,
6539 ret = buildRecvBuf(info, bufLen, rxArr, dBufs, numDBufs, &msg,
6543 /* check if the function returned RNA */
6546 /* Incase of UDP/RAW messages allocate a flat buffer. Incase
6547 * of TCP ignore this error condition. The user will call
6548 * cmInetRecvMsg again */
6549 /* cm_inet_c_001.main_62:Warning fix */
6550 if (sockFd->type != (U8)CM_INET_STREAM)/* G++ */
6553 #ifdef T2K_MEM_LEAK_DBG
6554 char * file = __FILE__;
6555 U32 line = __LINE__;
6558 /* cleanup the dBuf array */
6559 for (i = 0; i < msg.msg_iovlen; i++)
6560 SPutDBuf(info->region, info->pool, dBufs[i]);
6562 SPutSBuf(info->region, info->pool, (Data*)dBufs,
6563 numDBufs * sizeof(Buffer*));
6565 /* allocate flat receive buffer */
6566 ret = SGetSBuf(info->region, info->pool, &recvBuf, bufLen);
6570 allocFlatBuf = TRUE;
6572 /* update the message structure */
6574 rxArr[0].iov_base = (Void*)recvBuf;
6575 rxArr[0].iov_len = (U32)bufLen;
6577 rxArr[0].iov_base = (S8*)recvBuf;
6578 rxArr[0].iov_len = bufLen;
6579 #endif /* SS_LINUX */
6580 msg.msg_iov = rxArr;
6586 SPutSBuf(info->region, info->pool, (Data*)dBufs,
6587 numDBufs*sizeof(Buffer*));
6592 numBuf = msg.msg_iovlen;
6594 /* setup destination Internet address structure */
6595 if (fromAddr != NULLP)
6598 msg.msg_name = (Void*)&remSockAddr;
6601 msg.msg_name = (char *)&remSockAddr;
6603 msg.msg_name = (caddr_t)&remSockAddr;
6605 #endif /* SS_LINUX */
6606 msg.msg_namelen = sizeof(remSockAddr);
6610 msg.msg_name = NULLP;
6611 msg.msg_namelen = 0;
6614 /* added defined(_XPG4_2). Also changed the
6616 #if (defined(SS_LINUX) || defined(_XPG4_2))
6617 msg.msg_control = ancillData;
6618 msg.msg_controllen = sizeof(ancillData);
6620 msg.msg_accrights = NULLP;
6621 msg.msg_accrightslen = 0;
6622 #endif /* SS_LINUX */
6624 recvLen = recvmsg(sockFd->fd, &msg, flags);
6625 if ((recvLen == INET_ERR) || (recvLen > CM_INET_MAX_MSG_LEN))
6627 /* Moved up the cleanup precedures here before returning */
6628 /* Cleanup flat buffer if allocated */
6630 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6634 for (i = 0; i < numBuf; i++)
6636 #ifdef T2K_MEM_LEAK_DBG
6637 char * file = __FILE__;
6638 U32 line = __LINE__;
6641 SPutDBuf(info->region, info->pool, dBufs[i]);
6643 SPutSBuf(info->region, info->pool, (Data*)dBufs,
6644 numDBufs*sizeof(Buffer*));
6647 /* cm_inet_c_001.main_50 - Free the buffer only when valid, it might be that
6648 * it has partially received data
6650 /* added check ERR_AGAIN when CMINETFLATBUF is not defined.
6651 added check ERR_WOULDBLOCK */
6652 if ((INET_ERR_CODE == ERR_AGAIN) ||
6653 (INET_ERR_CODE == ERR_WOULDBLOCK))
6655 /* cm_inet_c_001.main_50 : If message is read partially then just return
6656 * OK without freeing the mPtr. This will gaurd us
6657 * against unexpected WOULDBLOCKS observed in solaris
6665 /* cm_inet_c_001.main_50 - Free the buffer only when valid, it might be that
6666 * it has partially received data
6674 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
6675 /* cm_inet_c_001.main_62:Warning fix */
6676 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() Failed : error(%d),"
6677 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
6678 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET035, 0, prntBuf);
6680 /* cm_inet_c_001.main_62:Warning fix */
6681 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() Failed : error(%d),"
6682 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
6683 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET035, 0, prntBuf);
6684 #endif /*ALIGN_64BIT*/
6685 #endif /* CMINETDBG */
6687 /* If this happens then cmInetRecvMsg must return RCLOSED.
6688 * Needed for getting icmp msgs */
6689 if (INET_ERR_CODE == ERR_CONNABORTED)
6699 /* added for IPv6 extn headers */
6700 #if (defined(IPV6_OPTS_SUPPORTED) || defined(LOCAL_INTF))
6702 /* check if ancillary data has been received.
6703 * Return the allocated memory when no ancillary data received */
6704 #if (defined(SS_LINUX) || defined(_XPG4_2))
6705 if (msg.msg_controllen)
6707 cmsgptr = CMSG_FIRSTHDR(&msg);
6713 #endif /* SS_LINUX || _XPG4_2 */
6715 if (cmsgptr != NULLP)
6717 #ifdef IPV6_OPTS_SUPPORTED
6718 if(ipHdrParams != NULLP)
6720 ipHdrParams->u.ipv6HdrParm.ttl.pres = FALSE;
6721 ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhHdrPrsnt = FALSE;
6722 ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsPrsnt = FALSE;
6723 ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsPrsnt = FALSE;
6725 /* get all ancillary data objects recvd one by one */
6726 for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULLP;
6727 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
6729 if (cmsgptr->cmsg_level == IPPROTO_IPV6)
6731 /* Initialise ipHdrParams properly */
6732 ipHdrParams->type = CM_INET_IPV6ADDR_TYPE;
6734 if (cmsgptr->cmsg_type == IPV6_HOPOPTS)
6736 /* build up HBH opt array from recvd ancillary data */
6737 ret = cmInet6BuildRecvHopOptsArr(
6738 (U8 *)CMSG_DATA(cmsgptr), cmsgptr->cmsg_len,
6739 &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhOptsArr,
6743 ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhHdrPrsnt =
6747 else if(cmsgptr->cmsg_type == IPV6_DSTOPTS)
6749 else if ((cmsgptr->cmsg_type == IPV6_DSTOPTS) ||
6750 (cmsgptr->cmsg_type == IPV6_RTHDRDSTOPTS))
6751 #endif /* SS_LINUX */
6753 /* build up Dest opt array from recvd ancillary data */
6754 ret = cmInet6BuildRecvDstOptsArr(
6755 (U8 *)CMSG_DATA(cmsgptr), cmsgptr->cmsg_len,
6756 &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsArr,
6760 ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsPrsnt =
6763 else if (cmsgptr->cmsg_type == IPV6_RTHDR)
6765 /* build up Route Hdr from recvd ancillary data */
6766 ret = cmInet6BuildRecvRtHdr(
6767 (U8 *)CMSG_DATA(cmsgptr), cmsgptr->cmsg_len, &rtHdr0,
6768 &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsArr,
6772 ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsPrsnt =
6775 else if(cmsgptr->cmsg_type == IPV6_HOPLIMIT)
6777 /* get the received hoplimit */
6778 ret = cmInet6GetHopLimitValue((U8 *)CMSG_DATA(cmsgptr),
6779 cmsgptr->cmsg_len, &ipHdrParams->u.ipv6HdrParm);
6786 #endif /* IPV6_OPTS_SUPPORTED */
6788 #ifdef IPV6_SUPPORTED
6790 for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULLP;
6791 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
6793 if(cmsgptr->cmsg_type == IPV6_PKTINFO)
6795 pkt6Info = (struct in6_pktinfo *)CMSG_DATA(cmsgptr);
6796 localIf->intfPrsnt = TRUE;
6797 localIf->localIf = pkt6Info->ipi6_ifindex;
6798 localIf->localIfAddr.type = CM_INET_IPV6ADDR_TYPE;
6799 memcpy(&localIf->localIfAddr.u.ipv6NetAddr,
6800 &pkt6Info->ipi6_addr, 16);
6803 #endif /* LOCAL_INTF */
6806 #if (defined(SS_LINUX) && defined(LOCAL_INTF))
6807 #ifdef IPV6_SUPPORTED
6808 if(sockFd->protType == AF_INET)
6811 for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
6812 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
6814 if (cmsgptr->cmsg_level == IPPROTO_IP &&
6815 cmsgptr->cmsg_type == IP_PKTINFO)
6817 pkt4Info = (struct in_pktinfo *)CMSG_DATA(cmsgptr);
6818 localIf->intfPrsnt = TRUE;
6819 localIf->localIf = pkt4Info->ipi_ifindex;
6820 localIf->localIfAddr.type = CM_INET_IPV4ADDR_TYPE;
6821 localIf->localIfAddr.u.ipv4NetAddr =
6822 ntohl(*(int *)&pkt4Info->ipi_addr);
6825 #ifdef IPV6_SUPPORTED
6828 #endif /* SS_LINUX */
6830 #endif /* IPV6_OPTS_SUPPORTED || LOCAL_INTF */
6832 /* setup return destination Internet address */
6833 if (fromAddr != NULLP)
6835 #ifdef IPV6_SUPPORTED
6836 if (msg.msg_namelen == sizeof(struct sockaddr_in6))
6838 remAddr6 = (struct sockaddr_in6 *)&remSockAddr;
6839 fromAddr->type = CM_INET_IPV6ADDR_TYPE;
6840 fromAddr->u.ipv6Addr.port =
6841 CM_INET_NTOH_U16(remAddr6->sin6_port);
6842 CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr,
6843 &remAddr6->sin6_addr);
6847 remAddr = (struct sockaddr_in *)&remSockAddr;
6848 fromAddr->type = CM_INET_IPV4ADDR_TYPE;
6849 fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(remAddr->sin_port);
6850 fromAddr->u.ipv4Addr.address =
6851 CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
6854 remAddr = (struct sockaddr_in *)&remSockAddr;
6855 fromAddr->port = CM_INET_NTOH_U16(remAddr->sin_port);
6856 fromAddr->address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
6857 #endif /* IPV6_SUPPORTED */
6860 /* Incase a flat buffer was allocated get
6861 * a message to pass up */
6867 ret = SGetMsg(info->region, info->pool, &tempMsg);
6871 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6875 /* cm_inet_c_001.main_48 : A 0 len UDP packet could be received */
6878 ret = SAddPstMsgMult(recvBuf, recvLen, tempMsg);
6881 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6889 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6890 /* cm_inet_c_001.main_48 :flat buffers are allocated
6891 * for non -TCP sockets. On these sockets we can receive
6892 * only one message at a time
6894 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6895 *len = (MsgLen)recvLen;
6900 /* build message out of dBufs */
6901 ret = buildRecvMsg(info, rxArr, numBuf, recvLen, dBufs, &tempMsg);
6904 /* Deallocate previously allocated
6908 SPutSBuf(info->region, info->pool, (Data*)dBufs,
6909 numDBufs*sizeof(Buffer*));
6916 /* it's first recvmsg() call */
6921 /* concatenate messages */
6922 ret = SCatMsg(*mPtr, tempMsg, M1M2);
6928 SPutSBuf(info->region, info->pool, (Data*)dBufs,
6929 numDBufs*sizeof(Buffer*));
6935 SPutSBuf(info->region, info->pool, (Data*)dBufs,
6936 numDBufs*sizeof(Buffer*));
6939 * a message is always read atomically on a datagram socket,
6940 * therefore it's ok to read less than pending data!
6943 if ((sockFd->type == CM_INET_DGRAM) ||
6944 (sockFd->type == CM_INET_RAW))
6946 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6947 *len = (MsgLen)recvLen;
6950 #else /* CM_INET2 */
6951 if (sockFd->type == CM_INET_DGRAM)
6953 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6954 *len = (MsgLen)recvLen;
6957 #endif /* CM_INET2 */
6958 } /* while(bufLen > 0) (only for stream sockets) */
6960 /* cm_inet_c_001.main_48 : For UDP, it is possible to receive
6961 * a 0 byte datagram, in this case just return ROKDNA
6965 if ((sockFd->type == CM_INET_DGRAM || sockFd->type == CM_INET_RAW)
6968 if ((sockFd->type == CM_INET_DGRAM) && (*len == 0))
6980 /* Received len == CM_INET_MAX_UDPRAW_MSGSIZE+1
6985 if ((sockFd->type == CM_INET_DGRAM || sockFd->type == CM_INET_RAW)
6986 && (*len == (CM_INET_MAX_UDPRAW_MSGSIZE+1)))
6988 if ((sockFd->type == CM_INET_DGRAM)
6989 && (*len == (CM_INET_MAX_UDPRAW_MSGSIZE+1)))
7000 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7001 /* cm_inet_c_001.main_62:Warning fix */
7002 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() recevied a message > than"
7003 " allowed(%d),sockFd->fd(%ld)\n",
7004 CM_INET_MAX_UDPRAW_MSGSIZE, sockFd->fd);
7005 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET069, 0, prntBuf);
7007 /* cm_inet_c_001.main_62:Warning fix */
7008 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() recevied a message > than"
7009 " allowed(%d),sockFd->fd(%d)\n",
7010 CM_INET_MAX_UDPRAW_MSGSIZE, sockFd->fd);
7011 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET069, 0, prntBuf);
7018 #endif /* WIN32 | CMINETFLATBUF */
7022 /* not enough data pending yet */
7027 } /* end of cmInetRecvMsg */
7030 /* cm_inet_c_001.main_56: Added new function cmInetPeekNew() */
7034 * Fun: cmInetPeekNew
7036 * Desc: Reads some data from the socket without destroying the socket
7038 * The data is specified by the byte positon (first byte is at
7039 * position 0) and the length.
7041 * Ret: ROK - successful
7042 * ROKDNA - ok, data not available
7043 * RCLOSED - connection closed by peer
7046 * Notes: Following are the differences from the cmInetPeek to cmInetPeekNew.
7047 * This primitive does not call the select function as this is already
7048 * taken care by the called primitive. This primitive will not use any
7049 * ioctl calls, because on some machines due to latency in ioctl call
7050 * length may return as ZERO, even there is some data to be read from
7051 * the socket and this primitive only peek buffer using recvfrom.
7053 * Caller of this function need to allocate the sufficient memory to hold
7054 * the data peeked from the socket i.e. dataPos + dataLen. Socket data
7055 * will be copied in the "data" starting from dataPos offset.
7057 * For example, caller passed the following values to this function.
7058 * dataPos = 2 and dataLen = 10,then size of data buffer received should
7059 * be minimum of (dataPos + dataLen)12 bytes and socket data will be
7060 * copied in the data buffer from offset 2 (dataPos) onwards.
7069 CmInetFd *sockFd, /* socket file descriptor */
7070 CmInetAddr *fromAddr, /* sender Internet address/port */
7071 CmInetMemInfo *info, /* buffer allocation info */
7072 MsgLen dataPos, /* position of data */
7073 MsgLen dataLen, /* length of read data */
7074 Data *data /* read data */
7077 S16 cmInetPeekNew(sockFd, fromAddr, info, dataPos, dataLen, data)
7078 CmInetFd *sockFd; /* socket file descriptor */
7079 CmInetAddr *fromAddr; /* sender Internet address/port */
7080 CmInetMemInfo *info; /* buffer allocation info */
7081 MsgLen dataPos; /* position of data */
7082 MsgLen dataLen; /* length of read data */
7083 Data *data; /* read data */
7086 /* cm_inet_c_001.main_57 - Fix for validation and compilation warning */
7087 S32 recvLen; /* number of received octets */
7088 S32 remAddrLen; /* length of remote address length */
7089 struct sockaddr_in *remAddr; /* remote Internet address */
7090 #ifdef IPV6_SUPPORTED
7091 struct sockaddr_in6 *remAddr6; /* remote Internet IPV6 address */
7092 struct sockaddr_in6 remSockAddr; /* to get packet's source IP address */
7094 CmInetSockAddr remSockAddr; /* to get packet's source IP address */
7095 #endif /* IPV6_SUPPORTED */
7098 #if (ERRCLASS & ERRCLS_INT_PAR)
7099 /* error check on parameters */
7100 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
7101 (info == NULLP) || (data == NULLP) ||
7102 (dataPos < 0) || (dataLen < 0))
7106 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7108 /* check if fromAddr is present or not */
7109 if (fromAddr != NULLP)
7111 remAddrLen = sizeof(remSockAddr);
7118 /* added different recvfrom calls with different 6th arg for
7119 * different OS If remAddrLen is 0, pass NULLP */
7120 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
7122 recvLen = recvfrom(sockFd->fd,(S8*)(data + dataPos), (dataLen),
7123 CM_INET_MSG_PEEK, &remSockAddr, (int*)&remAddrLen);
7125 recvLen = recvfrom(sockFd->fd,(S8*)(data + dataPos), (dataLen),
7126 CM_INET_MSG_PEEK, NULLP, (int*)&remAddrLen);
7128 #if ( defined(SUNOS) || defined(SS_LINUX))
7130 recvLen = recvfrom(sockFd->fd, (S8*)(data + dataPos),(dataLen),
7131 CM_INET_MSG_PEEK, (struct sockaddr *)&remSockAddr,
7132 (socklen_t *)&remAddrLen);
7134 recvLen = recvfrom(sockFd->fd, (S8*)(data + dataPos),(dataLen),
7135 CM_INET_MSG_PEEK, NULLP, (socklen_t *)&remAddrLen);
7138 recvLen = recvfrom(sockFd->fd,(S8*)(data + dataPos), (dataLen),
7139 CM_INET_MSG_PEEK, &remSockAddr, (S32*)&remAddrLen);
7141 recvLen = recvfrom(sockFd->fd,(S8*)(data + dataPos), (dataLen),
7142 CM_INET_MSG_PEEK, NULLP, (S32*)&remAddrLen);
7143 #endif /* defined(SUNOS) || defined(SS_LINUX) */
7144 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */
7146 /* removed the check of returned remAddrLen */
7147 if (recvLen == INET_ERR)
7149 /* added check ERR_WOULDBLOCK */
7150 if ((INET_ERR_CODE == ERR_AGAIN) ||
7151 (INET_ERR_CODE == ERR_WOULDBLOCK))
7156 /* cm_inet_c_001.main_61: added host unreachable check */
7157 if ((INET_ERR_CODE == ERR_CONNABORTED) ||
7158 (INET_ERR_CODE == ERR_CONNRESET) ||
7159 (INET_ERR_CODE == ERR_HOSTUNREACH) ||
7160 (INET_ERR_CODE == ERR_CONNREFUSED))
7167 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7168 /* cm_inet_c_001.main_62:Warning fix */
7169 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetPeekNew() Failed : error(%d), sockFd->fd(%ld)\n",
7170 INET_ERR_CODE, sockFd->fd);
7171 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET070, 0, prntBuf);
7173 /* cm_inet_c_001.main_62:Warning fix */
7174 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetPeekNew() Failed : error(%d), sockFd->fd(%d)\n",
7175 INET_ERR_CODE, sockFd->fd);
7176 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET070, 0, prntBuf);
7178 #endif /* CMINETDBG */
7182 else if (recvLen == 0)
7187 /* cm_inet_c_001.main_57 - Fix for validation */
7188 if (recvLen < (S32)dataLen) /* maybe happen */
7193 /* setup return destination Internet address */
7194 /* added the check of (remAddLen > 0) */
7195 if ((fromAddr != NULLP) && (remAddrLen > 0))
7197 #ifdef IPV6_SUPPORTED
7198 memset(fromAddr, 0, sizeof(fromAddr));
7199 if (remAddrLen == sizeof(struct sockaddr_in6))
7201 remAddr6 = (struct sockaddr_in6 *)&remSockAddr;
7202 fromAddr->type = CM_INET_IPV6ADDR_TYPE;
7203 fromAddr->u.ipv6Addr.port =
7204 CM_INET_NTOH_U16(remAddr6->sin6_port);
7205 CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr,
7206 &remAddr6->sin6_addr);
7210 remAddr = (struct sockaddr_in *)&remSockAddr;
7211 fromAddr->type = CM_INET_IPV4ADDR_TYPE;
7212 fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(remAddr->sin_port);
7213 fromAddr->u.ipv4Addr.address =
7214 CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
7217 remAddr = (struct sockaddr_in *)&remSockAddr;
7218 fromAddr->port = CM_INET_NTOH_U16(remAddr->sin_port);
7219 fromAddr->address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
7220 #endif /* IPV6_SUPPORTED */
7224 } /* end of cmInetPeeknew */
7231 * Desc: Reads some data from the socket without destroying the socket
7233 * The data is specified by the byte positon (first byte is at
7234 * position 0) and the length.
7236 * Ret: ROK - successful
7237 * ROKDNA - ok, data not available
7238 * RCLOSED - connection closed by peer
7250 CmInetFd *sockFd, /* socket file descriptor */
7251 CmInetAddr *fromAddr, /* sender Internet address/port */
7252 CmInetMemInfo *info, /* buffer allocation info */
7253 MsgLen dataPos, /* position of data */
7254 MsgLen dataLen, /* length of read data */
7255 Data *data /* read data */
7258 S16 cmInetPeek(sockFd, fromAddr, info, dataPos, dataLen, data)
7259 CmInetFd *sockFd; /* socket file descriptor */
7260 CmInetAddr *fromAddr; /* sender Internet address/port */
7261 CmInetMemInfo *info; /* buffer allocation info */
7262 MsgLen dataPos; /* position of data */
7263 MsgLen dataLen; /* length of read data */
7264 Data *data; /* read data */
7267 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
7268 Data *recvBuf = NULLP; /* plain receive buffer */
7269 /* cm_inet_c_001.main_47: 102069 Changed from S32 to MsgLen for bufLen*/
7270 MsgLen bufLen; /* buffer length */
7271 MsgLen i; /* index */
7272 MsgLen j; /* index */
7273 S32 ret; /* temporary return value */
7274 U32 timeout; /* timeout for cmInetSelect() */
7275 U32 *timeoutPtr; /* pointer to timeout */
7276 S16 numFdS; /* number of ready descriptors */
7277 /* cm_inet_c_001.main_45 - fixing the UMR issue in 64bit linux */
7278 U32 pendLen = 0; /* pending data length */
7279 S32 recvLen; /* number of received octets */
7280 S32 remAddrLen; /* length of remote address length */
7281 CmInetFdSet readFdS; /* socket file descriptor set */
7282 struct sockaddr_in *remAddr; /* remote Internet address */
7283 #ifdef IPV6_SUPPORTED
7284 struct sockaddr_in6 *remAddr6; /* remote Internet IPV6 address */
7285 struct sockaddr_in6 remSockAddr; /* to get packet's source IP address */
7287 CmInetSockAddr remSockAddr; /* to get packet's source IP address */
7288 #endif /* IPV6_SUPPORTED */
7291 #if (ERRCLASS & ERRCLS_INT_PAR)
7292 /* error check on parameters */
7293 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
7294 (info == NULLP) || (data == NULLP) ||
7295 (dataPos < 0) || (dataLen < 0))
7299 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7301 /* check if there are some datas */
7302 if (sockFd->blocking)
7309 /* poll (non-blocking) */
7311 timeoutPtr = &timeout;
7313 CM_INET_FD_ZERO(&readFdS);
7314 CM_INET_FD_SET(sockFd, &readFdS);
7316 ret = cmInetSelect(&readFdS, NULLP, timeoutPtr, &numFdS);
7317 if (CM_INET_FD_ISSET(sockFd, &readFdS))
7319 /* get number of pending data */
7320 /* removed 3rd arg memInfo. MemInfo is no longer needed as we
7321 call ioctl for all sockets */
7322 ret = cmInetGetNumRead(sockFd, &pendLen);
7325 /* cm_inet_c_001.main_50
7326 * Return RCLOSED if cmInetGetNumRead returns RCLOSED. For other
7327 * errors just return RFAILED.
7335 /* check if connection got closed */
7339 /* cm_inet_c_001.main_50
7340 * Due to latency (mostly in solaris) sometimes ioctl(FIONREAD)
7341 * (inside cmInetGetNumRead) returns pend length as 0 on a TCP
7342 * socket that select says is ready to read. This should not be
7343 * considered as connection closed. So return ROKDNA instead of
7344 * RCLOSED even for TCP sockets
7348 /* added check for TCP/UDP socket. Pending data len in the socket
7349 recv buffer is determined by ioctl call in cmInetGetNumRead.
7350 For TCP it can't be > CM_INET_MAX_MSG_LEN.
7351 For UDP it can't be > CM_INET_MAX_UDPRAW_MSGSIZE. */
7352 if (sockFd->type == CM_INET_STREAM)
7354 /* max message length is limited to control the memory usage */
7355 if (pendLen > CM_INET_MAX_MSG_LEN)
7356 pendLen = CM_INET_MAX_MSG_LEN;
7357 /* In STREAM remote address is not required */
7362 if (pendLen > CM_INET_MAX_UDPRAW_MSGSIZE)
7363 pendLen = CM_INET_MAX_UDPRAW_MSGSIZE;
7365 remAddrLen = sizeof(CmInetSockAddr);
7368 /* check if there are enough pending data to read */
7369 bufLen = dataPos + dataLen;
7371 /* check if fromAddr is present or not */
7372 if (fromAddr != NULLP)
7374 remAddrLen = sizeof(remSockAddr);
7381 /* cm_inet_c_001.main_58: Fix for g++ compilation warning */
7382 if ((MsgLen)pendLen >= bufLen)
7384 /* allocate receive buffer (flat structure) */
7385 ret = SGetSBuf(info->region, info->pool, &recvBuf, bufLen);
7391 /* added different recvfrom calls with
7392 * different 6th arg for different OS */
7394 /* If remAddrLen is 0, pass NULLP */
7395 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
7397 recvLen = recvfrom(sockFd->fd,(S8*)recvBuf, bufLen,
7398 CM_INET_MSG_PEEK, &remSockAddr, (int*)&remAddrLen);
7400 recvLen = recvfrom(sockFd->fd,(S8*)recvBuf, bufLen,
7401 CM_INET_MSG_PEEK, NULLP, (int*)&remAddrLen);
7403 #if ( defined(SUNOS) || defined(SS_LINUX))
7405 recvLen = recvfrom(sockFd->fd, (S8*)recvBuf,bufLen,
7406 CM_INET_MSG_PEEK, (struct sockaddr *)&remSockAddr,
7407 (socklen_t *)&remAddrLen);
7409 recvLen = recvfrom(sockFd->fd, (S8*)recvBuf,bufLen,
7410 CM_INET_MSG_PEEK, NULLP, (socklen_t *)&remAddrLen);
7413 recvLen = recvfrom(sockFd->fd,(S8*)recvBuf, bufLen,
7414 CM_INET_MSG_PEEK, &remSockAddr, (S32*)&remAddrLen);
7416 recvLen = recvfrom(sockFd->fd,(S8*)recvBuf, bufLen,
7417 CM_INET_MSG_PEEK, NULLP, (S32*)&remAddrLen);
7418 #endif /* defined(SUNOS) || defined(SS_LINUX) */
7419 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */
7421 /* removed the check of returned remAddrLen */
7422 if (recvLen == INET_ERR)
7425 /* moved cleanup here */
7426 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
7428 /* added check ERR_WOULDBLOCK */
7429 if ((INET_ERR_CODE == ERR_AGAIN) ||
7430 (INET_ERR_CODE == ERR_WOULDBLOCK))
7436 /* moved up the cleanup */
7440 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7441 /* cm_inet_c_001.main_62:Warning fix */
7442 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetPeek() Failed : error(%d), sockFd->fd(%ld)\n",
7443 INET_ERR_CODE, sockFd->fd);
7444 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET036, 0, prntBuf);
7446 /* cm_inet_c_001.main_62:Warning fix */
7447 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetPeek() Failed : error(%d), sockFd->fd(%d)\n",
7448 INET_ERR_CODE, sockFd->fd);
7449 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET036, 0, prntBuf);
7451 #endif /* CMINETDBG */
7453 if ((INET_ERR_CODE == ERR_CONNABORTED) ||
7454 (INET_ERR_CODE == ERR_CONNRESET))
7462 if (recvLen < (S32)bufLen) /* maybe happen */
7465 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
7470 for (j = 0, i = dataPos; i < bufLen; j++, i++)
7471 data[j] = recvBuf[i];
7473 /* setup return destination Internet address */
7474 /* added the check of (remAddLen > 0) */
7475 if ((fromAddr != NULLP) && (remAddrLen > 0))
7477 #ifdef IPV6_SUPPORTED
7478 memset(fromAddr, 0, sizeof(fromAddr));
7479 if (remAddrLen == sizeof(struct sockaddr_in6))
7481 remAddr6 = (struct sockaddr_in6 *)&remSockAddr;
7482 fromAddr->type = CM_INET_IPV6ADDR_TYPE;
7483 fromAddr->u.ipv6Addr.port =
7484 CM_INET_NTOH_U16(remAddr6->sin6_port);
7485 CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr,
7486 &remAddr6->sin6_addr);
7490 remAddr = (struct sockaddr_in *)&remSockAddr;
7491 fromAddr->type = CM_INET_IPV4ADDR_TYPE;
7492 fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(remAddr->sin_port);
7493 fromAddr->u.ipv4Addr.address =
7494 CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
7497 remAddr = (struct sockaddr_in *)&remSockAddr;
7498 fromAddr->port = CM_INET_NTOH_U16(remAddr->sin_port);
7499 fromAddr->address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
7500 #endif /* IPV6_SUPPORTED */
7504 SPutSBuf(info->region, info->pool, recvBuf, bufLen);
7508 /* not enough data pending yet */
7514 /* no data pending */
7519 } /* end of cmInetPeek */
7526 * Desc: Close a socket gracefully.
7528 * Ret: ROK - successful
7540 CmInetFd *sockFd /* socket file descriptor */
7543 S16 cmInetClose(sockFd)
7544 CmInetFd *sockFd; /* socket file descriptor */
7547 S32 ret; /* temporary return value */
7550 #if (ERRCLASS & ERRCLS_INT_PAR)
7551 /* error check on parameters */
7552 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
7556 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7559 ret = closesocket(sockFd->fd);
7561 ret = close(sockFd->fd);
7563 if (ret == INET_ERR)
7567 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7568 /* cm_inet_c_001.main_62:Warning fix */
7569 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetClose() Failed : error(%d), sockFd->fd(%ld)\n",
7570 INET_ERR_CODE, sockFd->fd);
7571 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET037, 0, prntBuf);
7573 /* cm_inet_c_001.main_62:Warning fix */
7574 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetClose() Failed : error(%d), sockFd->fd(%d)\n",
7575 INET_ERR_CODE, sockFd->fd);
7576 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET037, 0, prntBuf);
7577 #endif /*ALIGN_64BIT*/
7578 #endif /* CMINETDBG */
7583 } /* end of cmInetClose */
7588 * Fun: cmInetShutdown
7590 * Desc: Close an Internet connection with more control over the data of
7591 * the full-duplex connection.
7592 * Values for the howTo parameter:
7594 * CM_INET_SHTDWN_RECV - discard data in receive buffer
7595 * CM_INET_SHTDWN_SEND - discard data in transmit buffer
7596 * CM_INET_SHTDWN_BOTH - discard data in receive and transmit buffer
7598 * Ret: ROK - successful
7601 * Notes: This function does not free the socket descriptor but only closes the
7602 * connection (cmInetClose() has to be called afterwards).
7603 * No error is returned if the socket is not connected while calling
7613 CmInetFd *sockFd, /* socket file descriptor */
7614 S32 howTo /* operation flag */
7617 S16 cmInetShutdown(sockFd, howTo)
7618 CmInetFd *sockFd; /* socket file descriptor */
7619 S32 howTo; /* operation flag */
7622 S32 ret; /* temporary return value */
7625 #if (ERRCLASS & ERRCLS_INT_PAR)
7626 /* error check on parameters */
7627 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
7631 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7633 ret = shutdown(sockFd->fd, howTo);
7634 if (ret == INET_ERR)
7636 if (INET_ERR_CODE == ERR_NOTCONN)
7638 /* socket is not connected */
7646 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7647 /* cm_inet_c_001.main_62:Warning fix */
7648 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetShutdown() Failed : error(%d),"
7649 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
7650 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET038, 0, prntBuf);
7652 /* cm_inet_c_001.main_62:Warning fix */
7653 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetShutdown() Failed : error(%d),"
7654 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
7655 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET038, 0, prntBuf);
7656 #endif /*ALIGN_64BIT*/
7657 #endif /* CMINETDBG */
7663 } /* end of cmInetShutdown */
7670 * Desc: Allows multiplex i/o requests among multiple sockets.
7671 * If the parameter mSecTimeout points to a value of zero the
7672 * call immediatley returns (poll), if it is a null pointer, the
7673 * timeout is set to infinit.
7674 * numFdS returns the number of ready file descriptors contained
7675 * in the file descriptor sets
7677 * Ret: ROK - successful
7678 * RTIMEOUT - timout expired
7690 CmInetFdSet *readFdS, /* read socket descriptor file set */
7691 CmInetFdSet *writeFdS, /* write socket descriptor file set */
7692 U32 *mSecTimeout, /* timeout in msecs */
7693 S16 *numFdS /* number of ready descriptors */
7696 S16 cmInetSelect(readFdS, writeFdS, mSecTimeout, numFdS)
7697 CmInetFdSet *readFdS; /* read socket descriptor file set */
7698 CmInetFdSet *writeFdS; /* write socket descriptor file set */
7699 U32 *mSecTimeout; /* timeout in msecs */
7700 S16 *numFdS; /* number of ready descriptors */
7703 S32 ret; /* temporary return value */
7704 struct timeval timeout; /* timeout structure */
7705 struct timeval *timeoutPtr;
7708 #if (ERRCLASS & ERRCLS_INT_PAR)
7709 /* error check on parameters */
7710 if (numFdS == NULLP)
7714 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7718 if (mSecTimeout != NULLP)
7720 timeout.tv_sec = *mSecTimeout / 1000;
7721 timeout.tv_usec = (*mSecTimeout % 1000) * 1000;
7722 timeoutPtr = &timeout;
7726 /* infinite timeout */
7732 timeout.tv_usec = 1;
7735 /* cm_inet_c_001.main_53 - Removed do-while loop */
7736 ret = select(FD_SETSIZE, readFdS, writeFdS, (fd_set*)0, timeoutPtr);
7738 /* cm_inet_c_001.main_53 - Return ROKDNA in case select was interrupted */
7739 if ((ret == INET_ERR) && (INET_ERR_CODE == ERR_EINTR))
7744 /* timeout occured */
7750 if (ret == INET_ERR)
7752 /* asa: Added a check for ERR_INVAL to return ROK
7753 * readFdS and writeFdS may be passed as NULL to
7754 * cmInetSelect() call
7756 switch(errCode = INET_ERR_CODE)
7763 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7764 /* cm_inet_c_001.main_62:Warning fix */
7765 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSelect() Failed : error(%d)\n",
7767 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET039, 0, prntBuf);
7768 #endif /* CMINETDBG */
7771 } /* end of switch */
7774 /* return number of ready file descriptors */
7775 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
7779 } /* end of cmInetSelect */
7786 * Desc: Sets a socket option.
7787 * The function supports following options:
7789 * CM_INET_OPT_BLOCK:
7790 * value: CM_INET_OPT_DISABLE non-blocking
7791 * value: CM_INET_OPT_ENABLE blocking
7793 * CM_INET_OPT_REUSEADDR:
7794 * value: CM_INET_OPT_ENABLE reuse address
7796 * CM_INET_OPT_BROADCAST:
7797 * value: CM_INET_OPT_DISABLE
7798 * value: CM_INET_OPT_ENABLE
7800 * CM_INET_OPT_KEEPALIVE:
7801 * value: CM_INET_OPT_DISABLE
7802 * value: CM_INET_OPT_ENABLE
7804 * CM_INET_OPT_RX_BUF_SIZE:
7805 * value: receive buffer size in bytes
7807 * CM_INET_OPT_TX_BUF_SIZE:
7808 * value: transmitter buffer size in bytes
7810 * CM_INET_OPT_ADD_MCAST_MBR:
7811 * value: address of CmInetMCastInf structure
7813 * CM_INET_OPT_DRP_MCAST_MBR:
7814 * value: address of CmInetMCastInf structure
7816 * CM_INET_OPT_TCP_NODELAY:
7817 * value: CM_INET_OPT_DISABLE
7818 * value: CM_INET_OPT_ENABLE
7820 * CM_INET_OPT_BSD_COMPAT: For Linux only
7821 * value: CM_INET_OPT_ENABLE
7822 * value: CM_INET_OPT_DISABLE
7824 * CM_INET_OPT_HDR_INCLD:
7825 * value: CM_INET_ENABLE
7826 * value: CM_INET_DISABLE
7828 * CM_INET_OPT_DONT_FRAGMENT:
7829 * value: CM_INET_OPT_ENABLE
7830 * value: CM_INET_DISABLE
7833 * value: Type of Service.
7836 * value: Time To Live.
7838 * CM_INET_OPT_IP_OPTIONS:
7839 * value: IPv4 header option value
7842 * CM_INET_OPT_IP_ROUTER_ALERT:
7843 * value: CM_INET_OPT_DISABLE
7844 * value: CM_INET_OPT_ENABLE
7846 * CM_INET_OPT_IPV4_PKTINFO
7847 * value: CM_INET_OPT_ENABLE
7848 * value: CM_INET_OPT_DISABLE
7850 * CM_INET_OPT_MCAST_LOOP:
7851 * value: CM_INET_OPT_DISABLE
7852 * value: CM_INET_OPT_ENABLE
7854 * CM_INET_OPT_MCAST_IF:
7855 * value: Address of interface.
7857 * CM_INET_OPT_MCAST_TTL:
7858 * value: TTL of the outgoing multicast packet.
7860 * The next options are defined only if IPV6 is
7863 * CM_INET_OPT_ADD_MCAST6_MBR:
7864 * value: address of CmInetMCastInf6 structure
7866 * CM_INET_OPT_DRP_MCAST6_MBR:
7867 * value: address of CmInetMCastInf6 structure
7869 * CM_INET_OPT_MCAST6_LOOP:
7870 * value: CM_INET_OPT_DISABLE
7871 * value: CM_INET_OPT_ENABLE
7873 * CM_INET_OPT_MCAST6_IF:
7874 * value: Interface index
7876 * CM_INET_OPT_MCAST6_HOPS:
7877 * value: multicast hop limit
7879 * CM_INET_OPT_RECVIPV6_HOPLIM:
7880 * value: CM_INET_OPT_ENABLE hop limit will be returned
7882 * value: CM_INET_OPT_DISABLE hop limit wont be returned
7885 * CM_INET_OPT_RECVIPV6_HBHOPTS:
7886 * value: CM_INET_OPT_ENABLE HBH Options will be returned
7888 * value: CM_INET_OPT_DISABLE HBH Options wont be returned
7891 * CM_INET_OPT_RECVIPV6_DSTOPTS:
7892 * value: CM_INET_OPT_ENABLE Dest Options will be returned
7894 * value: CM_INET_OPT_DISABLE Dest Options wont be returned
7897 * CM_INET_OPT_RECVIPV6_RTHDR:
7898 * value: CM_INET_OPT_ENABLE Route Hdr Opt will be turned
7900 * value: CM_INET_OPT_DISABLE Route Hdr Opt will be turned
7901 * OFF on the socket.
7903 * CM_INET_OPT_IP_ROUTER_ALERT6
7904 * value: CM_INET_OPT_ENABLE
7905 * value: CM_INET_OPT_DISABLE
7907 * CM_INET_OPT_IPV6_PKTINFO
7908 * value: CM_INET_OPT_ENABLE Enable sending and receiving
7910 * value: CM_INET_OPT_DISABLE Disable sending and receiving
7913 * CM_INET_OPT_LINGER
7914 * value: address of CmInetSockLinger structure
7916 * CM_INET_OPT_SCTP_EVENTS
7917 * value: address of CmInetSctpSockEvent structure
7919 * CM_INET_OPT_SCTP_PRIM_ADDR
7920 * value: address of CmInetSctpPrimAddr structure
7922 * CM_INET_OPT_SCTP_PEERADDR_PARAMS
7923 * value: address of CmInetSctpPeerAddrParams structure
7926 * Ret: ROK - successful
7928 * RNA - failed, option not available
7929 * (Only when CM_INET2 is defined)
7931 * Notes: The send and receive buffer size may be system
7932 * specific. The cmInetSetOpt() call may return
7933 * successfuly although not the entire buffer size
7942 CmInetFd *sockFd, /* socket file descriptor */
7943 U32 level, /* option level */
7944 U32 type, /* option type */
7945 Ptr value /* option value */
7948 S16 cmInetSetOpt(sockFd, level, type, value)
7949 CmInetFd *sockFd; /* socket file descriptor */
7950 U32 level; /* option level */
7951 U32 type; /* option type */
7952 Ptr value; /* option value */
7955 S32 ret = ROK; /* temporary return value */
7956 U32 disable = 0; /* disable option */
7957 U32 enable = 1; /* enable option */
7959 /* added for IPv4 options */
7960 #ifdef IPV4_OPTS_SUPPORTED
7961 #if((!defined (SS_VW)) && (!defined(SS_LINUX)))
7962 TknStr64 *tempTknStr64; /* points TknStr64 structure */
7963 /* which has value for IPv4 hdr options.*/
7964 #endif /* SS_VW && SS_LINUX */
7968 #endif /* IPV4_OPTS_SUPPORTED */
7970 #if (defined(SUNOS)|| defined(WIN32) || defined(SS_PS) || defined(SS_VW_MCAST)\
7972 U8 lpEnable = 1; /* multicast loop enable */
7973 U8 lpDisable = 0; /* multicast loop disable */
7974 #endif /* SUNOS || WIN32 || SS_PS || SS_VW_MCAST || HPOS */
7977 BOOL boolEnable = TRUE; /* enable option */
7978 BOOL boolDisable = FALSE; /* disable option */
7981 #if (defined(SUNOS) || defined(WIN32) || defined(SS_PS) || \
7982 defined(SS_VW_MCAST) || defined(HPOS))
7983 struct ip_mreq stMreq;
7984 CmInetMCastInf *mCast;
7985 #endif /* SUNOS || WIN32 || SS_PS || SS_VW_MCAST || HPOS */
7987 #ifdef IPV6_SUPPORTED
7988 U32 loopEna = 1; /* IPv6 multicast loop enable */
7989 U32 loopDis = 0; /* IPv6 multicast loop disable */
7990 struct ipv6_mreq *stMreq6Ptr;
7991 /* cm_inet_c_001.main_44 : some operating system doesnt have icmp6_filter. so
7992 this flag is gaurded under ICMPV6_FILTER_SUPPORTED. so if user want this
7993 support he has to enable the above flag.*/
7994 /* cm_inet_c_001.main_58 : Protaected under flag CM_ICMP_FILTER_SUPPORT
7995 * to support filteration of ICMP messages */
7996 #if (defined(ICMPV6_FILTER_SUPPORTED) || defined(CM_ICMP_FILTER_SUPPORT))
7997 struct icmp6_filter *icmp6Filter;
7998 #endif /* ICMPV6_FILTER_SUPPORTED */
7999 #endif /* IPV6_SUPPORTED */
8001 /* cm_inet_c_001.main_58 : Added new local variables to support filteration
8002 * of ICMP messages */
8004 #ifdef CM_ICMP_FILTER_SUPPORT
8005 struct icmp_filter icmpFilter;
8009 /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
8012 struct sctp_event_subscribe event;
8013 struct sctp_paddrparams addrParams;
8014 struct sctp_setprim setPrim;
8015 struct sockaddr_in *pAddr;
8016 struct sctp_assocparams assocParams;
8017 struct sctp_initmsg initmsg;
8018 struct sctp_rtoinfo rtoinfo;
8019 #ifdef IPV6_SUPPORTED
8020 struct sockaddr_in6 *pAddr6;
8021 #endif /* IPV6_SUPPORTED */
8023 CmInetSockLinger *pSockLinger;
8024 CmInetSctpSockEvent *pSctpEvent;
8025 CmInetSctpPrimAddr *pSctpPrimAddr;
8026 CmInetSctpPeerAddrParams *pSctpPAddrParams;
8027 CmInetSctpRtoInfo *pSctpRtoInfo;
8028 CmInetSctpInitMsg *pSctpInitMsg;
8029 CmInetSctpAssocParams *pSctpAssocParams;
8035 /* cm_inet_c_001.main_58 : Added NULL check for value field */
8041 #if (ERRCLASS & ERRCLS_INT_PAR)
8042 /* error check on parameters */
8043 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
8047 #endif /* ERRCLASS & ERRCLS_INT_PAR */
8051 case CM_INET_OPT_BLOCK:
8052 optVal = (U32*)value;
8055 case CM_INET_OPT_ENABLE:
8058 /* cm_inet_c_001.main_59: Fix for compilation warning */
8059 ret = ioctlsocket(sockFd->fd, FIONBIO, (U32 *)&disable);
8062 ret = ioctl(sockFd->fd, FIONBIO, (char*)&disable);
8065 ret = ioctl(sockFd->fd, (S32)FIONBIO, (S32)&disable);
8067 ret = ioctl(sockFd->fd, (S32)FIONBIO, &disable);
8072 sockFd->blocking = 1;
8075 case CM_INET_OPT_DISABLE:
8077 /* cm_inet_c_001.main_59: Fix for compilation warning */
8078 ret = ioctlsocket(sockFd->fd, FIONBIO, (U32 *)&enable);
8081 ret = ioctl(sockFd->fd, FIONBIO, (char*)&enable);
8084 ret = ioctl(sockFd->fd, (S32)FIONBIO, (S32)&enable);
8086 ret = ioctl(sockFd->fd, (S32)FIONBIO, &enable);
8090 sockFd->blocking = 0;
8100 case CM_INET_OPT_REUSEADDR:
8101 optVal = (U32*)value;
8102 if (*optVal == CM_INET_OPT_ENABLE)
8105 ret = setsockopt(sockFd->fd, level, SO_REUSEADDR,
8106 (char*)&boolEnable, sizeof(boolEnable));
8108 ret = setsockopt(sockFd->fd, level, SO_REUSEADDR,
8109 (char*)&enable, sizeof(enable));
8111 setsockopt(sockFd->fd, level, SO_REUSEPORT,
8112 (char*)&enable, sizeof(enable));
8116 else if (*optVal == CM_INET_OPT_DISABLE)
8119 ret = setsockopt(sockFd->fd, level, SO_REUSEADDR,
8120 (char*)&boolDisable, sizeof(boolDisable));
8122 ret = setsockopt(sockFd->fd, level, SO_REUSEADDR,
8123 (char*)&disable, sizeof(disable));
8125 ret = setsockopt(sockFd->fd, level, SO_REUSEPORT,
8126 (char*)&disable, sizeof(disable));
8132 case CM_INET_OPT_BROADCAST:
8133 optVal = (U32*)value;
8134 if (*optVal == CM_INET_OPT_ENABLE)
8137 ret = setsockopt(sockFd->fd, level, SO_BROADCAST,
8138 (char*)&boolEnable, sizeof(boolEnable));
8140 ret = setsockopt(sockFd->fd, level, SO_BROADCAST,
8141 (char*)&enable, sizeof(enable));
8144 else if (*optVal == CM_INET_OPT_DISABLE)
8147 ret = setsockopt(sockFd->fd, level, SO_BROADCAST,
8148 (char*)&boolDisable, sizeof(boolDisable));
8150 ret = setsockopt(sockFd->fd, level, SO_BROADCAST,
8151 (char*)&disable, sizeof(disable));
8156 case CM_INET_OPT_KEEPALIVE:
8157 optVal = (U32*)value;
8158 if (*optVal == CM_INET_OPT_ENABLE)
8161 ret = setsockopt(sockFd->fd, level, SO_KEEPALIVE,
8162 (char*)&boolEnable, sizeof(boolEnable));
8164 ret = setsockopt(sockFd->fd, level, SO_KEEPALIVE,
8165 (char*)&enable, sizeof(enable));
8168 else if (*optVal == CM_INET_OPT_DISABLE)
8171 ret = setsockopt(sockFd->fd, level, SO_KEEPALIVE,
8172 (char*)&boolDisable, sizeof(boolDisable));
8174 ret = setsockopt(sockFd->fd, level, SO_KEEPALIVE,
8175 (char*)&disable, sizeof(disable));
8180 case CM_INET_OPT_RX_BUF_SIZE:
8181 optVal = (U32*)value;
8182 ret = setsockopt(sockFd->fd, level, SO_RCVBUF,
8183 (char*)optVal, sizeof(*optVal));
8186 case CM_INET_OPT_TX_BUF_SIZE:
8187 optVal = (U32*)value;
8188 ret = setsockopt(sockFd->fd, level, SO_SNDBUF,
8189 (char*)optVal, sizeof(*optVal));
8192 case CM_INET_OPT_TCP_NODELAY:
8193 optVal = (U32*)value;
8194 if (*optVal == CM_INET_OPT_ENABLE)
8198 ret = setsockopt(sockFd->fd, level, TCP_NODELAY,
8199 (char*)&boolEnable, sizeof(boolEnable));
8200 #endif /* SS_WINCE */
8202 ret = setsockopt(sockFd->fd, level, TCP_NODELAY,
8203 (char*)&enable, sizeof(enable));
8206 else if (*optVal == CM_INET_OPT_DISABLE)
8210 ret = setsockopt(sockFd->fd, level, TCP_NODELAY,
8211 (char*)&boolDisable, sizeof(boolDisable));
8212 #endif /* SS_WINCE */
8214 ret = setsockopt(sockFd->fd, level, TCP_NODELAY,
8215 (char*)&disable, sizeof(disable));
8220 #if (defined(SUNOS)|| defined(WIN32) || defined(SS_PS) || \
8221 defined(SS_VW_MCAST) || defined(HPOS))
8223 case CM_INET_OPT_ADD_MCAST_MBR:
8224 mCast = (CmInetMCastInf*)value;
8226 /* Copy the addresses to stMreq structure */
8228 stMreq.imr_mcastaddr.s_addr = CM_INET_HTON_U32(mCast->mCastAddr);
8230 stMreq.imr_multiaddr.s_addr = CM_INET_HTON_U32(mCast->mCastAddr);
8232 stMreq.imr_interface.s_addr = CM_INET_HTON_U32(mCast->localAddr);
8234 ret = setsockopt(sockFd->fd, level, IP_ADD_MEMBERSHIP,
8235 (char*)&stMreq, sizeof(stMreq));
8238 case CM_INET_OPT_DRP_MCAST_MBR:
8239 mCast = (CmInetMCastInf*)value;
8241 /* Copy the addresses to stMreq structure */
8243 stMreq.imr_mcastaddr.s_addr = CM_INET_HTON_U32(mCast->mCastAddr);
8245 stMreq.imr_multiaddr.s_addr = CM_INET_HTON_U32(mCast->mCastAddr);
8247 stMreq.imr_interface.s_addr = CM_INET_HTON_U32(mCast->localAddr);
8249 ret = setsockopt(sockFd->fd, level, IP_DROP_MEMBERSHIP,
8250 (char*)&stMreq, sizeof(stMreq));
8253 #endif /* SUNOS || WIN32 || SS_PS || SS_VW_MCAST || HPOS */
8256 /* cm_inet_c_001.main_37 - Enable CMINET_BSDCOMPAT flag if system doesnt
8257 support CM_INET_OPT_BSD_COMPAT */
8258 #ifndef CMINET_BSDCOMPAT
8259 case CM_INET_OPT_BSD_COMPAT:
8260 optVal = (U32*)value;
8261 if (*optVal == CM_INET_OPT_ENABLE)
8263 ret = setsockopt(sockFd->fd, level, SO_BSDCOMPAT,
8264 &enable, sizeof(enable));
8266 else if (*optVal == CM_INET_OPT_DISABLE)
8268 ret = setsockopt(sockFd->fd, level, SO_BSDCOMPAT,
8269 &disable, sizeof(disable));
8272 #endif /* CMINET_BSDCOMPAT */
8273 #endif /* SS_LINUX */
8276 /* Added for support of Raw socket modify according to the
8277 * option available on different platform */
8278 #if (defined(SUNOS)|| defined(WIN32) || defined(SS_PS) || defined(SS_VW) \
8280 case CM_INET_OPT_HDR_INCLD:
8281 optVal = (U32*)value;
8282 if (*optVal == CM_INET_OPT_ENABLE)
8287 ret = setsockopt(sockFd->fd, level, IP_HDRINCL,
8288 (char*)&enable, sizeof(enable));
8291 else if (*optVal == CM_INET_OPT_DISABLE)
8296 ret = setsockopt(sockFd->fd, level, IP_HDRINCL,
8297 (char*)&disable, sizeof(disable));
8302 /* added new options */
8303 #ifdef IPV4_OPTS_SUPPORTED
8305 /* Linux: set Router Alert socket option to Intercept RAW RSVP
8306 packets at the Intermediate node(Router) with Router Alert SET.
8307 This socket option is MUST be set (when this server is opened)
8308 if the RSVP server wants to intercept raw RSVP packets. */
8309 case CM_INET_OPT_IP_ROUTER_ALERT:
8310 optVal = (U32*)value;
8311 if (*optVal == CM_INET_OPT_ENABLE)
8313 ret = setsockopt(sockFd->fd, level, IP_ROUTER_ALERT,
8314 (char*)&enable, sizeof(enable));
8318 else if (*optVal == CM_INET_OPT_DISABLE)
8320 ret = setsockopt(sockFd->fd, level, IP_ROUTER_ALERT,
8321 (char*)&disable, sizeof(disable));
8326 #endif /* SS_LINUX */
8328 /* set Router Alert socket option */
8329 case CM_INET_OPT_IP_OPTIONS:
8330 #if (defined (SS_VW) || defined(SS_LINUX))
8333 tempTknStr64=(TknStr64 *)value;
8334 if (tempTknStr64->pres == TRUE)
8336 if (tempTknStr64->len == 0)
8338 /* disable the IP_OPTIONS for Router Alert. */
8340 ret = setsockopt(sockFd->fd, level, IP_OPTIONS,
8341 (CONSTANT char *)&disableOpt, sizeof(int));
8343 ret = setsockopt(sockFd->fd, level, IP_OPTIONS, NULL, 0);
8347 /* enable the IP_OPTIONS for Router Alert */
8348 ret = setsockopt(sockFd->fd, level, IP_OPTIONS,
8349 (char *)tempTknStr64->val, tempTknStr64->len);
8352 return RFAILED; /* Trying to set IPv4 Hdr option
8353 * without giving option values*/
8354 #endif /* SS_VW || SS_LINUX */
8356 #endif /* IPV4_OPTS_SUPPORTED */
8358 /* added new options */
8359 #if (defined(SS_LINUX) && (!defined(SS_VW) && !defined(WIN32)))
8361 case CM_INET_OPT_IPV4_PKTINFO:
8362 optVal = (U32*)value;
8363 if (*optVal == CM_INET_OPT_ENABLE)
8365 /* set IP_PKTINFO option when IP_ROUTER_ALERT is set in linux */
8366 ret = setsockopt(sockFd->fd, level, IP_PKTINFO,
8367 (char*)&enable, sizeof(enable));
8372 else if (*optVal == CM_INET_OPT_DISABLE)
8374 /* disable IP_PKTINFO when IP_ROUTER_ALERT is set in linux */
8375 ret = setsockopt(sockFd->fd, level, IP_PKTINFO,
8376 (char*)&disable, sizeof(disable));
8382 #endif /* LOCAL_INTF */
8383 #endif /* SS_LINUX */
8385 #endif /* SUNOS || WIN32 || SS_PS || SS_VW || HPOS */
8387 case CM_INET_OPT_DONTFRAGMENT:
8388 optVal = (U32*)value;
8389 if (*optVal == CM_INET_OPT_ENABLE)
8392 ret = setsockopt(sockFd->fd, level, IP_DONTFRAGMENT,
8393 (char*)&boolEnable, sizeof(boolEnable));
8396 else if (*optVal == CM_INET_OPT_DISABLE)
8399 ret = setsockopt(sockFd->fd, level, IP_DONTFRAGMENT,
8400 (char*)&boolDisable, sizeof(boolDisable));
8405 /* also add these 2 options for VxWorks */
8406 #if (defined(SUNOS)|| defined(WIN32) || defined(HPOS) || defined(SS_VW))
8407 case CM_INET_OPT_TOS:
8408 optVal = (U32*)value;
8409 ret = setsockopt(sockFd->fd, level, IP_TOS,
8410 (char*)optVal, sizeof(*optVal));
8413 case CM_INET_OPT_TTL:
8414 optVal = (U32*)value;
8415 ret = setsockopt(sockFd->fd, level, IP_TTL,
8416 (char*)optVal, sizeof(*optVal));
8418 #endif /* SUNOS || WIN32 || HPOS || SS_VW */
8419 #endif /* CM_INET2 */
8421 #if (defined(SUNOS)|| defined(WIN32) || defined(SS_PS) || defined(SS_VW_MCAST) \
8423 case CM_INET_OPT_MCAST_LOOP:
8424 optVal = (U32*)value;
8425 if (*optVal == CM_INET_OPT_ENABLE)
8428 ret = setsockopt(sockFd->fd, level, IP_MULTICAST_LOOP,
8429 (char *)&lpEnable, sizeof(lpEnable));
8431 ret = setsockopt(sockFd->fd, level, IP_MULTICAST_LOOP,
8432 (CONSTANT char *)&lpEnable, sizeof(lpEnable));
8438 ret = setsockopt(sockFd->fd, level, IP_MULTICAST_LOOP,
8439 (char *)&lpDisable, sizeof(lpDisable));
8441 ret = setsockopt(sockFd->fd, level, IP_MULTICAST_LOOP,
8442 (CONSTANT char *)&lpDisable, sizeof(lpDisable));
8447 case CM_INET_OPT_MCAST_IF:
8448 optVal = (U32*)value;
8449 *optVal = CM_INET_HTON_U32((U32)*optVal);
8450 ret = setsockopt(sockFd->fd, level, IP_MULTICAST_IF,
8451 (char *)optVal, sizeof(struct in_addr));
8454 case CM_INET_OPT_MCAST_TTL:
8455 optVal = (U32*)value;
8456 /* remove CONSTANT in setsockopt for VW */
8458 ret = setsockopt(sockFd->fd, level, IP_MULTICAST_TTL,
8459 (char *)optVal, sizeof(U8));
8461 ret = setsockopt(sockFd->fd, level, IP_MULTICAST_TTL,
8462 (CONSTANT char *)optVal, sizeof(U8));
8465 #endif /* SUNOS || WIN32 || SS_PS || SS_VW_MCAST || HPOS */
8467 #ifdef IPV6_SUPPORTED
8468 case CM_INET_OPT_IPV6_TTL:
8469 optVal = (U32*)value;
8470 ret = setsockopt(sockFd->fd, level, IPV6_UNICAST_HOPS,
8471 (char*)optVal, sizeof(*optVal));
8474 case CM_INET_OPT_ADD_MCAST6_MBR:
8475 stMreq6Ptr = (struct ipv6_mreq *)value;
8476 ret = setsockopt(sockFd->fd, level, IPV6_JOIN_GROUP,
8477 (char*)stMreq6Ptr, sizeof(struct ipv6_mreq));
8480 case CM_INET_OPT_DRP_MCAST6_MBR:
8481 stMreq6Ptr = (struct ipv6_mreq *)value;
8482 ret = setsockopt(sockFd->fd, level, IPV6_LEAVE_GROUP,
8483 (char*)stMreq6Ptr, sizeof(struct ipv6_mreq));
8486 case CM_INET_OPT_MCAST6_LOOP:
8487 optVal = (U32*)value;
8488 if (*optVal == CM_INET_OPT_ENABLE)
8490 ret = setsockopt(sockFd->fd, level, IPV6_MULTICAST_LOOP,
8491 &loopEna, sizeof(loopEna));
8495 ret = setsockopt(sockFd->fd, level, IPV6_MULTICAST_LOOP,
8496 &loopDis, sizeof(loopDis));
8500 case CM_INET_OPT_MCAST6_IF:
8501 ret = setsockopt(sockFd->fd, level, IPV6_MULTICAST_IF,
8502 (U32 *)value, sizeof(U32));
8505 case CM_INET_OPT_MCAST6_HOPS:
8506 optVal = (U32*)value;
8507 ret = setsockopt(sockFd->fd, level, IPV6_MULTICAST_HOPS,
8508 (char *)optVal, sizeof(U32));
8511 /* cm_inet_c_001.main_44 : some operating system doesnt have icmp6_filter. so
8512 this flag is gaurded under ICMPV6_SUPPORTED. so if user want this
8513 support he has to enable the above flag.*/
8514 /* cm_inet_c_001.main_58 : Protaected under flag CM_ICMP_FILTER_SUPPORT
8515 * to support filteration of ICMP messages */
8516 #if (defined(ICMPV6_FILTER_SUPPORTED) || defined(CM_ICMP_FILTER_SUPPORT))
8517 case CM_INET_OPT_ICMP6_FILTER:
8518 icmp6Filter = (struct icmp6_filter *)value;
8519 ret = setsockopt(sockFd->fd, level, ICMP6_FILTER,
8520 (char *)icmp6Filter, sizeof(struct icmp6_filter));
8522 #endif /* ICMPV6_FILTER_SUPPORTED */
8524 /* added new options */
8525 #ifdef IPV6_OPTS_SUPPORTED
8526 case CM_INET_OPT_RECVIPV6_HOPLIM:
8527 optVal = (U32*)value;
8529 ret = setsockopt(sockFd->fd, level, IPV6_HOPLIMIT,
8530 (char *)optVal, sizeof(U32));
8532 ret = setsockopt(sockFd->fd, level, IPV6_HOPLIMIT,
8533 (char *)optVal, sizeof(U32));
8534 /* enable the reception of IPv6 HopLimit value as ancillary data */
8535 ret = setsockopt(sockFd->fd, level, IPV6_RECVHOPLIMIT,
8536 (char*)&enable, sizeof(enable));
8537 #endif /* SS_LINUX */
8541 case CM_INET_OPT_RECVIPV6_HBHOPTS:
8542 optVal = (U32*)value;
8544 ret = setsockopt(sockFd->fd, level, IPV6_HOPOPTS,
8545 (char *)optVal, sizeof(U32));
8547 ret = setsockopt(sockFd->fd, level, IPV6_RECVHOPOPTS,
8548 (char *)optVal, sizeof(U32));
8549 #endif /* SS_LINUX */
8552 case CM_INET_OPT_RECVIPV6_DSTOPTS:
8553 optVal = (U32*)value;
8555 ret = setsockopt(sockFd->fd, level, IPV6_DSTOPTS,
8556 (char *)optVal, sizeof(U32));
8558 ret = setsockopt(sockFd->fd, level, IPV6_RECVDSTOPTS,
8559 (char *)optVal, sizeof(U32));
8560 #endif /* SS_LINUX */
8563 case CM_INET_OPT_RECVIPV6_RTHDR:
8564 optVal = (U32*)value;
8566 ret = setsockopt(sockFd->fd, level, IPV6_RTHDR,
8567 (char *)optVal, sizeof(U32));
8569 ret = setsockopt(sockFd->fd, level, IPV6_RECVRTHDR,
8570 (char *)optVal, sizeof(U32));
8571 #endif /* SS_LINUX */
8574 /* works ONLY for IPPROTO_RAW type socket. so if it this socket
8575 * option is tried to set for IPPROTO_RSVP, then it is supposed
8576 * to fail with EINVAL according to net/ipv6/ipv6_sockglue.c
8578 * if HI_SRVC_RAW_RAW is not used during ServOpenReq as the server
8579 * type, then it will fail here due to above reason */
8581 case CM_INET_OPT_IP_ROUTER_ALERT6:
8582 optVal = (U32*)value;
8583 if(*optVal == CM_INET_OPT_ENABLE)
8584 ret = setsockopt(sockFd->fd, IPPROTO_IPV6, IPV6_ROUTER_ALERT,
8585 (char *)&enable, sizeof(enable));
8587 ret = setsockopt(sockFd->fd, level, IPV6_ROUTER_ALERT,
8588 (char *)&disable, sizeof(disable));
8591 #endif /* SS_LINUX */
8592 #endif /* IPV6_OPTS_SUPPORTED */
8595 case CM_INET_OPT_IPV6_PKTINFO:
8596 optVal = (U32*)value;
8598 ret = setsockopt(sockFd->fd, level, IPV6_PKTINFO,
8599 (char *)optVal, sizeof(U32));
8601 ret = setsockopt(sockFd->fd, level, IPV6_RECVPKTINFO,
8602 (char *)&enable, sizeof(enable));
8603 #endif /* SS_LINUX */
8605 #endif /* LOCAL_INTF */
8607 #endif /* IPV6_SUPPORTED */
8609 /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
8611 case CM_INET_OPT_LINGER:
8612 pSockLinger = (CmInetSockLinger *)value;
8614 memset(&lngr, 0, sizeof(struct linger));
8616 if (pSockLinger->enable == TRUE)
8621 lngr.l_linger = pSockLinger->lingerTime;
8622 ret = setsockopt(sockFd->fd, level, SO_LINGER, &lngr, sizeof(lngr));
8625 case CM_INET_OPT_SCTP_EVENTS:
8626 pSctpEvent = (CmInetSctpSockEvent *)value;
8628 memset(&event, 0, sizeof(struct sctp_event_subscribe));
8630 if (pSctpEvent->dataIoEvent == TRUE)
8631 event.sctp_data_io_event = 1;
8633 if (pSctpEvent->associationEvent == TRUE)
8634 event.sctp_association_event = 1;
8636 if (pSctpEvent->addressEvent == TRUE)
8637 event.sctp_address_event = 1;
8639 if (pSctpEvent->sendFailureEvent == TRUE)
8640 event.sctp_send_failure_event = 1;
8642 if (pSctpEvent->peerErrorEvent == TRUE)
8643 event.sctp_peer_error_event = 1;
8645 if (pSctpEvent->shutdownEvent == TRUE)
8646 event.sctp_shutdown_event = 1;
8648 if (pSctpEvent->partialDeliveryEvent == TRUE)
8649 event.sctp_partial_delivery_event = 1;
8651 if (pSctpEvent->adaptationLayerEvent == TRUE)
8653 event.sctp_adaption_layer_event = 1;
8655 event.sctp_adaptation_layer_event = 1;
8658 ret = setsockopt(sockFd->fd, level, SCTP_EVENTS, &event, sizeof(event));
8661 case CM_INET_OPT_SCTP_PRIM_ADDR:
8662 pSctpPrimAddr = (CmInetSctpPrimAddr *)value;
8664 memset(&setPrim, 0, sizeof(struct sctp_setprim));
8666 #ifdef IPV6_SUPPORTED
8667 if (pSctpPrimAddr->addr.type == CM_INET_IPV6ADDR_TYPE)
8669 if (sockFd->protType == AF_INET)
8673 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
8674 /* cm_inet_c_001.main_62:Warning fix */
8675 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid address: sockFd->protType(%d),"
8676 " sockFd->fd(%ld)\n", sockFd->protType, sockFd->fd);
8677 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET040, 0, prntBuf);
8679 /* cm_inet_c_001.main_62:Warning fix */
8680 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid address: sockFd->protType(%d),"
8681 " sockFd->fd(%d)\n", sockFd->protType, sockFd->fd);
8682 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET040, 0, prntBuf);
8683 #endif /*ALIGN_64BIT*/
8684 #endif /* CMINETDBG */
8688 pAddr6 = (struct sockaddr_in6*)&(setPrim.ssp_addr);
8689 pAddr6->sin6_family = AF_INET6;
8690 pAddr6->sin6_port = CM_INET_HTON_U16(pSctpPrimAddr->port);
8691 CM_INET_COPY_IPV6ADDR(&pAddr6->sin6_addr.s6_addr, &pSctpPrimAddr->addr.u.ipv6NetAddr);
8695 pAddr = (struct sockaddr_in*)&(setPrim.ssp_addr);
8696 pAddr->sin_family = AF_INET;
8697 pAddr->sin_port = CM_INET_HTON_U16(pSctpPrimAddr->port);
8698 pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pSctpPrimAddr->addr.u.ipv4NetAddr);
8701 pAddr = (struct sockaddr_in*)&(setPrim.ssp_addr);
8702 pAddr->sin_family = AF_INET;
8703 pAddr->sin_port = CM_INET_HTON_U16(pSctpPrimAddr->port);
8704 pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pSctpPrimAddr->addr.u.ipv4NetAddr);
8705 #endif /* IPV6_SUPPORTED */
8707 setPrim.ssp_assoc_id = pSctpPrimAddr->assocId;
8709 ret = setsockopt(sockFd->fd, level, SCTP_PRIMARY_ADDR, &setPrim, sizeof(setPrim));
8712 case CM_INET_OPT_SCTP_PEERADDR_PARAMS:
8713 pSctpPAddrParams = (CmInetSctpPeerAddrParams *)value;
8715 memset(&addrParams, 0, sizeof(struct sctp_paddrparams));
8718 if (pSctpPAddrParams->s.addrPres == TRUE)
8720 #ifdef IPV6_SUPPORTED
8721 if (pSctpPAddrParams->s.addr.type == CM_INET_IPV6ADDR_TYPE)
8723 if (sockFd->protType == AF_INET)
8727 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
8728 /* cm_inet_c_001.main_62:Warning fix */
8729 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid address: sockFd->protType(%d),"
8730 " sockFd->fd(%ld)\n", sockFd->protType, sockFd->fd);
8731 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET041, 0, prntBuf);
8733 /* cm_inet_c_001.main_62:Warning fix */
8734 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid address: sockFd->protType(%d),"
8735 " sockFd->fd(%d)\n", sockFd->protType, sockFd->fd);
8736 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET041, 0, prntBuf);
8737 #endif /*ALIGN_64BIT*/
8738 #endif /* CMINETDBG */
8743 pAddr6 = (struct sockaddr_in6*)&(addrParams.spp_address);
8744 pAddr6->sin6_family = AF_INET6;
8745 pAddr6->sin6_port = CM_INET_HTON_U16(pSctpPAddrParams->s.port);
8746 CM_INET_COPY_IPV6ADDR(&pAddr6->sin6_addr.s6_addr, &pSctpPAddrParams->s.addr.u.ipv6NetAddr);
8750 pAddr = (struct sockaddr_in*)&(addrParams.spp_address);
8751 pAddr->sin_family = AF_INET;
8752 pAddr->sin_port = CM_INET_HTON_U16(pSctpPAddrParams->s.port);
8753 pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pSctpPAddrParams->s.addr.u.ipv4NetAddr);
8756 pAddr = (struct sockaddr_in*)&(addrParams.spp_address);
8757 pAddr->sin_family = AF_INET;
8758 pAddr->sin_port = CM_INET_HTON_U16(pSctpPAddrParams->s.port);
8759 pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pSctpPAddrParams->s.addr.u.ipv4NetAddr);
8760 #endif /* IPV6_SUPPORTED */
8764 #ifdef IPV6_SUPPORTED
8765 if (sockFd->protType == AF_INET6)
8766 addrParams.spp_address.ss_family = AF_INET6;
8768 addrParams.spp_address.ss_family = AF_INET;
8770 addrParams.spp_address.ss_family = AF_INET;
8774 /* Not validating the address, whether addr is a valid address or not */
8776 addrParams.spp_assoc_id = pSctpPAddrParams->assocId;
8777 /*cm_inet_c_001.main_58 : fix for klockwork issue */
8778 addrParams.spp_pathmaxrxt = (U16)pSctpPAddrParams->pathMaxRxt;
8780 if (pSctpPAddrParams->hbEnblFlag == CM_INET_OPT_ENABLE)
8781 addrParams.spp_hbinterval = pSctpPAddrParams->hbInterval;
8783 addrParams.spp_hbinterval = 0;
8786 addrParams.spp_flags = 0;
8788 if (pSctpPAddrParams->pmtudFlag == CM_INET_OPT_ENABLE)
8790 addrParams.spp_flags |= SPP_PMTUD_ENABLE;
8791 addrParams.spp_pathmtu = pSctpPAddrParams->pathMtu;
8793 else if(pSctpPAddrParams->pmtudFlag == CM_INET_OPT_DISABLE)
8794 addrParams.spp_flags |= SPP_PMTUD_DISABLE;
8796 if (pSctpPAddrParams->sackDelayFlag == CM_INET_OPT_ENABLE)
8798 addrParams.spp_flags |= SPP_SACKDELAY_ENABLE;
8799 addrParams.spp_sackdelay = pSctpPAddrParams->sackDelay;
8801 else if(pSctpPAddrParams->sackDelayFlag == CM_INET_OPT_DISABLE)
8802 addrParams.spp_flags |= SPP_SACKDELAY_DISABLE;
8804 if (pSctpPAddrParams->hbEnblFlag == CM_INET_OPT_ENABLE)
8806 addrParams.spp_flags |= SPP_HB_ENABLE;
8807 addrParams.spp_hbinterval = pSctpPAddrParams->hbInterval;
8809 else if(pSctpPAddrParams->hbEnblFlag == CM_INET_OPT_DISABLE)
8810 addrParams.spp_flags |= SPP_HB_DISABLE;
8812 ret = setsockopt(sockFd->fd, level, SCTP_PEER_ADDR_PARAMS, &addrParams, sizeof(addrParams));
8815 case CM_INET_OPT_SCTP_ASSOC_PARAMS:
8816 pSctpAssocParams = (CmInetSctpAssocParams *)value;
8818 memset(&assocParams, 0, sizeof(struct sctp_assocparams));
8820 assocParams.sasoc_cookie_life = pSctpAssocParams->cookieLife;
8821 assocParams.sasoc_asocmaxrxt = pSctpAssocParams->assocMaxReTx;
8822 assocParams.sasoc_assoc_id = pSctpAssocParams->assocId;
8823 assocParams.sasoc_number_peer_destinations = pSctpAssocParams->numberOfPeerDest;
8824 assocParams.sasoc_peer_rwnd = pSctpAssocParams->peerRwnd;
8825 assocParams.sasoc_local_rwnd = pSctpAssocParams->localRwnd;
8827 ret = setsockopt(sockFd->fd, level, SCTP_ASSOCINFO, &assocParams, sizeof(assocParams));
8830 case CM_INET_OPT_SCTP_RTO_INFO:
8831 pSctpRtoInfo = (CmInetSctpRtoInfo *)value;
8833 memset(&rtoinfo, 0, sizeof(struct sctp_rtoinfo));
8835 rtoinfo.srto_assoc_id = pSctpRtoInfo->assocId;
8836 rtoinfo.srto_initial = pSctpRtoInfo->rtoInitial;
8837 rtoinfo.srto_max = pSctpRtoInfo->rtoMax;
8838 rtoinfo.srto_min = pSctpRtoInfo->rtoMin;
8840 ret = setsockopt(sockFd->fd, level, SCTP_RTOINFO, &rtoinfo, sizeof(rtoinfo));
8843 case CM_INET_OPT_SCTP_INIT_MSG:
8844 pSctpInitMsg = (CmInetSctpInitMsg *)value;
8846 memset(&initmsg, 0, sizeof(struct sctp_initmsg));
8848 initmsg.sinit_max_attempts = pSctpInitMsg->maxInitReTx;
8849 initmsg.sinit_max_init_timeo = pSctpInitMsg->maxInitTimeout;
8850 initmsg.sinit_num_ostreams = pSctpInitMsg->numOstreams;
8851 initmsg.sinit_max_instreams = pSctpInitMsg->maxInstreams;
8853 ret = setsockopt(sockFd->fd, level, SCTP_INITMSG, &initmsg, sizeof(initmsg));
8856 #endif /*CM_LKSCTP*/
8858 /* cm_inet_c_001.main_58 : Added to support filteration of ICMP
8859 * messages and protected under CM_ICMP_FILTER_SUPPORT flag. Its a
8860 * partial implementaion for icmp filter done for TUCL */
8862 #ifdef CM_ICMP_FILTER_SUPPORT
8863 case CM_INET_OPT_ICMP_FILTER:
8864 optVal = (U32*)value;
8865 ret = setsockopt(sockFd->fd, level, ICMP_FILTER,
8866 optVal, sizeof(icmpFilter));
8872 /* wrong socket option type */
8877 if (ret == INET_ERR)
8881 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
8882 /* cm_inet_c_001.main_62:Warning fix */
8883 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSetOpt() Failed : error(%d), sockFd->fd(%ld)\n",
8884 INET_ERR_CODE, sockFd->fd);
8885 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET042, 0, prntBuf);
8887 /* cm_inet_c_001.main_62:Warning fix */
8888 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSetOpt() Failed : error(%d), sockFd->fd(%d)\n",
8889 INET_ERR_CODE, sockFd->fd);
8890 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET042, 0, prntBuf);
8891 #endif /*ALIGN_64BIT*/
8892 #endif /* CMINETDBG */
8896 } /* end of cmInetSetOpt */
8902 * Fun: cmInetGetNumRead
8904 * Desc: Gives the number of pending octets in the socket receive buffer.
8906 * Ret: ROK - successful
8916 S16 cmInetGetNumRead
8918 CmInetFd *sockFd, /* socket file descriptor */
8919 U32 *dataLen /* number of pending octets */
8920 /* removed 3rd argument memInfo */
8923 S16 cmInetGetNumRead(sockFd, dataLen)
8924 CmInetFd *sockFd; /* socket file descriptor */
8925 U32 *dataLen; /* number of pending octets */
8926 /* removed 3rd argument memInfo */
8929 S32 ret; /* temporary return value */
8931 /* removed local variables added for recvfrom call */
8934 #if (ERRCLASS & ERRCLS_INT_PAR)
8935 /* error check on parameters */
8936 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
8943 /* use ioctl call for all types of socket to get length of
8944 pending data in the socket recv buffer */
8946 /* cm_inet_c_001.main_59: Fix for compilation warning */
8947 ret = ioctlsocket(sockFd->fd, FIONREAD, (U32 *)dataLen);
8950 ret = ioctl(sockFd->fd, FIOREAD, (char*)dataLen);
8953 ret = ioctl(sockFd->fd, FIONREAD, (S32)dataLen);
8955 ret = ioctl(sockFd->fd, FIONREAD, dataLen);
8960 /* For UDP socket assign the length of pending data in the
8961 socket recv buffer to largest datagram size.
8962 Removed recvfrom call & necessary processing for it. */
8964 if (ret == INET_ERR)
8966 /* removed error check CONABORTED added for recvfrom call.
8967 Also return value changed from RCLOSED to ROK */
8968 /* Check for reset connection */
8969 /* cm_inet_c_001.main_45: Close the TCP connection only when err is one of these*/
8970 if ((INET_ERR_CODE == ERR_CONNREFUSED) ||
8971 (INET_ERR_CODE == ERR_CONNABORTED) ||
8972 (INET_ERR_CODE == ERR_TIMEDOUT))
8976 /* cm_inet_c_001.main_50
8977 * Return RCLOSED instead of ROK to initiate connection closure.
8978 * ROK will be returned only if the ioctl call above returns ROK.
8979 * The routines calling this function have been modified to not
8980 * return RCLOSED when this function returns ROK with pending data
8981 * length value of 0. This modification is needed because:
8982 * Due to latency (mostly in solaris) sometimes ioctl(FIONREAD)
8983 * returns successfully with pend length as 0 on a TCP socket that
8984 * select says is ready to read. This should not be considered as
8985 * connection closed.
8990 /* removed error check ERR_WOULDBLOCK */
8991 /* cm_inet_c_001.main_45: Dont close the connection in case of ERR_CONNRESET */
8992 if ((INET_ERR_CODE == ERR_AGAIN) ||
8993 (INET_ERR_CODE == ERR_CONNRESET))
9000 /* cm_inet_c_001.main_45: Change 2048 to CM_INET_MAX_UDPRAW_MSGSIZE */
9001 *dataLen = CM_INET_MAX_UDPRAW_MSGSIZE;
9003 #endif /* SS_LINUX */
9005 /* removed error debug printing added for recvfrom call. */
9009 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9010 /* cm_inet_c_001.main_62:Warning fix */
9011 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetNumRead() Failed : error(%d),"
9012 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
9013 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET043, 0, prntBuf);
9015 /* cm_inet_c_001.main_62:Warning fix */
9016 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetNumRead() Failed : error(%d),"
9017 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
9018 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET043, 0, prntBuf);
9019 #endif /*ALIGN_64BIT*/
9020 #endif /* CMINETDBG */
9025 } /* end of cmInetGetNumRead */
9031 * Fun: cmInetGetHostByName
9033 * Desc: Resolves a host name into the appropriate 4 byte Internet
9036 * Ret: ROK - successful
9046 S16 cmInetGetHostByName
9048 S8 *hostName, /* host name */
9049 CmInetIpAddrTbl *addrTbl /* Address Table of IPV4 Addresses */
9052 S16 cmInetGetHostByName (hostName, addrTbl)
9053 S8 *hostName; /* host name */
9054 CmInetIpAddrTbl *addrTbl; /* Address Table of IPV4 Addresses */
9058 U8 numAddrs; /* Number of Addresses */
9061 #if (defined(WIN32) || defined(SS_LINUX) || defined(HPOS))
9062 struct hostent *hostid; /* pointer to host information */
9065 struct hostent hostid; /* host information */
9066 S8 infoBuf[CM_INET_MAX_INFO]; /* info buffer */
9067 S32 err; /* error code */
9069 #endif /* WIN32 || SS_LINUX || HPOS */
9072 #if (ERRCLASS & ERRCLS_INT_PAR)
9073 /* error check on parameters */
9074 if ((hostName == NULLP) || (addrTbl == NULLP))
9078 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9087 #if (defined(WIN32) || defined(SS_LINUX) || defined(HPOS))
9088 hostid = gethostbyname(hostName);
9092 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9093 /* cm_inet_c_001.main_62:Warning fix */
9094 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d),"
9095 " hostName(%p)\n", INET_ERR_CODE, hostName);
9096 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET044, 0, prntBuf);
9097 #endif /* CMINETDBG */
9100 if (hostid->h_addrtype != AF_INET)
9103 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9104 /* cm_inet_c_001.main_62:Warning fix */
9105 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetHostByName() Failed : error(%d),"
9106 " hostName(%p), hostid->h_addrtype(%d)\n",
9107 INET_ERR_CODE, hostName, hostid->h_addrtype);
9108 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET045, 0, prntBuf);
9109 #endif /* CMINETDBG */
9114 while ((numAddrs < CM_INET_IPV4_NUM_ADDR) &&
9115 (hostid->h_addr_list[numAddrs] != NULLP))
9117 addrTbl->netAddr[addrTbl->count++] =
9118 CM_INET_NTOH_U32 (*((U32 *) hostid->h_addr_list[numAddrs]));
9128 vwIpAddr = hostGetByName(hostName);
9129 if (vwIpAddr == INET_ERR)
9132 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9133 /* cm_inet_c_001.main_62:Warning fix */
9134 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d),"
9135 " hostName(%p)\n", INET_ERR_CODE, hostName);
9136 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET046, 0, prntBuf);
9137 #endif /* CMINETDBG */
9140 CM_COPY_VWIPADDR(vwIpAddr, &(addrTbl->netAddr[addrTbl->count]));
9145 err = 0; /* err is not reset by gethostnyname_r()! */
9147 gethostbyname_r(hostName, &hostid, infoBuf, CM_INET_MAX_INFO, (int*)&err);
9148 if ((hostid.h_addrtype != AF_INET) || (err < 0))
9151 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9152 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d), hostName(%p),"
9153 " hostid.h_addrtype(%d)\n",
9154 INET_ERR_CODE, hostName, hostid.h_addrtype);
9155 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET047, 0, prntBuf);
9156 #endif /* CMINETDBG */
9161 while ((numAddrs < CM_INET_IPV4_NUM_ADDR) &&
9162 (hostid.h_addr_list[numAddrs] != NULLP))
9164 addrTbl->netAddr[addrTbl->count++] =
9165 CM_INET_NTOH_U32 (*((U32 *) hostid.h_addr_list[numAddrs]));
9171 #endif /* WIN32 || SS_LINUX || HPOS */
9175 } /* end of cmInetGetHostByName */
9178 /* The getipnodebyname is not supported on all the Solaris Operating system
9179 * versions. This has to be supported on operating systems that support IPV6
9180 * as per the RFC on the IPV6 socket interface. Hence this function is moved
9181 * under the IPV6_SUPPORTED flag */
9183 /* This function now can be called for both IPv4 and IPv6. However, we will
9184 * call cmInetGetHostByName inside for IPv4. Move all flag dependencies
9185 * inside this function. */
9188 * Fun: cmInetGetIpNodeByName
9190 * Desc: Resolves a host name into the appropriate 4 byte Internet
9191 * address or into the appropriate 16 byte IPV6 address.
9192 * This function is expected to be thread safe and should be used
9193 * instead of the cmInetGetHostByName function.
9195 * Ret: ROK - successful
9204 S16 cmInetGetIpNodeByName
9206 S8 *hostName, /* host name */
9207 CmInetIpAddrArr *addrArr /* Array of addressed filled in */
9210 S16 cmInetGetIpNodeByName(hostName, addrArr)
9211 S8 *hostName; /* host name */
9212 CmInetIpAddrArr *addrArr; /* Array of addressed filled in */
9215 /* for return value from cmInetGetHostByName */
9216 #ifndef IPV6_SUPPORTED
9221 U8 numAddrs=0; /* Number of addresses */
9222 int err=0; /* error code */
9223 struct hostent *hostid; /* host information */
9224 #endif /* SS_LINUX */
9226 #endif /* IPV6_SUPPORTED */
9230 #if (ERRCLASS & ERRCLS_INT_PAR)
9231 /* error check on parameters */
9232 if ((hostName == NULLP) || (addrArr == NULLP))
9236 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9238 #ifdef IPV6_SUPPORTED
9242 #ifdef IPV6_SUPPORTED
9243 if (addrArr->type == CM_INET_IPV6ADDR_TYPE)
9244 hostid = getipnodebyname(hostName, AF_INET6, 0, &err);
9246 #endif /* IPV6_SUPPORTED */
9247 hostid = getipnodebyname(hostName, AF_INET, 0, &err);
9251 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9252 /* cm_inet_c_001.main_62:Warning fix */
9253 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetIpNodeByName() Failed : error(%d),"
9254 " hostName(%p), addrArr->type(%d)n",
9255 err, hostName, addrArr->type);
9256 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET048, 0, prntBuf);
9257 #endif /* CMINETDBG */
9261 #ifdef IPV6_SUPPORTED
9262 if (addrArr->type == CM_INET_IPV6ADDR_TYPE)
9264 if (hostid->h_addrtype == AF_INET6)
9266 while ((numAddrs < CM_INET_IPV6_NUM_ADDR) &&
9267 (hostid->h_addr_list[numAddrs] != NULLP))
9269 /* Use the cminet fill macro here */
9270 CM_INET_COPY_IPV6ADDR(&addrArr->u.ipv6AddrArr.netAddr[numAddrs],
9271 hostid->h_addr_list[numAddrs]);
9272 addrArr->u.ipv6AddrArr.count++;
9279 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9280 /* cm_inet_c_001.main_62:Warning fix */
9281 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetIpNodeByName() Failed : error(%d),"
9282 " hostName(%p), addrArr->type(%d),hostid->h_addrtype(%d) \n",
9283 err, hostName, addrArr->type, hostid->h_addrtype);
9284 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET049, 0, prntBuf);
9285 #endif /* CMINETDBG */
9290 #endif /* IPV6_SUPPORTED */
9292 if (hostid->h_addrtype == AF_INET)
9294 while ((numAddrs < CM_INET_IPV4_NUM_ADDR) &&
9295 (hostid->h_addr_list[numAddrs] != NULLP))
9297 addrArr->u.ipv4AddrArr.count ++;
9298 addrArr->u.ipv4AddrArr.netAddr[numAddrs] =
9299 CM_INET_NTOH_U32 (*((U32 *) hostid->h_addr_list[numAddrs]));
9306 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9307 /* cm_inet_c_001.main_62:Warning fix */
9308 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetIpNodeByName() Failed : error(%d),"
9309 " hostName(%p), hostid->h_addrtype(%d), addrArr->type(%d)\n",
9310 err, hostName, hostid->h_addrtype, addrArr->type);
9311 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET050, 0, prntBuf);
9312 #endif /* CMINETDBG */
9316 #endif /* SS_LINUX */
9321 ret = cmInetGetHostByName(hostName, &addrArr->u.ipv4AddrArr);
9323 #endif /* IPV6_SUPPORTED */
9325 } /* end of cmInetGetIpNodeByName */
9332 * Desc: Converts an ASCII string containig an internet address
9333 * ("xxx.xxx.xxx.xxx") into a CmInetIpAddr (U32) format.
9334 * This function is a wrapper for the inet_addr() call.
9336 * Ret: ROK - successful
9347 S8 *asciiAddr, /* ascii address representation */
9348 CmInetIpAddr *address /* 4 byte interent address */
9351 S16 cmInetAddr(asciiAddr, address)
9352 S8 *asciiAddr; /* ascii address representation */
9353 CmInetIpAddr *address; /* 4 byte interent address */
9357 #if (ERRCLASS & ERRCLS_INT_PAR)
9358 /* error check on parameters */
9359 if (asciiAddr == NULLP)
9363 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9365 *address = inet_addr(asciiAddr);
9366 if (*address == (U32)ERR_INADDRNONE)
9368 /* asciiAddr does not contain a valid internet address */
9380 * Desc: Converts an CmInetIPAddr based IP address into a string
9381 * of the format "xxx.xxx.xxx.xxx".
9382 * This function is a wrapper for the inet_ntoa() call.
9384 * Ret: ROK - successful
9387 * Notes: This function delivers a pointer to a static buffer
9388 * within the system. Therefore the string has to be copied
9389 * by the caller before another call is made!
9397 CmInetIpAddr address, /* 4 byte interent address */
9398 S8 **asciiAddr /* ascii address representation */
9401 S16 cmInetNtoa(address, asciiAddr)
9402 CmInetIpAddr address; /* 4 byte interent address */
9403 S8 **asciiAddr; /* ascii address representation */
9406 struct in_addr inetAddr; /* internet address structure */
9409 #if (ERRCLASS & ERRCLS_INT_PAR)
9410 /* error check on parameters */
9411 if (asciiAddr == NULLP)
9415 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9417 inetAddr.s_addr = address;
9419 *asciiAddr = inet_ntoa(inetAddr);
9420 if (*asciiAddr == NULL)
9431 * Desc: Converts an network address into a string.
9432 * This function is a wrapper for the inet_ntop() call.
9434 * Ret: ROK - successful
9437 * Notes: This function copies the resulting string to the buffer pointed to
9438 * by asciiaddr,which must be a non NULL pointer.The caller specifies
9439 * the number of bytes available in this buffer in the argument len.
9447 U8 type, /* ip address type */
9448 Void *address, /* 4/16 byte interent address */
9449 S8 *asciiAddr, /* ascii adress representation */
9453 S16 cmInetNtop(type,address, asciiAddr,len)
9454 U8 type; /* ip address type */
9455 Void *address; /* 4/16 byte interent address */
9456 S8 *asciiAddr; /* ascii adress representation */
9463 #if (ERRCLASS & ERRCLS_INT_PAR)
9464 /* error check on parameters */
9465 if (asciiAddr == NULLP || address == NULLP || len == 0 )
9470 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9473 case CM_INET_IPV4ADDR_TYPE :
9476 case CM_INET_IPV6ADDR_TYPE :
9480 if(inet_ntop(domain,address,asciiAddr,len) == NULL)
9489 /* The inet_pton is not supported on all the Solaris Operating system
9490 * versions. This has to be supported on operating systems that support
9491 * IPV6 as per the RFC on the IPV6 socket interface. Hence this function
9492 *is moved under the IPV6_SUPPORTED flag */
9493 #ifdef IPV6_SUPPORTED
9500 * Desc: Converts a IP address string to address.
9502 * Ret: ROK - successful
9513 CmInetIpAddr *address, /* 4 byte interent address */
9514 S8 *asciiAddr /* ascii address representation */
9517 S16 cmInetPton(address, asciiAddr)
9518 CmInetIpAddr *address; /* 4 byte interent address */
9519 S8 *asciiAddr; /* ascii address representation */
9525 #if (ERRCLASS & ERRCLS_INT_PAR)
9526 /* error check on parameters */
9527 if ((asciiAddr == NULLP) || (address == NULLP))
9531 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9533 ret = inet_pton(AF_INET, asciiAddr, (void *)address);
9540 } /* end of cmInetPton */
9542 #endif /* IPV6_SUPPORTED */
9544 #ifdef IPV6_SUPPORTED
9550 * Desc: Converts a IP address string to IPV6 address suitable
9551 * to be used in bind.
9553 * Ret: ROK - successful
9563 CmInetIpAddr6 *address6, /* 16 byte interent address */
9564 S8 *asciiAddr /* ascii address representation */
9567 S16 cmInetPton6(address6, asciiAddr)
9568 CmInetIpAddr6 *address6; /* 16 byte interent address */
9569 S8 *asciiAddr; /* ascii address representation */
9575 struct sockaddr_storage ss;
9576 U32 sslen = sizeof(ss);
9579 #if (ERRCLASS & ERRCLS_INT_PAR)
9580 /* error check on parameters */
9581 if ((asciiAddr == NULLP) || (address6 == NULLP))
9585 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9588 ret = inet_pton(AF_INET6, asciiAddr, (void *)address6);
9594 /* cm_inet_c_001.main_44 : In windows inet_pton is not implemented. so we are using the below function
9595 * to convert the ipv6 address string to appropriate form */
9596 WSAStringToAddressA((LPTSTR)asciiAddr, AF_INET6, NULL, (struct sockaddr*)&ss, &sslen);
9597 memcpy(address6, &(((struct sockaddr_in6 *)&ss)->sin6_addr), sizeof(CmInetIpAddr6));
9601 } /* end of cmInetPton6 */
9602 #endif /* IPV6_SUPPORTED */
9608 * Fun: cmInetGetMemSize
9610 * Desc: This function gives the max number of static buffer space that
9611 * the internet library will allocate.
9613 * Ret: ROK - successful
9622 S16 cmInetGetMemSize(
9623 S32 *size /* max used memory size */
9626 S16 cmInetGetMemSize(size)
9627 S32 *size; /* max used memory size */
9631 /* max static memory size depends on max flat buffer size */
9632 *size = CM_INET_MAX_MSG_LEN;
9634 /* max static memory size depends on max flat buffer or iovect size */
9635 *size = CM_INET_MAX_MSG_LEN;
9647 * Desc: This function initializes the socket library.
9649 * Ret: ROK - successful
9651 * Notes: Required only for Winsock and not for 4.3BSD
9662 S16 cmInetInit(Void)
9670 version = MAKEWORD(CM_INET_HIGH_VER, CM_INET_LOW_VER);
9671 err = WSAStartup(version, &data);
9686 * Desc: This function de initializes the socket library. The
9687 * WINSOCK implementation de registers the application and
9688 * releases any resources allocated on behalf of the
9691 * Ret: ROK - successful
9693 * Notes: Required only for Winsock and not for 4.3BSD
9704 S16 cmInetDeInit(Void)
9718 }/* end of cmInetDeInit() */
9723 * Fun: cmInetGetSockName
9725 * Desc: This function is used to retireve the current name
9726 * for the specified socket descriptor. It returns the
9727 * local association(address and port) for the socket.
9729 * Ret: ROK - successful
9732 * Notes: Please note if the socket was bound to CM_INET_INADDR_ANY
9733 * cmInetGetSockName() will not necessarily return the local
9734 * address information unless the socket has been connected.
9741 S16 cmInetGetSockName
9743 CmInetFd *sockFd, /* socket file descriptor */
9747 S16 cmInetGetSockName(sockFd, locAddr)
9748 CmInetFd *sockFd; /* socket file descriptor */
9749 CmInetAddr *locAddr;
9752 struct sockaddr_in *sockAddr;
9753 #ifdef IPV6_SUPPORTED
9754 struct sockaddr_in6 *sockAddr6;
9755 struct sockaddr_in6 lclSockAddr;
9757 CmInetSockAddr lclSockAddr;
9758 #endif /* IPV6_SUPPORTED */
9763 #endif /* SS_LINUX */
9765 /*cm_inet_c_001.main_58 : fix for klockwork issue */
9769 #if (ERRCLASS & ERRCLS_INT_PAR)
9770 /* error check on parameters */
9771 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
9776 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9778 memset(&lclSockAddr, 0, sizeof(lclSockAddr));
9779 size = sizeof(lclSockAddr);
9782 ret = getsockname(sockFd->fd, (CmInetSockAddr*)&lclSockAddr,
9783 (socklen_t *)&size);
9785 ret = getsockname(sockFd->fd, (CmInetSockAddr*)&lclSockAddr, (int*)&size);
9786 #endif /* SS_LINUX */
9790 switch(errCode = INET_ERR_CODE)
9793 sockAddr = (struct sockaddr_in *)&lclSockAddr;
9794 #ifdef IPV6_SUPPORTED
9795 locAddr->type = CM_INET_IPV4ADDR_TYPE;
9796 locAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(sockAddr->sin_port);
9798 locAddr->port = CM_INET_NTOH_U16(sockAddr->sin_port);
9799 #endif /* IPV6_SUPPORTED */
9805 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9806 /* cm_inet_c_001.main_62:Warning fix */
9807 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d),"
9808 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
9809 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET051, 0, prntBuf);
9811 /* cm_inet_c_001.main_62:Warning fix */
9812 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d),"
9813 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
9814 CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET051, 0, prntBuf);
9815 #endif /* ALIGN_64BIT */
9816 #endif /* CMINETDBG */
9818 }/* end of switch */
9822 /* Fill the returned address in to locAddr */
9823 #ifdef IPV6_SUPPORTED
9824 memset(locAddr, 0, sizeof(CmInetAddr));
9825 if (size == sizeof(struct sockaddr_in6))
9827 sockAddr6 = (struct sockaddr_in6 *)&lclSockAddr;
9828 locAddr->type = CM_INET_IPV6ADDR_TYPE;
9829 locAddr->u.ipv6Addr.port = CM_INET_NTOH_U16(sockAddr6->sin6_port);
9830 CM_INET_COPY_IPV6ADDR(&locAddr->u.ipv6Addr.ipv6NetAddr,
9831 &sockAddr6->sin6_addr);
9835 sockAddr = (struct sockaddr_in *)&lclSockAddr;
9836 locAddr->type = CM_INET_IPV4ADDR_TYPE;
9837 locAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(sockAddr->sin_port);
9838 locAddr->u.ipv4Addr.address =
9839 CM_INET_NTOH_U32(sockAddr->sin_addr.s_addr);
9842 sockAddr = (struct sockaddr_in *)&lclSockAddr;
9843 locAddr->port = CM_INET_NTOH_U16(sockAddr->sin_port);
9844 locAddr->address = CM_INET_NTOH_U32(sockAddr->sin_addr.s_addr);
9845 #endif /* IPV6_SUPPORTED */
9847 }/* end of cmInetGetSockName() */
9849 /* New functions to peek into the file descriptor
9851 #if (defined(SUNOS) || defined(WIN32) || defined(SS_LINUX) || defined(SS_VW) \
9856 * Fun: cmInetFdSetInfoInit
9858 * Desc: This function is used to initialise operating system specific
9859 * data that will be used to peek into the file descriptor lists
9860 * to get the sockets that are set
9862 * Ret: ROK - successful
9872 S16 cmInetFdSetInfoInit
9874 CmInetFdSetInfo *fdSetInfo
9877 S16 cmInetFdSetInfoInit(fdSetInfo)
9878 CmInetFdSetInfo *fdSetInfo;
9881 #if (defined(SUNOS) || defined(SS_LINUX) || defined(SS_VW) || defined(HPOS))
9886 #endif /* SUNOS || SS_LINUX || SS_VW */
9888 #if (ERRCLASS & ERRCLS_INT_PAR)
9889 if (fdSetInfo == NULLP)
9891 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9893 if (fdSetInfo->initDone == TRUE)
9897 fdSetInfo->numFds = 0;
9900 #if (defined(SUNOS) || defined(SS_LINUX) || defined(SS_VW)|| defined(HPOS))
9901 /* Check if we are on a big endian machine */
9904 fdSetInfo->bigEndian = FALSE;
9906 fdSetInfo->bigEndian = TRUE;
9908 fdSetInfo->arIdx = 0;
9909 fdSetInfo->ar[0] = 0xff;
9911 /* Initialise the array */
9912 /* The array contains bit positions for the first bit
9913 * for each integer from 1 to 2^8.
9915 for (arIdx = 1; arIdx < 256; arIdx++)
9917 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
9918 curByte = (U8)arIdx;
9925 fdSetInfo->ar[arIdx] = bitPos;
9929 curByte = curByte >> 1;
9932 /* Calculate the number of array elements in this fd_set */
9933 #if (defined(SS_LINUX) && !defined(_GNU_SOURCE))
9934 fdSetInfo->numArElems = sizeof(CmInetFdSet)/sizeof(fdSet->__fds_bits[0]);
9936 fdSetInfo->numArElems = sizeof(CmInetFdSet)/sizeof(fdSet->fds_bits[0]);
9937 #endif /* SS_LINUX */
9938 #endif /* SUNOS || SS_LINUX || SS_VW || HPOS */
9940 fdSetInfo->initDone = TRUE;
9942 }/* end of cmInetFdSetInfoInit() */
9949 * Desc: This function is used to get the file descriptor from the
9950 * file descriptor set.
9952 * Ret: ROK - successful
9953 * ROKDNA - socket not found
9955 * RNA - failed, initialisation not done
9957 * Notes: If the application modifies fdSet between calls to this
9958 * function then the results are undefined. This function should
9959 * be called in a loop till either it returns - not ROK, or if
9960 * all sockets in the file descriptor set are processed.
9969 CmInetFdSetInfo *fdSetInfo,
9971 CmInetFdType *sockFd
9974 S16 cmInetGetFd(fdSetInfo, fdSet, sockFd)
9975 CmInetFdSetInfo *fdSetInfo;
9977 CmInetFdType *sockFd;
9980 /*cm_inet_c_001.main_58 : Fix for klockwork issue */
9981 #if (!defined (WIN32))
9982 U32 sizOfFdSetArElem;
9988 #endif /* !defined (WIN32) */
9990 #if (ERRCLASS & ERRCLS_INT_PAR)
9991 if ((fdSetInfo == NULLP) || (fdSet == NULLP) || (sockFd == NULLP))
9994 if (fdSetInfo->initDone != TRUE)
9996 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9999 #if (ERRCLASS & ERRCLS_DEBUG)
10000 if (fdSetInfo->numFds > FD_SETSIZE)
10002 #endif /* ERRCLASS & ERRCLS_DEBUG */
10003 /* cm_inet_c_001.main_32 : Corrected check for number of fd set in
10004 a fdset for WIN32*/
10005 if (fdSetInfo->numFds >= fdSet->fd_count)
10008 *sockFd = fdSet->fd_array[fdSetInfo->numFds];
10009 fdSetInfo->numFds += 1;
10013 /* cm_inet_c_001.main_59: Protected under if not defined WIN32 */
10014 #if (!defined (WIN32))
10015 /* Start with arIdx and continue upto number of array elements. */
10016 curIdx = fdSetInfo->arIdx;
10019 #if (defined(SS_LINUX) && !defined(_GNU_SOURCE))
10020 sizOfFdSetArElem = sizeof(fdSet->__fds_bits[0]);
10022 sizOfFdSetArElem = sizeof(fdSet->fds_bits[0]);
10023 #endif /* SS_LINUX */
10025 for (curIdx = fdSetInfo->arIdx; curIdx < fdSetInfo->numArElems;
10028 #if (defined(SS_LINUX) && !defined(_GNU_SOURCE))
10029 if (fdSet->__fds_bits[curIdx])
10031 if (fdSet->fds_bits[curIdx])
10032 #endif /* SS_LINUX */
10034 /* Walk through the bytes in this element */
10035 #if (defined(SS_LINUX) && !defined(_GNU_SOURCE))
10036 tempByte = (U8 *)&fdSet->__fds_bits[curIdx];
10038 tempByte = (U8 *)&fdSet->fds_bits[curIdx];
10039 #endif /* SS_LINUX */
10041 /* Set the starting byte offset */
10042 if (fdSetInfo->bigEndian)
10043 tempByte += sizOfFdSetArElem - 1;
10045 for (bytesScanned = 0; bytesScanned < sizOfFdSetArElem;
10050 bitPos = fdSetInfo->ar[*tempByte];
10051 /* cm_inet_c_001.main_54: Fix for Klockworks issue */
10052 fdSetInfo->arIdx = (U16)curIdx;
10053 /* Calculate fd depending on where we are */
10054 *sockFd = ((bytesScanned << 3) + bitPos);
10055 *sockFd += (curIdx * (sizOfFdSetArElem << 3));
10056 /* Clear the file descriptor */
10057 *tempByte &= ~(1 << bitPos);
10060 if (fdSetInfo->bigEndian)
10073 #endif /* SUNOS || SS_LINUX || SS_VW || HPOS */
10074 } /* end of cmInetGetFd */
10076 #endif /* SUNOS || WIN32 || SS_LINUX || SS_VW || HPOS */
10079 /* add cmInetConvertStrToIpAddr and
10080 * cmInetAsciiToIpv4 functions */
10083 * Fun: cmInetConvertStrToIpAddr
10085 * Desc: This function parses the input string for an IPV4/IPV6 address.
10087 * 1) IPV4 in dot number format:
10089 * 2) IPV6, in uncompressed, compressed, and IPV4 embedded format
10090 * 10:20:30:40:502:610:70C:80ad
10092 * 45::AB:34:123.34.5.667
10094 * Ret: ROK - SUCCESS
10095 * RFAILED - FAILURE
10104 S16 cmInetConvertStrToIpAddr
10106 U16 len, /* Length of IP address */
10107 U8 *val, /* Domain Name String */
10108 CmInetNetAddr *address /* IP Address */
10111 S16 cmInetConvertStrToIpAddr(len, val, address)
10112 U16 len; /* Length of IP address */
10113 U8 *val; /* Domain Name String */
10114 CmInetNetAddr *address; /* IP Address */
10117 U8 idx; /* Index for string*/
10118 U8 ipv4[CM_INET_IPV4ADDR_SIZE]; /* IPV4 Address bytes */
10119 #ifdef IPV6_SUPPORTED
10120 U16 *ipv6; /* IPV6 Address bytes */
10121 U16 ipv6Reg[8]; /* regular IPV6 Address bytes */
10122 U16 ipv6Cmp[8]; /* compressed IPV6 Address bytes */
10123 U8 numBlk; /* number of blocks in IPV6 addr */
10124 Bool compressed; /* IPV6 in compressed format */
10125 U8 ipv6Idx; /* counter for IPV6 */
10126 U8 blkBeginIdx; /* IPV6, char index for the
10127 beginning of the block */
10128 U8 i; /* counter for IPV6 */
10129 S16 retVal; /* return value */
10130 Bool embedIPV4 = FALSE; /* IPV4 embedded in IPV6 ? */
10131 #endif /* IPV6_SUPPORTED*/
10135 #ifdef IPV6_SUPPORTED
10138 compressed = FALSE;
10140 ipv6 = ipv6Reg; /* assign pointer to IPV6 regular, uncompressed */
10141 memset(ipv6Reg, 0, CM_INET_IPV6ADDR_SIZE);
10142 memset(ipv6Cmp, 0, CM_INET_IPV6ADDR_SIZE);
10143 #endif /* IPV6_SUPPORTED*/
10145 memset(ipv4, 0, CM_INET_IPV4ADDR_SIZE);
10147 /* Check for IP Address */
10148 while ((val[idx] != '.') && (val[idx] != ':') &&
10151 #if (ERRCLASS & ERRCLS_DEBUG)
10152 if (((val[idx] < '0') || (val[idx] > '9')) &&
10153 ((val[idx] < 'a') || (val[idx] > 'f')) &&
10154 ((val[idx] < 'A') || (val[idx] > 'F')))
10159 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10161 /* Convert Ascii to integer */
10162 CM_INET_ATOI(ipv4[0], val[idx]);
10164 #ifdef IPV6_SUPPORTED
10165 /* convert Ascii to hex */
10166 CM_INET_ATOH(ipv6[0], val[idx]);
10167 #endif /* IPV6_SUPPORTED */
10169 idx++; /* move to the next character */
10170 } /* while, try to determine IPV4 or IPV6 */
10172 #if (ERRCLASS & ERRCLS_DEBUG)
10173 if ((val[idx] != '.') && (val[idx] != ':'))
10177 } /* if, couldn't determine IPV4 or IPV6 */
10178 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10181 if (val[idx] == '.')
10184 cmInetAsciiToIpv4(3, &(ipv4[1]), (U16)(len - idx), &(val[idx]));
10186 address->type = CM_INET_IPV4ADDR_TYPE;
10187 CM_INET_GET_IPV4_ADDR_FRM_STRING(address->u.ipv4NetAddr, ipv4);
10189 #ifdef IPV6_SUPPORTED
10192 numBlk = 1; /* already converted the 1st block */
10194 while ((val[idx] != '\0') && (idx < len) && (numBlk <= 8))
10196 idx++; /* go to the next char, either a number or the 2nd : */
10197 if (val[idx] == ':')
10199 #if (ERRCLASS & ERRCLS_DEBUG)
10200 if (compressed == TRUE)
10202 /* can't have 2 :: */
10205 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10208 idx++; /* skip the : */
10211 } /* if, IPV6 in compressed format :: */
10215 } /* else, uncompressed, convert next block */
10217 numBlk++; /* increase number of blocks */
10219 /* assign the index the beginning of the block */
10222 while(val[idx] != ':' && val[idx] != '\0' && idx < len)
10224 if (val[idx] == '.')
10226 /* convert number to IPV4 */
10227 ipv6[ipv6Idx] = 0; /* clear out whatever we did */
10228 memset(ipv4, 0, CM_INET_IPV4ADDR_SIZE);
10229 retVal = cmInetAsciiToIpv4(4, ipv4, len - blkBeginIdx,
10230 &(val[blkBeginIdx]));
10231 /* stop the loop, embedded IPV4 is the last part of
10239 } /* if, '.' means IPV4 address embedded in IPV6 */
10241 #if (ERRCLASS & ERRCLS_DEBUG)
10242 if (((val[idx] < '0') || (val[idx] > '9')) &&
10243 ((val[idx] < 'a') || (val[idx] > 'f')) &&
10244 ((val[idx] < 'A') || (val[idx] > 'F')))
10249 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10251 /* Convert Ascii to integer */
10252 CM_INET_ATOH(ipv6[ipv6Idx], val[idx]);
10254 /* move to the next index */
10256 } /* while, convert a block of 16 bits Hex number */
10257 if (embedIPV4 == TRUE)
10259 ipv6Idx--; /* deccrease in case of compressed IPV6 */
10260 break; /* stop the while look */
10261 } /* if, IPV4 embedded in IPV6 */
10262 } /* while, IPV6 parsing */
10263 if (compressed == TRUE)
10265 if (embedIPV4 == TRUE)
10267 numBlk = 5; /* the last 2 blocks are IPV4 */
10268 } /* if, IPV4 embedded */
10271 numBlk = 7; /* copy from the last block */
10272 } /* else, no embedded IPV4 */
10274 /* type cast U8 over -1 becasue we want to copy the last block,
10277 for (i = ipv6Idx; i != (U8) (-1); i --)
10279 ipv6Reg[numBlk] = ipv6Cmp[i];
10281 } /* for, copying compress IPV6 to regular IPV6 */
10282 } /* if, compressed format */
10284 if (embedIPV4 == TRUE)
10286 ipv6Reg[6] = PutHiByte(ipv6Reg[6], ipv4[0]);
10287 ipv6Reg[6] = PutLoByte(ipv6Reg[6], ipv4[1]);
10288 ipv6Reg[7] = PutHiByte(ipv6Reg[7], ipv4[2]);
10289 ipv6Reg[7] = PutLoByte(ipv6Reg[7], ipv4[3]);
10290 } /* if, IPV4 embedded */
10292 /* convert IPV6 to cmInetIpv6 */
10293 address->type = CM_INET_IPV6ADDR_TYPE;
10294 memcpy(address->u.ipv6NetAddr,
10295 ipv6Reg, CM_INET_IPV6ADDR_SIZE);
10297 #endif /* IPV6_SUPPORTED */
10300 } /* cmInetConvertStrToIpAddr */
10305 * Fun: cmInetAsciiToIpv4
10307 * Desc: This function parses the input string to an IPV4 address.
10308 * The input string can be
10309 * - the whole IPV4 address, '123.43.45.56', or
10310 * - a part of it. '34.56.454'
10311 * numBytes: number of bytes needs to be converted, IPV4 has
10312 * 4 bytes. If we are only converting the end of an
10313 * address, this number needs to be adjusted. For
10314 * example, when converting '34.56.454]', the number
10317 * Ret: ROK - SUCCESS
10318 * RFAILED - FAILURE
10326 S16 cmInetAsciiToIpv4
10328 U8 numBytes, /* number of Byte to convert */
10329 U8 *ipv4Addr, /* IPV4 Address */
10330 U16 len, /* Length of IP address */
10331 U8 *val /* Domain Name String */
10334 S16 cmInetAsciiToIpv4(numBytes, ipv4Addr, len, val)
10335 U8 numBytes; /* number of Byte to convert */
10336 U8 *ipv4Addr; /* IPV4 Address */
10337 U16 len; /* Length of IP address */
10338 U8 *val; /* Domain Name String */
10341 U8 byteCount; /* Byte Count */
10342 U8 idx; /* Index for string*/
10346 for (byteCount = 0; byteCount < numBytes; byteCount++)
10348 while((val[idx] != '.') && (idx < len))
10350 #if (ERRCLASS & ERRCLS_DEBUG)
10351 if (val[idx] < '0' || val[idx] > '9')
10356 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10358 /* Convert Ascii to integer */
10359 CM_INET_ATOI(ipv4Addr[byteCount], val[idx]);
10361 /* move to the next index */
10368 } /* cmInetAsciiToIpv4 */
10370 /* cm_inet_c_001.main_34:Added wrapper function for getaddrinfo and freeaddrinfo */
10371 #if (!defined(SS_VW) && !defined(SS_PS) && !defined(WIN32))
10375 * Fun: cmInetGetAddrInfo
10377 * Desc: a socket file descriptor to a local Internet
10380 * Ret: Value returned by getaddrinfo
10389 S32 cmInetGetAddrInfo
10391 CONSTANT S8 *node, /* Network addr which has to be resolved */
10392 CONSTANT S8 *service, /* Sets the port number in network addr */
10393 CONSTANT CmInetAddrInfo *hints, /* Specifies preferred socket type or protocol */
10394 CmInetAddrInfo **res /* Link list of addrInfo structure */
10397 S32 cmInetGetAddrInfo(node,service,hints,res)
10398 CONSTANT S8 *node; /* Network addr which has to be resolved */
10399 CONSTANT S8 *service; /* Sets the port number in network addr */
10400 CONSTANT CmInetAddrInfo *hints; /* Specifies preferred socket type or protocol */
10401 CmInetAddrInfo **res; /* Link list of addrInfo structure */
10407 #if (ERRCLASS & ERRCLS_INT_PAR)
10408 /* error check on parameters */
10409 if ((node == NULLP) || (hints == NULLP))
10413 #endif /* ERRCLASS & ERRCLS_INT_PAR */
10415 ret = getaddrinfo(node,service,hints,res);
10419 #ifndef ALIGN_64BIT
10420 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
10421 /* cm_inet_c_001.main_62:Warning fix */
10422 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetAddrInfo() Failed : error(%ld), node(%p),"
10423 " service(%p)\n", ret, node, service);
10424 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET052, 0, prntBuf);
10426 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
10427 /* cm_inet_c_001.main_62:Warning fix */
10428 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetAddrInfo() Failed : error(%d), node(%p),"
10429 " service(%p)\n ", ret, node, service);
10430 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET053, 0, prntBuf);
10431 #endif /* ALIGN_64BIT */
10432 #endif /* CMINETDBG */
10435 } /* end of cmInetGetAddrInfo */
10440 * Fun: cmInetFreeAddrInfo
10442 * Desc: Free the dynamically allocated addrinfo structure
10453 Void cmInetFreeAddrInfo
10455 CmInetAddrInfo *res /* Link list of addrInfo structure */
10458 Void cmInetFreeAddrInfo(res)
10459 CmInetAddrInfo *res; /* Link list of addrInfo structure */
10463 #if (ERRCLASS & ERRCLS_INT_PAR)
10464 /* error check on parameters */
10467 #endif /* ERRCLASS & ERRCLS_INT_PAR */
10470 } /* end of cmInetFreeAddrInfo */
10472 #endif /* SS_VW | SS_PS | WIN32*/
10474 /* cm_inet_c_001.main_36 : 1. Added new interface - cmInetFlushRecvBuf()
10475 to flush the data from socket receive buffer. */
10476 #ifdef CM_INET_FLUSH_RECV_BUF
10480 * Fun: cmInetFlushRcvBuf
10482 * Desc: Reads all the data from a socket and throw it!!
10483 * The buffers for the receive buffer for recvfrom() are allocated from the stack.
10485 * Ret: ROK - successful
10486 * ROKDNA - ok, data not available
10487 * RCLOSED - connection closed by peer
10488 * ROUTRES - failed, out of resources
10497 S16 cmInetFlushRecvBuf
10499 CmInetFd *sockFd, /* socket file descriptor */
10500 MsgLen *len, /* number of octects to be flushed */
10501 S32 flags /* additional control flags */
10504 S16 cmInetFlushRecvBuf(sockFd, len, flags)
10505 CmInetFd *sockFd; /* socket file descriptor */
10506 MsgLen *len; /* number of octects to be flushed */
10507 S32 flags; /* additional control flags */
10511 Data recvTempBuf[CM_INET_MAX_BYTES_READ];
10513 #if (defined(WIN32) || defined(CMINETFLATBUF))
10514 S32 ret; /* temporary return value */
10515 U32 pendLen; /* pending data length */
10516 S32 recvLen; /* number of received octets by recvmsg() */
10517 MsgLen curLen; /* current number of octets in buffer */
10518 U32 remAddrLen; /* length of remote address */
10519 struct sockaddr_in *remAddr; /* remote Internet address */
10520 #ifdef IPV6_SUPPORTED
10521 struct sockaddr_in6 remSockAddr; /* to get packet's source IP address */
10523 CmInetSockAddr remSockAddr; /* to get packet's source IP address */
10524 #endif /* IPV6_SUPPORTED */
10526 S32 ret; /* temporary return value */
10527 MsgLen curLen; /* current number of octets in buffer */
10528 U32 pendLen; /* pending data length */
10529 S32 recvLen; /* number of received octets by recvmsg() */
10530 struct msghdr msg; /* message header */
10531 CmInetIovec rxArr[CM_INET_MAX_DBUF]; /* dynamic gather array */
10532 U32 remAddrLen; /* length of remote address */
10533 #ifdef IPV6_SUPPORTED
10534 struct sockaddr_in6 remSockAddr;/* to get packet's source IP address */
10536 #if (defined(SS_LINUX) || defined(_XPG4_2))
10537 U8 ancillData[CM_INET_IPV6_ANCIL_DATA];
10538 /* from stack for IPv6 ancill data */
10541 CmInetSockAddr remSockAddr; /* to get packet's src IP address */
10542 #if (defined(SS_LINUX) || defined(_XPG4_2))
10543 U8 ancillData[CM_INET_IPV4_ANCIL_DATA];
10544 /* from stack for IPv4 ancill data */
10546 #endif /* IPV6_SUPPORTED */
10547 #endif /* WIN32 | CMINETFLATBUF */
10549 /* used by getsockopt */
10550 U32 errValue; /* error value */
10551 U32 optLen; /* option length */
10554 #if (ERRCLASS & ERRCLS_INT_PAR)
10555 /* error check on parameters */
10556 if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
10560 #endif /* ERRCLASS & ERRCLS_INT_PAR */
10563 #if (defined(WIN32) || defined(CMINETFLATBUF))
10565 #endif /* (WIN32 | CMINETFLATBUF) */
10567 /* clear the structure */
10568 memset(&remSockAddr, 0, sizeof(remSockAddr));
10570 /* get number of pending data */
10571 ret = cmInetGetNumRead(sockFd, &pendLen);
10574 /* ret may be RFAILED or ROUTRES */
10578 /* check if connection got closed */
10581 if (sockFd->type == CM_INET_STREAM)
10584 /* cm_inet_c_001.main_50
10585 * Due to latency (mostly in solaris) sometimes ioctl(FIONREAD)
10586 * (inside cmInetGetNumRead) returns pend length as 0 on a TCP
10587 * socket that select says is ready to read. This should not be
10588 * considered as connection closed. So return ROKDNA instead of
10594 /* clear error if there is any, because if there is internal error
10595 * here it will cause infinite loop in TUCL */
10598 optLen = sizeof(int);
10600 ret = getsockopt(sockFd->fd, SOL_SOCKET, SO_ERROR,
10601 (char*)&errValue, (socklen_t *)&optLen);
10603 #if (defined(SS_VW) || defined(SS_PS))
10604 ret = getsockopt(sockFd->fd, SOL_SOCKET, SO_ERROR,
10605 (char*)&errValue, (int *)&optLen);
10608 ret = getsockopt(sockFd->fd, SOL_SOCKET, SO_ERROR,
10609 (char*)&errValue, (int *)&optLen);
10610 #endif /* SS_WINCE */
10612 #endif /* SS_LINUX */
10613 if (ret == INET_ERR)
10616 #ifndef ALIGN_64BIT
10617 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
10618 /* cm_inet_c_001.main_62:Warning fix */
10619 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10620 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
10621 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET054, 0, prntBuf);
10623 /* cm_inet_c_001.main_62:Warning fix */
10624 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10625 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
10626 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET054, 0, prntBuf);
10627 #endif /*ALIGN_64BIT*/
10628 #endif /* CMINETDBG */
10634 /* added separate recvfrom calls different OS */
10635 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
10636 recvLen = recvfrom(sockFd->fd, (S8 *)&tempBuf, pendLen, 0,
10637 (struct sockaddr *)&remSockAddr, (int *)&remAddrLen);
10639 #if ( defined(SUNOS) || defined(SS_LINUX))
10640 recvLen = recvfrom(sockFd->fd, (S8 *)&tempBuf, pendLen, 0,
10641 NULLP, (socklen_t *)&remAddrLen);
10643 recvLen = recvfrom(sockFd->fd, (S8 *)&tempBuf, pendLen, 0,
10644 NULLP, (S32 *)&remAddrLen);
10646 #endif /* defined(SUNOS) || defined(SS_LINUX) */
10647 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */
10652 }/* if (pendLen == 0)*/
10655 if((*len == CM_INET_READ_THROW) || (*len >= CM_INET_MAX_BYTES_READ))
10657 curLen = CM_INET_MAX_BYTES_READ;
10661 curLen = *len; /*set to given number of messasges to be flushed */
10664 if((*len != CM_INET_READ_THROW) && (*len < pendLen))
10669 #if (defined(WIN32) || defined(CMINETFLATBUF))
10673 * maybe needs more than one recvfrom() call to read an entire
10678 memset(recvTempBuf, 0, CM_INET_MAX_BYTES_READ);
10679 /* added separate recvfrom calls different OS */
10681 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
10682 recvLen = recvfrom(sockFd->fd, (S8 *)recvTempBuf, curLen, 0,
10683 (struct sockaddr *)&remSockAddr, (int *)&remAddrLen);
10685 #if ( defined(SUNOS) || defined(SS_LINUX))
10686 recvLen = recvfrom(sockFd->fd, (S8 *)recvTempBuf, curLen, 0,
10687 (struct sockaddr *)&remSockAddr, (socklen_t *)&remAddrLen);
10689 recvLen = recvfrom(sockFd->fd, (S8 *)recvTempbuf, curLen, 0,
10690 &remSockAddr, (S32 *)&remAddrLen);
10692 #endif /* defined(SUNOS) || defined(SS_LINUX) */
10693 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */
10695 if (recvLen == INET_ERR)
10698 /* added check ERR_WOULDBLOCK */
10699 if ((INET_ERR_CODE == ERR_AGAIN) ||
10700 (INET_ERR_CODE == ERR_WOULDBLOCK))
10707 /* In Windows the recvfrom function fails
10708 * with error code which maps to either WSAECONNABORTED. If
10709 * this happens then cmInetFlushRecvBuf must return RCLOSED */
10710 if ((INET_ERR_CODE == ERR_CONNABORTED) ||
10711 (INET_ERR_CODE == ERR_CONNRESET))
10718 #ifndef ALIGN_64BIT
10719 /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
10720 /* cm_inet_c_001.main_62:Warning fix */
10721 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10722 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
10723 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET055, 0, prntBuf);
10725 /* cm_inet_c_001.main_62:Warning fix */
10726 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10727 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
10728 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET055, 0, prntBuf);
10729 #endif /*ALIGN_64BIT*/
10730 #endif /* CMINETDBG */
10735 if(recvLen < curLen)
10738 pendLen -= recvLen;
10740 if(pendLen < curLen)
10743 } /* while (curLen > 0) */
10745 #else /* end of Win NT/flat buffer specific part */
10748 * maybe needs more than one recvmsg() call to read entire message
10749 * on a stream socket
10753 memset(recvTempBuf, 0, CM_INET_MAX_BYTES_READ);
10754 /* update the message structure */
10756 rxArr[0].iov_base = (Void*)recvTempBuf;
10757 rxArr[0].iov_len = (U32)curLen;
10759 rxArr[0].iov_base = (S8*)recvTempBuf;
10760 rxArr[0].iov_len = curLen;
10761 #endif /* SS_LINUX */
10762 msg.msg_iov = rxArr;
10763 msg.msg_iovlen = 1;
10765 msg.msg_name = NULLP;
10766 msg.msg_namelen = 0;
10768 /* added defined(_XPG4_2). Also changed the
10770 #if (defined(SS_LINUX) || defined(_XPG4_2))
10771 msg.msg_control = ancillData;
10772 msg.msg_controllen = sizeof(ancillData);
10775 msg.msg_accrights = NULLP;
10776 msg.msg_accrightslen = 0;
10777 #endif /* SS_LINUX */
10779 recvLen = recvmsg(sockFd->fd, &msg, flags);
10780 if ((recvLen == INET_ERR) || (recvLen > CM_INET_MAX_MSG_LEN))
10782 /* added check ERR_AGAIN when CMINETFLATBUF is not defined.
10783 added check ERR_WOULDBLOCK */
10784 if ((INET_ERR_CODE == ERR_AGAIN) ||
10785 (INET_ERR_CODE == ERR_WOULDBLOCK))
10792 #ifndef ALIGN_64BIT
10793 /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
10794 /* cm_inet_c_001.main_62:Warning fix */
10795 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10796 " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
10797 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET056, 0, prntBuf);
10799 /* cm_inet_c_001.main_62:Warning fix */
10800 snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10801 " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
10802 CMINETLOGERROR(ERRCLS_DEBUG, ECMINET056, 0, prntBuf);
10803 #endif /*ALIGN_64BIT*/
10804 #endif /* CMINETDBG */
10806 /* If this happens then cmInetFlushRecvBuf must return RCLOSED.
10807 * Needed for getting icmp msgs */
10808 if (INET_ERR_CODE == ERR_CONNABORTED)
10814 }/* if ((recvLen == INET_ERR) || (recvLen > CM_INET_MAX_MSG_LEN))*/
10816 if(recvLen < curLen)
10819 pendLen -= recvLen;
10821 if(pendLen < curLen)
10824 } /* while(curLen > 0) */
10826 #endif /* WIN32 | CMINETFLATBUF */
10830 } /* end of cmInetFlushRecvBuf */
10832 #endif /* CM_INET_FLUSH_RECV_BUF*/
10834 /**********************************************************************
10836 **********************************************************************/