set 5 - last warning set
[o-du/l2.git] / src / cm / cm_inet.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 \f
20 /********************************************************************20**
21   
22         Name:     common Internet socket library
23     
24         Type:     C Source file 
25   
26         Desc:     common library for Internet sockets,
27                   always link this library with following libraries:
28                        Trillium's libos.a
29                        Solaris    nsl, socket 
30  
31         File:     cm_inet.c
32   
33 *********************************************************************21*/
34  
35 \f
36 /*
37  *      This software may be combined with the following TRILLIUM
38  *      software:
39  *
40  *      part no.                      description
41  *      --------    ----------------------------------------------
42  *      1000151     TCAP over TCP/IP   
43  */
44
45 \f  
46 /* header include files (.h) */
47   
48 #include "envopt.h"             /* environment options */  
49 #include "envdep.h"             /* environment dependent */
50 #include "envind.h"             /* environment independent */
51
52 #include "gen.h"                /* general */
53 #include "ssi.h"                /* system services interface */
54 #include "cm_inet.h"            /* socket library file */
55
56 /*cm_inet_c_001.main_35 : Updated for C++ compilation */
57 #ifdef __cplusplus
58 extern "C" {
59 #endif /* __cplusplus */
60
61 /* environment dependent include files */
62 #ifdef WIN32
63 #ifndef IN
64 #define IN
65 #endif
66 #include <winsock2.h>
67 #include <ws2tcpip.h>
68 #ifdef WIN2K
69 #include <Mswsock.h>
70 #endif /* WIN2K */
71 #else /* WIN32 */
72 #include <errno.h>
73 #if (!defined(SS_VW) && !defined(SS_PS))
74 #include <netdb.h>
75 #endif
76 #ifndef SS_PS
77 #include <unistd.h>
78 #endif
79 #include <string.h>
80 #include <sys/types.h>
81 #ifdef SS_PS
82 #include <pna.h>
83 #else
84 #include <sys/socket.h>
85 #include <sys/ioctl.h>
86 #endif /* SS_PS */
87 #ifdef SS_VW
88 #include <sys/times.h>
89 #include <ioLib.h>
90 #include <sockLib.h>
91 #include <selectLib.h>
92 #include <hostLib.h>
93 #else
94 #if (!defined (SS_PS) && !defined(HPOS))
95 #include <sys/select.h>
96 #include <sys/time.h>
97 #ifdef SS_LINUX
98 #include <sys/uio.h>
99 #else
100 #include <sys/filio.h>
101 #endif /* SS_LINUX */
102 #endif /* SS_PS && HPOS */
103 #ifdef HPOS
104 #include <sys/time.h>
105 #endif /* HPOS */
106 #endif /* SS_VW */
107 #ifndef SS_PS
108 #include <netinet/in.h>
109 #include <arpa/inet.h>
110 #include <netinet/tcp.h>
111 #ifdef IPV6_SUPPORTED 
112
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>
118 #else 
119 #include <netinet/icmp6.h>
120 #endif    
121
122 #endif /* IPV6_SUPPORTED */
123 #endif /* SS_PS */
124 #endif /* WIN32 */
125
126 /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
127 #ifdef CM_LKSCTP
128 #include <netinet/sctp.h>
129 #endif
130
131    /* cm_inet_c_001.main_58: Added new header files to support filteration 
132     * of ICMP messages */
133 #ifdef SS_LINUX
134 #ifdef CM_ICMP_FILTER_SUPPORT
135 #include <asm/types.h>
136 #include <linux/icmp.h>
137 #endif
138 #endif
139  /* cm_inet_c_001.main_62:Warning fix */
140 #if (!defined(SS_VW) && !defined(SS_PS) && !defined(WIN32))
141 #include <netdb.h>
142 #endif
143 #ifdef __cplusplus
144 }
145 #endif /* __cplusplus */
146 /* header/extern include files (.x) */
147
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 */
152 #ifdef NTL_LIB
153 #include "ntl_lib.h"
154 #endif 
155
156 \f  
157 /* local defines */
158
159 /* BSD and Winsock error handling is different */
160 #ifdef WIN32
161 #define INET_ERR             SOCKET_ERROR
162 #define INET_ERR_CODE        WSAGetLastError()
163 #define ERR_INPROGRESS       WSAEINPROGRESS  
164 #define ERR_ISCONN           WSAEISCONN
165 #define ERR_WOULDBLOCK       WSAEWOULDBLOCK
166 #define ERR_INADDRNONE       INADDR_NONE
167 #define ERR_NOTCONN          WSAENOTCONN
168 #define ERR_ALREADY          WSAEALREADY
169 #define ERR_AGAIN            WSAEWOULDBLOCK 
170 #define ERR_INVAL            WSAEINVAL
171 #define ERR_CONNREFUSED       WSAECONNREFUSED
172 #define ERR_PIPE             WSAENOTCONN
173 /* Changed ERR_TIMEOUT for pSos compilation */
174 #define ERR_TIMEDOUT         WSAETIMEDOUT
175 #define ERR_CONNRESET        WSAECONNRESET
176 #define ERR_CONNABORTED      WSAECONNABORTED
177 /* cm_inet_c_001.main_36 Do select again in case of interrupt */
178 #define ERR_EINTR            WSAEINTR
179 /* cm_inet_c_001.main_37 network unreacheble error is added */
180 #define ERR_NETUNREACH       WSAENETUNREACH
181 /* cm_inet_c_001.main_61: host unreachable is added */
182 #define ERR_HOSTUNREACH      WSAEHOSTUNREACH
183 #else
184 #define INET_ERR             -1
185 #define INET_ERR_CODE        errno
186 #define ERR_INPROGRESS       EINPROGRESS
187 #define ERR_ISCONN           EISCONN
188 #define ERR_WOULDBLOCK       EWOULDBLOCK
189 #define ERR_INADDRNONE       -1
190 #define ERR_NOTCONN          ENOTCONN       
191 #define ERR_ALREADY          EALREADY
192 #define ERR_AGAIN            EAGAIN
193 /* cm_inet_c_001.main_36 Do select again in case of interrupt */
194 #define ERR_EINTR            EINTR
195 /* EINVAL is not mapped because it is a valid error code here */
196 #define ERR_INVAL            0 
197 #define ERR_CONNREFUSED      ECONNREFUSED
198 #define ERR_PIPE             EPIPE 
199 /* Changed ERR_TIMEOUT for pSos compilation */
200 #define ERR_TIMEDOUT         ETIMEDOUT
201 #define ERR_CONNRESET        ECONNRESET
202 #define ERR_CONNABORTED      ECONNABORTED
203 /* cm_inet_c_001.main_37 network unreacheble error is added */
204 #define ERR_NETUNREACH       ENETUNREACH
205 /* cm_inet_c_001.main_61: host unreachable is added */
206 #define ERR_HOSTUNREACH      EHOSTUNREACH
207 #endif /* WIN32 */
208
209 /* back log range */
210 #define MIN_BACK_LOG  0
211
212 /* added a win2k specific defines in. */
213 #ifdef WIN32
214 #ifdef WIN2K
215 #ifndef SIO_UDP_CONNRESET
216 #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR, 12)
217 #endif 
218 #endif /* WIN2K */
219 #define MAX_BACK_LOG  1
220 #else
221 #define MAX_BACK_LOG  5
222 #endif /* WIN32 */
223
224 #ifdef IPV6_OPTS_SUPPORTED
225 #ifndef IPV6_SUPPORTED
226 #error "Enable IPV6_SUPPORTED flag if IPV6_OPTS_SUPPORTED is defined."
227 #endif 
228 #if (!defined(SS_LINUX) && !defined(_XPG4_2))
229 #error "Enable _XPG4_2 or SS_LINUX if IPV6_OPTS_SUPPORTED is defined."
230 #endif /* SS_LINUX || _XPG4_2 */
231 #endif /* IPV6_OPTS_SUPPORTED */
232
233 #ifdef LOCAL_INTF
234 #if (!defined(SS_LINUX) && !defined(_XPG4_2))
235 #error "Enable _XPG4_2 or SS_LINUX if LOCAL_INTF is defined."
236 #endif /* SS_LINUX || _XPG4_2 */
237 #endif /* LOCAL_INTF */
238
239 /* local typedefs */
240
241 /* local externs */
242   
243 /* forward references */
244
245 /* added !(defined(CMINETFLATBUF) */
246 #if (!(defined(WIN32)) && !(defined(CMINETFLATBUF)))
247 /* Added another function parameter */
248 PRIVATE S16 buildRecvBuf ARGS((CmInetMemInfo *info, MsgLen len, 
249                                CmInetIovec rxArr[], Buffer *dBuf[], U16 maxSize,
250                                struct msghdr *msg, Bool isStrmMsg));
251 PRIVATE S16 buildRecvMsg ARGS((CmInetMemInfo *info, CmInetIovec rxArr[], 
252                                S16 numBduf, MsgLen msgLen, Buffer *dBufs[], 
253                                Buffer **mPtr));
254 /* cm_inet_c_001.main_50 - Added parameter to get length of dbufs packed for partial
255  *               send handling 
256  */
257 PRIVATE S16 buildSendIovec ARGS((Buffer *mBuf, MsgLen msgLen, 
258                                  CmInetIovec txArr[], S16 numDBuf, 
259                                  S16 *numIovElems, U32 *strtEndDBufNum,
260                                  MsgLen *ioLen)); 
261 #endif /* (defined(WIN32)) && !(defined(CMINETFLATBUF)) */
262
263 /* prototypes of new functions needed to send and 
264  * process after receiving the extension headers through ancillary data */
265
266 #ifdef IPV6_SUPPORTED
267 #ifdef IPV6_OPTS_SUPPORTED
268 PRIVATE S16 cmInet6BuildSendHBHOpts    ARGS((CmInetIpv6HBHHdrArr *hbhOptsArr, 
269                                             U8 *cmsgBuf, U32 *curMsgIdx, 
270                                             U8 hdrId));
271 PRIVATE S16 cmInet6BuildSendRouteOpts  ARGS((CmInetIpv6RtHdr *rtOptsArr, 
272                                             U8 *cmsgBuf, U32 *curMsgIdx));
273
274 PRIVATE S16 cmInet6BuildRecvRtHdr      ARGS((U8 *cmsgData, U32 rtDataLen, 
275                                             CmInetIpv6RtHdr0 *rtHdr0, 
276                                             CmInetIpv6RtHdr *rtOptsArr,
277                                             CmInetMemInfo *info));
278 PRIVATE S16 cmInet6BuildRecvHopOptsArr ARGS((U8 *cmsgData, U32 hbhDataLen, 
279                                             CmInetIpv6HBHHdrArr *hbhOptsArr, 
280                                             U8 hdrId, CmInetMemInfo *info));
281 PRIVATE S16 cmInet6GetHopLimitValue    ARGS((U8 *cmsgData, U32 hopLimitDataLen,
282                                             CmInetIpv6HdrParm *ipv6HdrParam));
283
284 #ifdef SS_LINUX
285 PRIVATE S16 cmInetBuildSendHoplimit        ARGS((U32 hoplimit, U8 *cmsgBuf, 
286                                             U32 *curMsgIdx));
287 #endif /* SS_LINUX */
288 #ifdef LOCAL_INTF
289 PRIVATE S16 cmInet6BuildSendPktinfo         ARGS((CmInetIpAddr6 *srcAddr,
290                                             U8 *cmsgBuf, U32 *curMsgIdx,
291                                             U8 protType));
292 #endif /* LOCAL_INTF */
293 #endif /* IPV6_OPTS_SUPPORTED */
294 #endif /* IPV6_SUPPORTED */
295
296 /* public variable declarations */
297
298 /* private variable declarations */
299
300 #ifdef CMINETDBG
301 /* Global buffer for debug prints */
302 /*cm_inet_c_001.main_62:Warning fix*/
303 Txt   prntBuf[CMINET_PRNT_BUF_SIZE];
304 #endif /* CMINETDBG */
305
306 /* cm_inet_c_001.main_60 POLL Specific Functions defined */
307
308 /*
309 *
310 *      Fun:   cmInetPoll
311 *
312 *      Desc:  Poll on pollfdarr
313 *
314 *      Ret:   Number of File Descriptor Selected
315 *
316 *      Notes: None
317 *
318 *      File:  cm_inet.c
319 *
320 */
321
322 #ifdef ANSI
323 PUBLIC S16 cmInetPoll
324 (
325 CmInetPollFd  *pollFdArr,               /* poll FD Array */
326 U32               numFds,               /* Number of Fds to be monitored */
327 S16              *numRdyFds,            /* number of ready descriptors */
328 U32              timeout                /* timeout value for Poll */
329 )
330 #else
331 PUBLIC S16 cmInetPoll(pollFdArr,numFds,numRdyFds,timeout)
332 CmInetPollFd  *pollFdArr;               /* poll FD Array */
333 U32               numFds;               /* Number of Fds to be monitored */
334 S16              *numRdyFds;            /* number of ready descriptors */
335 U32               timeout;              /* timeout value for Poll */
336 #endif
337 {
338    S32  ret;
339
340    TRC2(cmInetPoll); 
341    ret = 0;
342    *numRdyFds = 0;
343
344    if(numFds > CM_INET_POLL_MAXFDSUPP)
345    {
346 #ifdef CMINETDBG
347 /* cm_inet_c_001.main_62:Warning fix */
348 #ifndef ALIGN_64BIT
349       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPoll() : number of file descriptor (%lu) invalid \n",numFds);
350 #else
351       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPoll() : number of file descriptor (%u) invalid \n",numFds);
352 #endif
353       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
354 #endif /* CMINETDBG */      
355       RETVALUE(RFAILED);
356    } 
357
358 #if (ERRCLASS & ERRCLS_INT_PAR)
359       /* error check on parameters */
360       if (pollFdArr == NULLP)
361       {
362 #ifdef CMINETDBG
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 */      
367          RETVALUE(RFAILED);
368       }
369 #endif /* ERRCLASS & ERRCLS_INT_PAR */
370
371    ret = poll(pollFdArr,numFds,timeout);
372    if (ret == 0)
373    { 
374       RETVALUE(RTIMEOUT);
375    }
376    if (ret == INET_ERR)
377    {
378       switch(INET_ERR_CODE)
379       {
380          case ERR_EINTR:
381             RETVALUE(ROKDNA);
382
383          default:
384 #ifdef CMINETDBG
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);
388             SPrint(prntBuf);
389 #endif /* CMINETDBG */
390             RETVALUE(RFAILED);
391
392       } /* end of switch */
393    }
394    
395    *numRdyFds = (S16)ret;
396   
397    RETVALUE(ROK);
398
399 }
400
401 /*
402 *
403 *      Fun:   cmInetPollSetFd
404 *
405 *      Desc:  Set the selected fd in pollFdArr with event eventMask
406 *
407 *      Ret:   RFAILED : if file descriptor is out of range
408 *             ROK     : if pollFdArr is set.
409 *
410 *      Notes: None
411 *
412 *      File:  cm_inet.c
413 *
414 */
415
416 #ifdef ANSI
417 PUBLIC S16 cmInetPollSetFd
418 (
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 */
423 )
424 #else
425 PUBLIC 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 */
430 #endif
431 {
432    
433    TRC2(cmInetPollSetFd); 
434
435    if ((idx) >= CM_INET_POLL_MAXFDSUPP || (idx) < 0)
436    {
437 #ifdef CMINETDBG
438       /* cm_inet_c_001.main_62:Warning fix */
439       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollSetFd() : Invalid idx(%d) \n",idx);
440       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
441 #endif /* CMINETDBG */
442
443       RETVALUE(RFAILED);
444    }
445
446 #if (ERRCLASS & ERRCLS_INT_PAR)
447       /* error check on parameters */
448       if (pollFdArr == NULLP)
449       {
450 #ifdef CMINETDBG
451       /* cm_inet_c_001.main_62:Warning fix */
452       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollSetFd() : Invalid Parameter (pollFdArr is NULL)");
453       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
454 #endif /* CMINETDBG */      
455          RETVALUE(RFAILED);
456       }
457 #endif /* ERRCLASS & ERRCLS_INT_PAR */
458
459 #ifdef CMINETDBG
460 #ifndef ALIGN_64BIT
461       /* cm_inet_c_001.main_62:Warning fix */
462       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, 
463                "cmInetPollSetFd() Before Setting fd : sockFd->fd(%d) Index(%d) Event(%d) \n Fd and event to be set   fd(%ld) event(%d) \n",
464                pollFdArr[idx].fd,idx, pollFdArr[idx].events,sockFd->fd,eventMask);
465       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf); 
466 #else
467       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,
468                "cmInetPollSetFd() Before Setting fd: sockFd->fd(%d) Index(%d) Event(%d) \n Fd and event to be set   fd(%d) event(%d) \n",
469                pollFdArr[idx].fd,idx, pollFdArr[idx].events,sockFd->fd,eventMask);
470       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
471 #endif /*ALIGN_64BIT */
472 #endif /* CMINETDBG */
473
474 /* Setting fd and events with eventMask */
475    pollFdArr[idx].fd = sockFd->fd;
476    pollFdArr[idx].events |= eventMask;
477
478
479 #ifdef CMINETDBG
480 #ifndef ALIGN_64BIT
481       /* cm_inet_c_001.main_62:Warning fix */
482       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollSetFd() After Setting fd: sockFd->fd(%d) Index(%d) Event(%d) \n",
483             pollFdArr[idx].fd,idx, pollFdArr[idx].events);
484       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
485 #else
486       /* cm_inet_c_001.main_62:Warning fix */
487       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollSetFd() After Setting fd: sockFd->fd(%d) Index(%d) Event(%d) \n",
488             pollFdArr[idx].fd,idx, pollFdArr[idx].events);
489       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
490 #endif /*ALIGN_64BIT */
491 #endif /* CMINETDBG */
492
493    RETVALUE(ROK);
494
495 }
496
497
498 /*
499 *
500 *      Fun:   cmInetPollFdIsSet
501 *
502 *      Desc:  Checks whether fd is selected
503 *
504 *      Ret:   TRUE : If Fd is Selected
505 *             FALSE: If Fd is not Selected
506 *
507 *      Notes: None
508 *
509 *      File:  cm_inet.c
510 *
511 */
512
513 #ifdef ANSI
514 PUBLIC S16 cmInetPollFdIsSet
515 (
516 CmInetPollFd  *pollFdArr,            /* poll FD Array */
517 S16               idx,               /* poll Fd Array Index */
518 U16               eventMask          /* Event Mask to be set */
519 )
520 #else
521 PUBLIC S16 cmInetPollFdIsSet(pollFdArr,idx,eventMask)
522 CmInetPollFd  *pollFdArr;            /* poll FD Array */
523 S16               idx;               /* poll Fd Array Index */
524 U16               eventMask;         /* Event Mask to be set */
525 #endif
526 {
527    S16  ret;
528
529    TRC2(cmInetPollFdIsSet); 
530
531    if((idx < 0) || (idx > CM_INET_POLL_MAXFDSUPP))
532    {
533 #ifdef CMINETDBG
534       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollFdIsSet() : Invalid Index (%d) \n",idx);
535       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
536 #endif /* CMINETDBG */
537       RETVALUE(RFAILED);
538    }
539
540 #if (ERRCLASS & ERRCLS_INT_PAR)
541       /* error check on parameters */
542       if (pollFdArr == NULLP)
543       {
544 #ifdef CMINETDBG
545       /* cm_inet_c_001.main_62:Warning fix */
546       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollFdIsSet() : Invalid Parameter (pollFdArr is NULL)");
547       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
548 #endif /* CMINETDBG */      
549          RETVALUE(RFAILED);
550       }
551 #endif /* ERRCLASS & ERRCLS_INT_PAR */
552
553    ret = (pollFdArr[idx].revents & eventMask);
554
555    RETVALUE(ret);
556 }
557
558 /*
559 *
560 *      Fun:   cmInetPollClearFdREvent
561 *
562 *      Desc:  clears the reventMask in revent of the givent FD.
563 *
564 *      Ret:   ROK
565 *             
566 *
567 *      Notes: None
568 *
569 *      File:  cm_inet.c
570 *
571 */
572
573 #ifdef ANSI
574 PUBLIC S16 cmInetPollClearFdREvent
575 (
576 CmInetPollFd  *pollFdArr,            /* poll FD Array */
577 S16               idx,               /* poll Fd Array Index */
578 U16               eventMask          /* Event Mask to be set */
579 )
580 #else
581 PUBLIC S16 cmInetPollClearFdREvent(sockFd,pollFdArr,eventMask)
582 CmInetPollFd  *pollFdArr;            /* poll FD Array */
583 S16               idx;               /* poll Fd Array Index */
584 U16               eventMask;         /* Event Mask to be set */
585 #endif
586 {
587
588    TRC2(cmInetPollClearFdREvent); 
589
590
591    if((idx < 0) || (idx > CM_INET_POLL_MAXFDSUPP))
592    {
593 #ifdef CMINETDBG
594       /* cm_inet_c_001.main_62:Warning fix */
595       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() : Invalid Index (%d) \n",idx);
596       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
597 #endif /* CMINETDBG */
598       RETVALUE(RFAILED);
599    }
600
601 #if (ERRCLASS & ERRCLS_INT_PAR)
602       /* error check on parameters */
603       if (pollFdArr == NULLP)
604       {
605 #ifdef CMINETDBG
606       /* cm_inet_c_001.main_62:Warning fix */
607       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() : Invalid Parameter (pollFdArr is NULL)");
608       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
609 #endif /* CMINETDBG */      
610          RETVALUE(RFAILED);
611       }
612 #endif /* ERRCLASS & ERRCLS_INT_PAR */
613
614 #ifdef CMINETDBG
615 #ifndef ALIGN_64BIT
616       /* cm_inet_c_001.main_62:Warning fix */
617       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() Before clearing fd revents with eventMask: \n sockFd->fd(%d) Index(%d) REvent(%d) EventMask(%d) \n",
618             pollFdArr[idx].fd,idx, pollFdArr[idx].revents,eventMask);
619       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
620 #else
621       /* cm_inet_c_001.main_62:Warning fix */
622       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() Before clearing fd revents with eventMask: \n sockFd->fd(%d) Index(%d) REvent(%d) EventMask(%d) \n",
623             pollFdArr[idx].fd,idx, pollFdArr[idx].revents,eventMask);
624       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
625 #endif /*ALIGN_64BIT */
626 #endif /* CMINETDBG */
627
628 /* Clearing the events with eventMask */
629    pollFdArr[idx].revents = (pollFdArr[idx].revents & (~(eventMask)));
630
631 #ifdef CMINETDBG
632 #ifndef ALIGN_64BIT
633       /* cm_inet_c_001.main_62:Warning fix */
634       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() After clearing fd revents with eventMask: \n sockFd->fd(%d) Index(%d) REvent(%d) EventMask(%d) \n",
635             pollFdArr[idx].fd,idx, pollFdArr[idx].revents,eventMask);
636       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
637 #else
638       /* cm_inet_c_001.main_62:Warning fix */
639       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdREvent() After clearing fd revents with eventMask: \n sockFd->fd(%d) Index(%d) REvent(%d) EventMask(%d) \n",
640             pollFdArr[idx].fd,idx, pollFdArr[idx].revents,eventMask);
641       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
642 #endif /*ALIGN_64BIT */
643 #endif /* CMINETDBG */
644
645    RETVALUE(ROK);
646
647 }
648
649
650 /*
651 *
652 *      Fun:   cmInetPollClearFdEvent
653 *
654 *      Desc:  clears the eventMask in event of the givent FD.
655 *
656 *      Ret:   ROK
657 *             
658 *
659 *      Notes: None
660 *
661 *      File:  cm_inet.c
662 *
663 */
664
665 #ifdef ANSI
666 PUBLIC S16 cmInetPollClearFdEvent
667 (
668 CmInetPollFd  *pollFdArr,            /* poll FD Array */
669 S16               idx,               /* poll Fd Array Index */
670 U16               eventMask          /* Event Mask to be set */
671 )
672 #else
673 PUBLIC S16 cmInetPollClearFdEvent(sockFd,pollFdArr,eventMask)
674 CmInetPollFd   *pollFdArr;            /* poll FD Array */
675 S16             idx;                  /* poll Fd Array Index */
676 U16             eventMask;            /* Event Mask to be set */
677 #endif
678 {
679
680    TRC2(cmInetPollClearFdEvent); 
681
682
683    if((idx < 0) || (idx > CM_INET_POLL_MAXFDSUPP))
684    {
685 #ifdef CMINETDBG
686       /* cm_inet_c_001.main_62:Warning fix */
687       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() : Invalid Index (%d) \n",idx);
688       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
689 #endif /* CMINETDBG */
690       RETVALUE(RFAILED);
691    }
692
693 #if (ERRCLASS & ERRCLS_INT_PAR)
694       /* error check on parameters */
695       if (pollFdArr == NULLP)
696       {
697 #ifdef CMINETDBG
698       /* cm_inet_c_001.main_62:Warning fix */
699       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() : Invalid Parameter (pollFdArr is NULL)");
700       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
701 #endif /* CMINETDBG */      
702          RETVALUE(RFAILED);
703       }
704 #endif /* ERRCLASS & ERRCLS_INT_PAR */
705
706 #ifdef CMINETDBG
707 #ifndef ALIGN_64BIT
708       /* cm_inet_c_001.main_62:Warning fix */
709       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() Before clearing fd events with eventMask: \n sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
710             pollFdArr[idx].fd,idx, pollFdArr[idx].events,eventMask);
711       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
712 #else
713       /* cm_inet_c_001.main_62:Warning fix */
714       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() Before clearing fd events with eventMask:\n  sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
715             pollFdArr[idx].fd,idx, pollFdArr[idx].events,eventMask);
716       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
717 #endif /*ALIGN_64BIT */
718 #endif /* CMINETDBG */
719
720 /* Clearing events with eventMask */
721    pollFdArr[idx].events = (pollFdArr[idx].events & (~(eventMask)));
722
723 #ifdef CMINETDBG
724 #ifndef ALIGN_64BIT
725       /* cm_inet_c_001.main_62:Warning fix */
726       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() After clearing fd events with eventMask: sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
727             pollFdArr[idx].fd,idx, pollFdArr[idx].events,eventMask);
728       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
729 #else
730       /* cm_inet_c_001.main_62:Warning fix */
731       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollClearFdEvent() After clearing fd events with eventMask: sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
732             pollFdArr[idx].fd,idx, pollFdArr[idx].events,eventMask);
733       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
734 #endif /*ALIGN_64BIT */
735 #endif /* CMINETDBG */
736
737    RETVALUE(ROK);
738
739 }
740
741
742 /*
743 *
744 *      Fun:   cmInetPollDelFd
745 *
746 *      Desc:  Delete the given FD from the pollFdArray
747 *             delIdx : Poll Fd Array Index at which fd has to be deleted.
748 *             lastIdx: Last index of poll fd array.
749 *
750 *             It deletes fd from array by swapping lastIdx pollFd
751 *             values to index to be deleted and deinitializes the 
752 *             lastIdx values.
753 *
754 *      Ret:   ROK
755 *             
756 *
757 *      Notes: It does not decrement the lastIdx and it has to be 
758 *             decremented by the caller of this function.
759 *
760 *      File:  cm_inet.c
761 *
762 */
763
764 #ifdef ANSI
765 PUBLIC S16 cmInetPollDelFd
766 (
767 CmInetPollFd  *pollFdArr,             /* poll FD Array */
768 S16               delIdx,             /* poll Fd Array Index for which fd has to be deleted*/
769 S16               lastIdx             /* Last index of poll Fd Array */
770 )
771 #else
772 PUBLIC S16 cmInetPollDelFd(pollFdArr, delIdx, lastIdx)
773 CmInetPollFd  *pollFdArr;            /* poll FD Array */
774 S16               delIdx;            /* poll Fd Array Index for which fd has to be deleted*/
775 S16               lastIdx;           /* Last index of poll Fd Array */
776 #endif
777 {
778
779    TRC2(cmInetPollDelFd); 
780
781    if(lastIdx < delIdx || lastIdx < 0 || delIdx < 0)
782    {
783 #ifdef CMINETDBG
784       /* cm_inet_c_001.main_62:Warning fix */
785       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollDelFd() : Invalid Index \n Current Index (%d) Delete Index (%d) \n",lastIdx,delIdx);
786       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
787 #endif /* CMINETDBG */
788       RETVALUE(RFAILED);
789    }
790
791
792 #if (ERRCLASS & ERRCLS_INT_PAR)
793       /* error check on parameters */
794       if (pollFdArr == NULLP)
795       {
796 #ifdef CMINETDBG
797       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollDelFd() : Invalid Parameter (pollFdArr is NULL)");
798       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
799 #endif /* CMINETDBG */      
800          RETVALUE(RFAILED);
801       }
802 #endif /* ERRCLASS & ERRCLS_INT_PAR */
803
804 #ifdef CMINETDBG
805 #ifndef ALIGN_64BIT
806       /* cm_inet_c_001.main_62:Warning fix */
807       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollDelFd() Deleting the sockFd->fd(%d) Index(%d) Event(%d) revent(%d) \n",
808             pollFdArr[delIdx].fd,delIdx, pollFdArr[delIdx].events,pollFdArr[delIdx].revents);
809       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
810 #else
811       /* cm_inet_c_001.main_62:Warning fix */
812       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollDelFd() After clearing fd events with eventMask: sockFd->fd(%d) Index(%d) Event(%d) EventMask(%d) \n",
813             pollFdArr[delIdx].fd,delIdx, pollFdArr[delIdx].events,pollFdArr[delIdx].revents);
814       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
815 #endif /*ALIGN_64BIT */
816 #endif /* CMINETDBG */
817
818    pollFdArr[delIdx].fd = pollFdArr[lastIdx].fd;
819    pollFdArr[delIdx].events = pollFdArr[lastIdx].events;
820    pollFdArr[delIdx].revents = pollFdArr[lastIdx].revents;
821
822    pollFdArr[lastIdx].fd = -1;
823    pollFdArr[lastIdx].events = 0;
824    pollFdArr[lastIdx].revents = 0;
825    
826    RETVALUE(ROK);
827
828 }
829
830 /*
831 *
832 *      Fun:   cmInetPollInitFdArr
833 *
834 *      Desc: Cleans all elements of fd array. 
835 *
836 *      Ret:   ROK
837 *             
838 *
839 *      Notes:  It does not allocates/deallocates memory for Poll Fd Array.
840 *              Caller of function has to allocate/deallocate memory for 
841 *              array.
842 *
843 *      File:  cm_inet.c
844 *
845 */
846
847 #ifdef ANSI
848 PUBLIC S16 cmInetPollInitFdArr
849 (
850 CmInetPollFd  *pollFdArr             /* poll FD Array */
851 )
852 #else
853 PUBLIC S16 cmInetPollInitFdArr(pollFdArr)
854 CmInetPollFd  *pollFdArr;            /* poll FD Array */
855 #endif
856 {
857    S16 idx;
858
859    TRC2(cmInetPollInitFdArr); 
860 /* Sets each element of pollFdArr to initial value
861    fd = -1
862    events = 0
863    revents = 0
864 */
865 #if (ERRCLASS & ERRCLS_INT_PAR)
866       /* error check on parameters */
867       if (pollFdArr == NULLP)
868       {
869 #ifdef CMINETDBG
870       /* cm_inet_c_001.main_62:Warning fix */
871       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetPollInitFdArr() : Invalid Parameter (pollFdArr is NULL)");
872       CMINETLOGERROR(ERRCLS_DEBUG, ECMINETXXX, 0, prntBuf);
873 #endif /* CMINETDBG */      
874          RETVALUE(RFAILED);
875       }
876 #endif /* ERRCLASS & ERRCLS_INT_PAR */
877
878    for(idx=0; idx < CM_INET_POLL_MAXFDSUPP; idx++)
879    {
880       pollFdArr[idx].fd = -1;
881       pollFdArr[idx].events = 0;
882       pollFdArr[idx].revents = 0;
883    }
884    RETVALUE(ROK);
885 }
886
887 #if (!(defined(WIN32)) && !(defined(CMINETFLATBUF)))
888 /*
889 *
890 *      Fun:   buildRecvBuf
891 *
892 *      Desc:  Allocates dBufs to receive an entire message.
893 *
894 *      Ret:   ROK     - successful
895 *             RFAILED - failed
896 *             ROUTRES - failed, out of resources
897 *
898 *      Notes: None
899 *
900 *      File:  cm_inet.c
901 *
902 */
903
904 #ifdef ANSI
905 PRIVATE S16 buildRecvBuf
906 (
907 CmInetMemInfo  *info,           /* buffer allocation info */
908 MsgLen          len,            /* message length */
909 CmInetIovec     rxArr[],        /* gather array */
910 Buffer         *dBuf[],         /* allocated dBufs */
911 U16             maxSize,        /* size of rxArr/dBuf array */       
912 struct msghdr  *msg,            /* message header for recvmsg() */           
913 Bool           isStrmMsg        /* Is a TCP message */
914 )
915 #else
916 PRIVATE S16 buildRecvBuf(info, len, rxArr, dBuf, maxSize, msg, isStrmMsg)
917    CmInetMemInfo   *info;          /* buffer allocation info */
918    MsgLen           len;           /* message length */        
919    CmInetIovec      rxArr[];       /* gather array */         
920    Buffer          *dBuf[];        /* allocated dBufs */
921    U16              maxSize;       /* size of rxArr/dBuf array */       
922    struct msghdr   *msg;           /* message header for recvmsg() */        
923    Bool            isStrmMsg;      /* Is a TCP message */
924 #endif
925 {
926    S16     ret;                 /* temporary return value */
927    U16     numBuf;              /* number of dBufs */
928    U16     i;                   /* dBuf index counter */
929    Data   *dPtr;                /* data pointer */
930    /* cm_inet_c_001.main_47: 102069 Changed from S32 to MsgLen for bufLen*/
931    MsgLen  bufLen;              /* entire receive buffer length, if S16 
932                                    could wrap to negative number */
933    MsgLen  dLen;                /* buffer length */ 
934
935    numBuf = 0;
936    bufLen = 0; 
937
938    /* Initialise ret and part of msg here */
939    ret = ROK;
940
941    /* added defined(_XPG4_2) */
942    /* Moved initialisation of msg here. */
943
944 #if (defined(SS_LINUX) || defined(_XPG4_2))
945    msg->msg_control    = NULLP;
946    msg->msg_controllen  = 0;
947 #else
948    msg->msg_accrights     = NULLP;
949    msg->msg_accrightslen  = 0;
950 #endif /* SS_LINUX */   
951
952    /* Check if maxSize if enough to hold the entire message length before 
953     * going into the loop. If the boolean isStrmMsg is TRUE then the recv 
954     * buf is built even if the whole message cannot be accomodated. */
955
956 #ifdef T2K_MEM_LEAK_DBG
957    char * file = __FILE__;
958    U32  line   = __LINE__;
959    ret = SGetDBuf(info->region, info->pool, &dBuf[numBuf]); 
960 #else
961    ret = SGetDBuf(info->region, info->pool, &dBuf[numBuf]); 
962 #endif
963    if (ret != ROK)
964       RETVALUE(ret);
965
966    /* Get the data part */
967    ret = SGetDataRx(dBuf[numBuf], 0, &dPtr, &dLen);
968    if (ret != ROK)
969    {
970       numBuf++;           /* because of cleanup */
971       goto cleanup;
972    }
973
974    if (!isStrmMsg)
975    {
976       /* The assumption here is that all dBuf's from a given region and 
977        * pool have a constance size */
978       if (len > (maxSize * dLen))
979       {
980          ret = RNA;
981          numBuf++;           /* because of cleanup */
982          goto cleanup;
983       }
984    }
985
986 #ifdef SS_LINUX
987   rxArr[numBuf].iov_base = (Void*)dPtr;  
988   rxArr[numBuf].iov_len = (U32)dLen;    
989 #else
990   rxArr[numBuf].iov_base = (S8*)dPtr;
991   rxArr[numBuf].iov_len = dLen;
992 #endif /* SS_LINUX */
993
994   bufLen += dLen;
995   numBuf++;  
996
997    /* allocate buffer space for entire message length */
998    while (bufLen < len)
999    {
1000       if (numBuf >= maxSize)
1001       {
1002          /* to big to fit in gather vector array */ 
1003          ret = RNA;
1004          break;
1005       }
1006       ret = SGetDBuf(info->region, info->pool, &dBuf[numBuf]); 
1007       if (ret != ROK)
1008       {
1009          goto cleanup;
1010       } 
1011       ret = SGetDataRx(dBuf[numBuf], 0, &dPtr, &dLen);
1012       if (ret != ROK)
1013       {
1014          numBuf++;           /* because of cleanup */
1015          goto cleanup;
1016       }
1017 #ifdef SS_LINUX
1018       rxArr[numBuf].iov_base = (Void*)dPtr;  
1019       rxArr[numBuf].iov_len = (U32)dLen;    
1020 #else
1021       rxArr[numBuf].iov_base = (S8*)dPtr;
1022       rxArr[numBuf].iov_len = dLen;
1023 #endif /* SS_LINUX */
1024
1025       bufLen += dLen;
1026       numBuf++;  
1027    }
1028    /* adjust last buffer length */
1029    /*  check if we broke out because numBuf >= maxSize */
1030    if (bufLen < len)
1031       rxArr[numBuf - 1].iov_len = dLen;
1032    else
1033       rxArr[numBuf - 1].iov_len = dLen - (bufLen - len); 
1034
1035    /* setup recvmsg() message header */
1036    msg->msg_iov           = rxArr;
1037    msg->msg_iovlen        = numBuf;
1038
1039    RETVALUE(ret);
1040
1041 cleanup:
1042    /* cleanup */
1043    for (i = 0; i < numBuf; i++)
1044       SPutDBuf(info->region, info->pool, dBuf[i]);
1045
1046    msg->msg_iovlen = 0;
1047
1048    RETVALUE(ret);
1049 } /* end of buildRecvBuf */
1050
1051 /*
1052 *
1053 *      Fun:   buildRecvMsg
1054 *
1055 *      Desc:  Builds a message out of the received dBufs.
1056 *
1057 *      Ret:   ROK     - successful
1058 *             RFAILED - failed
1059 *             ROUTRES - failed, out of resources
1060 *
1061 *      Notes: None
1062 *
1063 *      File:  cm_inet.c
1064 *
1065 */
1066
1067 #ifdef ANSI
1068 PRIVATE S16 buildRecvMsg
1069 (
1070 CmInetMemInfo  *info,           /* buffer allocation info */
1071 CmInetIovec     rxArr[],        /* scatter array */  
1072 S16             numBuf,         /* number of allocated dBufs */
1073 MsgLen          msgLen,         /* message length */
1074 Buffer         *dBufs[],        /* dBufs */
1075 Buffer        **mPtr            /* message built from dBufs */     
1076 )
1077 #else
1078 PRIVATE S16 buildRecvMsg(info, rxArr, numBuf, msgLen, dBufs, mPtr)
1079 CmInetMemInfo  *info;           /* buffer allocation info */   
1080 CmInetIovec     rxArr[];        /* scatter array */            
1081 S16             numBuf;         /* number of allocated dBufs */
1082 MsgLen          msgLen;         /* length of one particular dBuf */          
1083 Buffer         *dBufs[];        /* dBufs */
1084 Buffer        **mPtr;           /* message built from dBufs */   
1085 #endif
1086 {
1087    S16      ret;                 /* return value */ 
1088    S16      i;                   /* dBuf index counter */
1089    MsgLen   bufLen;              /* length of one particular dBuf */
1090    /* cm_inet_c_001.main_54: Fix for Klockworks issue */
1091    Buffer  *mBuf = NULLP;        /* allocated message */  
1092
1093    ret = RFAILED;   
1094    i   = 0;
1095
1096    /* build message */
1097    ret = SGetMsg(info->region, info->pool, &mBuf);
1098    if (ret != ROK)
1099    {
1100       goto cleanup;
1101    }
1102
1103    /* link buffers to message */
1104    while (i < numBuf)
1105    {
1106       /* cm_inet_c_001.main_58: fix for klockwork issue */
1107       bufLen = (MsgLen)rxArr[i].iov_len; 
1108       if (msgLen < bufLen)
1109       {
1110          bufLen = msgLen;
1111       }
1112       ret = SUpdMsg(mBuf, dBufs[i], bufLen);
1113       if (ret != ROK)
1114       { 
1115          SPutMsg(mBuf);
1116          goto cleanup;
1117       }
1118       msgLen -= bufLen;
1119       i++;
1120       if (msgLen <= 0)
1121       {
1122          ret = ROK;      
1123          break;
1124       }
1125    }
1126
1127    *mPtr = mBuf;
1128
1129 cleanup:
1130    /* cleanup unused buffers */
1131    while (i < numBuf)
1132    {
1133 #ifdef T2K_MEM_LEAK_DBG
1134    char * file = __FILE__;
1135    U32  line   = __LINE__;
1136    SPutDBuf(info->region, info->pool, dBufs[i]);
1137 #else
1138    SPutDBuf(info->region, info->pool, dBufs[i]);
1139 #endif
1140     i++;
1141    }
1142
1143    RETVALUE(ret);
1144 } /* end of buildRecvMsg */
1145
1146 \f
1147
1148 /*
1149 *
1150 *      Fun:   buildSendIovec 
1151 *
1152 *      Desc:  Builds a io vector to send a message.
1153 *
1154 *      Ret:   ROK     - successful
1155 *             RFAILED - failed
1156 *             ROUTRES - failed, out of resources
1157 *             RNA     - failed, not available, indicates that the
1158 *                       maximum number of dBufs are not sufficient
1159 *                       to hold the entire message.
1160 *
1161 *      Notes: None
1162 *
1163 *      File:  cm_inet.c
1164 *
1165 */
1166 #ifdef ANSI
1167 PRIVATE S16 buildSendIovec
1168 (
1169 Buffer         *mBuf,           /* Message buffer */
1170 MsgLen         msgLen,          /* Length of mBuf */
1171 CmInetIovec    txArr[],         /* transmit scatter vector array */ 
1172 S16            numDBufs,        /* Maximum number of dBufs to use */
1173 S16            *numIovElems,    /* Number of iov elements in array */
1174 U32            *strtEndDBufNum, /* dBuf number to start and end */
1175 MsgLen         *ioLen           /* cm_inet_c_001.main_50 - Len of dbuf packed into IO-vector */ 
1176 )
1177 #else
1178 PRIVATE S16 buildSendIovec(mBuf, msgLen, txArr, numDBufs, numIovElems, 
1179                            strtEndDBufNum,ioLen) 
1180 Buffer         *mBuf;           /* Message buffer */
1181 MsgLen         msgLen;          /* Length of mBuf */
1182 CmInetIovec    txArr[];         /* transmit scatter vector array */ 
1183 S16            numDBufs;        /* Maximum number of dBufs to use */
1184 S16            *numIovElems;    /* Number of iov elements in array */
1185 U32            *strtEndDBufNum; /* dBuf number to start and end */
1186 MsgLen         *ioLen;          /* cm_inet_c_001.main_50 - Len of dbuf packed into IO-vector */ 
1187 #endif
1188 {
1189    S16         ret;
1190    MsgLen      dLen;
1191    S16         iovIdx;       
1192    Buffer      *dBuf;
1193    Data        *dPtr;
1194    MsgLen      allocLen;
1195    U32         dBufsToSkip;
1196
1197    /* Initialisations */
1198    (*numIovElems) = 0;
1199    iovIdx = 0;
1200    allocLen = 0;
1201
1202    /* cm_inet_c_001.main_50 - Intialize the newly added parameter */
1203    *ioLen = 0;
1204
1205    /* Set up vector for gathering send */
1206    ret = SInitNxtDBuf(mBuf);
1207    if (ret != ROK)
1208    {
1209       RETVALUE(RFAILED);
1210    }
1211
1212    iovIdx = 0;
1213    txArr[iovIdx].iov_len = 0;
1214
1215    if ((*strtEndDBufNum != 0))
1216    {
1217       /* Skip through the required number of dBufs */
1218       dBufsToSkip = *strtEndDBufNum;
1219
1220       while(dBufsToSkip)
1221       {
1222          ret = SGetNxtDBuf(mBuf, &dBuf);
1223          if (ret != ROK)
1224             RETVALUE(RFAILED);
1225          dBufsToSkip --;
1226       }
1227    }
1228
1229    for (;;)
1230    {
1231       ret = SGetNxtDBuf(mBuf, &dBuf);
1232       if (ret == ROK)
1233       {
1234          ret = SGetDataTx(dBuf, &dPtr, &dLen);
1235          if (ret != ROK)
1236          {  
1237             ret = RFAILED;
1238             break;
1239          }
1240
1241          txArr[iovIdx].iov_base = (S8 *)dPtr;
1242          txArr[iovIdx].iov_len = dLen;
1243
1244          allocLen += dLen;
1245       }
1246       else if  (ret == ROKDNA)
1247       {  
1248          ret = ROK;
1249          break;
1250       }
1251       else
1252       {
1253          ret = RFAILED;
1254          break;
1255       }
1256
1257       iovIdx += 1;
1258
1259       if (iovIdx >= numDBufs)
1260       {
1261          if (allocLen >= msgLen)
1262             ret = ROK;
1263          else
1264             ret = RNA;
1265          break;
1266       }
1267    }
1268
1269    (*numIovElems) = iovIdx;
1270    (*strtEndDBufNum) += iovIdx;
1271
1272    /* cm_inet_c_001.main_50 - Assign the value of dbufs packed in IO-vector */
1273    *ioLen = allocLen;
1274
1275    RETVALUE(ret);
1276
1277 } /* end of buildSendIovec */
1278 #endif /* (defined(WIN32)) && !(defined(CMINETFLATBUF)) */
1279
1280 \f
1281 /*
1282 *
1283 *      Fun:   cmInetSocket
1284 *
1285 *      Desc:  Creates an Internet socket descriptor.
1286 *             On default the socket is non-blocking ( can be changed 
1287 *             with the function cmInetSetOpt()).
1288 *             Values for type:
1289 *
1290 *             CM_INET_STREAM   (TCP)
1291 *             CM_INET_DGRAM    (UDP)
1292 *
1293 *      Ret:   ROK     - successful
1294 *             RFAILED - failed
1295 *
1296 *      Notes: None
1297 *
1298 *      File:  cm_inet.c
1299 *
1300 */
1301 #ifdef ANSI
1302 #ifdef CM_INET2  
1303 #ifdef IPV6_SUPPORTED
1304 PUBLIC S16 cmInetSocket
1305 (
1306 U8        type,                 /* socket type */
1307 CmInetFd *sockFd,               /* socket file descriptor */
1308 U8       protocol,              /* protocol value */
1309 U8       domain                 /* domain */
1310 )
1311 #else
1312 PUBLIC S16 cmInetSocket
1313 (
1314 U8        type,                 /* socket type */
1315 CmInetFd *sockFd,               /* socket file descriptor */
1316 U8       protocol               /* protocol value */
1317 )
1318 #endif /* IPV6_SUPPORTED */
1319 #else   /* CM_INET2 */ 
1320 PUBLIC S16 cmInetSocket
1321 (
1322 U8        type,                 /* socket type */
1323 CmInetFd *sockFd                /* socket file descriptor */
1324 )
1325 #endif /* CM_INET2 */ 
1326 #else
1327 #ifdef CM_INET2  
1328 #ifdef IPV6_SUPPORTED
1329 PUBLIC S16 cmInetSocket(type, sockFd, protocol, domain)
1330 U8        type;                 /* socket type */
1331 CmInetFd *sockFd;               /* socket file descriptor */
1332 U8        protocol;             /* protocol value */
1333 U8        domain;               /* domain */
1334 #else
1335 PUBLIC S16 cmInetSocket(type, sockFd, protocol)
1336 U8        type;                 /* socket type */
1337 CmInetFd *sockFd;               /* socket file descriptor */
1338 U8        protocol;             /* protocol value */
1339 #endif /* IPV6_SUPPORTED */
1340 #else /* CM_INET2 */ 
1341 PUBLIC S16 cmInetSocket(type, sockFd)
1342 U8        type;                 /* socket type */
1343 CmInetFd *sockFd;               /* socket file descriptor */
1344 #endif /* CM_INET2 */ 
1345 #endif /* ANSI */
1346 {
1347    S32 ret;                     /* temporary return value */
1348
1349    U32 optVal;
1350
1351 #if (defined(WIN32) && defined(WIN2K))
1352    S32 bytesReturned;
1353    Bool bNewBehavior;
1354 #endif /* WIN2K && WIN32 */
1355
1356    TRC2(cmInetSocket);
1357
1358 #if (defined(WIN32) && defined(WIN2K))
1359    bytesReturned = 0;
1360    bNewBehavior = FALSE;
1361 #endif /* WIN32 && WIN2K */  
1362
1363    /* create socket */
1364 #ifdef CM_INET2  
1365 #ifdef IPV6_SUPPORTED
1366    sockFd->fd = socket(domain, type, protocol);
1367 #else
1368    sockFd->fd = socket(AF_INET, type, protocol);
1369 #endif /* IPV6_SUPPORTED */
1370 #else   /* CM_INET2 */ 
1371    sockFd->fd = socket(AF_INET, type, 0);
1372 #endif  /* CM_INET2 */ 
1373    if (CM_INET_INV_SOCK_FD(sockFd))
1374    {   
1375 #ifdef CMINETDBG
1376 #ifndef ALIGN_64BIT
1377       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1378       /* cm_inet_c_001.main_62:Warning fix */
1379       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSocket() Failed : errno(%d), sockFd->fd(%ld)\n", 
1380             INET_ERR_CODE, sockFd->fd);
1381       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET001, 0, prntBuf);
1382 #else
1383       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSocket() Failed : errno(%d), sockFd->fd(%d)\n", 
1384             INET_ERR_CODE, sockFd->fd);
1385       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET001, 0, prntBuf);
1386 #endif /*ALIGN_64BIT */
1387 #endif /* CMINETDBG */
1388       /* Set sockFd->fd to invalid socket */
1389       sockFd->fd = CM_INET_INV_SOCKFD;
1390       RETVALUE(RFAILED);   
1391    }
1392
1393    /* set socket type */
1394    sockFd->type = type;
1395
1396    /* set socket protocol type (IPv4/IPv6) */
1397 #ifdef IPV6_SUPPORTED   
1398    sockFd->protType = domain; 
1399 #endif /* IPV6_SUPPORTED */
1400
1401    /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
1402 #ifdef CM_LKSCTP
1403    if (protocol != IPPROTO_SCTP)
1404    {
1405 #endif
1406    /* set default options */
1407    optVal = CM_INET_OPT_DISABLE;
1408    ret = cmInetSetOpt(sockFd, SOL_SOCKET, CM_INET_OPT_BLOCK, (Ptr)&optVal); 
1409    if (ret != ROK) 
1410    {
1411       ret = cmInetClose(sockFd);
1412       RETVALUE(RFAILED);
1413    }
1414
1415 #ifdef SS_LINUX
1416 #ifndef CMINET_BSDCOMPAT
1417    optVal = CM_INET_OPT_ENABLE;
1418    ret = cmInetSetOpt(sockFd, SOL_SOCKET, CM_INET_OPT_BSD_COMPAT, (Ptr)&optVal);
1419    if (ret != ROK) 
1420    {
1421       ret = cmInetClose(sockFd);
1422       RETVALUE(RFAILED);
1423    }
1424 #endif /* CMINET_BSDCOMPAT */
1425 #endif /* SS_LINUX */
1426
1427 #if (defined(WIN32) && defined(WIN2K))   
1428    if(type == CM_INET_DGRAM)
1429       {
1430          ret = WSAIoctl(sockFd->fd, SIO_UDP_CONNRESET, &bNewBehavior,
1431                sizeof(bNewBehavior), NULLP, 0, &bytesReturned,
1432                NULLP, NULLP);
1433          if(ret == INET_ERR)
1434          {
1435 #ifdef CMINETDBG
1436 #ifndef ALIGN_64BIT
1437             /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
1438             /* cm_inet_c_001.main_62:Warning fix */
1439             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "WSAIoctl() Failed : error(%d), sockFd->fd(%ld)\n", 
1440                   INET_ERR_CODE, sockFd->fd);
1441             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET002, 0, prntBuf);
1442 #else
1443             /* cm_inet_c_001.main_62:Warning fix */
1444             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "WSAIoctl() Failed : error(%d), sockFd->fd(%d)\n", 
1445                   INET_ERR_CODE, sockFd->fd);
1446             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET002, 0, prntBuf);
1447 #endif /*ALIGN_64BIT*/
1448 #endif /* CMINETDBG */      
1449             ret = cmInetClose(sockFd);
1450             RETVALUE(RFAILED);
1451          }
1452       }
1453 #endif /* WIN2K && WIN32 */   
1454       /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
1455 #ifdef CM_LKSCTP
1456    }
1457 #ifdef CM_LKSCTP_NONBLOCK
1458    else
1459    {
1460       /* cm_inet_c_001.main_47:if non-blocking SCTP socket compile time
1461        *        * flag is set then even for kernel SCTP make the socket
1462        *               * non-blocking
1463        *                      */
1464       optVal = CM_INET_OPT_DISABLE;
1465       ret = cmInetSetOpt(sockFd, SOL_SOCKET, CM_INET_OPT_BLOCK, (Ptr)&optVal);
1466       if (ret != ROK)
1467       {
1468          ret = cmInetClose(sockFd);
1469          RETVALUE(RFAILED);
1470       }
1471    }
1472 #endif  /* CM_LKSCTP_NONBLOCK ends */
1473 #endif
1474    RETVALUE(ROK);
1475 } /* end of cmInetSocket */
1476
1477 \f
1478 /*
1479 *
1480 *      Fun:   cmInetBind 
1481 *
1482 *      Desc:  Binds a socket file descriptor to a local Internet 
1483 *             address/port.
1484 *
1485 *      Ret:   ROK     - successful
1486 *             RFAILED - failed
1487 *
1488 *      Notes: None.
1489 *
1490 *      File:  cm_inet.c
1491 *
1492 */
1493
1494 #ifdef ANSI
1495 PUBLIC S16 cmInetBind
1496 (
1497 CmInetFd   *sockFd,             /* socket file descriptor */ 
1498 CmInetAddr *myAddr              /* locale Internet address/port */
1499 )
1500 #else
1501 PUBLIC S16 cmInetBind(sockFd, myAddr)
1502 CmInetFd   *sockFd;             /* socket file descriptor */ 
1503 CmInetAddr *myAddr;             /* locale Internet address/port */
1504 #endif
1505 {
1506    S32 ret;                     /* temporary return value */
1507    struct sockaddr_in srcAddr;  /* local Internet address/port */
1508 #ifdef IPV6_SUPPORTED 
1509    struct sockaddr_in6 srcAddr6; /* local IPV6 address/port */
1510 #ifdef CMINETDBG
1511    U16    port;
1512 #endif /* CMINETDBG */
1513 #endif /* IPV6_SUPPORTED */
1514    U32    sizeOfAddr;            /* sizeof address passed to the bind call */
1515    CmInetSockAddr *sockAddrPtr; 
1516
1517    TRC2(cmInetBind);
1518
1519 #if (ERRCLASS & ERRCLS_INT_PAR)
1520    /* error check on parameters */
1521    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
1522        (myAddr == NULLP))
1523    {
1524       RETVALUE(RFAILED);
1525    }
1526 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1527
1528 #ifdef IPV6_SUPPORTED 
1529    if (myAddr->type == CM_INET_IPV6ADDR_TYPE)
1530    {
1531       cmMemset((U8*)&srcAddr6, 0, sizeof(srcAddr6));
1532       srcAddr6.sin6_family      = AF_INET6;
1533       srcAddr6.sin6_port        = CM_INET_HTON_U16(myAddr->u.ipv6Addr.port);
1534       CM_INET_COPY_IPV6ADDR(&srcAddr6.sin6_addr, 
1535                             &myAddr->u.ipv6Addr.ipv6NetAddr);
1536       sizeOfAddr               = sizeof(struct sockaddr_in6);
1537       sockAddrPtr              = (CmInetSockAddr *)&srcAddr6;
1538    }
1539    else 
1540    {
1541       cmMemset((U8*)&srcAddr, 0, sizeof(srcAddr));
1542       srcAddr.sin_family      = AF_INET;
1543       srcAddr.sin_port        = CM_INET_HTON_U16(myAddr->u.ipv4Addr.port);
1544       srcAddr.sin_addr.s_addr = CM_INET_HTON_U32(myAddr->u.ipv4Addr.address);
1545       sizeOfAddr               = sizeof(struct sockaddr_in);
1546       sockAddrPtr              = (CmInetSockAddr *)&srcAddr;
1547    }
1548 #else 
1549    cmMemset((U8*)&srcAddr, 0, sizeof(srcAddr));
1550    srcAddr.sin_family      = AF_INET;
1551    srcAddr.sin_port        = CM_INET_HTON_U16(myAddr->port);
1552    srcAddr.sin_addr.s_addr = CM_INET_HTON_U32(myAddr->address);
1553    sizeOfAddr              = sizeof(struct sockaddr_in);
1554    sockAddrPtr             = (CmInetSockAddr *)&srcAddr;
1555 #endif /* IPV6_SUPPORTED */
1556
1557    ret = bind(sockFd->fd, sockAddrPtr, sizeOfAddr); 
1558    if (ret == INET_ERR)
1559    {
1560 #ifdef CMINETDBG
1561 #ifdef IPV6_SUPPORTED 
1562       if (myAddr->type == CM_INET_IPV6ADDR_TYPE)
1563          port = myAddr->u.ipv6Addr.port;
1564       else
1565          port = myAddr->u.ipv4Addr.port;
1566 #ifndef ALIGN_64BIT
1567       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1568       /* cm_inet_c_001.main_62:Warning fix */
1569       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetBind() Failed : error(%d), addrType(%d)," 
1570             " port(%d), sockFd->fd(%ld)\n", 
1571             INET_ERR_CODE , myAddr->type, port, sockFd->fd);
1572       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET003, 0, prntBuf);
1573 #else
1574       /* cm_inet_c_001.main_62:Warning fix */
1575       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetBind() Failed : error(%d), addrType(%d)," 
1576             " port(%d), sockFd->fd(%d)\n ", 
1577             INET_ERR_CODE , myAddr->type, port, sockFd->fd);
1578       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET003, 0, prntBuf);
1579 #endif /*ALIGN_64BIT*/
1580 #else
1581 #ifndef ALIGN_64BIT
1582       /* cm_inet_c_001.main_62:Warning fix */
1583       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetBind() Failed : error(%d), addr(0x%lx), port(%d),"
1584             "sockFd->fd(%ld)\n",
1585             INET_ERR_CODE , myAddr->address, myAddr->port, sockFd->fd);
1586       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET004, 0, prntBuf);
1587 #else
1588       /* cm_inet_c_001.main_62:Warning fix */
1589       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetBind() Failed : error(%d), addr(0x%x), port(%d),"
1590             " sockFd->fd(%d)\n",
1591             INET_ERR_CODE , myAddr->address, myAddr->port, sockFd->fd);
1592       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET004, 0, prntBuf);
1593 #endif /*ALIGN_64BIT*/
1594 #endif /* IPV6_SUPPORTED */
1595 #endif /* CMINETDBG */
1596       RETVALUE(RFAILED);
1597    }
1598
1599    RETVALUE(ROK); 
1600 } /* end of cmInetBind */
1601
1602 /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
1603 /* cm_inet_c_001.main_51 Added Ipv6 support to KSCtP implementation */
1604 #ifdef CM_LKSCTP
1605 /*
1606 *
1607 *      Fun:   cmInetSctpBindx 
1608 *
1609 *      Desc:  Binds a SCTP socket file descriptor to local Internet 
1610 *             address list
1611 *
1612 *      Ret:   ROK     - successful
1613 *             RFAILED - failed
1614 *
1615 *      Notes: None.
1616 *
1617 *      File:  cm_inet.c
1618 *
1619 */
1620 #ifdef ANSI
1621 PUBLIC S16 cmInetSctpBindx
1622 (
1623 CmInetFd          *sockFd,       /* socket file descriptor */ 
1624 CmInetNetAddrLst  *addrLst,      /* local Internet address list */
1625 U16                port          /* port number */
1626 )
1627 #else
1628 PUBLIC S16 cmInetSctpBindx(sockFd, addrLst, port)
1629 CmInetFd          *sockFd;       /* socket file descriptor */ 
1630 CmInetNetAddrLst  *addrLst;      /* locale Internet address list */
1631 U16                port;         /* port number */
1632 #endif
1633 {
1634    S32    ret;                     /* temporary return value */
1635    S32    idx;
1636    S32    idx4 = 0;
1637    U32    ipv4_array_size = 0;
1638    struct sockaddr_in  addrs[CM_INET_NUM_NET_ADDR];
1639 #ifndef IPV6_SUPPORTED
1640    Data   address_array[(CM_INET_NUM_NET_ADDR * sizeof(struct sockaddr_in))];
1641 #else
1642    Data   address_array[(CM_INET_NUM_NET_ADDR * sizeof(struct sockaddr_in6))];
1643 #endif /* IPV6_SUPPORTED */
1644
1645 #ifdef SUN_KSCTP
1646    Data   *tempAddrPtr = NULLP;
1647 #endif 
1648    U32    addresses_array_size = 0;
1649 #ifdef IPV6_SUPPORTED 
1650 #ifdef SUN_KSCTP
1651    S8     *addrString = NULLP;
1652    U32    addrLen = 0;
1653    S8     ipv4Format[23] = "::ffff:";
1654 #endif /* SUN_KSCTP */
1655    S32    idx6 = 0;
1656    U32    ipv6_array_size = 0;
1657    struct sockaddr_in6 addrs6[CM_INET_NUM_NET_ADDR];
1658 #endif /* IPV6_SUPPORTED */
1659    struct sockaddr *sockAddrPtr = NULLP;
1660    U32    sockAddrLen = 0;
1661
1662 #if (ERRCLASS & ERRCLS_INT_PAR)
1663    /* error check on parameters */
1664    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
1665        (addrLst == NULLP))
1666    {
1667       RETVALUE(RFAILED);
1668    }
1669
1670    if(addrLst->count > CM_INET_NUM_NET_ADDR)
1671    {
1672 #ifdef CMINETDBG
1673 #ifndef ALIGN_64BIT
1674       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1675       /* cm_inet_c_001.main_62:Warning fix */
1676       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "No of address(%d) is greater than Max(%d),"
1677             " sockFd->fd(%ld)\n",
1678             addrLst->count, CM_INET_NUM_NET_ADDR, sockFd->fd);
1679       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET005, 0, prntBuf);   
1680 #else
1681       /* cm_inet_c_001.main_62:Warning fix */
1682       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "No of address(%d) is greater than Max(%d),"
1683             " sockFd->fd(%d)\n", 
1684             addrLst->count, CM_INET_NUM_NET_ADDR, sockFd->fd);
1685       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET005, 0, prntBuf);   
1686 #endif /*ALIGN_64BIT*/
1687 #endif /* CMINETDBG */
1688       RETVALUE(RFAILED);
1689    }
1690 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1691
1692    cmMemset((U8*)&addrs, 0, (sizeof(struct sockaddr_in) * CM_INET_NUM_NET_ADDR));
1693 #ifdef IPV6_SUPPORTED 
1694    cmMemset((U8*)&addrs6, 0, (sizeof(struct sockaddr_in6) * CM_INET_NUM_NET_ADDR));
1695 #endif /* IPV6_SUPPORTED */
1696
1697    for (idx = 0; idx < addrLst->count; idx++)
1698    {
1699 #ifdef IPV6_SUPPORTED 
1700       if (addrLst->addrs[idx].type == CM_INET_IPV6ADDR_TYPE)
1701       {
1702          ipv6_array_size += sizeof(struct sockaddr_in6);
1703          addresses_array_size += sizeof(struct sockaddr_in6);
1704          if (sockFd->protType == AF_INET)
1705          {
1706 #ifdef CMINETDBG
1707 #ifndef ALIGN_64BIT
1708             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1709             /* cm_inet_c_001.main_62:Warning fix */
1710             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't bind IPV6 address on IPV4 socket,"
1711                   " sockFd->fd(%ld)\n", sockFd->fd);
1712             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET057, 0, prntBuf);
1713 #else
1714            /* cm_inet_c_001.main_62:Warning fix */
1715             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't bind IPV6 address on IPV4 socket," 
1716                   " sockFd->fd(%d)\n", sockFd->fd);
1717             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET057, 0, prntBuf);
1718 #endif /*ALIGN_64BIT*/
1719 #endif /* CMINETDBG */
1720             RETVALUE(RFAILED);
1721          }
1722
1723          addrs6[idx6].sin6_family      = AF_INET6;
1724          addrs6[idx6].sin6_port        = CM_INET_HTON_U16(port);
1725          CM_INET_COPY_IPV6ADDR((addrs6[idx6].sin6_addr.s6_addr), &(addrLst->addrs[idx].u.ipv6NetAddr));
1726          idx6++;
1727       }
1728       else 
1729       {
1730 #ifdef SUN_KSCTP
1731
1732          ipv6_array_size += sizeof(struct sockaddr_in6);
1733          addresses_array_size += sizeof(struct sockaddr_in6);
1734          if (sockFd->protType == AF_INET)
1735          {
1736 #ifdef CMINETDBG
1737 #ifndef ALIGN_64BIT
1738             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1739             /* cm_inet_c_001.main_62:Warning fix */
1740             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't bind IPV6 address on IPV4 socket,"
1741                   " sockFd->fd(%ld)\n", sockFd->fd);
1742             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET058, 0, prntBuf);
1743 #else
1744             /* cm_inet_c_001.main_62:Warning fix */
1745             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't bind IPV6 address on IPV4 socket," 
1746                   " sockFd->fd(%d)\n", sockFd->fd);
1747             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET058, 0, prntBuf);
1748 #endif /*ALIGN_64BIT*/
1749 #endif /* CMINETDBG */
1750             RETVALUE(RFAILED);
1751          }
1752
1753          addrs6[idx6].sin6_family      = AF_INET6;
1754          addrs6[idx6].sin6_port        = CM_INET_HTON_U16(port);
1755          addrLst->addrs[idx].u.ipv4NetAddr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
1756          cmInetNtoa(addrLst->addrs[idx].u.ipv4NetAddr, &addrString);
1757          addrLen = cmStrlen((U8*)addrString);
1758          cmMemcpy((U8*)(ipv4Format+7), (U8*)addrString, addrLen);
1759          ipv4Format[7+addrLen] = '\0';
1760          cmInetPton6((CmInetIpAddr6*)(addrs6[idx6].sin6_addr.s6_addr), ipv4Format);
1761          idx6++;
1762 #else
1763          ipv4_array_size += sizeof(struct sockaddr_in);
1764          addresses_array_size += sizeof(struct sockaddr_in);
1765          addrs[idx4].sin_family      = AF_INET;
1766          addrs[idx4].sin_port        = CM_INET_HTON_U16(port);
1767          addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
1768          idx4++;
1769 #endif /* SUN_KSCTP */
1770       }
1771 #else 
1772       ipv4_array_size += sizeof(struct sockaddr_in);
1773       addresses_array_size += sizeof(struct sockaddr_in);
1774       addrs[idx4].sin_family      = AF_INET;
1775       addrs[idx4].sin_port        = CM_INET_HTON_U16(port);
1776       addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
1777       idx4++;
1778 #endif /* IPV6_SUPPORTED */
1779    }
1780
1781
1782    if(ipv4_array_size > 0)
1783    {
1784        sockAddrPtr = (struct sockaddr*)address_array;
1785       sockAddrLen = sizeof(struct sockaddr_in);
1786       cmMemcpy((U8*)address_array, (U8*)addrs, ipv4_array_size); 
1787    }
1788 #ifdef IPV6_SUPPORTED
1789    else
1790    {
1791        sockAddrPtr = (struct sockaddr*)address_array;
1792       sockAddrLen = sizeof(struct sockaddr_in6);
1793    }
1794
1795    if(ipv6_array_size > 0)
1796    {
1797       cmMemcpy((U8*)(address_array + ipv4_array_size), (U8*)addrs6, ipv6_array_size); 
1798    }
1799 #endif /* IPV6_SUPPORTED */
1800
1801
1802 #ifdef SUN_KSCTP
1803    ret = bind(sockFd->fd, sockAddrPtr, sockAddrLen); 
1804    if (ret == INET_ERR)
1805    {
1806
1807 #ifdef CMINETDBG
1808 #ifndef ALIGN_64BIT
1809       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1810       /* cm_inet_c_001.main_62:Warning fix */
1811       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx() Failed : error(%d), port(%d),"
1812             " sockFd->fd(%ld)\n",INET_ERR_CODE, port, sockFd->fd);
1813       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET006, 0, prntBuf);
1814 #else
1815       /* cm_inet_c_001.main_62:Warning fix */
1816       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx() Failed : error(%d), port(%d),"
1817             " sockFd->fd(%d)\n",INET_ERR_CODE, port, sockFd->fd);
1818       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET006, 0, prntBuf);
1819 #endif /*ALIGN_64BIT*/
1820 #endif /* CMINETDBG */
1821       RETVALUE(RFAILED);
1822    }
1823
1824    if (addrLst->count > 1)
1825    {
1826       if(((struct sockaddr*)address_array)->sa_family == AF_INET)
1827       {
1828          tempAddrPtr = address_array + (sizeof(struct sockaddr_in));
1829       }
1830       else if(((struct sockaddr*)address_array)->sa_family == AF_INET6)
1831       {
1832          tempAddrPtr = address_array + (sizeof(struct sockaddr_in6));
1833       }
1834       else
1835       {
1836 #ifdef CMINETDBG
1837 #ifndef ALIGN_64BIT
1838          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1839          /* cm_inet_c_001.main_62:Warning fix */
1840          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx(Invalid address Type) failed:"
1841                " sockFd->fd(%ld),  error(%d), port(%d)\n ",
1842                INET_ERR_CODE, port, sockFd->fd);
1843          CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET059, 0, prntBuf);
1844 #else
1845          /* cm_inet_c_001.main_62:Warning fix */
1846          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx(Invalid address Type) failed:"
1847                " sockFd->fd(%d), error(%d), port(%d)\n ", 
1848                INET_ERR_CODE, port, sockFd->fd);
1849          CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET059, 0, prntBuf);
1850 #endif /*ALIGN_64BIT*/
1851 #endif /* CMINETDBG */
1852          RETVALUE(RFAILED);
1853       }
1854
1855       ret = sctp_bindx(sockFd->fd, (Void*)tempAddrPtr, addrLst->count - 1, SCTP_BINDX_ADD_ADDR); 
1856    }
1857 #else
1858    /* linux */
1859    ret = sctp_bindx(sockFd->fd, (struct sockaddr*)address_array, addrLst->count, SCTP_BINDX_ADD_ADDR); 
1860         UNUSED(sockAddrPtr);
1861         UNUSED(sockAddrLen);
1862 #endif
1863    if (ret == INET_ERR)
1864    {
1865 #ifdef CMINETDBG
1866 #ifndef ALIGN_64BIT
1867       /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
1868       /* cm_inet_c_001.main_62:Warning fix */
1869       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx() Failed : error(%d), port(%d),"
1870             " sockFd->fd(%ld)\n",INET_ERR_CODE, port, sockFd->fd);
1871       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET007, 0, prntBuf);
1872 #else
1873       /* cm_inet_c_001.main_62:Warning fix */
1874       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpBindx() Failed : error(%d), port(%d),"
1875             " sockFd->fd(%d)\n",INET_ERR_CODE, port, sockFd->fd);
1876       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET007, 0, prntBuf);
1877 #endif /*ALIGN_64BIT*/
1878 #endif /* CMINETDBG */
1879       RETVALUE(RFAILED);
1880    }
1881
1882    RETVALUE(ROK); 
1883 }
1884
1885 /*
1886 *
1887 *      Fun:   cmInetSctpConnectx 
1888 *
1889 *      Desc:  Establishes a sctp connection with remote addresses
1890 *
1891 *      Ret:   ROK     - successful
1892 *             RFAILED - failed
1893 *
1894 *      Notes: None.
1895 *
1896 *      File:  cm_inet.c
1897 *
1898 */
1899 #ifdef ANSI
1900 PUBLIC S16 cmInetSctpConnectx
1901 (
1902 CmInetFd          *sockFd,       /* socket file descriptor */ 
1903 CmInetNetAddr     *primAddr,     /* primary destination Internet address */
1904 CmInetNetAddrLst  *addrLst,      /* destination Internet address list */
1905 U16                port          /* port number */
1906 )
1907 #else
1908 PUBLIC S16 cmInetSctpConnectx(sockFd, primAddr, addrLst, port)
1909 CmInetFd          *sockFd;       /* socket file descriptor */ 
1910 CmInetNetAddr     *primAddr;     /* primary destination Internet address */
1911 CmInetNetAddrLst  *addrLst;      /* destination Internet address list */
1912 U16                port;         /* port number */
1913 #endif
1914 {
1915    S32   ret;   
1916    U32   cnt;
1917    /* cm_inet_c_001.main_46: Removed SS_LINUX flag */
1918    S32   idx;
1919
1920 /* cm_inet_c_001.main_64: New variable used as an argument for sctp_connectx */
1921 #ifdef SCTP_CONNECTX_NEW
1922    U32    assocId = 0;
1923 #endif   
1924    U32    addresses_array_size = 0;
1925    U32    idx4 = 0;
1926    struct sockaddr_in  addrs[CM_INET_NUM_NET_ADDR];
1927    U32    ipv4_array_size = 0;
1928
1929 #ifndef IPV6_SUPPORTED
1930    Data   address_array[(CM_INET_NUM_NET_ADDR * sizeof(struct sockaddr_in))];
1931 #else
1932    Data   address_array[(CM_INET_NUM_NET_ADDR * sizeof(struct sockaddr_in6))];
1933 #endif /* IPV6_SUPPORTED */
1934
1935 #ifdef IPV6_SUPPORTED
1936 #ifdef SUN_KSCTP
1937    S8     *addrString = NULLP;
1938    U32    addrLen = 0;
1939    S8     ipv4Format[23] = "::ffff:";
1940    CmInetIpAddr ipv4NetAddr;
1941 #endif /* SUN_KSCTP */
1942    U32    idx6 = 0;
1943    struct sockaddr_in6  addrs6[CM_INET_NUM_NET_ADDR];
1944    U32    ipv6_array_size = 0;
1945 #endif /* IPV6_SUPPORTED */
1946 #ifndef SS_LINUX
1947    U32    sockAddrLen = 0;
1948 #endif /* sockAddrLen */
1949
1950 #ifndef SS_LINUX
1951    CmInetSockAddr *sockAddrPtr = NULLP;
1952 #endif /* SS_LINUX */
1953 #if (ERRCLASS & ERRCLS_INT_PAR)
1954    /* error check on parameters */
1955    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
1956          (primAddr == NULLP))
1957    {
1958       RETVALUE(RFAILED);
1959    }
1960     /* cm_inet_c_001.main_58 : Added check for addrLst to fix klockwork issue */
1961    if (addrLst == NULLP)
1962    {
1963       RETVALUE(RFAILED);
1964    }
1965    /* cm_inet_c_001.main_46: Included check for no of address aginst max */
1966    if( addrLst->count > CM_INET_NUM_NET_ADDR )
1967    {
1968 #ifdef CMINETDBG
1969 #ifndef ALIGN_64BIT
1970       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
1971       /* cm_inet_c_001.main_62:Warning fix */
1972       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "No of address(%d) is greater than Max(%d),"
1973             " sockFd->fd(%ld)\n", 
1974             addrLst->count, CM_INET_NUM_NET_ADDR, sockFd->fd);
1975       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET060, 0, prntBuf);
1976 #else
1977       /* cm_inet_c_001.main_62:Warning fix */
1978       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "No of address(%d) is greater than Max(%d),"
1979             " sockFd->fd(%d)\n", 
1980             addrLst->count, CM_INET_NUM_NET_ADDR, sockFd->fd);
1981       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET060, 0, prntBuf);
1982 #endif /*ALIGN_64BIT*/
1983 #endif /* CMINETDBG */
1984       RETVALUE(RFAILED);
1985    }
1986 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1987
1988
1989    cmMemset((U8*)&addrs, 0, (sizeof(struct sockaddr_in) * CM_INET_NUM_NET_ADDR));
1990 #ifdef IPV6_SUPPORTED
1991    cmMemset((U8*)&addrs6, 0, (sizeof(struct sockaddr_in6) * CM_INET_NUM_NET_ADDR));
1992 #endif /* IPV6_SUPPORTED */
1993
1994    cnt = 0;
1995
1996 #ifdef IPV6_SUPPORTED 
1997    if (primAddr->type == CM_INET_IPV6ADDR_TYPE)
1998    {
1999       if (sockFd->protType == AF_INET)
2000       {
2001 #ifdef CMINETDBG
2002 #ifndef ALIGN_64BIT
2003          /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2004          /* cm_inet_c_001.main_62:Warning fix */
2005          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't connect to IPV6 address through IPV4 socket,"
2006                " sockFd->fd(%ld)\n", sockFd->fd);
2007          CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET008, 0, prntBuf);
2008 #else
2009          /* cm_inet_c_001.main_62:Warning fix */
2010          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't connect to IPV6 address through IPV4 socket,"
2011                " sockFd->fd(%d)\n",  sockFd->fd);
2012          CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET008, 0, prntBuf);
2013 #endif /*ALIGN_64BIT*/
2014 #endif /* CMINETDBG */
2015          RETVALUE(RFAILED);
2016       }
2017
2018       addrs6[idx6].sin6_family      = AF_INET6;
2019       addrs6[idx6].sin6_port        = CM_INET_HTON_U16(port);
2020       CM_INET_COPY_IPV6ADDR(&(addrs6[idx6].sin6_addr.s6_addr), &(primAddr->u.ipv6NetAddr));
2021       addresses_array_size += sizeof(struct sockaddr_in6);
2022       ipv6_array_size += sizeof(struct sockaddr_in6);
2023       idx6++;
2024    }
2025    else 
2026    {
2027 #ifdef SUN_KSCTP
2028       if (sockFd->protType == AF_INET)
2029       {
2030 #ifdef CMINETDBG
2031 #ifndef ALIGN_64BIT
2032          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2033          /* cm_inet_c_001.main_62:Warning fix */
2034          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4 socket,"
2035                " sockFd->fd(%ld)\n", sockFd->fd);
2036          CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET061, 0, prntBuf);
2037 #else
2038          /* cm_inet_c_001.main_62:Warning fix */
2039          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4 socket,"
2040                " sockFd->fd(%d)\n", sockFd->fd);
2041          CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET061, 0, prntBuf);
2042 #endif /*ALIGN_64BIT*/
2043 #endif /* CMINETDBG */
2044          RETVALUE(RFAILED);
2045       }
2046       addrs6[idx6].sin6_family      = AF_INET6;
2047       addrs6[idx6].sin6_port        = CM_INET_HTON_U16(port);
2048       ipv4NetAddr = CM_INET_HTON_U32(primAddr->u.ipv4NetAddr);
2049       cmInetNtoa(ipv4NetAddr, &addrString);
2050       addrLen = cmStrlen((U8*)addrString);
2051       cmMemcpy((U8*)(ipv4Format+7), (U8*)addrString, addrLen);
2052       ipv4Format[7+addrLen] = '\0';
2053       cmInetPton6((CmInetIpAddr6*)&(addrs6[idx6].sin6_addr), ipv4Format);
2054       addresses_array_size += sizeof(struct sockaddr_in6);
2055       ipv6_array_size += sizeof(struct sockaddr_in6);
2056       idx6++;
2057 #else
2058       addrs[idx4].sin_family      = AF_INET;
2059       addrs[idx4].sin_port        = CM_INET_HTON_U16(port);
2060       addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(primAddr->u.ipv4NetAddr);
2061       addresses_array_size += sizeof(struct sockaddr_in);
2062       ipv4_array_size += sizeof(struct sockaddr_in);
2063       idx4++;
2064 #endif 
2065    }
2066 #else 
2067    addrs[idx4].sin_family      = AF_INET;
2068    addrs[idx4].sin_port        = CM_INET_HTON_U16(port);
2069    addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(primAddr->u.ipv4NetAddr);
2070    addresses_array_size += sizeof(struct sockaddr_in);
2071    ipv4_array_size += sizeof(struct sockaddr_in);
2072    idx4++;
2073 #endif /* IPV6_SUPPORTED */
2074
2075    cnt++;
2076
2077    /* cm_inet_c_001.main_46: Moved the SS_LINUX flag down, 
2078     * copy addresses in Solaris also */
2079    if (addrLst != NULLP)
2080    {
2081       for (idx = 0; idx < addrLst->count; idx++)
2082       {
2083
2084          /* cm_inet_c_001.main_46: Don't include the primary address 
2085           * if its prersent in list */
2086          if ( addrLst->addrs[idx].type == CM_INET_IPV4ADDR_TYPE )
2087          {
2088             if ( addrLst->addrs[idx].u.ipv4NetAddr == primAddr->u.ipv4NetAddr )
2089             {
2090                continue;
2091             }
2092          }
2093 #ifdef IPV6_SUPPORTED
2094          else if ( addrLst->addrs[idx].type == CM_INET_IPV6ADDR_TYPE )
2095          {
2096             if (( cmMemcmp(addrLst->addrs[idx].u.ipv6NetAddr,
2097                    primAddr->u.ipv6NetAddr, sizeof(CmInetIpAddr6) )) == 0 )
2098             {
2099                continue;
2100             }
2101          }
2102
2103          if (addrLst->addrs[idx].type == CM_INET_IPV6ADDR_TYPE)
2104          {
2105             if (sockFd->protType == AF_INET)
2106             {
2107 #ifdef CMINETDBG
2108 #ifndef ALIGN_64BIT
2109                /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2110                /* cm_inet_c_001.main_62:Warning fix */
2111                snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't connect to IPV6 address through IPV4 socket,"
2112                      " sockFd->fd(%ld)\n", sockFd->fd);
2113                CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET009, 0, prntBuf);
2114 #else
2115                /* cm_inet_c_001.main_62:Warning fix */
2116                snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't connect to IPV6 address through IPV4 socket,"
2117                      " sockFd->fd(%d)\n", sockFd->fd);
2118                CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET009, 0, prntBuf);
2119 #endif /*ALIGN_64BIT*/
2120 #endif /* CMINETDBG */
2121                RETVALUE(RFAILED);
2122             }
2123
2124             addrs6[idx6].sin6_family      = AF_INET6;
2125             addrs6[idx6].sin6_port        = CM_INET_HTON_U16(port);
2126             CM_INET_COPY_IPV6ADDR(&(addrs6[idx6].sin6_addr.s6_addr),
2127                                   &(addrLst->addrs[idx].u.ipv6NetAddr));
2128             addresses_array_size += sizeof(struct sockaddr_in6);
2129             ipv6_array_size += sizeof(struct sockaddr_in6);
2130             idx6++;
2131          }
2132          else 
2133          {
2134 #ifdef SUN_KSCTP
2135             if (sockFd->protType == AF_INET)
2136             {
2137 #ifdef CMINETDBG
2138 #ifndef ALIGN_64BIT
2139                /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2140                /* cm_inet_c_001.main_62:Warning fix */
2141                snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4 socket,"
2142                      " sockFd->fd(%ld)\n", sockFd->fd);
2143                CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET062, 0, prntBuf);
2144 #else
2145                /* cm_inet_c_001.main_62:Warning fix */
2146                snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4 socket,"
2147                      " sockFd->fd(%d)\n", sockFd->fd);
2148                CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET062, 0, prntBuf);
2149 #endif /*ALIGN_64BIT*/
2150 #endif /* CMINETDBG */
2151                RETVALUE(RFAILED);
2152             }
2153             addrs6[idx6].sin6_family      = AF_INET6;
2154             addrs6[idx6].sin6_port        = CM_INET_HTON_U16(port);
2155             ipv4NetAddr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
2156             cmInetNtoa(ipv4NetAddr, &addrString);
2157             addrLen = cmStrlen((U8*)addrString);
2158             cmMemcpy((U8*)(ipv4Format+7), (U8*)addrString, addrLen);
2159             ipv4Format[7+addrLen] = '\0';
2160             cmInetPton6((CmInetIpAddr6*)(addrs6[idx6].sin6_addr.s6_addr), ipv4Format);
2161             addresses_array_size += sizeof(struct sockaddr_in6);
2162             ipv6_array_size += sizeof(struct sockaddr_in6);
2163             idx6++;
2164 #else
2165             addrs[idx4].sin_family      = AF_INET;
2166             addrs[idx4].sin_port        = CM_INET_HTON_U16(port);
2167             addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
2168             addresses_array_size += sizeof(struct sockaddr_in);
2169             ipv4_array_size += sizeof(struct sockaddr_in);
2170             idx4++;
2171 #endif /* SUN_KSCTP */
2172          }
2173 #else 
2174          addrs[idx4].sin_family      = AF_INET;
2175          addrs[idx4].sin_port        = CM_INET_HTON_U16(port);
2176          addrs[idx4].sin_addr.s_addr = CM_INET_HTON_U32(addrLst->addrs[idx].u.ipv4NetAddr);
2177          addresses_array_size += sizeof(struct sockaddr_in);
2178          ipv4_array_size += sizeof(struct sockaddr_in);
2179          idx4++;
2180 #endif /* IPV6_SUPPORTED */
2181          /*cm_inet_c_001.main_39 */
2182          cnt++;
2183       }
2184    }
2185
2186    /* cm_inet_c_001.main_46: Moved SS_LINUX flag to here */
2187 #ifdef SS_LINUX
2188    /*cm_inet_c_001.main_58 : Added check array_size to fix klockwork issue */
2189    if((ipv4_array_size > 0) && (ipv4_array_size <= (CM_INET_NUM_NET_ADDR * \
2190                sizeof(struct sockaddr_in))))
2191    {
2192       cmMemcpy((U8*)address_array, (U8*)&addrs[0], ipv4_array_size); 
2193    }
2194    else
2195    {
2196       RETVALUE(RFAILED);
2197    }
2198
2199 #ifdef IPV6_SUPPORTED
2200    if((ipv6_array_size > 0) && (ipv6_array_size <= (CM_INET_NUM_NET_ADDR * \
2201                sizeof(struct sockaddr_in))))
2202    {
2203       cmMemcpy((U8*)(address_array + ipv4_array_size), (U8*)addrs6, ipv6_array_size); 
2204    }
2205    else
2206    {
2207       RETVALUE(RFAILED);
2208    }
2209 #endif /* IPV6_SUPPORTED */
2210
2211 /* cm_inet_c_001.main_64: Support for new definition of sctp_connectx */
2212 #ifndef SCTP_CONNECTX_NEW   
2213    ret = sctp_connectx(sockFd->fd, (struct sockaddr*)address_array, cnt);
2214 #else
2215    ret = sctp_connectx(sockFd->fd, (struct sockaddr*)address_array, cnt, (sctp_assoc_t *)&assocId);
2216 #endif
2217
2218 #else
2219    /* solaris */
2220    /* cm_inet_c_001.main_46: Use next provided address to connect if 
2221     * first one fails */
2222
2223 #ifdef CMINET_SUN_CONNECTX
2224    idx4 = 0;
2225 #ifdef IPV6_SUPPORTED
2226    idx6 = 0;
2227 #endif /* IPV6_SUPPORTED */
2228    for (idx = 0; idx < cnt; idx++)
2229    {
2230       if( addrs[idx4].sin_family == AF_INET)
2231       {
2232         sockAddrPtr = (CmInetSockAddr *)&addrs[idx4];
2233         sockAddrLen = sizeof(struct sockaddr_in);
2234         idx4++;
2235       }
2236 #ifdef IPV6_SUPPORTED
2237       else 
2238       {
2239         sockAddrPtr = (CmInetSockAddr *)&addrs6[idx6];
2240         sockAddrLen = sizeof(struct sockaddr_in6);
2241         idx6++;
2242       }
2243 #endif/* IPV6_SUPPORTED */
2244
2245       ret = connect(sockFd->fd, sockAddrPtr, sockAddrLen);
2246
2247         if ( ret != INET_ERR )
2248         {
2249             break;
2250         }
2251 #ifdef CMINETDBG
2252 #ifndef ALIGN_64BIT
2253       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2254       /* cm_inet_c_001.main_62:Warning fix */
2255       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpConnectx() failed:error(%d), port(0x%1x),"
2256             " sockFd->fd(%ld)\n", INET_ERR_CODE, port, sockFd->fd);
2257       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET063, 0, prntBuf);
2258 #else
2259       /* cm_inet_c_001.main_62:Warning fix */
2260       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpConnectx() failed:error(%d), port(0x%1x),"
2261             " sockFd->fd(%d)\n", INET_ERR_CODE, port, sockFd->fd);
2262       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET063, 0, prntBuf);
2263 #endif /*ALIGN_64BIT*/
2264 #endif /* CMINETDBG */
2265
2266    }
2267 #else
2268
2269    if( addrs[0].sin_family == AF_INET)
2270    {
2271      sockAddrPtr = (CmInetSockAddr*)&addrs[0];
2272      sockAddrLen = sizeof(struct sockaddr_in);
2273      idx4++;
2274    }
2275 #ifdef IPV6_SUPPORTED
2276    else 
2277    {
2278      sockAddrPtr = (CmInetSockAddr*)&addrs6[0];
2279      sockAddrLen = sizeof(struct sockaddr_in6);
2280      idx6++;
2281    }
2282 #endif/* IPV6_SUPPORTED */
2283
2284    ret = connect(sockFd->fd, sockAddrPtr, sockAddrLen);
2285
2286 #endif /* CMINET_SUN_CONNECTX */
2287 #endif /* SS_LINUX */
2288
2289    if (ret == INET_ERR)
2290    {
2291 #ifdef CMINETDBG
2292 #ifndef ALIGN_64BIT
2293       /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2294       /* cm_inet_c_001.main_62:Warning fix */
2295       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "CmInetSctpConnectx() Failed : error(%d), port(0x%1x),"
2296             " sockFd->fd(%ld)\n", INET_ERR_CODE, port, sockFd->fd);
2297       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET010, 0, prntBuf);
2298 #else
2299       /* cm_inet_c_001.main_62:Warning fix */
2300       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "CmInetSctpConnectx() Failed : error(%d), port(0x%1x),"
2301             " sockFd->fd(%d)\n", INET_ERR_CODE, port, sockFd->fd);
2302       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET010, 0, prntBuf);
2303 #endif /*ALIGN_64BIT*/
2304 #endif /* CMINETDBG */
2305
2306       switch (INET_ERR_CODE)
2307       {
2308          /* non-blocking: connection is in progress */
2309          case ERR_INPROGRESS:
2310             RETVALUE(RINPROGRESS);
2311             break;   
2312
2313          /* 
2314           * non-blocking: connection is established 
2315           * blocking    : connection is already established
2316           */
2317          case ERR_ISCONN:
2318             RETVALUE(RISCONN);
2319             break;               
2320
2321          /* resource temporarily unavailable */
2322          case ERR_WOULDBLOCK:
2323             RETVALUE(ROKDNA);
2324             break;
2325
2326          /* non-blocking: connection is in progress */
2327          case ERR_ALREADY:
2328             RETVALUE(RINPROGRESS);
2329             break;
2330
2331          case ERR_INVAL:
2332             RETVALUE(RINPROGRESS);
2333             break;
2334
2335          /*  Check for connection refused and timeout errors */
2336          case ERR_CONNREFUSED:
2337          case ERR_TIMEDOUT:
2338             RETVALUE(RCLOSED);
2339             break;
2340
2341          /* it is a real error */ 
2342          default:
2343             RETVALUE(RFAILED);
2344             break;
2345       }
2346    }
2347
2348    RETVALUE(ROK);
2349 }
2350
2351 /*
2352 *
2353 *      Fun:   cmInetSctpPeelOff 
2354 *
2355 *      Desc:  Branches an existing sctp association off to a seperate socket 
2356 *
2357 *      Ret:   ROK     - successful
2358 *             RFAILED - failed
2359 *
2360 *      Notes: None.
2361 *
2362 *      File:  cm_inet.c
2363 *
2364 */
2365 #ifdef ANSI
2366 PUBLIC S16 cmInetSctpPeelOff
2367 (
2368 CmInetFd          *sockFd,       /* socket file descriptor */ 
2369 U32                assocId,      /* association id */
2370 CmInetFdType      *assocFd       /* association fd */
2371 )
2372 #else
2373 PUBLIC S16 cmInetSctpPeelOff(sockFd, assocId, assocFd)
2374 CmInetFd          *sockFd;       /* socket file descriptor */ 
2375 U32                assocId;      /* association id */
2376 CmInetFdType      *assocFd;      /* association fd */
2377 #endif
2378 {
2379    S32 ret;
2380
2381 #if (ERRCLASS & ERRCLS_INT_PAR)
2382    /* error check on parameters */
2383    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) || (assocFd == NULLP)) 
2384    {
2385       RETVALUE(RFAILED);
2386    }
2387 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2388
2389
2390    ret = sctp_peeloff(sockFd->fd, assocId);
2391    if (ret == INET_ERR)
2392    {
2393 #ifdef CMINETDBG
2394 #ifndef ALIGN_64BIT
2395       /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2396       /* cm_inet_c_001.main_62:Warning fix */
2397       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpPeelOff() Failed : error(%d) assocId(%ld),"
2398             " sockFd->fd(%ld)\n", INET_ERR_CODE, assocId, sockFd->fd);
2399       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET011, 0, prntBuf);
2400 #else
2401       /* cm_inet_c_001.main_55: Fix for compilation warning */
2402       /* cm_inet_c_001.main_62:Warning fix */
2403       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpPeelOff() Failed : error(%d) assocId(%d),"
2404             " sockFd->fd(%d)\n", INET_ERR_CODE, assocId, sockFd->fd);
2405       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET011, 0, prntBuf);
2406 #endif /*ALIGN_64BIT*/
2407 #endif /* CMINETDBG */
2408
2409       RETVALUE(RFAILED);
2410    }
2411
2412    *assocFd = ret;
2413
2414    RETVALUE(ROK);
2415 }
2416
2417 /*
2418 *
2419 *      Fun:   cmInetSctpSendMsg 
2420 *
2421 *      Desc:  invokes sctp socket API to send message to the remote addresses
2422 *
2423 *      Ret:   ROK     - successful
2424 *             RFAILED - failed
2425 *
2426 *      Notes: None.
2427 *
2428 *      File:  cm_inet.c
2429 *
2430 */
2431 #ifdef ANSI
2432 PUBLIC S16 cmInetSctpSendMsg
2433 (
2434 CmInetFd        *sockFd,       /* socket file descriptor */ 
2435 CmInetNetAddr   *dstAddr,      /* destination Internet address/port */
2436 U16              port,         /* destination port no. */
2437 CmInetMemInfo   *info,         /* buffer allocation info */
2438 Buffer          *mBuf,         /* buffer structure to send */
2439 MsgLen          *len,          /* number of actually sent octets */
2440 U16              strmId,       /* sctp stream identifier */
2441 Bool             unorderFlg,   /* flag to enable the unordered delivery */
2442 U16              ttl,          /* time to live */
2443 U32              ppId,         /* opaque value passed along with the message */
2444 U32              context       /* value to be passed back, if error occurs */
2445 )
2446 #else
2447 PUBLIC S16 cmInetSctpSendMsg(sockFd, dstAddr, port, info, mBuf, len, strmId, 
2448                              unorderFlg, ttl, ppId, context)
2449 CmInetFd        *sockFd;       /* socket file descriptor */ 
2450 CmInetNetAddr   *dstAddr;      /* destination Internet address/port */
2451 U16              port;         /* destination port no. */
2452 CmInetMemInfo   *info;         /* buffer allocation info */
2453 Buffer          *mBuf;         /* buffer structure to send */
2454 MsgLen          *len;          /* number of actually sent octets */
2455 U16              strmId;       /* sctp stream identifier */
2456 Bool             unorderFlg;   /* flag to enable the unordered delivery */
2457 U16              ttl;          /* time to live */
2458 U32              ppId;         /* opaque value passed along with the message */
2459 U32              context;      /* value to be passed back, if error occurs */
2460 #endif
2461 {
2462    S32     ret;   
2463  /* cm_inet_c_001.main_58 : Fix for klockwork issue */
2464    MsgLen  msgLen = 0;              /* message length */    
2465    MsgLen  bufLen = 0;              /* send buffer length */     
2466    Data   *sendBuf = NULLP;             /* plain send buffer */
2467    U32     flags;
2468    CmInetSockAddr *sockAddrPtr = NULLP;
2469    /* cm_inet_c_001.main_58 : Fix for klockwork issue */
2470    MsgLen          sockAddrLen = 0; 
2471    struct sockaddr_in  addr;
2472 #ifdef IPV6_SUPPORTED
2473 #ifdef SUN_KSCTP
2474    S8     *addrString = NULLP;
2475    U32    addrLen = 0;
2476    S8     ipv4Format[23] = "::ffff:";
2477    CmInetIpAddr ipv4NetAddr;
2478 #endif /* SUN_KSCTP */
2479    struct sockaddr_in6  addr6;
2480 #endif /* IPV6_SUPPORTED */
2481
2482 #if (ERRCLASS & ERRCLS_INT_PAR)
2483    /* error check on parameters */
2484    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd)
2485        || (info == NULLP) || (mBuf == NULLP) || (len == NULLP))
2486    {
2487       RETVALUE(RFAILED);
2488    }
2489 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2490
2491
2492    cmMemset((U8*)&addr, 0, sizeof(struct sockaddr_in));
2493 #ifdef IPV6_SUPPORTED
2494    cmMemset((U8*)&addr6, 0, sizeof(struct sockaddr_in6));
2495 #endif /* IPV6_SUPPORTED */
2496
2497    /* copy message to a flat buffer */
2498    ret = SFndLenMsg(mBuf, &bufLen);
2499    if (ret != ROK)
2500    {
2501       RETVALUE(RFAILED);
2502    }
2503    /* max message length is limited to control the memory usage */
2504    /* casting bufLen to avoid warnings */
2505    if ((bufLen > 0) && ((U32)bufLen > CM_INET_MAX_MSG_LEN))
2506    {
2507       RETVALUE(RFAILED);
2508    }
2509    ret = SGetSBuf(info->region, info->pool, &sendBuf, bufLen);                  
2510    if (ret != ROK)
2511    {
2512       RETVALUE(ROUTRES);
2513    }
2514    ret = SCpyMsgFix(mBuf, 0, bufLen, sendBuf, &msgLen);
2515    if ((ret != ROK) || (msgLen != bufLen)) 
2516    {
2517       SPutSBuf(info->region, info->pool, sendBuf, bufLen);       
2518       RETVALUE(RFAILED);
2519    }
2520
2521    if ( dstAddr != NULLP)
2522    {
2523 #ifdef IPV6_SUPPORTED 
2524       if (dstAddr->type == CM_INET_IPV6ADDR_TYPE)
2525       {
2526          if (sockFd->protType == AF_INET)
2527          {
2528             SPutSBuf(info->region, info->pool, sendBuf, bufLen);       
2529 #ifdef CMINETDBG
2530 #ifndef ALIGN_64BIT
2531             /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2532             /* cm_inet_c_001.main_62:Warning fix */
2533             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't send message to IPV6 address through"
2534                   " IPV4 socket, sockFd->fd(%ld)\n", sockFd->fd);
2535             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET012, 0, prntBuf);
2536 #else
2537             /* cm_inet_c_001.main_62:Warning fix */
2538             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Can't send message to IPV6 address through"
2539                   " IPV4 socket, sockFd->fd(%d)\n", sockFd->fd);
2540             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET012, 0, prntBuf);
2541 #endif /*ALIGN_64BIT*/
2542 #endif /* CMINETDBG */
2543             RETVALUE(RFAILED);
2544          }
2545
2546          addr6.sin6_family      = AF_INET6;
2547          addr6.sin6_port        = CM_INET_HTON_U16(port);
2548          CM_INET_COPY_IPV6ADDR(&addr6.sin6_addr.s6_addr, &dstAddr->u.ipv6NetAddr); 
2549          sockAddrLen = sizeof(struct sockaddr_in6);
2550          sockAddrPtr = (CmInetSockAddr*)&addr6;
2551       }
2552       else 
2553       {
2554
2555 #ifdef SUN_KSCTP
2556          if (sockFd->protType == AF_INET)
2557          {
2558 #ifdef CMINETDBG
2559 #ifndef ALIGN_64BIT
2560             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2561             /* cm_inet_c_001.main_62:Warning fix */
2562             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4"
2563                   " socket, sockFd->fd(%ld)\n", sockFd->fd);
2564             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET064, 0, prntBuf);
2565 #else
2566             /* cm_inet_c_001.main_62:Warning fix */
2567             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "can't connect to IPV6 address through IPV4"
2568                   " socket, sockFd->fd(%d)\n", sockFd->fd);
2569             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET064, 0, prntBuf);
2570 #endif /*ALIGN_64BIT*/
2571 #endif /* CMINETDBG */
2572             RETVALUE(RFAILED);
2573          }
2574          addr6.sin6_family      = AF_INET6;
2575          addr6.sin6_port        = CM_INET_HTON_U16(port);
2576          ipv4NetAddr = CM_INET_HTON_U32(dstAddr->u.ipv4NetAddr);
2577          cmInetNtoa(ipv4NetAddr, &addrString);
2578          addrLen = cmStrlen((U8*)addrString);
2579          cmMemcpy((U8*)(ipv4Format+7), (U8*)addrString, addrLen);
2580          ipv4Format[7+addrLen] = '\0';
2581          cmInetPton6((CmInetIpAddr6*)(addr6.sin6_addr.s6_addr), ipv4Format);
2582          sockAddrLen = sizeof(struct sockaddr_in6);
2583          sockAddrPtr = (CmInetSockAddr*)&addr6;
2584 #else
2585          addr.sin_family      = AF_INET;
2586          addr.sin_port        = CM_INET_HTON_U16(port);
2587          addr.sin_addr.s_addr = CM_INET_HTON_U32(dstAddr->u.ipv4NetAddr);
2588          sockAddrLen = sizeof(struct sockaddr_in);
2589          sockAddrPtr = (CmInetSockAddr*)&addr;
2590 #endif /* SUN_KSCTP */
2591       }
2592 #else 
2593       addr.sin_family      = AF_INET;
2594       addr.sin_port        = CM_INET_HTON_U16(port);
2595       addr.sin_addr.s_addr = CM_INET_HTON_U32(dstAddr->u.ipv4NetAddr);
2596       /* cm_inet_c_001.main_58 : Fix for Klockwork issue */
2597       sockAddrLen = (MsgLen)sizeof(struct sockaddr_in);
2598       sockAddrPtr = (CmInetSockAddr*)&addr;
2599 #endif /* IPV6_SUPPORTED */
2600    }
2601    else
2602    {
2603 #ifdef SUN_KSCTP
2604       sockAddrPtr = NULL;
2605 #else
2606       sockAddrPtr = (CmInetSockAddr*)&addr;
2607 #endif
2608       /* cm_inet_c_001.main_58 : initialized sockAddrLen properly */
2609 #ifdef IPV6_SUPPORTED 
2610       sockAddrLen = sizeof(struct sockaddr_in6);
2611 #else
2612       sockAddrLen = sizeof(struct sockaddr_in);
2613 #endif
2614    }
2615
2616    /* Not validating the address, whether addr is a valid address or not */
2617
2618    *len  = 0;
2619    flags = 0x00000000;
2620
2621    if (unorderFlg == TRUE)
2622    {
2623 #ifdef SUN_KSCTP 
2624       flags |= MSG_UNORDERED;
2625 #else
2626       /* linux */
2627       flags |= SCTP_UNORDERED;
2628 #endif
2629    }
2630    /*cm_inet_c_001.main_54: converting ppid to network*/
2631    ppId = CM_INET_HTON_U32(ppId);
2632    ret = sctp_sendmsg(sockFd->fd, (Void*)sendBuf, bufLen, 
2633          (struct sockaddr*)sockAddrPtr, (size_t)sockAddrLen, 
2634          ppId, flags, strmId, ttl, context);
2635    if (ret == INET_ERR)
2636    {
2637       SPutSBuf(info->region, info->pool, sendBuf, bufLen);       
2638 #ifdef CMINETDBG
2639 #ifndef ALIGN_64BIT
2640       /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2641       /* cm_inet_c_001.main_62:Warning fix */
2642       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpSendMsg() Failed : error(%d) ppId(%ld),"
2643             " strmId(%u),sockFd->fd(%ld)\n",
2644             INET_ERR_CODE, ppId, strmId, sockFd->fd);
2645       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET013, 0, prntBuf);
2646 #else
2647       /* cm_inet_c_001.main_55: Fix for compilation warning */
2648       /* cm_inet_c_001.main_62:Warning fix */
2649       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpSendMsg() Failed : error(%d) ppId(%d),"
2650             " strmId(%u),sockFd->fd(%d)\n",
2651             INET_ERR_CODE, ppId, strmId, sockFd->fd);
2652       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET013, 0, prntBuf);
2653 #endif /*ALIGN_64BIT*/
2654 #endif /* CMINETDBG */
2655
2656       if ((INET_ERR_CODE == ERR_AGAIN) || (INET_ERR_CODE == ERR_WOULDBLOCK))
2657          RETVALUE(RWOULDBLOCK);
2658       else if (INET_ERR_CODE == ERR_PIPE)
2659          RETVALUE(RCLOSED);
2660       else 
2661          RETVALUE(RFAILED);
2662    }
2663
2664    /* cm_inet_c_001.main_58 : Fix for klockwork issue */
2665    *len = (MsgLen)ret; 
2666
2667    /* cleanup */
2668    SPutSBuf(info->region, info->pool, sendBuf, bufLen);       
2669
2670    RETVALUE(ROK);
2671 }
2672
2673 /*
2674 *
2675 *      Fun:   cmInetSctpRecvMsg 
2676 *
2677 *      Desc:  invokes sctp API to get the message received at sctp socket
2678 *
2679 *      Ret:   ROK     - successful
2680 *             RFAILED - failed
2681 *
2682 *      Notes: None.
2683 *
2684 *      File:  cm_inet.c
2685 *
2686 */
2687 #ifdef ANSI
2688 PUBLIC S16 cmInetSctpRecvMsg
2689 (
2690 CmInetFd               *sockFd,       /* socket file descriptor */ 
2691 CmInetNetAddr          *srcAddr,      /* source Internet address/port */
2692 U16                    *port,         /* source port no. */
2693 CmInetMemInfo          *meminfo,      /* buffer allocation info */
2694 Buffer                 **mBuf,         /* buffer structure received */
2695 MsgLen                 *len,          /* number of octets received */
2696 CmInetSctpSndRcvInfo   *sinfo,        /* sctp send-receive info */ 
2697 U32                    *flag,         /* flags */
2698 CmInetSctpNotification *ntfy        /* notification parameters */
2699 )
2700 #else
2701 PUBLIC S16 cmInetSctpRecvMsg(sockFd, srcAddr, port, meminfo, mBuf, len, 
2702                              sinfo, flag, ntfy)
2703 CmInetFd               *sockFd;       /* socket file descriptor */ 
2704 CmInetNetAddr          *srcAddr;      /* source Internet address/port */
2705 U16                    *port;         /* source port no. */
2706 CmInetMemInfo          *meminfo;      /* buffer allocation info */
2707 Buffer                 **mBuf;        /* buffer structure received */
2708 MsgLen                 *len;          /* number of octets received */
2709 CmInetSctpSndRcvInfo   *sinfo;        /* sctp send-receive info */ 
2710 U32                    *flag;         /* flags */
2711 CmInetSctpNotification *ntfy;         /* notification parameters */
2712 #endif
2713 {
2714    S32                        ret;   
2715    S32                        msgFlags;
2716    struct sctp_sndrcvinfo     info;
2717    struct sockaddr_storage    addr;
2718    struct sockaddr_in        *pAddr = NULLP;
2719 #ifdef IPV6_SUPPORTED
2720    struct sockaddr_in6       *pAddr6 = NULLP;
2721 #endif 
2722    socklen_t                  addrlen;
2723    Data                      *recvbuf = NULLP;
2724    MsgLen                     buflen;
2725    union sctp_notification   *sctpNtfy = NULLP;
2726    /* cm_inet_c_001.main_46: Defined new variable to store length of data */
2727 #ifdef SS_LINUX
2728    MsgLen                     datlen;
2729 #endif /* SS_LINUX */
2730
2731 #if (ERRCLASS & ERRCLS_INT_PAR)
2732    /* error check on parameters */
2733    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) || 
2734        (srcAddr == NULLP) || (port == NULLP) || (meminfo == NULLP) || 
2735        (mBuf == NULLP) || (len == NULLP) || (sinfo == NULLP) || (flag == NULLP))
2736    {
2737       RETVALUE(RFAILED);
2738    }
2739 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2740
2741
2742    *mBuf = NULLP;
2743    *len  = 0;
2744    cmMemset((U8*)ntfy, 0, sizeof(CmInetSctpNotification));
2745
2746    buflen = CM_INET_MAX_MSG_LEN;
2747
2748    /* allocate flat receive buffer */
2749    ret = SGetSBuf(meminfo->region, meminfo->pool, &recvbuf, buflen);
2750    if (ret != ROK)
2751    {
2752 #ifdef CMINETDBG
2753       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
2754       /* cm_inet_c_001.main_62:Warning fix */
2755       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SGetSBuf failed to allocate memory\n");
2756       CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET065, 0, prntBuf);
2757 #endif /* CMINETDBG */
2758       RETVALUE(RFAILED);
2759    }
2760
2761    addrlen = sizeof(struct sockaddr_storage);
2762    msgFlags = 0;
2763    cmMemset((U8*)&addr, 0, sizeof(struct sockaddr_storage));
2764    cmMemset((U8*)&info, 0, sizeof(struct sctp_sndrcvinfo));
2765
2766    ret = sctp_recvmsg(sockFd->fd, (Void *)recvbuf, (size_t)buflen, 
2767                       (struct sockaddr*)&addr, &addrlen, &info, 
2768                       (int*)&msgFlags);
2769    if (ret == INET_ERR)
2770    {
2771       /* cleanup */
2772       SPutSBuf(meminfo->region, meminfo->pool, recvbuf, buflen);       
2773 #ifdef CMINETDBG
2774 #ifndef ALIGN_64BIT
2775       /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
2776       /* cm_inet_c_001.main_62:Warning fix */
2777       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpRecvMsg() Failed : error(%d),"
2778             " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
2779       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET014, 0, prntBuf);
2780 #else
2781       /* cm_inet_c_001.main_62:Warning fix */
2782       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpRecvMsg() Failed : error(%d),"
2783             " sockFd->fd(%d)\n",  INET_ERR_CODE, sockFd->fd);
2784       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET014, 0, prntBuf);
2785 #endif /*ALIGN_64BIT*/
2786 #endif /* CMINETDBG */
2787
2788       RETVALUE(RFAILED);
2789    }
2790
2791    /* save the length of the received message */
2792    /* cm_inet_c_001.main_58 : Fix for klockwork issue */
2793    *len = (MsgLen)ret;
2794
2795 #ifdef IPV6_SUPPORTED 
2796    if (addr.ss_family == AF_INET6)
2797    {
2798        U8 ipv4Format[12] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff};
2799        pAddr6 = (struct sockaddr_in6*)&addr;
2800        *port = CM_INET_NTOH_U16(pAddr6->sin6_port);
2801
2802       if((cmMemcmp(ipv4Format, pAddr6->sin6_addr.s6_addr, 12)) == 0)
2803       {
2804          srcAddr->type          = CM_INET_IPV4ADDR_TYPE;
2805          cmMemcpy((U8*)&srcAddr->u.ipv4NetAddr, (U8*)((pAddr6->sin6_addr.s6_addr) + 12), sizeof(U32));
2806          srcAddr->u.ipv4NetAddr = CM_INET_HTON_U32(srcAddr->u.ipv4NetAddr);
2807       }
2808
2809       else
2810       {
2811          srcAddr->type = CM_INET_IPV6ADDR_TYPE;
2812          CM_INET_COPY_IPV6ADDR(&srcAddr->u.ipv6NetAddr, &pAddr6->sin6_addr.s6_addr); 
2813       }
2814    }
2815    else 
2816    {
2817       pAddr = (struct sockaddr_in*)&addr;
2818       *port = CM_INET_NTOH_U16(pAddr->sin_port);
2819       srcAddr->type          = CM_INET_IPV4ADDR_TYPE;
2820       srcAddr->u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
2821    }
2822 #else 
2823    pAddr = (struct sockaddr_in*)&addr;
2824    *port = CM_INET_NTOH_U16(pAddr->sin_port);
2825    srcAddr->type          = CM_INET_IPV4ADDR_TYPE;
2826    srcAddr->u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
2827 #endif /* IPV6_SUPPORTED */
2828
2829    /* fill sndrcv info */
2830    sinfo->stream     = info.sinfo_stream;
2831    sinfo->ssn        = info.sinfo_ssn;
2832    sinfo->flags      = info.sinfo_flags;
2833    /*cm_inet_c_001.main_54: converting ppid to host*/
2834    sinfo->ppid       = CM_INET_NTOH_U32(info.sinfo_ppid);
2835    sinfo->context    = info.sinfo_context;
2836    sinfo->timetolive = info.sinfo_timetolive;
2837    sinfo->tsn        = info.sinfo_tsn;
2838    sinfo->cumtsn     = info.sinfo_cumtsn;
2839    sinfo->assocId    = info.sinfo_assoc_id;
2840
2841    /* fill message flags */
2842    *flag = 0;
2843    if ((msgFlags & MSG_EOR) != 0)
2844       *flag |= CM_INET_SCTP_MSG_EOR;
2845
2846    if ((msgFlags & MSG_NOTIFICATION) != 0)
2847    {
2848       *flag |= CM_INET_SCTP_MSG_NOTIFICATION;
2849       *mBuf = NULLP;
2850
2851       sctpNtfy = (union sctp_notification*)recvbuf;
2852
2853       ntfy->header.nFlags = sctpNtfy->sn_header.sn_flags;
2854       ntfy->header.nLen   = sctpNtfy->sn_header.sn_length;
2855
2856       switch(sctpNtfy->sn_header.sn_type)
2857       {
2858          case SCTP_ASSOC_CHANGE:
2859             ntfy->header.nType  = CM_INET_SCTP_ASSOC_CHANGE;
2860             switch(sctpNtfy->sn_assoc_change.sac_state)
2861             {
2862                 case SCTP_COMM_UP:
2863                      ntfy->u.assocChange.state = CM_INET_SCTP_COMM_UP;
2864                      break;
2865                 case SCTP_COMM_LOST:
2866                      ntfy->u.assocChange.state = CM_INET_SCTP_COMM_LOST;
2867                      break;
2868                 case SCTP_RESTART:
2869                      ntfy->u.assocChange.state = CM_INET_SCTP_RESTART;
2870                      break;
2871                 case SCTP_SHUTDOWN_COMP:
2872                      ntfy->u.assocChange.state = CM_INET_SCTP_SHUTDOWN_COMP;
2873                      break;
2874                 case SCTP_CANT_STR_ASSOC:
2875                      ntfy->u.assocChange.state = CM_INET_SCTP_CANT_STR_ASSOC;
2876                      break;
2877                 default:
2878                      break;
2879             }
2880             ntfy->u.assocChange.error      = sctpNtfy->sn_assoc_change.sac_error;
2881             ntfy->u.assocChange.outStreams = sctpNtfy->sn_assoc_change.sac_outbound_streams;
2882             ntfy->u.assocChange.inStreams  = sctpNtfy->sn_assoc_change.sac_inbound_streams;
2883             ntfy->u.assocChange.assocId    = sctpNtfy->sn_assoc_change.sac_assoc_id;
2884 #ifdef SS_LINUX
2885             ntfy->u.assocChange.info       = sctpNtfy->sn_assoc_change.sac_info;
2886 #endif
2887             break;
2888          case SCTP_PEER_ADDR_CHANGE:
2889             ntfy->header.nType  = CM_INET_SCTP_PEER_ADDR_CHANGE;
2890             switch(sctpNtfy->sn_paddr_change.spc_state)
2891             {
2892                 case SCTP_ADDR_AVAILABLE:
2893                      ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_AVAILABLE;
2894                      break;
2895                 case SCTP_ADDR_UNREACHABLE:
2896                      ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_UNREACHABLE;
2897                      break;
2898                 case SCTP_ADDR_REMOVED:
2899                      ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_REMOVED;
2900                      break;
2901                 case SCTP_ADDR_ADDED:
2902                      ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_ADDED;
2903                      break;
2904                 case SCTP_ADDR_MADE_PRIM:
2905                      ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_MADE_PRIM;
2906                      break;
2907 #ifdef SS_LINUX
2908                 case SCTP_ADDR_CONFIRMED:
2909                      ntfy->u.paddrChange.state = CM_INET_SCTP_ADDR_CONFIRMED;
2910                      break;
2911 #endif
2912                 default:
2913                 break;
2914             }
2915
2916 #ifdef IPV6_SUPPORTED 
2917             if (sctpNtfy->sn_paddr_change.spc_aaddr.ss_family == AF_INET6)
2918             {
2919                pAddr6 = (struct sockaddr_in6*)&(sctpNtfy->sn_paddr_change.spc_aaddr);
2920                ntfy->u.paddrChange.addr.type = CM_INET_IPV6ADDR_TYPE;
2921                CM_INET_COPY_IPV6ADDR(&ntfy->u.paddrChange.addr.u.ipv6NetAddr, 
2922                                                     &pAddr6->sin6_addr.s6_addr); 
2923             }
2924             else 
2925             {
2926                pAddr = (struct sockaddr_in*)&(sctpNtfy->sn_paddr_change.spc_aaddr);
2927                ntfy->u.paddrChange.addr.type = CM_INET_IPV4ADDR_TYPE;
2928                ntfy->u.paddrChange.addr.u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
2929             }
2930 #else 
2931             pAddr = (struct sockaddr_in*)&(sctpNtfy->sn_paddr_change.spc_aaddr);
2932             ntfy->u.paddrChange.addr.type = CM_INET_IPV4ADDR_TYPE;
2933             ntfy->u.paddrChange.addr.u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
2934 #endif /* IPV6_SUPPORTED */
2935
2936             ntfy->u.paddrChange.error   = sctpNtfy->sn_paddr_change.spc_error;
2937             ntfy->u.paddrChange.assocId = sctpNtfy->sn_paddr_change.spc_assoc_id;
2938             break;
2939          case SCTP_REMOTE_ERROR:
2940             ntfy->header.nType  = CM_INET_SCTP_REMOTE_ERROR;
2941
2942             ntfy->u.remoteErr.error   = sctpNtfy->sn_remote_error.sre_error;
2943             ntfy->u.remoteErr.assocId = sctpNtfy->sn_remote_error.sre_assoc_id;
2944 #ifdef SS_LINUX
2945             /* cm_inet_c_001.main_46: Allocate memory for data before copying */
2946             datlen = cmStrlen(sctpNtfy->sn_remote_error.sre_data) + 1;
2947
2948             ret = SGetSBuf( meminfo->region, meminfo->pool, \
2949                   &ntfy->u.remoteErr.data, datlen );
2950             if( ret != ROK )
2951             {
2952                ntfy->u.remoteErr.data = NULLP;
2953                break;
2954             }
2955             cmMemcpy(ntfy->u.remoteErr.data,\
2956                   sctpNtfy->sn_remote_error.sre_data, datlen);
2957 #endif
2958             break;
2959          case SCTP_SEND_FAILED:
2960             ntfy->header.nType = CM_INET_SCTP_SEND_FAILED;
2961
2962             ntfy->u.sndFailed.error           = sctpNtfy->sn_send_failed.ssf_error;
2963             ntfy->u.sndFailed.assocId         = sctpNtfy->sn_send_failed.ssf_assoc_id;
2964 #ifdef SS_LINUX
2965             /* cm_inet_c_001.main_46: Allocate memory for data before copying */
2966             datlen = cmStrlen(sctpNtfy->sn_send_failed.ssf_data) + 1;
2967
2968             ret = SGetSBuf( meminfo->region, meminfo->pool, \
2969                   &ntfy->u.sndFailed.data, datlen );
2970             if( ret != ROK )
2971             {
2972                ntfy->u.sndFailed.data = NULLP;
2973                break;
2974             }
2975             cmMemcpy(ntfy->u.sndFailed.data,\
2976                   sctpNtfy->sn_send_failed.ssf_data, datlen );
2977 #endif
2978             ntfy->u.sndFailed.info.stream     = sctpNtfy->sn_send_failed.ssf_info.sinfo_stream;
2979             ntfy->u.sndFailed.info.ssn        = sctpNtfy->sn_send_failed.ssf_info.sinfo_ssn;
2980             ntfy->u.sndFailed.info.flags      = sctpNtfy->sn_send_failed.ssf_info.sinfo_flags;
2981             ntfy->u.sndFailed.info.ppid       = sctpNtfy->sn_send_failed.ssf_info.sinfo_ppid;
2982             ntfy->u.sndFailed.info.context    = sctpNtfy->sn_send_failed.ssf_info.sinfo_context;
2983             ntfy->u.sndFailed.info.timetolive = sctpNtfy->sn_send_failed.ssf_info.sinfo_timetolive;
2984             ntfy->u.sndFailed.info.tsn        = sctpNtfy->sn_send_failed.ssf_info.sinfo_tsn;
2985             ntfy->u.sndFailed.info.cumtsn     = sctpNtfy->sn_send_failed.ssf_info.sinfo_cumtsn;
2986             ntfy->u.sndFailed.info.assocId    = sctpNtfy->sn_send_failed.ssf_info.sinfo_assoc_id;
2987             break;
2988          case SCTP_SHUTDOWN_EVENT:
2989             ntfy->header.nType  = CM_INET_SCTP_SHUTDOWN_EVENT;
2990
2991             ntfy->u.shutdownEvt.assocId = sctpNtfy->sn_shutdown_event.sse_assoc_id;
2992             break;
2993 #ifdef SUN_KSCTP
2994          case SCTP_ADAPTION_INDICATION :
2995 #else
2996             /* linux */
2997          case SCTP_ADAPTATION_INDICATION :
2998 #endif
2999             ntfy->header.nType  = CM_INET_SCTP_ADAPTATION_INDICATION;
3000
3001 #ifdef SUN_KSCTP
3002             ntfy->u.adaptationEvt.adaptationInd = sctpNtfy->sn_adaption_event.sai_adaption_ind;
3003             ntfy->u.adaptationEvt.assocId       = sctpNtfy->sn_adaption_event.sai_assoc_id;
3004 #else
3005             /* linux */
3006             ntfy->u.adaptationEvt.adaptationInd = sctpNtfy->sn_adaptation_event.sai_adaptation_ind;
3007             ntfy->u.adaptationEvt.assocId       = sctpNtfy->sn_adaptation_event.sai_assoc_id;
3008 #endif
3009             break;
3010          case SCTP_PARTIAL_DELIVERY_EVENT:
3011             ntfy->header.nType  = CM_INET_SCTP_PARTIAL_DELIVERY_EVENT;
3012
3013             ntfy->u.pdapiEvt.indication = sctpNtfy->sn_pdapi_event.pdapi_indication;
3014             ntfy->u.pdapiEvt.assocId    = sctpNtfy->sn_pdapi_event.pdapi_assoc_id;
3015             break;
3016          default:
3017             break;
3018       }
3019    }
3020    else
3021    {
3022       /* get a message buffer */
3023       ret = SGetMsg(meminfo->region, meminfo->pool, mBuf);
3024       if (ret != ROK)
3025       {
3026          SPutSBuf(meminfo->region, meminfo->pool, recvbuf, buflen);
3027          RETVALUE(RFAILED);
3028       }
3029
3030       ret = SAddPstMsgMult(recvbuf, *len, *mBuf);
3031       if (ret != ROK)
3032       {
3033          SPutMsg(*mBuf);
3034          SPutSBuf(meminfo->region, meminfo->pool, recvbuf, buflen);
3035          RETVALUE(RFAILED);
3036       }
3037    }
3038
3039    /* cleanup */
3040    SPutSBuf(meminfo->region, meminfo->pool, recvbuf, buflen);       
3041
3042    RETVALUE(ROK);
3043 }
3044
3045 /*
3046 *
3047 *      Fun:   cmInetSctpGetPAddrs 
3048 *
3049 *      Desc:  returns the list of peer addresses 
3050 *
3051 *      Ret:   ROK     - successful
3052 *             RFAILED - failed
3053 *
3054 *      Notes: None.
3055 *
3056 *      File:  cm_inet.c
3057 *
3058 */
3059 #ifdef ANSI
3060 PUBLIC S16 cmInetSctpGetPAddrs
3061 (
3062 CmInetFd             *sockFd,       /* socket file descriptor */ 
3063 U32                   assocId,      /* association id */
3064 CmInetNetAddrLst     *addrlst       /* peer address list */
3065 )
3066 #else
3067 PUBLIC S16 cmInetSctpGetPAddrs(sockFd, assocId, addrlst)
3068 CmInetFd             *sockFd;       /* socket file descriptor */ 
3069 U32                   assocId;      /* association id */
3070 CmInetNetAddrLst     *addrlst;      /* peer address list */
3071 #endif
3072 {
3073    /* cm_inet_c_001.main_58 : Fix for Klockwork issue */
3074    S32   cnt;
3075    S32   idx;
3076    U8    *byteAddress;   
3077    struct sockaddr    *peerAddrList;
3078    struct sockaddr_in *pAddr;
3079 #ifdef IPV6_SUPPORTED
3080    struct sockaddr_in6 *pAddr6;
3081 #endif /* IPV6_SUPPORTED */
3082
3083 #ifdef SUN_KSCTP
3084    if((cnt = sctp_getpaddrs(sockFd->fd, assocId, (Void**)&peerAddrList)) == -1)
3085 #else
3086       if((cnt = sctp_getpaddrs(sockFd->fd, assocId, &peerAddrList)) == -1)
3087 #endif
3088       {
3089 #ifdef CMINETDBG
3090 #ifndef ALIGN_64BIT
3091          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
3092          /* cm_inet_c_001.main_62:Warning fix */
3093          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpGetPAddrs() Failed : error(%d),"
3094                " sockFd->fd(%ld), assocId(%ld)\n", 
3095                INET_ERR_CODE, sockFd->fd, assocId);
3096          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET015, 0, prntBuf);
3097 #else
3098       /* cm_inet_c_001.main_55: Fix for compilation warning */
3099       /* cm_inet_c_001.main_62:Warning fix */
3100          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSctpGetPAddrs() Failed : error(%d),"
3101                " sockFd->fd(%d),assocId(%d)\n", 
3102                INET_ERR_CODE, sockFd->fd, assocId);
3103          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET015, 0, prntBuf);
3104 #endif /*ALIGN_64BIT*/
3105 #endif /* CMINETDBG */
3106
3107          RETVALUE(RFAILED);
3108       }
3109
3110    byteAddress = (U8*)peerAddrList;
3111    for (idx = 0; idx < cnt; idx++)
3112    {
3113 #ifdef IPV6_SUPPORTED 
3114
3115       if (((struct sockaddr*)byteAddress)->sa_family == AF_INET6)
3116       {
3117          if (sockFd->protType == AF_INET)
3118          {
3119 #ifdef CMINETDBG
3120 #ifndef ALIGN_64BIT
3121             /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
3122             sprintf(prntBuf, "cmInetSctpGetPAddrs() Failed : Invalid address"
3123                   " sockFd->fd(%ld)", sockFd->fd);
3124             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET016, 0, prntBuf);
3125 #else
3126             sprintf(prntBuf, "cmInetSctpGetPAddrs() Failed : Invalid address"
3127                   " sockFd->fd(%d)", sockFd->fd);
3128             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET016, 0, prntBuf);
3129 #endif /*ALIGN_64BIT*/
3130 #endif /* CMINETDBG */
3131
3132             sctp_freepaddrs(peerAddrList);
3133             RETVALUE(RFAILED);
3134          }
3135
3136          pAddr6 = (struct sockaddr_in6*)byteAddress;
3137
3138          addrlst->addrs[idx].type = CM_INET_IPV6ADDR_TYPE;
3139          CM_INET_COPY_IPV6ADDR(&(addrlst->addrs[idx].u.ipv6NetAddr), &(pAddr6->sin6_addr.s6_addr));
3140          byteAddress += sizeof(struct sockaddr_in6);
3141       }
3142       else 
3143       {
3144          pAddr = (struct sockaddr_in*)byteAddress;
3145          addrlst->addrs[idx].type          = CM_INET_IPV4ADDR_TYPE;
3146          addrlst->addrs[idx].u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
3147          byteAddress += sizeof(struct sockaddr_in);
3148       }
3149 #else 
3150       pAddr = (struct sockaddr_in*)byteAddress;
3151       addrlst->addrs[idx].type          = CM_INET_IPV4ADDR_TYPE;
3152       addrlst->addrs[idx].u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
3153       byteAddress += sizeof(struct sockaddr_in);
3154 #endif /* IPV6_SUPPORTED */
3155    }
3156
3157    /* cm_inet_c_001.main_58 : Fix for klockwork issue */
3158    addrlst->count = (U8)cnt;   
3159
3160    sctp_freepaddrs(peerAddrList);
3161
3162    RETVALUE(ROK);
3163 }
3164
3165 /*
3166 *
3167 *      Fun:    cmInetGetOpt 
3168 *
3169 *      Desc:   invokes socket API to retrive specified socket options
3170 *
3171 *      Ret:   ROK     - successful
3172 *             RFAILED - failed
3173 *
3174 *      Notes:
3175 *
3176 *      File:   cm_inet.c
3177 *
3178 */
3179 #ifdef ANSI
3180 PUBLIC S16 cmInetGetOpt
3181 (
3182 CmInetFd *sockFd,               /* socket file descriptor */ 
3183 U32       level,                /* option level */
3184 U32       type,                 /* option type */
3185 Ptr       value                 /* option value */ 
3186
3187 #else
3188 PUBLIC S16 cmInetGetOpt(sockFd, level, type, value)
3189 CmInetFd *sockFd;               /* socket file descriptor */ 
3190 U32       level;                /* option level */
3191 U32       type;                 /* option type */
3192 Ptr       value;                /* option value */
3193 #endif
3194 {
3195    socklen_t                len;
3196    struct sctp_status       status;
3197    struct sctp_paddrinfo    addrInfo;
3198    struct sockaddr_in      *pAddr;
3199 #ifdef IPV6_SUPPORTED
3200    struct sockaddr_in6     *pAddr6;
3201 #endif /* IPV6_SUPPORTED */
3202    struct sctp_assocparams  assocParams;
3203 /*cm_inet_c_001.main_40 Updated for the support of configurable RTO parameters, 
3204                         HBeat value Max retransmissions (Init, Path, Association)*/
3205    struct sctp_initmsg      initMsg;
3206    struct sctp_rtoinfo      rtoInfo;
3207    struct sctp_paddrparams  addrParams;
3208    CmInetSctpStatus        *pSctpStatus;
3209    CmInetSctpPeerAddrInfo  *pPeerAddrInfo;
3210    CmInetSctpInitMsg       *pInitMsg;
3211    CmInetSctpAssocParams   *pAssocParams;
3212    CmInetSctpRtoInfo       *pRtoInfo;
3213    CmInetSctpPeerAddrParams *pPeerAddrParams;
3214    /*cm_inet_c_001.main_58  : fix for klockwork issue */
3215    S32                     ret;
3216
3217    TRC2(cmInetGetOpt);
3218
3219 #if (ERRCLASS & ERRCLS_INT_PAR)
3220    /* error check on parameters */
3221    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
3222    {
3223       RETVALUE(RFAILED);
3224    }
3225 #endif /* ERRCLASS & ERRCLS_INT_PAR */
3226
3227    switch (type) 
3228    {
3229       case CM_INET_OPT_SCTP_GET_ASSOC_STA:
3230          pSctpStatus = (CmInetSctpStatus*)value;
3231          cmMemset((U8*)&status, 0, sizeof(struct sctp_status));
3232          len = sizeof(status);
3233          status.sstat_assoc_id = pSctpStatus->assocId;
3234
3235          ret = getsockopt(sockFd->fd, level, SCTP_STATUS, &status, &len);
3236
3237          pSctpStatus->rwnd      = status.sstat_rwnd;
3238          pSctpStatus->unackdata = status.sstat_unackdata;
3239          pSctpStatus->penddata  = status.sstat_penddata;
3240          pSctpStatus->instrms   = status.sstat_instrms;
3241          pSctpStatus->outstrms  = status.sstat_outstrms;
3242          pSctpStatus->fragPoint = status.sstat_fragmentation_point; 
3243
3244          switch (status.sstat_state)
3245          {
3246 #ifdef SUN_KSCTP
3247             case SCTPS_IDLE:
3248             case SCTPS_BOUND:
3249             case SCTPS_LISTEN:
3250 #else
3251             case SCTP_EMPTY:
3252 #endif
3253                {
3254                   pSctpStatus->state = CM_INET_SCTP_STA_EMPTY;
3255                }
3256                break;
3257
3258 #ifdef SS_LINUX
3259             case SCTP_CLOSED:
3260                {
3261                   pSctpStatus->state = CM_INET_SCTP_STA_CLOSED;
3262                }
3263                break;
3264 #endif
3265
3266 #ifdef SUN_KSCTP
3267             case SCTPS_COOKIE_WAIT:
3268 #else
3269             case SCTP_COOKIE_WAIT:
3270 #endif
3271                {
3272                   pSctpStatus->state = CM_INET_SCTP_STA_COOKIE_WAIT;
3273                }
3274                break;
3275
3276 #ifdef SUN_KSCTP
3277             case SCTPS_COOKIE_ECHOED:
3278 #else
3279             case SCTP_COOKIE_ECHOED:
3280 #endif
3281                {
3282                   pSctpStatus->state = CM_INET_SCTP_STA_COOKIE_ECHOED;
3283                }
3284                break;
3285
3286 #ifdef SUN_KSCTP
3287             case SCTPS_ESTABLISHED:
3288 #else
3289             case SCTP_ESTABLISHED:
3290 #endif
3291                {
3292                   pSctpStatus->state = CM_INET_SCTP_STA_ESTABLISHED;
3293                }
3294                break;
3295
3296 #ifdef SUN_KSCTP
3297             case SCTPS_SHUTDOWN_PENDING:
3298 #else
3299             case SCTP_SHUTDOWN_PENDING:
3300 #endif
3301                {
3302                   pSctpStatus->state = CM_INET_SCTP_STA_SHUTDOWN_PENDING;
3303                }
3304                break;
3305
3306 #ifdef SUN_KSCTP
3307             case SCTPS_SHUTDOWN_SENT:
3308 #else
3309             case SCTP_SHUTDOWN_SENT:
3310 #endif
3311                {
3312                   pSctpStatus->state = CM_INET_SCTP_STA_SHUTDOWN_SENT;
3313                }
3314                break;
3315
3316 #ifdef SUN_KSCTP
3317             case SCTPS_SHUTDOWN_RECEIVED:
3318 #else
3319             case SCTP_SHUTDOWN_RECEIVED:
3320 #endif
3321                {
3322                   pSctpStatus->state = CM_INET_SCTP_STA_SHUTDOWN_RECEIVED;
3323                }
3324                break;
3325
3326 #ifdef SUN_KSCTP
3327             case SCTPS_SHUTDOWN_ACK_SENT:
3328 #else
3329             case SCTP_SHUTDOWN_ACK_SENT:
3330 #endif
3331                {
3332                   pSctpStatus->state = CM_INET_SCTP_STA_SHUTDOWN_ACK_SENT;
3333                }
3334                break;
3335
3336             default:
3337                {
3338                   RETVALUE(RFAILED);
3339                }
3340                break;
3341          }
3342
3343 #ifdef IPV6_SUPPORTED 
3344          if (status.sstat_primary.spinfo_address.ss_family == AF_INET6)
3345          {
3346             pAddr6 = (struct sockaddr_in6*)&(status.sstat_primary.spinfo_address);
3347             pSctpStatus->primary.port = CM_INET_NTOH_U16(pAddr6->sin6_port);
3348
3349             pSctpStatus->primary.addr.type = CM_INET_IPV6ADDR_TYPE;
3350             CM_INET_COPY_IPV6ADDR(&pSctpStatus->primary.addr.u.ipv6NetAddr, 
3351                   &pAddr6->sin6_addr.s6_addr); 
3352          }
3353          else 
3354          {
3355             pAddr = (struct sockaddr_in*)&(status.sstat_primary.spinfo_address);
3356             pSctpStatus->primary.port = CM_INET_NTOH_U16(pAddr->sin_port);
3357             pSctpStatus->primary.addr.type          = CM_INET_IPV4ADDR_TYPE;
3358             pSctpStatus->primary.addr.u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
3359          }
3360 #else 
3361          pAddr = (struct sockaddr_in*)&(status.sstat_primary.spinfo_address);
3362          pSctpStatus->primary.port = CM_INET_NTOH_U16(pAddr->sin_port);
3363          pSctpStatus->primary.addr.type          = CM_INET_IPV4ADDR_TYPE;
3364          pSctpStatus->primary.addr.u.ipv4NetAddr = CM_INET_NTOH_U32(pAddr->sin_addr.s_addr);
3365 #endif /* IPV6_SUPPORTED */
3366
3367          pSctpStatus->primary.assocId = status.sstat_primary.spinfo_assoc_id;
3368          if (status.sstat_primary.spinfo_state == SCTP_ACTIVE)
3369              pSctpStatus->primary.isActive = TRUE;
3370          else
3371              pSctpStatus->primary.isActive = FALSE;
3372              pSctpStatus->primary.cwnd = status.sstat_primary.spinfo_cwnd;
3373              pSctpStatus->primary.srtt = status.sstat_primary.spinfo_srtt;
3374              pSctpStatus->primary.rto  = status.sstat_primary.spinfo_rto;
3375              pSctpStatus->primary.mtu  = status.sstat_primary.spinfo_mtu;
3376          break;
3377
3378       case CM_INET_OPT_SCTP_GET_PADDR_INFO:
3379          pPeerAddrInfo = (CmInetSctpPeerAddrInfo*)value;
3380          cmMemset((U8*)&addrInfo, 0, sizeof(struct sctp_paddrinfo));
3381          len = sizeof(addrInfo);
3382          addrInfo.spinfo_assoc_id = pPeerAddrInfo->assocId;
3383
3384 #ifdef IPV6_SUPPORTED 
3385          if (pPeerAddrInfo->addr.type == CM_INET_IPV6ADDR_TYPE)
3386          {
3387             if (sockFd->protType == AF_INET)
3388             {
3389 #ifdef CMINETDBG
3390 #ifndef ALIGN_64BIT
3391                /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
3392                /* cm_inet_c_001.main_62:Warning fix */
3393                snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetOpt() Failed : Invalid address,"
3394                      " sockFd->fd(%ld)\n", sockFd->fd);
3395                CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET017, 0, prntBuf);
3396 #else
3397                /* cm_inet_c_001.main_62:Warning fix */
3398                snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetOpt() Failed : Invalid address,"
3399                      " sockFd->fd(%d)\n", sockFd->fd);
3400                CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET017, 0, prntBuf);
3401 #endif /*ALIGN_64BIT*/
3402 #endif /* CMINETDBG */
3403                RETVALUE(RFAILED);
3404             }
3405
3406             pAddr6 = (struct sockaddr_in6*)&(addrInfo.spinfo_address);
3407             pAddr6->sin6_family      = AF_INET6;
3408             pAddr6->sin6_port        = CM_INET_HTON_U16(pPeerAddrInfo->port);
3409             CM_INET_COPY_IPV6ADDR(&pAddr6->sin6_addr.s6_addr, &pPeerAddrInfo->addr.u.ipv6NetAddr); 
3410          }
3411          else 
3412          {
3413             pAddr = (struct sockaddr_in*)&(addrInfo.spinfo_address);
3414             pAddr->sin_family      = AF_INET;
3415             pAddr->sin_port        = CM_INET_HTON_U16(pPeerAddrInfo->port);
3416             pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pPeerAddrInfo->addr.u.ipv4NetAddr);
3417          }
3418 #else 
3419          pAddr = (struct sockaddr_in*)&(addrInfo.spinfo_address);
3420          pAddr->sin_family      = AF_INET;
3421          pAddr->sin_port        = CM_INET_HTON_U16(pPeerAddrInfo->port);
3422          pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pPeerAddrInfo->addr.u.ipv4NetAddr); 
3423 #endif /* IPV6_SUPPORTED */
3424
3425          /* Not validating the address, whether Addr is a valid address or not */
3426
3427          ret = getsockopt(sockFd->fd, level, SCTP_GET_PEER_ADDR_INFO, &addrInfo, &len);
3428
3429          if (addrInfo.spinfo_state == SCTP_ACTIVE)
3430             pPeerAddrInfo->isActive = TRUE;
3431          else
3432             pPeerAddrInfo->isActive = FALSE;
3433          pPeerAddrInfo->cwnd = addrInfo.spinfo_cwnd;
3434          pPeerAddrInfo->srtt = addrInfo.spinfo_srtt;
3435          pPeerAddrInfo->rto  = addrInfo.spinfo_rto;
3436          pPeerAddrInfo->mtu  = addrInfo.spinfo_mtu;
3437          break;
3438
3439       case CM_INET_OPT_SCTP_PEERADDR_PARAMS:
3440
3441          pPeerAddrParams = (CmInetSctpPeerAddrParams *)value;
3442
3443          cmMemset((U8*)&addrParams, 0, sizeof(struct sctp_paddrparams));
3444
3445          addrParams.spp_assoc_id = pPeerAddrParams->assocId;
3446
3447          if (pPeerAddrParams->s.addrPres == TRUE)
3448          {
3449 #ifdef IPV6_SUPPORTED 
3450             if (pPeerAddrParams->s.addr.type == CM_INET_IPV6ADDR_TYPE)
3451             {
3452                if (sockFd->protType == AF_INET)
3453                {
3454 #ifdef CMINETDBG
3455 #ifndef ALIGN_64BIT
3456                   /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
3457                   /* cm_inet_c_001.main_62:Warning fix */
3458                   snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "invalid address line:sockFd->fd(%ld)\n",
3459                         sockFd->fd);
3460                   CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET066, 0, prntBuf);
3461 #else
3462                   /* cm_inet_c_001.main_62:Warning fix */
3463                   snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "invalid address line:sockFd->fd(%d)\n",
3464                         sockFd->fd);
3465                   CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET066, 0, prntBuf);
3466 #endif /*ALIGN_64BIT*/
3467 #endif /* CMINETDBG */
3468                   RETVALUE(RFAILED);
3469                }
3470
3471                pAddr6 = (struct sockaddr_in6*)&(addrParams.spp_address);
3472                pAddr6->sin6_family      = AF_INET6;
3473                pAddr6->sin6_port        = CM_INET_HTON_U16(pPeerAddrParams->s.port);
3474                CM_INET_COPY_IPV6ADDR(&pAddr6->sin6_addr.s6_addr, &pPeerAddrParams->s.addr.u.ipv6NetAddr); 
3475             }
3476             else 
3477             {
3478                pAddr = (struct sockaddr_in*)&(addrParams.spp_address);
3479                pAddr->sin_family      = AF_INET;
3480                pAddr->sin_port        = CM_INET_HTON_U16(pPeerAddrParams->s.port);
3481                pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pPeerAddrParams->s.addr.u.ipv4NetAddr);
3482             }
3483 #else 
3484             pAddr = (struct sockaddr_in*)&(addrParams.spp_address);
3485             pAddr->sin_family      = AF_INET;
3486             pAddr->sin_port        = CM_INET_HTON_U16(pPeerAddrParams->s.port);
3487             pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pPeerAddrParams->s.addr.u.ipv4NetAddr);
3488 #endif /* IPV6_SUPPORTED */
3489          }
3490          else
3491          {
3492 #ifdef IPV6_SUPPORTED 
3493             if (sockFd->protType == AF_INET6)
3494                addrParams.spp_address.ss_family = AF_INET6;
3495             else
3496                addrParams.spp_address.ss_family = AF_INET;
3497 #else
3498             addrParams.spp_address.ss_family = AF_INET;
3499 #endif
3500          }
3501
3502          len = sizeof(addrParams);
3503
3504          ret = getsockopt(sockFd->fd, level, SCTP_PEER_ADDR_PARAMS, &addrParams, &len);
3505          /* cm_inet_c_001.main_41 : Fixed the Solaris compilation problem */
3506 #ifndef SUN_KSCTP
3507
3508          pPeerAddrParams->hbInterval    = addrParams.spp_hbinterval;
3509          pPeerAddrParams->pathMaxRxt    = addrParams.spp_pathmaxrxt;
3510          pPeerAddrParams->assocId       = addrParams.spp_assoc_id;
3511          pPeerAddrParams->pathMtu       = addrParams.spp_pathmtu;
3512          pPeerAddrParams->sackDelay     = addrParams.spp_sackdelay;
3513
3514          if (addrParams.spp_flags & SPP_HB_ENABLE)
3515             pPeerAddrParams->hbEnblFlag    = CM_INET_OPT_ENABLE;
3516          else
3517             pPeerAddrParams->hbEnblFlag    = CM_INET_OPT_DISABLE;
3518
3519          if (addrParams.spp_flags & SPP_PMTUD_ENABLE)
3520             pPeerAddrParams->pmtudFlag     = CM_INET_OPT_ENABLE;
3521          else
3522             pPeerAddrParams->pmtudFlag     = CM_INET_OPT_DISABLE;
3523
3524          if (addrParams.spp_flags & SPP_SACKDELAY_ENABLE)
3525             pPeerAddrParams->sackDelayFlag = CM_INET_OPT_ENABLE;
3526          else
3527             pPeerAddrParams->sackDelayFlag = CM_INET_OPT_DISABLE;
3528 #endif 
3529
3530          break;
3531
3532       case CM_INET_OPT_SCTP_ASSOC_PARAMS:
3533
3534          pAssocParams = (CmInetSctpAssocParams *)value;
3535
3536          cmMemset((U8*)&assocParams, 0, sizeof(struct sctp_assocparams));
3537
3538          assocParams.sasoc_assoc_id = pAssocParams->assocId;
3539
3540          len = sizeof(assocParams);
3541
3542          ret = getsockopt(sockFd->fd, level, SCTP_ASSOCINFO, &assocParams, &len);
3543
3544          pAssocParams->assocMaxReTx      = assocParams.sasoc_asocmaxrxt;
3545          pAssocParams->cookieLife        = assocParams.sasoc_cookie_life;
3546          pAssocParams->assocId           = assocParams.sasoc_assoc_id;
3547          pAssocParams->numberOfPeerDest  = assocParams.sasoc_number_peer_destinations;
3548          pAssocParams->peerRwnd          = assocParams.sasoc_peer_rwnd;
3549          pAssocParams->localRwnd         = assocParams.sasoc_local_rwnd;
3550
3551          break;
3552
3553       case CM_INET_OPT_SCTP_RTO_INFO:
3554
3555          pRtoInfo = (CmInetSctpRtoInfo *)value;
3556
3557          cmMemset((U8*)&rtoInfo, 0, sizeof(struct sctp_rtoinfo));
3558
3559          len = sizeof(rtoInfo);
3560
3561          ret = getsockopt(sockFd->fd, level, SCTP_RTOINFO, &rtoInfo, &len);
3562
3563          pRtoInfo->assocId    = rtoInfo.srto_assoc_id;
3564          pRtoInfo->rtoInitial = rtoInfo.srto_initial;
3565          pRtoInfo->rtoMax     = rtoInfo.srto_max;
3566          pRtoInfo->rtoMin     = rtoInfo.srto_min;
3567
3568          break;
3569
3570       case CM_INET_OPT_SCTP_INIT_MSG:
3571
3572          pInitMsg = (CmInetSctpInitMsg *)value;
3573
3574          cmMemset((U8*)&initMsg, 0, sizeof(struct sctp_initmsg));
3575
3576          len = sizeof(initMsg);
3577
3578          ret = getsockopt(sockFd->fd, level, SCTP_INITMSG, &initMsg, &len);
3579
3580          pInitMsg->maxInitReTx    = initMsg.sinit_max_attempts;
3581          pInitMsg->maxInitTimeout = initMsg.sinit_max_init_timeo;
3582          pInitMsg->numOstreams    = initMsg.sinit_num_ostreams;
3583          pInitMsg->maxInstreams   = initMsg.sinit_max_instreams;
3584
3585          break;
3586
3587       default:
3588          RETVALUE(RFAILED);
3589    }
3590
3591    if (ret == INET_ERR)
3592    {
3593 #ifdef CMINETDBG
3594 #ifndef ALIGN_64BIT
3595       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
3596       /* cm_inet_c_001.main_62:Warning fix */
3597       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetOpt() failed on line:"
3598             " error(%d), sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
3599       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET067, 0, prntBuf);
3600 #else
3601       /* cm_inet_c_001.main_62:Warning fix */
3602       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetOpt() failed on line:"
3603             " error(%d), sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
3604       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET067, 0, prntBuf);
3605 #endif /*ALIGN_64BIT*/
3606 #endif /* CMINETDBG */
3607       RETVALUE(RFAILED);
3608    }          
3609
3610    RETVALUE(ROK);
3611 }
3612
3613 /* cm_inet_c_001.main_54: Added new function cmInetShutDownSctp()*/
3614 /*
3615  *
3616  *      Fun:   cmInetShutDownSctp 
3617  *
3618  *      Desc:  Shutdown the SCTP association gracefully.
3619  *
3620  *      Ret:   ROK     - successful
3621  *             RFAILED - failed
3622  *
3623  *      Notes: None.
3624  *
3625  *      File:  cm_inet.c
3626  *
3627  */
3628 #ifdef ANSI
3629 PUBLIC S16 cmInetShutDownSctp
3630 (
3631  CmInetFd          *sockFd       /* socket file descriptor */ 
3632  )
3633 #else
3634 PUBLIC S16 cmInetShutDownSctp(sockFd)
3635    CmInetFd          *sockFd;       /* socket file descriptor */ 
3636 #endif
3637 {
3638    /*cm_inet_c_001.main_58  : fix for klockwork issue */
3639    S32                    ret;
3640    struct sctp_sndrcvinfo sndRcvInfo;
3641
3642    TRC2(cmInetShutDownSctp);
3643
3644    cmMemset((U8*)&sndRcvInfo, 0, sizeof(sndRcvInfo));
3645
3646 #ifdef SUN_KSCTP
3647    sndRcvInfo.sinfo_flags = MSG_EOF;
3648 #else
3649    sndRcvInfo.sinfo_flags = SCTP_EOF;
3650 #endif
3651
3652    /* Call the sctp_send with flag set to termiante the association */
3653
3654    ret = sctp_send(sockFd->fd, NULLP, 0, &sndRcvInfo, sndRcvInfo.sinfo_flags);
3655
3656    if(ret == INET_ERR)
3657    {
3658 #ifdef CMINETDBG
3659 #ifndef ALIGN_64BIT
3660       /* cm_inet_c_001.main_62:Warning fix */
3661       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetShutDownSctp() Failed : error(%d), sockFd->fd(%ld)\n",
3662             INET_ERR_CODE, sockFd->fd);
3663       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET018, 0, prntBuf);
3664 #else
3665       /* cm_inet_c_001.main_62:Warning fix */
3666       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetShutDownSctp() Failed : error(%d), sockFd->fd(%d)\n",
3667             INET_ERR_CODE, sockFd->fd);
3668       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET018, 0, prntBuf);
3669 #endif /*ALIGN_64BIT*/
3670 #endif /* CMINETDBG */
3671
3672       RETVALUE(RFAILED);
3673    }
3674
3675    RETVALUE(ROK);
3676 }
3677
3678 /* cm_inet_c_001.main_61: Added new function cmInetAbortSctpAssoc()*/
3679 /*
3680  *
3681  *      Fun:   cmInetAbortSctpAssoc
3682  *
3683  *      Desc:  ABORT the association.
3684  *
3685  *      Ret:   ROK     - successful
3686  *             RFAILED - failed
3687  *
3688  *      Notes: None.
3689  *
3690  *      File:  cm_inet.c
3691  *
3692  */
3693 #ifdef ANSI
3694 PUBLIC S16 cmInetAbortSctpAssoc
3695 (
3696  CmInetFd          *sockFd,       /* socket file descriptor */
3697  UConnId           assocId          /* Association ID */
3698  )
3699 #else
3700 PUBLIC S16 cmInetAbortSctpAssoc(sockFd, assocId)
3701    CmInetFd          *sockFd;       /* socket file descriptor */
3702    UConnId           assocId;          /* Association ID */
3703 #endif
3704 {
3705    S32                    ret;
3706    struct sctp_sndrcvinfo sndRcvInfo;
3707
3708    TRC2(cmInetAbortSctpAssoc);
3709
3710    cmMemset((U8*)&sndRcvInfo, 0, sizeof(sndRcvInfo));
3711
3712 #ifdef SUN_KSCTP
3713    sndRcvInfo.sinfo_flags = MSG_ABORT;
3714 #else
3715    sndRcvInfo.sinfo_flags = SCTP_ABORT;
3716 #endif
3717
3718    sndRcvInfo.sinfo_assoc_id = assocId;
3719
3720    /* Call the sctp_send with flag set to termiante the association */
3721
3722    ret = sctp_send(sockFd->fd, NULLP, 0, &sndRcvInfo, sndRcvInfo.sinfo_flags);
3723
3724    if(ret == INET_ERR)
3725    {
3726 #ifdef CMINETDBG
3727 #ifndef ALIGN_64BIT
3728       /* cm_inet_c_001.main_62:Warning fix */
3729       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAbortSctpAssoc() Failed : error(%d), sockFd->fd(%ld)\n",
3730             INET_ERR_CODE, sockFd->fd);
3731       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET018, 0, prntBuf);
3732 #else
3733       /* cm_inet_c_001.main_62:Warning fix */
3734       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAbortSctpAssoc() Failed : error(%d), sockFd->fd(%d)\n",
3735             INET_ERR_CODE, sockFd->fd);
3736       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET018, 0, prntBuf);
3737 #endif /*ALIGN_64BIT*/
3738 #endif /* CMINETDBG */
3739
3740       RETVALUE(RFAILED);
3741    }
3742
3743    RETVALUE(ROK);
3744 }
3745
3746 #endif
3747
3748 \f
3749 /*
3750  *
3751  *      Fun:   cmInetConnect
3752  *
3753  *      Desc:  Establishs a connection to a foreign address (TCP) or associates
3754  *             a UDP socket to a foreign address.
3755  *
3756  *      Ret:   ROK         - successful
3757 *             ROKDNA      - resource temporarily unavaiable
3758 *             RINPROGRESS - connection is in progress (only non-blocking)
3759 *             RISCONN     - connection is established (only non-blocking)
3760 *             RFAILED     - failed
3761 *
3762 *      Notes: None.
3763 *
3764 *      File:  cm_inet.c
3765 *
3766 */
3767
3768 #ifdef ANSI
3769 PUBLIC S16 cmInetConnect
3770 (
3771 CmInetFd   *sockFd,             /* socket file descriptor */
3772 CmInetAddr *servAddr            /* foreign Internet address/port */  
3773 )
3774 #else
3775 PUBLIC S16 cmInetConnect(sockFd, servAddr)
3776    CmInetFd   *sockFd;             /* socket file descriptor */
3777    CmInetAddr *servAddr;           /* foreign Internet address/port */  
3778 #endif
3779 {
3780    S32 ret;                     /* temporary return value */
3781    struct sockaddr_in dstAddr;  /* foreign Internet address/port */
3782 #ifdef IPV6_SUPPORTED 
3783    struct sockaddr_in6 dstAddr6; /* foreign Internet IPV6 address/port */
3784 #ifdef CMINETDBG
3785    U16            port;
3786 #endif /* CMINETDBG */
3787 #endif /* IPV6_SUPPORTED */
3788    S32    sizeOfAddr;
3789    CmInetSockAddr *sockAddrPtr;  
3790
3791    TRC2(cmInetConnect);
3792
3793 #if (ERRCLASS & ERRCLS_INT_PAR)
3794    /* error check on parameters */
3795    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
3796          (servAddr == NULLP))
3797    {
3798       RETVALUE(RFAILED);
3799    }
3800 #endif /* ERRCLASS & ERRCLS_INT_PAR */
3801
3802 #ifdef IPV6_SUPPORTED 
3803    if (servAddr->type == CM_INET_IPV6ADDR_TYPE)
3804    {
3805       cmMemset((U8*)&dstAddr6, 0, sizeof(dstAddr6));
3806       dstAddr6.sin6_family     = AF_INET6;
3807       dstAddr6.sin6_port       = CM_INET_HTON_U16(servAddr->u.ipv6Addr.port);
3808       CM_INET_COPY_IPV6ADDR(&dstAddr6.sin6_addr, 
3809                             &servAddr->u.ipv6Addr.ipv6NetAddr);
3810       sizeOfAddr              = sizeof(struct sockaddr_in6);
3811       sockAddrPtr             = (CmInetSockAddr *)&dstAddr6;
3812    }
3813    else
3814    {
3815       cmMemset((U8*)&dstAddr, 0, sizeof(dstAddr));
3816       dstAddr.sin_family      = AF_INET;
3817       dstAddr.sin_port        = CM_INET_HTON_U16(servAddr->u.ipv4Addr.port);
3818       dstAddr.sin_addr.s_addr = CM_INET_HTON_U32(servAddr->u.ipv4Addr.address);
3819       sizeOfAddr              = sizeof(struct sockaddr_in);
3820       sockAddrPtr             = (CmInetSockAddr *)&dstAddr;
3821    }
3822 #else
3823    cmMemset((U8*)&dstAddr, 0, sizeof(dstAddr));
3824    dstAddr.sin_family      = AF_INET;
3825    dstAddr.sin_port        = CM_INET_HTON_U16(servAddr->port);
3826    dstAddr.sin_addr.s_addr = CM_INET_HTON_U32(servAddr->address);
3827    sizeOfAddr              = sizeof(struct sockaddr_in);
3828    sockAddrPtr             = (CmInetSockAddr *)&dstAddr;
3829 #endif /* IPV6_SUPPORTED */
3830
3831    ret = connect(sockFd->fd, sockAddrPtr, sizeOfAddr);
3832    if (ret == INET_ERR)
3833    {
3834       switch (INET_ERR_CODE)
3835       {
3836          /* non-blocking: connection is in progress */
3837          case ERR_INPROGRESS:
3838             RETVALUE(RINPROGRESS);
3839             break;   
3840
3841             /* 
3842              * non-blocking: connection is established 
3843              * blocking    : connection is already established
3844              */
3845          case ERR_ISCONN:
3846             RETVALUE(RISCONN);
3847             break;               
3848
3849             /* resource temporarily unavailable */
3850          case ERR_WOULDBLOCK:
3851             RETVALUE(ROKDNA);
3852             break;
3853
3854             /* non-blocking: connection is in progress */
3855          case ERR_ALREADY:
3856             RETVALUE(RINPROGRESS);
3857             break;
3858
3859          case ERR_INVAL:
3860             RETVALUE(RINPROGRESS);
3861             break;
3862
3863             /*  Check for connection refused and timeout errors */
3864          case ERR_CONNREFUSED:
3865          case ERR_TIMEDOUT:
3866             RETVALUE(RCLOSED);
3867             break;
3868
3869             /* it is a real error */ 
3870          default:
3871 #ifdef CMINETDBG
3872 #ifdef IPV6_SUPPORTED 
3873             if (servAddr->type == CM_INET_IPV6ADDR_TYPE)
3874                port = servAddr->u.ipv6Addr.port;
3875             else
3876                port = servAddr->u.ipv4Addr.port;
3877
3878             /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
3879 #ifndef ALIGN_64BIT
3880             /* cm_inet_c_001.main_62:Warning fix */
3881             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetConnect() Failed : error(%d),"
3882                   " addrtype(0x%x), port(0x%1x), sockFd->fd(%ld)\n", 
3883                   INET_ERR_CODE, servAddr->type, port, sockFd->fd);
3884             CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET019, 0, prntBuf);
3885 #else
3886             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetConnect() Failed : error(%d),"
3887                   " addrtype(0x%x), port(0x%1x), sockFd->fd(%d)\n", 
3888                   INET_ERR_CODE, servAddr->type, port, sockFd->fd);
3889             CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET019, 0, prntBuf);
3890 #endif /*ALIGN_64BIT*/
3891 #else
3892 #ifndef ALIGN_64BIT
3893             /* cm_inet_c_001.main_62:Warning fix */
3894             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetConnect() Failed : error(%d), addr(0x%lx),"
3895                   "port(0x%1x), sockFd->fd(%ld)\n", INET_ERR_CODE , 
3896                   servAddr->address, servAddr->port, sockFd->fd);
3897             CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET020, 0, prntBuf);
3898 #else
3899             /* cm_inet_c_001.main_62:Warning fix */
3900             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetConnect() Failed : error(%d), addr(0x%x),"
3901                   "port(0x%x), sockFd->fd(%d)\n", INET_ERR_CODE , 
3902                   servAddr->address, servAddr->port, sockFd->fd);
3903             CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET020, 0, prntBuf);
3904 #endif /*ALIGN_64BIT*/
3905 #endif /* IPV6_SUPPORTED */
3906 #endif /* CMINETDBG */
3907             RETVALUE(RFAILED);
3908             break;
3909       }
3910    }
3911
3912    RETVALUE(ROK);
3913 } /* end of cmInetConnect */
3914
3915 \f
3916 /*
3917 *
3918 *      Fun:   cmInetListen
3919 *
3920 *      Desc:  Indicates the willingness of a socket to listen for incomming 
3921 *             connection requests.
3922 *
3923 *      Ret:   ROK     - successful
3924 *             RFAILED - failed
3925 *
3926 *      Notes: The backLog value has to be within 0..5
3927 *
3928 *      File:  cm_inet.c
3929 *
3930 */
3931
3932 #ifdef ANSI
3933 PUBLIC S16 cmInetListen
3934 (
3935 CmInetFd *sockFd,               /* socket file descriptor */ 
3936 S16       backLog               /* max. number of outstandig connections 0..5 */
3937 )
3938 #else
3939 PUBLIC S16 cmInetListen(sockFd, backLog)
3940 CmInetFd *sockFd;               /* socket file descriptor */ 
3941 S16       backLog;              /* max. number of outstandig connections 0..5 */
3942 #endif
3943 {
3944    S32 ret;                     /* temporary return value */
3945
3946    TRC2(cmInetListen);
3947
3948 #if (ERRCLASS & ERRCLS_INT_PAR)
3949    /* error check on parameters */
3950    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
3951          (backLog < MIN_BACK_LOG) || (backLog > MAX_BACK_LOG))
3952    {
3953       RETVALUE(RFAILED);
3954    }
3955 #endif /* ERRCLASS & ERRCLS_INT_PAR */
3956
3957    ret = listen(sockFd->fd, backLog);
3958    if (ret == INET_ERR) 
3959    {
3960 #ifdef CMINETDBG
3961 #ifndef ALIGN_64BIT
3962       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
3963       /* cm_inet_c_001.main_62:Warning fix */
3964       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetListen() Failed : error(%d), backLog(%d),"
3965             " sockFd->fd(%ld)\n", INET_ERR_CODE, backLog, sockFd->fd);
3966       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET021, 0, prntBuf);
3967 #else
3968       /* cm_inet_c_001.main_62:Warning fix */
3969       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetListen() Failed : error(%d), backLog(%d),"
3970             " sockFd->fd(%d)\n", INET_ERR_CODE, backLog, sockFd->fd);
3971       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET021, 0, prntBuf);
3972 #endif /*ALIGN_64BIT*/
3973 #endif /* CMINETDBG */
3974       RETVALUE(RFAILED);
3975    }
3976
3977    RETVALUE(ROK);
3978 } /* end of cmInetListen */
3979
3980 \f
3981 /*
3982 *
3983 *      Fun:   cmInetAccept 
3984 *
3985 *      Desc:  Accepts an incoming connection.
3986 *             On default the new socket is non-blocking. The options can be 
3987 *             changed with the function cmInetSetOpt().
3988 *
3989 *      Ret:   ROK     - successful
3990 *             ROKDNA  - there is no connection present to accept (only 
3991 *                       non-blocking) 
3992 *             RFAILED - failed
3993 *
3994 *      Notes: None.
3995 *
3996 *      File:  cm_inet.c
3997 *
3998 */
3999
4000 #ifdef ANSI
4001 PUBLIC S16 cmInetAccept
4002 (
4003 CmInetFd   *sockFd,     /* socket file descriptor */ 
4004 CmInetAddr *fromAddr,   /* calling Internet address/port */
4005 CmInetFd   *newSockFd   /* socket file descriptor for new connection*/
4006 )
4007 #else
4008 PUBLIC S16 cmInetAccept(sockFd, fromAddr, newSockFd)
4009 CmInetFd   *sockFd;     /* socket file descriptor */ 
4010 CmInetAddr *fromAddr;   /* calling Internet address/port */
4011 CmInetFd   *newSockFd;  /* socket file descriptor for new connection*/
4012 #endif
4013 {
4014    S32 ret;                         /* temporary return value */
4015    S32 addrLen;                     /* address structure length */
4016    struct sockaddr_in  *peerAddr;   /* calling Internet address/port */
4017 #ifdef IPV6_SUPPORTED 
4018    struct sockaddr_in6 *peerAddr6;  /* calling Internet address/port */
4019    struct sockaddr_in6 sockAddr;
4020 #else
4021    CmInetSockAddr sockAddr;  
4022 #endif /* IPV6_SUPPORTED */
4023
4024    U32 optVal;
4025
4026    /* added */
4027    TRC2(cmInetAccept)
4028
4029 #if (ERRCLASS & ERRCLS_INT_PAR)
4030    /* error check on parameters */
4031    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
4032    {
4033       RETVALUE(RFAILED);
4034    }
4035 #endif /* ERRCLASS & ERRCLS_INT_PAR */
4036
4037    /* change CmInetSockAddr to sockAddr */
4038    addrLen = sizeof(sockAddr);   
4039
4040    /* INSURE fix */
4041 #if ( defined(SUNOS) || defined(SS_LINUX)) 
4042    newSockFd->fd = accept(sockFd->fd, (CmInetSockAddr*)&sockAddr, 
4043                           (socklen_t *)&addrLen);
4044 #else
4045    newSockFd->fd = accept(sockFd->fd, (CmInetSockAddr*)&sockAddr, 
4046                           (int*)&addrLen);
4047 #endif /* SUNOS || SS_LINUX */   
4048
4049   /* cm_inet_c_001.main_58: Moved setting of protType below */
4050
4051    if (CM_INET_INV_SOCK_FD(newSockFd))
4052    {
4053       if (INET_ERR_CODE == ERR_WOULDBLOCK)
4054       {
4055          /* no connection present to accept */ 
4056          RETVALUE(ROKDNA);
4057       }
4058       else
4059       {
4060 #ifdef CMINETDBG
4061 #ifndef ALIGN_64BIT
4062          /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
4063          /* cm_inet_c_001.main_62:Warning fix */
4064          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAccept() Failed : error(%d),"
4065               " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
4066          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET022, 0, prntBuf);
4067 #else
4068          /* cm_inet_c_001.main_62:Warning fix */
4069          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAccept() Failed : error(%d),"
4070                " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
4071          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET022, 0, prntBuf);
4072 #endif /*ALIGN_64BIT*/
4073 #endif /* CMINETDBG */
4074          RETVALUE(RFAILED);
4075       }
4076    }     
4077
4078
4079   /* cm_inet_c_001.main_58: Fix for g++ compilation warning */
4080    /* added for IPv6/IPv4 socket distinguishing */
4081 #ifdef IPV6_SUPPORTED   
4082    if (addrLen == sizeof(struct sockaddr_in))
4083       newSockFd->protType = AF_INET;
4084    else if(addrLen == sizeof(struct sockaddr_in6))
4085       newSockFd->protType = AF_INET6;
4086    else
4087    {
4088 #ifdef CMINETDBG
4089 #ifndef ALIGN_64BIT
4090       /* cm_inet_c_001.main_62:Warning fix */
4091       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAccept() Failed : sockFd->fd(%ld)\n", sockFd->fd);
4092       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET071, 0, prntBuf);
4093 #else
4094       /* cm_inet_c_001.main_62:Warning fix */
4095       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetAccept() Failed : sockFd->fd(%d)\n", sockFd->fd);
4096       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET071, 0, prntBuf);
4097 #endif /*ALIGN_64BIT*/
4098 #endif /* CMINETDBG */
4099          RETVALUE(RFAILED);
4100    }
4101 #endif /* IPV6_SUPPORTED */      
4102
4103    /* set the new socket file descriptor type */
4104    newSockFd->type = CM_INET_STREAM;
4105
4106    /* set default options for new socket file descriptor */
4107    optVal = CM_INET_OPT_DISABLE;
4108    ret = cmInetSetOpt(newSockFd, SOL_SOCKET, CM_INET_OPT_BLOCK, &optVal); 
4109    if ( ret != ROK) 
4110    {
4111       ret = cmInetClose(newSockFd);
4112       RETVALUE(RFAILED);
4113    }
4114
4115 #ifdef IPV6_SUPPORTED
4116    cmMemset((U8*)fromAddr, 0, sizeof(fromAddr));
4117    if (addrLen == sizeof(struct sockaddr_in))
4118    {
4119       peerAddr = (struct sockaddr_in *)&sockAddr;
4120       fromAddr->type = CM_INET_IPV4ADDR_TYPE;
4121       fromAddr->u.ipv4Addr.port    = CM_INET_NTOH_U16(peerAddr->sin_port);
4122       fromAddr->u.ipv4Addr.address = 
4123                               CM_INET_NTOH_U32(peerAddr->sin_addr.s_addr);
4124    }
4125    else if (addrLen == sizeof(struct sockaddr_in6))
4126    {
4127       peerAddr6 = (struct sockaddr_in6 *)&sockAddr;
4128       fromAddr->type = CM_INET_IPV6ADDR_TYPE;
4129       fromAddr->u.ipv6Addr.port    = CM_INET_NTOH_U16(peerAddr6->sin6_port);
4130       CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr, 
4131                             &peerAddr6->sin6_addr);
4132    }
4133 #else
4134    peerAddr = (struct sockaddr_in *)&sockAddr;
4135    fromAddr->port    = CM_INET_NTOH_U16(peerAddr->sin_port);
4136    fromAddr->address = CM_INET_NTOH_U32(peerAddr->sin_addr.s_addr);
4137 #endif /* IPV6_SUPPORTED */
4138    RETVALUE(ROK);
4139 } /* end of cmInetAccept */ 
4140
4141 \f
4142 /*
4143 *
4144 *      Fun:   cmInet4FillTos 
4145 *
4146 *      Desc:  This function inserts tos (into ancillary data) which 
4147 *             will be used to fill tos value in ip header in outgoing IP packet
4148 *             when sending that packet using sendmsg()function.
4149 *
4150 *      Ret:   ROK   
4151 *
4152 *      Notes:  
4153 *
4154 *      File:  cm_inet.c
4155 *
4156 */
4157
4158 #ifdef ANSI
4159 PRIVATE S16 cmInet4FillTos
4160 (
4161 U8  tos,        /* tos value to be filled in ipheader */
4162 U8  *cmsgBuf,   /* flat buffer where to build ext hdrs */
4163 U32 *curMsgIdx  /* idx in cmsgBuf where HBH/Dest ext hdr ends */
4164 )
4165 #else
4166 PRIVATE S16 cmInet4FillTos(tos, cmsgBuf, curMsgIdx, protType)
4167 U8   tos;       /* tos value to be filled in ipheader */
4168 U8  *cmsgBuf;   /* flat buffer where to build ext hdrs */
4169 U32 *curMsgIdx; /* idx in cmsgBuf where HBH/Dest ext hdr ends */
4170 #endif /* ANSI */
4171 {
4172    struct cmsghdr *tempHdr;
4173    U8     len;
4174
4175    TRC2(cmInet4FillTos)
4176
4177       len = 0;
4178
4179
4180    /* cmsghdr struc will appear before data in the ancillary data object. 
4181     * So put cmsghdr struc in flat buffer first. */
4182
4183    /* cmsghdr struc points to flat buffer's starting address */
4184    tempHdr = (struct cmsghdr *)cmsgBuf;  
4185
4186    /* fill up level & type of cmsghdr structure */
4187    tempHdr->cmsg_level = IPPROTO_IPV6;
4188    tempHdr->cmsg_type = IP_TOS;
4189    (*(U8*)CMSG_DATA(tempHdr)) = tos;
4190    len = CMSG_SPACE(sizeof tos); 
4191
4192
4193    /* fill up the length of cmsghdr structure */
4194    tempHdr->cmsg_len = len;  
4195    *curMsgIdx += len;
4196
4197    RETVALUE(ROK);
4198
4199 }/* end of cmInet4FillTos */ 
4200 /*
4201 *
4202 *      Fun:   cmInetSendDscpMsg
4203 *
4204 *      Desc:  Sends the message data hold by mBuf. 
4205 *             The len paramter gives the actual written octets. If the socket
4206 *             is non-blocking this value can be differ from the mBuf length 
4207 *             because there was not enough transmit buffer space available. If 
4208 *             this occurs, RWOULDBLOCK is returned and only a part of the mBuf
4209 *             is sent.
4210 *             Values for flag parameter:
4211 *  
4212 *             CM_INET_NO_FLAG - no additional control flag
4213 *
4214 *      Ret:   ROK         - successful
4215 *             RWOULDBLOCK - no or not entire mBuf sent because would block
4216 *             ROUTRES     - failed, out of resources
4217 *             RCLOSED     - connection was closed by the peer
4218 *             RFAILED     - failed
4219 *                           
4220 *      Notes: The successful completion of a send call does not indicate that 
4221 *             the data has been successfully delivered! 
4222 *
4223 *             This function does not free any sent buffers.  
4224 *
4225 *   
4226 *      File:  cm_inet.c
4227 *
4228 */
4229
4230 #ifdef ANSI
4231 PUBLIC S16 cmInetSendDscpMsg
4232 (
4233 CmInetFd       *sockFd,         /* socket file descriptor */
4234 CmInetAddr     *dstAddr,        /* destination Internet address/port */
4235 CmInetMemInfo  *info,           /* buffer allocation info */
4236 Buffer         *mBuf,           /* buffer structure to send */
4237 MsgLen         *len,            /* number of actually sent octets */
4238 /* added for IPv6 ext hdr */
4239 CmInetIpHdrParm *ipHdrParams,   /* IPv6 extensions headers */
4240 S16             flags           /* additional control flags, unused */
4241 )
4242 #else
4243 /* added for IPv6 ext hdr */
4244 PUBLIC S16 cmInetSendDscpMsg(sockFd, dstAddr, info, mBuf, len, ipHdrParams, flags)
4245 CmInetFd       *sockFd;         /* socket file descriptor */
4246 CmInetAddr     *dstAddr;        /* destination Internet address/port */
4247 CmInetMemInfo  *info;           /* buffer allocation info */
4248 Buffer         *mBuf;           /* buffer structure to send */
4249 MsgLen         *len;            /* number of actually sent octets */
4250 CmInetIpHdrParm *ipHdrParams;   /* IPv6 extensions headers */
4251 S16             flags;          /* additional control flags, unused */
4252 #endif /* ANSI */
4253 {
4254 #if (defined(WIN32) || defined(CMINETFLATBUF))
4255    S32     ret;                 /* temporary return value */
4256    MsgLen  msgLen;              /* message length */ 
4257    MsgLen  bufLen;              /* send buffer length */
4258    Data   *sendBuf;             /* plain send buffer */
4259 #else
4260    S32 ret;                     /* temporary return value */
4261    S32 retVal;                  /* temporary return value */
4262    S16 i;                       /* loop index */
4263    CmInetIovec  txArr[CM_INET_MAX_DBUF]; /* scatter vector */
4264    S16      numDBufs;           /* number of dBufs in message */
4265    struct   msghdr msg;         /* sendmsg() message header */
4266    MsgLen   msgLen;             /* message length */ 
4267    U32      strtEndDBufNum;     /* starting/ending DBuf number */ 
4268    MsgLen   unSentLen;          /* sent len */
4269 #ifdef IPV6_SUPPORTED 
4270    U32    curMsgIdx;            /* indx in cmsgData where to write an ext hdr */
4271    /* added for IPv6 ext hdr */
4272 #if (defined(SS_LINUX) || defined(_XPG4_2))
4273    /* alloc from stack for IPv6 ancill data */
4274    U8     cmsgData[CM_INET_IPV6_ANCIL_DATA];
4275 #endif /* SS_LINUX || _XPG4_2 */
4276 #else
4277    U32    curMsgIdx;            /* indx in cmsgData where to write an ext hdr */
4278 #if (defined(SS_LINUX) || defined(_XPG4_2))
4279    /* alloc from stack for IPv4 ancill data */ 
4280     U8     cmsgData[CM_INET_IPV4_ANCIL_DATA];
4281 #endif /* SS_LINUX || _XPG4_2 */
4282 #endif /* IPV6_SUPPORTED */   
4283 #endif /* WIN32 | CMINETFLATBUF */  
4284
4285    struct  sockaddr_in remAddr; /* remote Internet address */   
4286 #ifdef IPV6_SUPPORTED
4287    struct   sockaddr_in6  remAddr6; /* remote Internet address */   
4288 #endif /* IPV8_SUPPORTED */
4289    CmInetSockAddr *sockAddrPtr;
4290    /* cm_inet_c_001.main_58 : Fix for klockwork issue */
4291    U32            sizeOfAddr;    
4292
4293    /* cm_inet_c_001.main_50 - Added for partial send handling */
4294    /* cm_inet_c_001.main_59: Protected under if not defined WIN32*/
4295 #if (!defined(WIN32)) 
4296    MsgLen         ioLen; 
4297 #endif
4298
4299    TRC2(cmInetSendDscpMsg)
4300
4301       UNUSED(flags);
4302
4303 #if (ERRCLASS & ERRCLS_INT_PAR)
4304    /* error check on parameters */
4305    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
4306          (info == NULLP) || (len == NULLP))
4307    {
4308       RETVALUE(RFAILED);
4309    }
4310 #endif /* ERRCLASS & ERRCLS_INT_PAR */
4311
4312    /* added for IPv6 ext hdr */
4313 #if !(defined(WIN32) || defined(CMINETFLATBUF))
4314 #if (defined(SS_LINUX) || defined(_XPG4_2))
4315 /*   cmMemset((U8*)cmsgData, 0, sizeof(cmsgData));    */
4316 #endif /* SS_LINUX || _XPG4_2 */
4317    curMsgIdx   = 0;
4318 #endif /* WIN32 | CMINETFLATBUF */
4319
4320    msgLen = 0;  /* need by CC to pass without warning */
4321    sockAddrPtr = NULLP;
4322    sizeOfAddr = 0;
4323
4324    /* setup remote address */
4325    if (dstAddr != NULLP)
4326    {
4327 #ifdef IPV6_SUPPORTED
4328       if (dstAddr->type == CM_INET_IPV6ADDR_TYPE)
4329       {
4330          cmMemset((U8*)&remAddr6, 0, sizeof(remAddr6));
4331          remAddr6.sin6_family = AF_INET6;
4332          remAddr6.sin6_port   = CM_INET_HTON_U16(dstAddr->u.ipv6Addr.port);
4333          CM_INET_COPY_IPV6ADDR(&remAddr6.sin6_addr, 
4334                &dstAddr->u.ipv6Addr.ipv6NetAddr); 
4335          sizeOfAddr = sizeof(remAddr6);
4336          sockAddrPtr = (CmInetSockAddr *)&remAddr6;
4337       }
4338       else
4339       {
4340          cmMemset((U8*)&remAddr, 0, sizeof(remAddr));
4341          remAddr.sin_family = AF_INET;
4342          remAddr.sin_port   = CM_INET_HTON_U16(dstAddr->u.ipv4Addr.port);
4343          remAddr.sin_addr.s_addr = 
4344             CM_INET_HTON_U32(dstAddr->u.ipv4Addr.address);
4345          sizeOfAddr = sizeof(remAddr);
4346          sockAddrPtr = (CmInetSockAddr *)&remAddr;
4347       }
4348 #else
4349 /*      cmMemset((U8*)&remAddr, 0, sizeof(remAddr)); */
4350       remAddr.sin_family      = AF_INET;
4351       remAddr.sin_port        = CM_INET_HTON_U16(dstAddr->port);
4352       remAddr.sin_addr.s_addr = CM_INET_HTON_U32(dstAddr->address);
4353       sizeOfAddr = sizeof(remAddr);
4354       sockAddrPtr = (CmInetSockAddr *)&remAddr;
4355 #endif /* IPV6_SUPPORTED */
4356    }
4357
4358 #if (defined(WIN32) || defined(CMINETFLATBUF))
4359    /* copy message to a flat buffer */
4360    ret = SFndLenMsg(mBuf, &bufLen);
4361    if (ret != ROK)
4362    {
4363       RETVALUE(RFAILED);
4364    }
4365    /* max message length is limited to control the memory usage */
4366    /* casting bufLen to avoid warnings */
4367    if ((bufLen > 0) && ((U32)bufLen > CM_INET_MAX_MSG_LEN))
4368    {
4369       RETVALUE(RFAILED);
4370    }
4371    ret = SGetSBuf(info->region, info->pool, &sendBuf, bufLen);                  
4372    if (ret != ROK)
4373    {
4374       RETVALUE(ROUTRES);
4375    }
4376    ret = SCpyMsgFix(mBuf, 0, bufLen, sendBuf, &msgLen);
4377    if ((ret != ROK) || (msgLen != bufLen)) 
4378    {
4379       /* cleanup */
4380       SPutSBuf(info->region, info->pool, sendBuf, bufLen);       
4381       RETVALUE(RFAILED);
4382    }
4383
4384    if (dstAddr == NULLP)
4385    {
4386       /* VxWorks sendto has some problem
4387        * with connected UDP socket, use send */
4388 #ifndef SS_VW
4389       ret = sendto(sockFd->fd, (S8 *)sendBuf, bufLen, 0, 
4390             NULLP, sizeOfAddr);
4391 #else
4392       ret = send(sockFd->fd, (S8 *)sendBuf, bufLen, 0);
4393 #endif /* end of SS_VW */
4394    }
4395    else
4396       /* cm_inet_c_001.main_54: Fix for vxworks 6.7 sending data on TCP sockets */
4397    {
4398 #if (defined(SS_VW) && defined(SS_VW6_7)) 
4399       if ((sockFd->type  == CM_INET_STREAM) || (sockFd->type == SOCK_RDM) )
4400       {
4401          ret = send(sockFd->fd, (S8 *)sendBuf, bufLen, 0);
4402       }
4403       else
4404 #endif /* end of SS_VW6_7 and SS_VW */
4405       {
4406          ret = sendto(sockFd->fd, (S8 *)sendBuf, bufLen, 0, 
4407                sockAddrPtr, sizeOfAddr); 
4408       }
4409    }
4410    if (ret == INET_ERR)
4411    {
4412       /* cleanup */
4413       SPutSBuf(info->region, info->pool, sendBuf, bufLen);      
4414
4415       if(INET_ERR_CODE == ERR_AGAIN)
4416       {
4417          *len = 0;
4418          RETVALUE(RWOULDBLOCK);
4419       }
4420
4421       /* Check for ERR_WOULDBLOCK */
4422       if(INET_ERR_CODE == ERR_WOULDBLOCK)
4423       {
4424          *len = 0;
4425          RETVALUE(RWOULDBLOCK);
4426       }
4427
4428 #ifdef CMINETDBG
4429 #ifndef ALIGN_64BIT
4430       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
4431       /* cm_inet_c_001.main_62:Warning fix */
4432       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendDscpMsg() Failed : error(%d), msgLen(%d),"
4433             " sockFd->fd(%ld)\n", INET_ERR_CODE, bufLen, sockFd->fd);
4434       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET023, 0, prntBuf);
4435 #else
4436       /* cm_inet_c_001.main_62:Warning fix */
4437       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendDscpMsg() Failed : error(%d), msgLen(%d),"
4438             " sockFd->fd(%d)\n", INET_ERR_CODE, bufLen, sockFd->fd);
4439       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET023, 0, prntBuf);
4440 #endif /*ALIGN_64BIT*/
4441 #endif /* CMINETDBG */
4442
4443       /* cm_inet_c_001.main_37 network unreacheble error is added */
4444       /* check if network is reacheble*/
4445       if ((INET_ERR_CODE == ERR_NETUNREACH))
4446       {
4447          RETVALUE(RNETFAILED);
4448       }
4449
4450
4451       /*  Check if connection was closed */
4452       if ((INET_ERR_CODE == ERR_PIPE) ||
4453             (INET_ERR_CODE == ERR_CONNABORTED) || 
4454             (INET_ERR_CODE == ERR_CONNRESET))
4455       {
4456          *len = 0;
4457          RETVALUE(RCLOSED);
4458       }
4459
4460       RETVALUE(RFAILED);
4461    }
4462
4463    *len = ret;
4464
4465    /* check if entire message could be sent */
4466
4467    if (ret < bufLen) 
4468    {   
4469       /* cleanup */
4470       SPutSBuf(info->region, info->pool, sendBuf, bufLen);      
4471       RETVALUE(RWOULDBLOCK);
4472    }
4473
4474    /* cleanup */
4475    SPutSBuf(info->region, info->pool, sendBuf, bufLen);      
4476
4477 #else /* end of Win NT/flat buffer specific part */
4478    ret = SFndLenMsg(mBuf, &msgLen);
4479    if (ret != ROK)
4480    {
4481       RETVALUE(RFAILED);
4482    }
4483
4484    /* added */
4485 /*   cmMemset((U8*)&msg, 0, sizeof(msg)); */
4486    msg.msg_flags = 0;
4487
4488    if (dstAddr != NULLP)
4489    {
4490 #ifdef SS_LINUX
4491       msg.msg_name    = (Void*)sockAddrPtr;
4492 #else
4493 #ifdef SS_PS
4494       msg.msg_name    = (char *)sockAddrPtr;
4495 #else
4496       msg.msg_name    = (caddr_t)sockAddrPtr;
4497 #endif /* SS_PS */
4498 #endif /* SS_LINUX */
4499       msg.msg_namelen = sizeOfAddr;
4500    }
4501    else
4502    {
4503       msg.msg_name    = NULLP;         
4504       msg.msg_namelen = 0;
4505    }
4506    /* added  defined(_XPG4_2) */
4507 #if (defined(SS_LINUX) || defined(_XPG4_2))
4508    msg.msg_control    = NULLP;
4509    msg.msg_controllen  = 0;
4510 #else
4511    msg.msg_accrights     = 0;
4512    msg.msg_accrightslen  = NULLP; 
4513 #endif /* SS_LINUX */
4514
4515    /* allocate scatter vector */
4516    numDBufs = CM_INET_MAX_DBUF;
4517    retVal = RNA;
4518    ret = ROK;
4519    unSentLen = msgLen;
4520    strtEndDBufNum = 0;
4521    *len = 0;
4522    if (ipHdrParams != NULLP && (ipHdrParams->type == CM_INET_IPV4ADDR_TYPE))
4523       if((ipHdrParams->u.hdrParmIpv4.tos.pres == TRUE)&& \
4524             (ipHdrParams->u.hdrParmIpv4.tos.val != 0))
4525       {
4526          cmInet4FillTos(ipHdrParams->u.hdrParmIpv4.tos.val, 
4527                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);
4528          msg.msg_control = cmsgData;     /* pointer to Ancillary Data */
4529          msg.msg_controllen = curMsgIdx; /* total length of ancillary Data */
4530       } 
4531    /* if the sender wants to send Ipv6 exten. headers */
4532 #ifdef IPV6_OPTS_SUPPORTED
4533    if (ipHdrParams != NULLP && (ipHdrParams->type == CM_INET_IPV6ADDR_TYPE))
4534    {     
4535 #ifdef SS_LINUX
4536       if(ipHdrParams->u.ipv6HdrParm.ttl.pres == TRUE)
4537       {
4538          cmInetBuildSendHoplimit((U32)ipHdrParams->u.ipv6HdrParm.ttl.val,
4539                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);  
4540       }
4541 #endif /* SS_LINUX */
4542
4543 #ifdef LOCAL_INTF      
4544       /* have to decide how to get the src addr to add in in6_pktinfo */
4545       if(ipHdrParams->u.ipv6HdrParm.srcAddr6.type == 6)
4546       {  
4547          cmInet6BuildSendPktinfo(
4548                &ipHdrParams->u.ipv6HdrParm.srcAddr6.u.ipv6NetAddr, 
4549                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx,
4550                sockFd->protType);
4551       }
4552 #endif /* LOCAL_INTF */
4553
4554       /* copy each ipv6 ext header from ipHdrParams to the flat buffer
4555        * cmsgData one by one. */
4556
4557       if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhHdrPrsnt == TRUE)
4558          /* build HBH ext header in cmsgData starting at indx 0 */
4559          cmInet6BuildSendHBHOpts(
4560                &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhOptsArr, 
4561                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx, 0);                           
4562
4563       /* now copy the elements from the Destination Option array one by
4564        * one to the Flat Buffer cmsgData. Start filling at indx curMsgIdx 
4565        * which is the end of HBH hdr. */          
4566       if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsPrsnt == TRUE)
4567          /* build Dest opt hdr starting at (cmsgData + curMsgIdx) */
4568          cmInet6BuildSendDestOpts(
4569                &(ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsArr),
4570                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx, 1);
4571
4572       /* copy Route header to to the Flat Buffer cmsgData */
4573       if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsPrsnt == TRUE)
4574          /* curMsgIdx will be the indx where Dest opt ends in cmsgData */
4575          cmInet6BuildSendRouteOpts(
4576                &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsArr,
4577                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);
4578
4579       /* msghrd struc's msg_control will point cmsgData and msg_controllen
4580        * will be the curMsgIdx */ 
4581       msg.msg_control = cmsgData;     /* pointer to Ancillary Data */
4582       msg.msg_controllen = curMsgIdx; /* total length of ancillary Data */
4583
4584    }
4585 #endif /* IPV6_OPTS_SUPPORTED */
4586
4587    /* Loop till all the data is sent or till the sendmsg call cannot send 
4588     * any more data. */
4589    do
4590    {
4591       /* build the send vector */ 
4592       /* cm_inet_c_001.main_50 - Partial send handling. Added variable to hold
4593          total length of the packed dbufs */
4594       retVal = buildSendIovec(mBuf, unSentLen, txArr, numDBufs, &i, 
4595             &strtEndDBufNum, &ioLen);
4596       if (retVal != ROK)
4597       {
4598          if (retVal == RNA)
4599          {
4600             /* Incase of UDP/RAW messages call SCompressMsg. */
4601             if (sockFd->type != CM_INET_STREAM)
4602             {
4603                /* Compress the message into a single dBuf */
4604                ret = SCompressMsg(mBuf);
4605                if (ret != ROK)
4606                   RETVALUE(RFAILED);
4607
4608                strtEndDBufNum = 0;
4609                /* Rebuild the send vector */
4610                /* cm_inet_c_001.main_50 - Partial send handling. Added variable to hold
4611                   total length of the packed dbuf */
4612                ret = buildSendIovec(mBuf, unSentLen, txArr, numDBufs, &i,
4613                      &strtEndDBufNum, &ioLen);
4614                if (ret != ROK)
4615                   RETVALUE(RFAILED);
4616
4617                retVal = ROK;
4618             }
4619          }
4620          else
4621             RETVALUE(RFAILED);
4622       }
4623       msg.msg_iov           = txArr;
4624       msg.msg_iovlen        = i;
4625
4626
4627 #ifdef NTL_LIB
4628      {
4629          extern int ntl_hLib;
4630          if ( sockFd->fd >= 0xD001)
4631              ret = ntl_sendmsg(ntl_hLib, sockFd->fd, &msg, 0);
4632              else
4633              ret = sendmsg(sockFd->fd, &msg, 0);
4634      }
4635 #else 
4636      ret = sendmsg(sockFd->fd, &msg, 0);
4637 #endif 
4638       /* cm_inet_c_001.main_50 - Update the length only in successful cases */
4639       if (ret == INET_ERR)
4640       {
4641          if((INET_ERR_CODE == ERR_AGAIN) ||
4642                (INET_ERR_CODE == ERR_WOULDBLOCK))
4643          {
4644             /* cm_inet_c_001.main_50 - Return without making length 0, if in case the partial 
4645                message was sent earlier */
4646             RETVALUE(RWOULDBLOCK);
4647          }
4648 #ifdef CMINETDBG
4649 #ifndef ALIGN_64BIT
4650          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
4651          /* cm_inet_c_001.main_62:Warning fix */
4652          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendDscpMsg() Failed : error(%d),"
4653                " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
4654          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET024, 0, prntBuf);
4655 #else
4656          /* cm_inet_c_001.main_62:Warning fix */
4657          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendDscpMsg() Failed : error(%d),"
4658                " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
4659          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET024, 0, prntBuf);
4660 #endif /*ALIGN_64BIT*/
4661 #endif /* CMINETDBG */
4662
4663          /* cm_inet_c_001.main_37 network unreacheble error is added */
4664          /* check if network is reacheble or not */
4665          if ((INET_ERR_CODE == ERR_NETUNREACH))      
4666          {
4667             RETVALUE(RNETFAILED);
4668          }
4669
4670          /*  Check if connection was closed by the peer */
4671          if ((INET_ERR_CODE == ERR_PIPE) ||
4672                (INET_ERR_CODE == ERR_CONNREFUSED) ||
4673                (INET_ERR_CODE == ERR_CONNABORTED))
4674          {
4675             *len = 0;
4676             RETVALUE(RCLOSED);
4677          }
4678          RETVALUE(RFAILED);
4679       }
4680
4681       /* cm_inet_c_001.main_50 - Update the length only in successful cases */
4682       *len += ret;
4683
4684       /* cm_inet_c_001.main_50 - if what is actually sent is less than what is attemped
4685        * to be sent, then return WOULDBLOCK
4686        */
4687       if (ret < ioLen)
4688          RETVALUE(RWOULDBLOCK);
4689
4690       unSentLen -= ret;
4691
4692    } while (*len < msgLen);
4693 #endif /* WIN32 | CMINETFLATBUF */
4694
4695    RETVALUE(ROK);
4696
4697 } /* end of cmInetSendDscpMsg */
4698
4699 /*
4700 *
4701 *      Fun:   cmInetSendMsg
4702 *
4703 *      Desc:  Sends the message data hold by mBuf. 
4704 *             The len paramter gives the actual written octets. If the socket
4705 *             is non-blocking this value can be differ from the mBuf length 
4706 *             because there was not enough transmit buffer space available. If 
4707 *             this occurs, RWOULDBLOCK is returned and only a part of the mBuf
4708 *             is sent.
4709 *             Values for flag parameter:
4710 *  
4711 *             CM_INET_NO_FLAG - no additional control flag
4712 *
4713 *      Ret:   ROK         - successful
4714 *             RWOULDBLOCK - no or not entire mBuf sent because would block
4715 *             ROUTRES     - failed, out of resources
4716 *             RCLOSED     - connection was closed by the peer
4717 *             RFAILED     - failed
4718 *                           
4719 *      Notes: The successful completion of a send call does not indicate that 
4720 *             the data has been successfully delivered! 
4721 *
4722 *             This function does not free any sent buffers.  
4723 *
4724 *   
4725 *      File:  cm_inet.c
4726 *
4727 */
4728
4729 #ifdef ANSI
4730 PUBLIC S16 cmInetSendMsg
4731 (
4732 CmInetFd       *sockFd,         /* socket file descriptor */
4733 CmInetAddr     *dstAddr,        /* destination Internet address/port */
4734 CmInetMemInfo  *info,           /* buffer allocation info */
4735 Buffer         *mBuf,           /* buffer structure to send */
4736 MsgLen         *len,            /* number of actually sent octets */
4737 /* added for IPv6 ext hdr */
4738 #ifdef IPV6_OPTS_SUPPORTED
4739 CmInetIpHdrParm *ipHdrParams,   /* IPv6 extensions headers */
4740 #endif /* IPV6_OPTS_SUPPORTED */
4741 S16             flags           /* additional control flags, unused */
4742 )
4743 #else
4744 /* added for IPv6 ext hdr */
4745 #ifdef IPV6_OPTS_SUPPORTED
4746 PUBLIC S16 cmInetSendMsg(sockFd, dstAddr, info, mBuf, len, ipHdrParams, flags)
4747 CmInetFd       *sockFd;         /* socket file descriptor */
4748 CmInetAddr     *dstAddr;        /* destination Internet address/port */
4749 CmInetMemInfo  *info;           /* buffer allocation info */
4750 Buffer         *mBuf;           /* buffer structure to send */
4751 MsgLen         *len;            /* number of actually sent octets */
4752 CmInetIpHdrParm *ipHdrParams;   /* IPv6 extensions headers */
4753 S16             flags;          /* additional control flags, unused */
4754 #else
4755 PUBLIC S16 cmInetSendMsg(sockFd, dstAddr, info, mBuf, len, flags)
4756 CmInetFd       *sockFd;         /* socket file descriptor */
4757 CmInetAddr     *dstAddr;        /* destination Internet address/port */
4758 CmInetMemInfo  *info;           /* buffer allocation info */
4759 Buffer         *mBuf;           /* buffer structure to send */
4760 MsgLen         *len;            /* number of actually sent octets */
4761 S16             flags;          /* additional control flags, unused */
4762 #endif /* IPV6_OPTS_SUPPORTED */
4763 #endif /* ANSI */
4764 {
4765 #if (defined(WIN32) || defined(CMINETFLATBUF))
4766    S32     ret;                 /* temporary return value */
4767    MsgLen  msgLen;              /* message length */ 
4768    MsgLen  bufLen;              /* send buffer length */
4769    Data   *sendBuf;             /* plain send buffer */
4770 #else
4771    S32 ret;                     /* temporary return value */
4772    S32 retVal;                  /* temporary return value */
4773    S16 i;                       /* loop index */
4774    CmInetIovec  txArr[CM_INET_MAX_DBUF]; /* scatter vector */
4775    S16      numDBufs;           /* number of dBufs in message */
4776    struct   msghdr msg;         /* sendmsg() message header */
4777    MsgLen   msgLen;             /* message length */ 
4778    U32      strtEndDBufNum;     /* starting/ending DBuf number */ 
4779    MsgLen   unSentLen;          /* sent len */
4780 #ifdef IPV6_SUPPORTED 
4781    /* added for IPv6 ext hdr */
4782 #ifdef IPV6_OPTS_SUPPORTED
4783    U32    curMsgIdx;            /* indx in cmsgData where to write an ext hdr */
4784 #if (defined(SS_LINUX) || defined(_XPG4_2))
4785    /* alloc from stack for IPv6 ancill data */
4786    U8     cmsgData[CM_INET_IPV6_ANCIL_DATA];
4787 #endif /* SS_LINUX || _XPG4_2 */
4788 #endif /* IPV6_OPTS_SUPPORTED */
4789 #else
4790 #if (defined(SS_LINUX) || defined(_XPG4_2))
4791    /* alloc from stack for IPv4 ancill data */ 
4792    /* U8     cmsgData[CM_INET_IPV4_ANCIL_DATA];*/
4793 #endif /* SS_LINUX || _XPG4_2 */
4794 #endif /* IPV6_SUPPORTED */   
4795 #endif /* WIN32 | CMINETFLATBUF */  
4796
4797    struct  sockaddr_in remAddr; /* remote Internet address */   
4798 #ifdef IPV6_SUPPORTED
4799    struct   sockaddr_in6  remAddr6; /* remote Internet address */   
4800 #endif /* IPV8_SUPPORTED */
4801    CmInetSockAddr *sockAddrPtr;
4802    /* cm_inet_c_001.main_58 : Fix for klockwork issue */
4803    U32            sizeOfAddr;    
4804
4805    /* cm_inet_c_001.main_50 - Added for partial send handling */
4806    /* cm_inet_c_001.main_59: Protected under if not defined WIN32*/
4807 #if (!defined(WIN32)) 
4808    MsgLen         ioLen; 
4809 #endif
4810
4811    TRC2(cmInetSendMsg)
4812
4813       UNUSED(flags);
4814
4815 #if (ERRCLASS & ERRCLS_INT_PAR)
4816    /* error check on parameters */
4817    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
4818          (info == NULLP) || (len == NULLP))
4819    {
4820       RETVALUE(RFAILED);
4821    }
4822 #endif /* ERRCLASS & ERRCLS_INT_PAR */
4823
4824    /* added for IPv6 ext hdr */
4825 #if !(defined(WIN32) || defined(CMINETFLATBUF))
4826 #if (defined(SS_LINUX) || defined(_XPG4_2))
4827 /*   cmMemset((U8*)cmsgData, 0, sizeof(cmsgData));    */
4828 #endif /* SS_LINUX || _XPG4_2 */
4829 #ifdef IPV6_OPTS_SUPPORTED
4830    curMsgIdx   = 0;
4831 #endif /* IPV6_SUPPORTED */ 
4832 #endif /* WIN32 | CMINETFLATBUF */
4833
4834    msgLen = 0;  /* need by CC to pass without warning */
4835    sockAddrPtr = NULLP;
4836    sizeOfAddr = 0;
4837
4838    /* setup remote address */
4839    if (dstAddr != NULLP)
4840    {
4841 #ifdef IPV6_SUPPORTED
4842       if (dstAddr->type == CM_INET_IPV6ADDR_TYPE)
4843       {
4844          cmMemset((U8*)&remAddr6, 0, sizeof(remAddr6));
4845          remAddr6.sin6_family = AF_INET6;
4846          remAddr6.sin6_port   = CM_INET_HTON_U16(dstAddr->u.ipv6Addr.port);
4847          CM_INET_COPY_IPV6ADDR(&remAddr6.sin6_addr, 
4848                &dstAddr->u.ipv6Addr.ipv6NetAddr); 
4849          sizeOfAddr = sizeof(remAddr6);
4850          sockAddrPtr = (CmInetSockAddr *)&remAddr6;
4851       }
4852       else
4853       {
4854          cmMemset((U8*)&remAddr, 0, sizeof(remAddr));
4855          remAddr.sin_family = AF_INET;
4856          remAddr.sin_port   = CM_INET_HTON_U16(dstAddr->u.ipv4Addr.port);
4857          remAddr.sin_addr.s_addr = 
4858             CM_INET_HTON_U32(dstAddr->u.ipv4Addr.address);
4859          sizeOfAddr = sizeof(remAddr);
4860          sockAddrPtr = (CmInetSockAddr *)&remAddr;
4861       }
4862 #else
4863 /*      cmMemset((U8*)&remAddr, 0, sizeof(remAddr)); */
4864       remAddr.sin_family      = AF_INET;
4865       remAddr.sin_port        = CM_INET_HTON_U16(dstAddr->port);
4866       remAddr.sin_addr.s_addr = CM_INET_HTON_U32(dstAddr->address);
4867       sizeOfAddr = sizeof(remAddr);
4868       sockAddrPtr = (CmInetSockAddr *)&remAddr;
4869 #endif /* IPV6_SUPPORTED */
4870    }
4871
4872 #if (defined(WIN32) || defined(CMINETFLATBUF))
4873    /* copy message to a flat buffer */
4874    ret = SFndLenMsg(mBuf, &bufLen);
4875    if (ret != ROK)
4876    {
4877       RETVALUE(RFAILED);
4878    }
4879    /* max message length is limited to control the memory usage */
4880    /* casting bufLen to avoid warnings */
4881    if ((bufLen > 0) && ((U32)bufLen > CM_INET_MAX_MSG_LEN))
4882    {
4883       RETVALUE(RFAILED);
4884    }
4885    ret = SGetSBuf(info->region, info->pool, &sendBuf, bufLen);                  
4886    if (ret != ROK)
4887    {
4888       RETVALUE(ROUTRES);
4889    }
4890    ret = SCpyMsgFix(mBuf, 0, bufLen, sendBuf, &msgLen);
4891    if ((ret != ROK) || (msgLen != bufLen)) 
4892    {
4893       /* cleanup */
4894       SPutSBuf(info->region, info->pool, sendBuf, bufLen);       
4895       RETVALUE(RFAILED);
4896    }
4897
4898    if (dstAddr == NULLP)
4899    {
4900       /* VxWorks sendto has some problem
4901        * with connected UDP socket, use send */
4902 #ifndef SS_VW
4903       ret = sendto(sockFd->fd, (S8 *)sendBuf, bufLen, 0, 
4904             NULLP, sizeOfAddr);
4905 #else
4906       ret = send(sockFd->fd, (S8 *)sendBuf, bufLen, 0);
4907 #endif /* end of SS_VW */
4908    }
4909    else
4910       /* cm_inet_c_001.main_54: Fix for vxworks 6.7 sending data on TCP sockets */
4911    {
4912 #if (defined(SS_VW) && defined(SS_VW6_7)) 
4913       if ((sockFd->type  == CM_INET_STREAM) || (sockFd->type == SOCK_RDM) )
4914       {
4915          ret = send(sockFd->fd, (S8 *)sendBuf, bufLen, 0);
4916       }
4917       else
4918 #endif /* end of SS_VW6_7 and SS_VW */
4919       {
4920          ret = sendto(sockFd->fd, (S8 *)sendBuf, bufLen, 0, 
4921                sockAddrPtr, sizeOfAddr); 
4922       }
4923    }
4924    if (ret == INET_ERR)
4925    {
4926       /* cleanup */
4927       SPutSBuf(info->region, info->pool, sendBuf, bufLen);      
4928
4929       if(INET_ERR_CODE == ERR_AGAIN)
4930       {
4931          *len = 0;
4932          RETVALUE(RWOULDBLOCK);
4933       }
4934
4935       /* Check for ERR_WOULDBLOCK */
4936       if(INET_ERR_CODE == ERR_WOULDBLOCK)
4937       {
4938          *len = 0;
4939          RETVALUE(RWOULDBLOCK);
4940       }
4941
4942 #ifdef CMINETDBG
4943 #ifndef ALIGN_64BIT
4944       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
4945       /* cm_inet_c_001.main_62:Warning fix */
4946       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendMsg() Failed : error(%d), msgLen(%d),"
4947             " sockFd->fd(%ld)\n", INET_ERR_CODE, bufLen, sockFd->fd);
4948       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET023, 0, prntBuf);
4949 #else
4950       /* cm_inet_c_001.main_62:Warning fix */
4951       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendMsg() Failed : error(%d), msgLen(%d),"
4952             " sockFd->fd(%d)\n", INET_ERR_CODE, bufLen, sockFd->fd);
4953       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET023, 0, prntBuf);
4954 #endif /*ALIGN_64BIT*/
4955 #endif /* CMINETDBG */
4956
4957       /* cm_inet_c_001.main_37 network unreacheble error is added */
4958       /* check if network is reacheble*/
4959       if ((INET_ERR_CODE == ERR_NETUNREACH))
4960       {
4961          RETVALUE(RNETFAILED);
4962       }
4963
4964
4965       /*  Check if connection was closed */
4966       if ((INET_ERR_CODE == ERR_PIPE) ||
4967             (INET_ERR_CODE == ERR_CONNABORTED) || 
4968             (INET_ERR_CODE == ERR_CONNRESET))
4969       {
4970          *len = 0;
4971          RETVALUE(RCLOSED);
4972       }
4973
4974       RETVALUE(RFAILED);
4975    }
4976
4977    *len = ret;
4978
4979    /* check if entire message could be sent */
4980
4981    if (ret < bufLen) 
4982    {   
4983       /* cleanup */
4984       SPutSBuf(info->region, info->pool, sendBuf, bufLen);      
4985       RETVALUE(RWOULDBLOCK);
4986    }
4987
4988    /* cleanup */
4989    SPutSBuf(info->region, info->pool, sendBuf, bufLen);      
4990
4991 #else /* end of Win NT/flat buffer specific part */
4992    ret = SFndLenMsg(mBuf, &msgLen);
4993    if (ret != ROK)
4994    {
4995       RETVALUE(RFAILED);
4996    }
4997
4998    /* added */
4999 /*   cmMemset((U8*)&msg, 0, sizeof(msg)); */
5000    msg.msg_flags = 0;
5001
5002    if (dstAddr != NULLP)
5003    {
5004 #ifdef SS_LINUX
5005       msg.msg_name    = (Void*)sockAddrPtr;
5006 #else
5007 #ifdef SS_PS
5008       msg.msg_name    = (char *)sockAddrPtr;
5009 #else
5010       msg.msg_name    = (caddr_t)sockAddrPtr;
5011 #endif /* SS_PS */
5012 #endif /* SS_LINUX */
5013       msg.msg_namelen = sizeOfAddr;
5014    }
5015    else
5016    {
5017       msg.msg_name    = NULLP;         
5018       msg.msg_namelen = 0;
5019    }
5020    /* added  defined(_XPG4_2) */
5021 #if (defined(SS_LINUX) || defined(_XPG4_2))
5022    msg.msg_control    = NULLP;
5023    msg.msg_controllen  = 0;
5024 #else
5025    msg.msg_accrights     = 0;
5026    msg.msg_accrightslen  = NULLP; 
5027 #endif /* SS_LINUX */
5028
5029    /* allocate scatter vector */
5030    numDBufs = CM_INET_MAX_DBUF;
5031    retVal = RNA;
5032    ret = ROK;
5033    unSentLen = msgLen;
5034    strtEndDBufNum = 0;
5035    *len = 0;
5036
5037    /* if the sender wants to send Ipv6 exten. headers */
5038 #ifdef IPV6_OPTS_SUPPORTED
5039    if (ipHdrParams != NULLP && (ipHdrParams->type == CM_INET_IPV6ADDR_TYPE))
5040    {     
5041 #ifdef SS_LINUX
5042       if(ipHdrParams->u.ipv6HdrParm.ttl.pres == TRUE)
5043       {
5044          cmInetBuildSendHoplimit((U32)ipHdrParams->u.ipv6HdrParm.ttl.val,
5045                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);  
5046       }
5047 #endif /* SS_LINUX */
5048
5049 #ifdef LOCAL_INTF      
5050       /* have to decide how to get the src addr to add in in6_pktinfo */
5051       if(ipHdrParams->u.ipv6HdrParm.srcAddr6.type == 6)
5052       {  
5053          cmInet6BuildSendPktinfo(
5054                &ipHdrParams->u.ipv6HdrParm.srcAddr6.u.ipv6NetAddr, 
5055                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx,
5056                sockFd->protType);
5057       }
5058 #endif /* LOCAL_INTF */
5059
5060       /* copy each ipv6 ext header from ipHdrParams to the flat buffer
5061        * cmsgData one by one. */
5062
5063       if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhHdrPrsnt == TRUE)
5064          /* build HBH ext header in cmsgData starting at indx 0 */
5065          cmInet6BuildSendHBHOpts(
5066                &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhOptsArr, 
5067                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx, 0);                           
5068
5069       /* now copy the elements from the Destination Option array one by
5070        * one to the Flat Buffer cmsgData. Start filling at indx curMsgIdx 
5071        * which is the end of HBH hdr. */          
5072       if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsPrsnt == TRUE)
5073          /* build Dest opt hdr starting at (cmsgData + curMsgIdx) */
5074          cmInet6BuildSendDestOpts(
5075                &(ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsArr),
5076                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx, 1);
5077
5078       /* copy Route header to to the Flat Buffer cmsgData */
5079       if (ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsPrsnt == TRUE)
5080          /* curMsgIdx will be the indx where Dest opt ends in cmsgData */
5081          cmInet6BuildSendRouteOpts(
5082                &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsArr,
5083                (U8 *)(cmsgData + curMsgIdx), &curMsgIdx);
5084
5085       /* msghrd struc's msg_control will point cmsgData and msg_controllen
5086        * will be the curMsgIdx */ 
5087       msg.msg_control = cmsgData;     /* pointer to Ancillary Data */
5088       msg.msg_controllen = curMsgIdx; /* total length of ancillary Data */
5089
5090    }
5091 #endif /* IPV6_OPTS_SUPPORTED */
5092
5093    /* Loop till all the data is sent or till the sendmsg call cannot send 
5094     * any more data. */
5095    do
5096    {
5097       /* build the send vector */ 
5098       /* cm_inet_c_001.main_50 - Partial send handling. Added variable to hold
5099          total length of the packed dbufs */
5100       retVal = buildSendIovec(mBuf, unSentLen, txArr, numDBufs, &i, 
5101             &strtEndDBufNum, &ioLen);
5102       if (retVal != ROK)
5103       {
5104          if (retVal == RNA)
5105          {
5106             /* Incase of UDP/RAW messages call SCompressMsg. */
5107             if (sockFd->type != CM_INET_STREAM)
5108             {
5109                /* Compress the message into a single dBuf */
5110                ret = SCompressMsg(mBuf);
5111                if (ret != ROK)
5112                   RETVALUE(RFAILED);
5113
5114                strtEndDBufNum = 0;
5115                /* Rebuild the send vector */
5116                /* cm_inet_c_001.main_50 - Partial send handling. Added variable to hold
5117                   total length of the packed dbuf */
5118                ret = buildSendIovec(mBuf, unSentLen, txArr, numDBufs, &i,
5119                      &strtEndDBufNum, &ioLen);
5120                if (ret != ROK)
5121                   RETVALUE(RFAILED);
5122
5123                retVal = ROK;
5124             }
5125          }
5126          else
5127             RETVALUE(RFAILED);
5128       }
5129       msg.msg_iov           = txArr;
5130       msg.msg_iovlen        = i;
5131
5132
5133 #ifdef NTL_LIB
5134      {
5135          extern int ntl_hLib;
5136          if ( sockFd->fd >= 0xD001)
5137              ret = ntl_sendmsg(ntl_hLib, sockFd->fd, &msg, 0);
5138              else
5139              ret = sendmsg(sockFd->fd, &msg, 0);
5140      }
5141 #else 
5142      ret = sendmsg(sockFd->fd, &msg, 0);
5143 #endif 
5144       /* cm_inet_c_001.main_50 - Update the length only in successful cases */
5145       if (ret == INET_ERR)
5146       {
5147          if((INET_ERR_CODE == ERR_AGAIN) ||
5148                (INET_ERR_CODE == ERR_WOULDBLOCK))
5149          {
5150             /* cm_inet_c_001.main_50 - Return without making length 0, if in case the partial 
5151                message was sent earlier */
5152             RETVALUE(RWOULDBLOCK);
5153          }
5154 #ifdef CMINETDBG
5155 #ifndef ALIGN_64BIT
5156          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5157          /* cm_inet_c_001.main_62:Warning fix */
5158          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendMsg() Failed : error(%d),"
5159                " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
5160          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET024, 0, prntBuf);
5161 #else
5162          /* cm_inet_c_001.main_62:Warning fix */
5163          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSendMsg() Failed : error(%d),"
5164                " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
5165          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET024, 0, prntBuf);
5166 #endif /*ALIGN_64BIT*/
5167 #endif /* CMINETDBG */
5168
5169          /* cm_inet_c_001.main_37 network unreacheble error is added */
5170          /* check if network is reacheble or not */
5171          if ((INET_ERR_CODE == ERR_NETUNREACH))      
5172          {
5173             RETVALUE(RNETFAILED);
5174          }
5175
5176          /*  Check if connection was closed by the peer */
5177          if ((INET_ERR_CODE == ERR_PIPE) ||
5178                (INET_ERR_CODE == ERR_CONNREFUSED) ||
5179                (INET_ERR_CODE == ERR_CONNABORTED))
5180          {
5181             *len = 0;
5182             RETVALUE(RCLOSED);
5183          }
5184          RETVALUE(RFAILED);
5185       }
5186
5187       /* cm_inet_c_001.main_50 - Update the length only in successful cases */
5188       *len += ret;
5189
5190       /* cm_inet_c_001.main_50 - if what is actually sent is less than what is attemped
5191        * to be sent, then return WOULDBLOCK
5192        */
5193       if (ret < ioLen)
5194          RETVALUE(RWOULDBLOCK);
5195
5196       unSentLen -= ret;
5197
5198    } while (*len < msgLen);
5199 #endif /* WIN32 | CMINETFLATBUF */
5200
5201    RETVALUE(ROK);
5202
5203 } /* end of cmInetSendMsg */
5204
5205 \f
5206 /* added new functions for IPv6 extension headers */
5207 #ifdef IPV6_OPTS_SUPPORTED
5208 #ifdef LOCAL_INTF
5209 /*
5210 *
5211 *      Fun:   cmInet6BuildSendPktinfo
5212 *
5213 *      Desc:  This function inserts src address (into ancillary data) which 
5214 *             will be used as the src addr in outgoing IP packet when sending
5215 *             that packet using sendmsg()function.
5216 *
5217 *      Ret:   ROK   
5218 *
5219 *      Notes:  
5220 *
5221 *      File:  cm_inet.c
5222 *
5223 */
5224
5225 #ifdef ANSI
5226 PRIVATE S16 cmInet6BuildSendPktinfo
5227 (
5228 CmInetIpAddr6 *srcAddr, /* src ip addr to set on outgoing packet */
5229 U8  *cmsgBuf,   /* flat buffer where to build ext hdrs */
5230 U32 *curMsgIdx, /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5231 U8   protType   /* whether IPv4/IPv6 socket */
5232 )
5233 #else
5234 PRIVATE S16 cmInet6BuildSendPktinfo(srcAddr, cmsgBuf, curMsgIdx, protType)
5235 CmInetIpAddr6 *srcAddr; /* src ip addr to set on outgoing packet */
5236 U8  *cmsgBuf;   /* flat buffer where to build ext hdrs */
5237 U32 *curMsgIdx; /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5238 U8   protType;  /* whether IPv4/IPv6 socket */
5239 #endif /* ANSI */
5240 {
5241    struct cmsghdr *tempHdr;
5242    struct in6_pktinfo *ipv6Pktinfo;
5243    struct in6_addr lpBkAddr;
5244    U8     len;
5245
5246    TRC2(cmInet6BuildSendPktinfo)
5247
5248       len = 0;
5249
5250    lpBkAddr = in6addr_loopback;
5251
5252    /* cmsghdr struc will appear before data in the ancillary data object. 
5253     * So put cmsghdr struc in flat buffer first. */
5254
5255    /* cmsghdr struc points to flat buffer's starting address */
5256    tempHdr = (struct cmsghdr *)cmsgBuf;  
5257
5258    /* fill up level & type of cmsghdr structure */
5259    if (protType == AF_INET6)
5260    {   
5261       tempHdr->cmsg_level = IPPROTO_IPV6;
5262       tempHdr->cmsg_type = IPV6_PKTINFO;
5263    }
5264 #ifdef CMINETDBG   
5265    else if(protType == AF_INET)
5266    {
5267       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5268       /* cm_inet_c_001.main_62:Warning fix */
5269       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid socket type in cmInet6BuildPktinfo(),"
5270             "protType(%d)\n", protType);
5271       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET025, 0, prntBuf);
5272
5273    }
5274 #endif
5275    /* skip length of cmsghdr structure - 12 bytes */
5276    len += sizeof(struct cmsghdr); 
5277
5278    if(protType == AF_INET6)
5279       ipv6Pktinfo = (struct in6_pktinfo *)(cmsgBuf + len);
5280 #ifdef CMINETDBG   
5281    else
5282    {
5283       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5284       /* cm_inet_c_001.main_62:Warning fix */
5285       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid socket type in cmInet6BuildPktinfo(),"
5286             "protType(%d)\n",  protType);
5287       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET026, 0, prntBuf);
5288    }
5289 #endif
5290
5291    /* insert the hoplimit. This will override the kernel's
5292     * default hoplimit value */
5293    if(protType == AF_INET6)
5294    {  
5295       /* store ipv6 src addr */ 
5296       cmMemcpy((U8 *)&(ipv6Pktinfo->ipi6_addr), (U8 *)srcAddr, 16);
5297       len += 16;
5298
5299       /* store interface index */
5300       /* 0 is invalid intf indx it tells kernel to chose any intf it likes to
5301        * send this pkt. if we use nozero intf indx then kernel will send this
5302        * pkt only through that intf */
5303       ipv6Pktinfo->ipi6_ifindex = 0;
5304       len += sizeof(int);
5305    }   
5306 #ifdef CMINETDBG   
5307    else if(protType == AF_INET)
5308    {
5309       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5310       /* cm_inet_c_001.main_62:Warning fix */
5311       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid socket type in cmInet6BuildPktinfo(),"
5312             "protType(%d)\n", protType);
5313       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET027, 0, prntBuf);
5314    }
5315 #endif
5316
5317    /* fill up the length of cmsghdr structure */
5318    tempHdr->cmsg_len = len;  
5319    *curMsgIdx += len;
5320
5321    RETVALUE(ROK);
5322
5323 }/* end of cmInet6BuildSendPktinfo */ 
5324 #endif /* LOCAL_INTF */
5325
5326 \f
5327 #ifdef SS_LINUX
5328 /*
5329 *
5330 *      Fun:   cmInetBuildSendHoplimit
5331 *
5332 *      Desc:  This function inserts hoplimit value to be sent out by ancillary
5333 *             data by calling sendmsg()function.
5334 *
5335 *      Ret:   ROK   
5336 *
5337 *      Notes:  
5338 *
5339 *      File:  cm_inet.c
5340 *
5341 */
5342
5343 #ifdef ANSI
5344 PRIVATE S16 cmInetBuildSendHoplimit
5345 (
5346 U32   hoplimit,  /* the hoplimit value to be set on outgoing packet */
5347 U8  *cmsgBuf,   /* flat buffer where to build ext hdrs */
5348 U32 *curMsgIdx  /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5349 )
5350 #else
5351 PRIVATE S16 cmInetBuildSendHoplimit(hoplimit, cmsgBuf, curMsgIdx)
5352 U32  hoplimit;  /* the hoplimit value to be sent on outgoing packet */
5353 U8  *cmsgBuf;   /* flat buffer where to build ext hdrs */
5354 U32 *curMsgIdx; /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5355 #endif /* ANSI */
5356 {
5357    struct cmsghdr *tempHdr; 
5358    U8    len;
5359
5360    TRC2(cmInetBuildSendHoplimit)
5361
5362       len = 0;
5363
5364    /* cmsghdr struc will appear before data in the ancillary data object. 
5365     * So put cmsghdr struc in flat buffer first. */
5366
5367    /* cmsghdr struc points to flat buffer's starting address */
5368    tempHdr = (struct cmsghdr *)cmsgBuf;  
5369
5370    /* fill up level & type of cmsghdr structure */
5371    tempHdr->cmsg_level = IPPROTO_IPV6;
5372    tempHdr->cmsg_type = IPV6_HOPLIMIT;
5373
5374    /* skip cmsghdr struc (length of cmsghdr structure) */
5375    len += sizeof(struct cmsghdr); 
5376
5377    /* insert the hoplimit. This will override the kernel's
5378     * default hoplimit value */ 
5379    *(cmsgBuf + len) = hoplimit;
5380    len += sizeof(hoplimit);
5381
5382    /* fill up the length of cmsghdr structure */
5383    tempHdr->cmsg_len = len;
5384    *curMsgIdx += len;
5385
5386    RETVALUE(ROK);
5387 } /* end of cmInetBuildSendHoplimit  */
5388 #endif /* SS_LINUX */
5389
5390 \f
5391 /*
5392 *
5393 *      Fun:   cmInet6BuildSendHBHOpts
5394 *
5395 *      Desc:  This function builds the HopByHop option which will be put
5396 *             in the data portion of the ancillary data object. To build  
5397 *             the HopByHop option this function takes an array of 
5398 *             individual HopByHop option and fill them in a flat buffer.
5399 *             cmsghdr struc always appear before HopBYHop Options, Dest 
5400 *             Options and Route header option.
5401 *
5402 *             The address of the flat Buffer *cmsgBuf is passed to this
5403 *             function from cmInetSendMsg. This buffer will have all extension
5404 *             headers. This buffer is passed as ancillary data by sendmsg()
5405 *     
5406 *      Ret:   
5407 *
5408 *      Notes: This function will also be used for Destination options 
5409 *
5410 *      File:  cm_inet.c
5411 *
5412 */
5413
5414 #ifdef ANSI
5415 PRIVATE S16 cmInet6BuildSendHBHOpts
5416 (
5417 CmInetIpv6HBHHdrArr *hbhOptsArr,/* IPv6 extensions headers HBH/Dest opts */
5418 U8 *cmsgBuf,                    /* flat buffer where to build ext hdrs */
5419 U32 *curMsgIdx,                 /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5420 U8 hdrId                        /* 0: HBH hdr, 1:Dest Hdr */
5421 )
5422 #else
5423 PRIVATE S16 cmInet6BuildSendHBHOpts(hbhOptsArr, cmsgBuf, curMsgIdx, hdrId)
5424 CmInetIpv6HBHHdrArr *hbhOptsArr;/* IPv6 extensions headers HBH/Dest opts */
5425 U8 *cmsgBuf;                    /* flat buffer where to build ext hdrs */
5426 U32 *curMsgIdx;                 /* idx in cmsgBuf where HBH/Dest ext hdr ends */
5427 U8 hdrId;                       /* 0: HBH hdr, 1:Dest Hdr */
5428 #endif
5429 {
5430    struct cmsghdr *tempHdr; 
5431    U8    len;
5432    U8    optsIdx;
5433
5434    TRC2(cmInet6BuildSendHBHOpts)
5435
5436       len = 0;
5437    optsIdx = 0;
5438
5439    /* cmsghdr struc will appear before data in the ancillary data object. 
5440     * So put cmsghdr struc in flat buffer first. */
5441
5442    /* cmsghdr struc points to flat buffer's starting address */
5443    tempHdr = (struct cmsghdr *)cmsgBuf;  
5444
5445    /* fill up level & type of cmsghdr structure */
5446    if (hdrId == 0)
5447    {   
5448       tempHdr->cmsg_level = IPPROTO_IPV6;
5449       tempHdr->cmsg_type = IPV6_HOPOPTS;
5450    }
5451    else if (hdrId == 1)
5452    {
5453       tempHdr->cmsg_level = IPPROTO_IPV6;
5454       tempHdr->cmsg_type = IPV6_DSTOPTS;
5455    }
5456
5457    /* skip cmsghdr struc (length of cmsghdr structure) */
5458    len += (sizeof(tempHdr->cmsg_level) + sizeof(tempHdr->cmsg_len) + 
5459          sizeof(tempHdr->cmsg_type));
5460
5461    /* Next Hdr: will be fill up accordingly by Kernel */ 
5462    *(cmsgBuf + len) = 0x00;
5463    len += 1;
5464
5465    /* Header Ext Length: will be fill up by us. In units of 8-byte excluding 
5466     * first 8 bytes starting from Next Header field. */       
5467    *(cmsgBuf + len) = 0x00; 
5468    len += 1;
5469
5470    /* fillup all HBH/dest options' TLV. Here, we assume that all the HBH/dest
5471     * options are packed inside 1 HBH option header. */      
5472    for (optsIdx = 0; optsIdx < hbhOptsArr->numHBHOpts; 
5473          optsIdx ++)
5474    {
5475       /* Copy the TLV into cmsgBuf data portion */
5476       /* copy type field of every HBH/dest option */
5477       *(cmsgBuf + len) = hbhOptsArr->hbhOpts[optsIdx].type;
5478       len += sizeof(hbhOptsArr->hbhOpts[optsIdx].type);
5479
5480       /* copy length field of every HBH/dest option */
5481       *(cmsgBuf + len) = hbhOptsArr->hbhOpts[optsIdx].length; 
5482       len += sizeof(hbhOptsArr->hbhOpts[optsIdx].length);         
5483
5484       /* copy all value bytes of current HBH/dest option to the flat buffer */
5485       cmMemcpy((U8 *)(cmsgBuf + len),
5486             (U8 *)(hbhOptsArr->hbhOpts[optsIdx].value), 
5487             hbhOptsArr->hbhOpts[optsIdx].length);
5488       len += hbhOptsArr->hbhOpts[optsIdx].length; 
5489    }
5490
5491    /* cuMsgIdx will have the total length of HBH options array */
5492    /* add this length to the length of cmsgHdr struc */
5493
5494    /* Padding: Different header has different padding requirement(xn+y). For
5495     * HBH Router Alert we need 2 bytes of padding. As this same function is
5496     * used for Destination option also and there is no option for it is yet
5497     * proposed, we are passing padN options - 6 bytes to make the Dest Option
5498     * hdr a multiple of 8 bytes. */
5499
5500    /* HBH: padN of 2 bytes needed for Router Alert */
5501    /* This logic is present currently to support router alert which is the 
5502     * only supported HBH option today. For other, generic method needed */ 
5503    if (hdrId == 0)
5504    {       
5505       *(cmsgBuf + len) = 0x01;
5506       len += 1;
5507       *(cmsgBuf + len) = 0x00;
5508       len += 1;
5509    }
5510
5511    /* fill up the length of cmsghdr structure */
5512    tempHdr->cmsg_len = len;
5513    *curMsgIdx += len;
5514
5515    RETVALUE(ROK);    
5516 } /* end of cmInet6BuildSendHBHOpts */
5517
5518 \f
5519 /*
5520 *
5521 *      Fun:   cmInet6BuildSendRouteOpts
5522 *
5523 *      Desc:  This function transfers bytes from the Route hdr array to the 
5524 *             flat buffer. First the top cmsghdr structure will be filled in
5525 *             the flat buffer, then route hdr type 0 will be added after 
5526 *             cmsghdr struc in the flat buffer. Then all IPV6 addresses will
5527 *             be filled up.
5528 *     
5529 *      Ret:   
5530 *
5531 *      Notes: None
5532 *
5533 *      File:  cm_inet.c
5534 *
5535 */
5536
5537 #ifdef ANSI
5538 PRIVATE S16 cmInet6BuildSendRouteOpts
5539 (
5540 CmInetIpv6RtHdr *rtOptsArr,  /* IPv6 destination options array */
5541 U8 *cmsgBuf,                 /* flat buffer where to build ext hdrs */
5542 U32 *curMsgIdx               /* idx in cmsgBuf where to start building RT hdr */
5543 )
5544 #else
5545 PRIVATE S16 cmInet6BuildSendRouteOpts(rtOptsArr, cmsgBuf, curMsgIdx)
5546 CmInetIpv6RtHdr *rtOptsArr;  /* IPv6 destination options array */
5547 U8 *cmsgBuf;                 /* flat buffer where to build ext hdrs */
5548 U32 *curMsgIdx;              /* idx in cmsgBuf where to start building RT hd */
5549 #endif /* ANSI */
5550 {
5551    struct cmsghdr *tempHdr;
5552    CmInetIpv6RtHdr0 *tempRtHdr;
5553    U8    len; 
5554    U8    addrIdx;
5555
5556    TRC2(cmInet6BuildSendRouteOpts);
5557
5558    len = 0;
5559    addrIdx = 0;
5560
5561    /* cmsghdr struc will appear before data in the ancillary data object. 
5562     * So put cmsghdr struc in flat buffer first */
5563
5564    /* cmsghdr struc points to flat buffer */
5565    tempHdr = (struct cmsghdr *)(cmsgBuf); 
5566
5567    tempHdr->cmsg_level = IPPROTO_IPV6;
5568    tempHdr->cmsg_type = IPV6_RTHDR;
5569
5570    /* skip cmsghdr structure */
5571    len += sizeof(struct cmsghdr);
5572
5573    /* we know the total size of Route hdr if we know the num of ipv6 addrs */
5574    tempHdr->cmsg_len = len + sizeof(CmInetIpv6RtHdr0)
5575       + rtOptsArr->numAddrs * sizeof(CmInetIpAddr6);
5576
5577    /* attach route hdr type 0 after cmsghdr structure */
5578    tempRtHdr = (CmInetIpv6RtHdr0 *)(cmsgBuf + len);
5579
5580    /* fill up fields of route hdr type 0 */
5581
5582    /* will be filled up by Kernel */
5583    tempRtHdr->ip6r0_nextHdr = 0x00;  
5584
5585    tempRtHdr->ip6r0_hdrExtLen = (2 * rtOptsArr->numAddrs); 
5586
5587    /* only type supported today */
5588    tempRtHdr->ip6r0_type = 0x00;        
5589
5590    tempRtHdr->ip6r0_segLeft = rtOptsArr->numAddrs; 
5591
5592    /* Note: rfc 2292(1998) mentions 1 reserve byte & 3 strict/loose bytes 
5593     * restricting total 23 ipv6 addresses can be added to the route header.
5594     * But rfc 2292(2002) mentions all 4 bytes are reserved which allows 
5595     * as many ipv6 addresses as wishes to be added to the route header */
5596
5597    tempRtHdr->ip6r0_resrvAndSLmap = rtOptsArr->slMap;
5598
5599    /* move pointer in the flat buffer to the end of this structure */
5600    len +=  sizeof(CmInetIpv6RtHdr0); 
5601
5602    /* fill up all IPV6 addresses from rtOptsArr in the flat buffer */
5603    for (addrIdx = 0; addrIdx < rtOptsArr->numAddrs; addrIdx++)
5604    {   
5605       cmMemcpy((U8 *)(cmsgBuf + len),
5606             (U8 *)(rtOptsArr->ipv6Addrs[addrIdx]), 16);
5607       len += 16;
5608    }
5609
5610    *curMsgIdx += len;  
5611    RETVALUE(ROK);
5612 } /* end of cmInet6BuildSendRouteOpts */
5613
5614 \f
5615 /*
5616 *
5617 *      Fun:   cmInet6BuildRecvHopOptsArr
5618 *
5619 *      Desc:  This function fills up the HopByHop Array of ipHdrParam from 
5620 *             the ancillary data received through recvmsg() call. The memory
5621 *             to hold the extension headers is allocated here. All received 
5622 *             ext hdr info will be passed to upper user as ipHdrParam.
5623 *     
5624 *      Ret:   ROK     - successful
5625 *             RFAILED - failed
5626 *
5627 *      Notes: None
5628 *
5629 *      File:  cm_inet.c
5630 *
5631 */
5632
5633 #ifdef ANSI
5634 PRIVATE S16 cmInet6BuildRecvHopOptsArr
5635 (
5636 U8 *cmsgData,                    /* flat buffer where to build ext hdrs */
5637 U32 hbhDataLen,                  /* byte len of cmsghdr + hbh ancil data */
5638 CmInetIpv6HBHHdrArr *hbhOptsArr, /* IPv6 extensions headers */
5639 U8 hdrId,                        /* 0: HBH, 1: DEST */
5640 CmInetMemInfo   *info            /* Memory information */
5641 )
5642 #else
5643 PRIVATE S16 cmInet6BuildRecvHopOptsArr(cmsgData, hbhDataLen, hbhOptsArr, hdrId, 
5644                                       info)
5645 U8 *cmsgData;                    /* flat buffer where to build ext hdrs  */
5646 U32 hbhDataLen;                  /* byte len of cmsghdr + hbh ancil data */
5647 CmInetIpv6HBHHdrArr *hbhOptsArr; /* IPv6 extensions headers */
5648 U8 hdrId;                        /* 0: HBH, 1: DEST */
5649 CmInetMemInfo   *info;           /* Memory information */
5650 #endif /* ANSI */
5651 {
5652    U32 curDataIdx;       /* to keep track where we are in the hbh Data */
5653    U8  optsIdx;          /* how many hbh opts present in data */
5654    U8  numOpts;          /* number of hbh opts present in data */
5655    U8  tempLen;
5656    U8  tempType;
5657    S16 ret;
5658
5659    TRC2(cmInet6BuildRecvHopOptsArr)
5660
5661       /* get length of actual hbh ancillary data */
5662       hbhDataLen -= sizeof(struct cmsghdr); 
5663
5664    curDataIdx = 0;                
5665    optsIdx = 0;
5666    numOpts = 0;
5667
5668    /* skip Next Hdr byte & Hdr Ext Length byte */
5669    curDataIdx += 2;               
5670
5671    /* First find out how many hop-by-hop headers we need to allocate */
5672    for (;;)   
5673    {
5674       /* break when all HBH data is copied to hbhOptsArr */
5675       if (curDataIdx >= hbhDataLen)
5676          break;   
5677
5678       numOpts += 1;
5679
5680       /* get type */ 
5681       tempType = *(U8 *)(cmsgData + curDataIdx);
5682       curDataIdx += 1;               
5683
5684       /* take care of pad1 option */
5685       if (tempType == 0) 
5686       {
5687          /* not considering the pad1 as valid option */
5688          numOpts -= 1; 
5689          continue;
5690       }
5691
5692       /* get length */
5693       tempLen = *(U8 *)(cmsgData + curDataIdx);
5694
5695       /* 1 is to skip length. tempLen to skip the value field */
5696       curDataIdx += (1 + tempLen);
5697
5698       /* considering the padN as valid option for Dest Opt Hdr!!! As this is
5699        * the "only" valid option today. Ignore for HBH hdr */
5700       if (hdrId != 1)
5701          if (tempType == 1) 
5702             numOpts -= 1;
5703    }
5704
5705    /* allocate mem needed to hold all HBH/Dest options */
5706    ret = SGetSBuf(info->region, info->pool, 
5707          (Data **)&hbhOptsArr->hbhOpts, 
5708          (Size)((sizeof(CmInetIpv6HBHHdr)) * numOpts)); 
5709    if (ret != ROK)
5710    {
5711 #ifdef CMINETDBG      
5712       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5713       /* cm_inet_c_001.main_62:Warning fix */
5714       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SGetSBuf failure 1 in cmInet6BuildRecvHopOptsArr\n");
5715       CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET028, 0, prntBuf);
5716 #endif /* CMINETDBG */     
5717       RETVALUE(ROUTRES);
5718    }   
5719
5720    curDataIdx = 0;                
5721    optsIdx = 0;
5722
5723    /* skip Next Hdr byte & Hdr Ext Length byte */
5724    curDataIdx += 2;               
5725
5726    hbhOptsArr->numHBHOpts = numOpts;
5727
5728    /* fill up HBH/dest opt array from recvd ancillary data */
5729    for (;;)   
5730    {
5731       /* break when all HBH data is copied to hbhOptsArr */
5732       if (curDataIdx >= hbhDataLen)
5733          break;   
5734
5735       /* only copy Router Alert HBH option part which has type 5. Otherwise,
5736        * skip it when it is a PAD1, PADN or Jumbogram option for HBH. But 
5737        * consider padN as valid option for dest opt hdr. */
5738
5739       /* get the type of current HBH/dest option */
5740       tempType = *(cmsgData + curDataIdx);
5741       curDataIdx += 1;
5742
5743       /* ignore PAD1 for both HBH/dest by skipping to next option */
5744       if (tempType == 0)
5745          continue; 
5746
5747       /* calculate how much to skip for padN in case of HBH */
5748       if (hdrId != 1)
5749       {   
5750          if (tempType == 1)
5751          {
5752             /* get the length field of padN option */
5753             tempLen = *(cmsgData + curDataIdx);
5754             curDataIdx += 1;
5755
5756             /* move pointer forward to skip value field */
5757             curDataIdx += tempLen;
5758             continue;
5759          }
5760       } 
5761       hbhOptsArr->hbhOpts[optsIdx].type = tempType; 
5762
5763       /* copy the length */
5764       hbhOptsArr->hbhOpts[optsIdx].length = *(cmsgData + curDataIdx);
5765       curDataIdx += 1;
5766
5767       /* take care of PADN = 2 when value field empty. We also don't need
5768        * to allocate memory for empty value field */
5769       if (hbhOptsArr->hbhOpts[optsIdx].length == 0)
5770          hbhOptsArr->hbhOpts[optsIdx].value = NULLP;
5771       else
5772       {   
5773          /* take care of all other options having valid value field
5774           * such as Router Alert, PADN >= 3 bytes and Jumbo */
5775          ret = SGetSBuf(info->region, info->pool, 
5776                (Data **)&hbhOptsArr->hbhOpts[optsIdx].value, 
5777                (Size)hbhOptsArr->hbhOpts[optsIdx].length);
5778          if (ret != ROK)
5779          {
5780 #ifdef CMINETDBG            
5781             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5782             /* cm_inet_c_001.main_62:Warning fix */
5783             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SGetSBuf failure 2 cmInet6BuildRecvHopOptsArr\n");
5784             CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET029, 0, prntBuf);
5785 #endif /* CMINETDBG */           
5786             /* now go inside every separate HBH option and free the memory
5787              * allocated for its value field */
5788             for (; optsIdx > 0; optsIdx --)
5789             {
5790                if (hbhOptsArr->hbhOpts[optsIdx - 1].value != NULLP)
5791                {
5792 #ifdef CMINETDBG                  
5793                   /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5794                   /* cm_inet_c_001.main_62:Warning fix */
5795                   snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SPutSBuf call 1 in BuildRecvHopOptsArr\n");
5796                   CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET030, 0, prntBuf);
5797 #endif /* CMINETDBG */                  
5798                   SPutSBuf(info->region, info->pool, 
5799                         (Data *)hbhOptsArr->hbhOpts[optsIdx - 1].value,
5800                         (Size)hbhOptsArr->hbhOpts[optsIdx - 1].length);
5801                }
5802             }
5803             /* clean up all CmInetIpv6HBHHdr structures allocated for all
5804              * arrived HBH options OR numOpts CmInetIpv6HBHHdr structures
5805              * allocated after counting numOpts */
5806 #ifdef CMINETDBG                                     
5807             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5808             /* cm_inet_c_001.main_62:Warning fix */
5809             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SPutSBuf call 2 in BuildRecvHopOptsArr\n");
5810             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET031, 0, prntBuf);
5811 #endif /* CMINETDBG */            
5812             SPutSBuf(info->region, info->pool, 
5813                   (Data *)hbhOptsArr->hbhOpts, numOpts * sizeof(CmInetIpv6HBHHdr));
5814             hbhOptsArr->numHBHOpts = 0;
5815             hbhOptsArr->hbhOpts = NULLP;
5816             RETVALUE(ROUTRES);
5817          }
5818          /* copy the value bytes */
5819          cmMemcpy((U8 *)hbhOptsArr->hbhOpts[optsIdx].value, 
5820                (U8 *)(cmsgData + curDataIdx),
5821                hbhOptsArr->hbhOpts[optsIdx].length);
5822          curDataIdx += hbhOptsArr->hbhOpts[optsIdx].length;      
5823       }  
5824
5825       /* get next option */
5826       optsIdx++; 
5827    }
5828    RETVALUE(ROK);
5829 } /* end of cmInet6BuildRecvHopOptsArr() */
5830
5831 \f
5832 /*
5833 *
5834 *      Fun:   cmInet6BuildRecvRtHdr
5835 *
5836 *      Desc:  This function fills up the Route Header in the cmInetIpv6HdrParm
5837 *             from the recvd ancillary data from recvmsg system call.
5838 *     
5839 *      Ret:   ROK     - successful
5840 *             RFAILED - failed
5841 *
5842 *      Notes: None
5843 *
5844 *      File:  cm_inet.c
5845 *
5846 */
5847
5848 #ifdef ANSI
5849 PRIVATE S16 cmInet6BuildRecvRtHdr
5850 (
5851 U8 *cmsgData,              /* flat buffer where to build Route hdr */ 
5852 U32 rtDataLen,             /* byte len of cmsghdr struc+rtHdr ancil data */
5853 CmInetIpv6RtHdr0 *rtHdr0,  /* rtHeader0 struct that precedes IPV6 addrss */
5854 CmInetIpv6RtHdr *rtOptsArr,/* IPv6 extensions headers */
5855 CmInetMemInfo   *info      /* Memory information */
5856 )
5857 #else
5858 PRIVATE S16 cmInet6BuildRecvRtHdr(cmsgData, rtDataLen, rtHdr0, rtOptsArr, info)
5859 U8 *cmsgData;              /* flat buffer where to build Route hdr */
5860 U32 rtDataLen;             /* byte len of cmsghdr struc+rtHdr ancil data */
5861 CmInetIpv6RtHdr0 *rtHdr0;  /* rtHeader0 struct that precedes IPV6 addrss */
5862 CmInetIpv6RtHdr *rtOptsArr;/* IPv6 extensions headers */
5863 CmInetMemInfo   *info;     /* Memory information */
5864 #endif /* ANSI */
5865 {
5866    U32 curDataIdx;         /* to keep track where we are in hbh Data */
5867    U8 i;                   /* loop counter */
5868    S16 ret;                /* temporary return value */
5869
5870    TRC2(cmInet6BuildRecvRtHdr)
5871    
5872    /* byte len of actual rtHdr ancil data */
5873    rtDataLen -= sizeof(struct cmsghdr);
5874
5875    /* start from beginning */
5876    curDataIdx = 0;                
5877
5878    /* copy next header byte */
5879    rtHdr0->ip6r0_nextHdr = *(cmsgData + curDataIdx);
5880    curDataIdx += 1;  
5881
5882    /* copy header extension length byte */
5883    rtHdr0->ip6r0_hdrExtLen = *(cmsgData + curDataIdx);
5884    curDataIdx += 1;
5885
5886    /* copy type byte (always 0) */
5887    rtHdr0->ip6r0_type = 0x00;
5888    curDataIdx += 1;
5889
5890    /* copy segment left byte */
5891    rtHdr0->ip6r0_segLeft = *(cmsgData + curDataIdx);
5892    curDataIdx += 1;
5893
5894    /* copy 1 reserve byte + 3 strict/loose bytes */  
5895    cmMemcpy((U8 *)(&rtOptsArr->slMap),
5896          (U8 *)(cmsgData + curDataIdx), 4);
5897    curDataIdx += 4;
5898
5899    /* also save reserv byte + 3 sl bytes to rtHdro struc */
5900    rtHdr0->ip6r0_resrvAndSLmap = rtOptsArr->slMap;
5901
5902    /* subtract 8 bytes for Next Hdr, Hdr Ext Len, .... + SL bit map */
5903    rtOptsArr->numAddrs = (rtDataLen - 8)/16;
5904
5905    ret = SGetSBuf(info->region, info->pool, 
5906          (Data **)&rtOptsArr->ipv6Addrs, 
5907          (Size)rtOptsArr->numAddrs * 16);
5908    if (ret != ROK)
5909    {
5910 #ifdef CMINETDBG      
5911       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
5912       /* cm_inet_c_001.main_62:Warning fix */
5913       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "SGetSBuf failure 1 in cmInet6BuildRecvRtHdr\n");
5914       CMINETLOGERROR(ERRCLS_ADD_RES, ECMINET032, 0, prntBuf);
5915 #endif /* CMINETDBG */     
5916       RETVALUE(ROUTRES);
5917    }
5918
5919    /* copy all the ipv6 addresses */
5920    for(i=0; i < rtOptsArr->numAddrs; i++)
5921    {
5922       cmMemcpy((U8 *)(rtOptsArr->ipv6Addrs[i]),
5923             (U8 *)(cmsgData + curDataIdx), 16);
5924       curDataIdx += 16;
5925    }
5926
5927    RETVALUE(ROK);
5928 } /* end of cmInet6BuildRecvRtHdr() */
5929
5930 \f
5931 /*
5932 *
5933 *      Fun:   cmInet6GetHopLimitValue
5934 *
5935 *      Desc:  This function extracts the hop limit value(ttl) of from the 
5936 *             ancillary data received through recvmsg() call. Then this
5937 *             hoplimit value will be passed to upper user as ipHdrParam.
5938 *     
5939 *      Ret:   ROK     - successful
5940 *
5941 *      Notes: None
5942 *
5943 *      File:  cm_inet.c
5944 *
5945 */
5946
5947 #ifdef ANSI
5948 PRIVATE S16 cmInet6GetHopLimitValue
5949 (
5950 U8 *cmsgData,        /* flat buffer where to build ext hdrs */
5951 U32 hopLimitDataLen, /* byte len of cmsghdr + hbh ancil data */
5952 CmInetIpv6HdrParm *ipv6HdrParam /* ipv6 header parameters */ 
5953 )
5954 #else
5955 PRIVATE S16 cmInet6GetHopLimitValue(cmsgData, hopLimitDataLen, ipv6HdrParam)
5956 U8 *cmsgData;         /* flat buffer where to build ext hdrs */
5957 U32 hopLimitDataLen;  /* byte len of cmsghdr + hbh ancil data */
5958 CmInetIpv6HdrParm *ipv6HdrParam; /* ipv6 header parameters */
5959 #endif /* ANSI */
5960 {
5961    U16 curDataIdx;       /* to keep track where we are in the ancillary Data */
5962    U32 *hopLimitValue;   /* ttl/hoplimit value */
5963
5964    hopLimitValue = NULL;
5965    curDataIdx = 0;                
5966
5967    /* get length of actual hbh ancillary data */
5968    hopLimitDataLen -= sizeof(struct cmsghdr);
5969
5970    /* go to the first byte of hop limit which present after cmsghdr struc */
5971    curDataIdx += sizeof(struct cmsghdr);
5972
5973    /* mark that hoplimit(ttl) is present */
5974    ipv6HdrParam->ttl.pres = TRUE;
5975
5976    /* the first byte will be the HopLimit value */
5977    hopLimitValue = (U32 *)(cmsgData);
5978    ipv6HdrParam->ttl.val = (U8)(*hopLimitValue);
5979
5980    RETVALUE(ROK);
5981 }
5982 #endif /* IPV6_OPTS_SUPPORTED */
5983
5984 \f
5985 /*
5986 *
5987 *      Fun:   cmInetRecvMsg
5988 *
5989 *      Desc:  Reads data from a socket into a message. 
5990 *             The buffers for the message  are allocated within the 
5991 *             cmInetRead() function from the pool and region Id set in the 
5992 *             info struct.  
5993 *             If the number of octets given by the paramter len is not 
5994 *             available the function immediately returns with RKDNA. 
5995 *             If the len parameter is set to CM_INET_READ_ANY, the currently 
5996 *             available data is read. 
5997 *             Values for flag parameter:
5998 *  
5999 *             CM_INET_NO_FLAG  - no additional control flag
6000 *             CM_INET_MSG_PEEK - do not destroy data on receive buffer
6001 *
6002 *      Ret:   ROK     - successful
6003 *             ROKDNA  - ok, data not available
6004 *             RCLOSED - connection closed by peer
6005 *             ROUTRES - failed, out of resources
6006 *             RFAILED - failed
6007 *
6008 *      Notes: None.
6009 *
6010 *      File:  cm_inet.c
6011 *
6012 */
6013 #ifdef ANSI
6014 PUBLIC S16 cmInetRecvMsg
6015 (
6016 CmInetFd        *sockFd,        /* socket file descriptor */ 
6017 CmInetAddr      *fromAddr,      /* sender Internet address/port */ 
6018 CmInetMemInfo   *info,          /* buffer allocation info */
6019 Buffer         **mPtr,          /* received buffer structure */
6020 MsgLen          *len,           /* number of octets to read */ 
6021 /*  added for IPv6 */
6022 #ifdef IPV6_OPTS_SUPPORTED
6023 CmInetIpHdrParm *ipHdrParams,    /* IPv6 extensions headers */
6024 #endif /* IPV6_OPTS_SUPPORTED */
6025 #ifdef LOCAL_INTF
6026 CmInetLocalInf  *localIf,       /* local interface on which pkt was recvd */
6027 #endif /* LOCAL_INTF */ 
6028 S32              flags          /* additional control flags */
6029 )
6030 #else
6031 /*  added for IPv6 */
6032 #ifdef IPV6_OPTS_SUPPORTED
6033 #ifdef LOCAL_INTF
6034 PUBLIC S16 cmInetRecvMsg(sockFd, fromAddr, info, mPtr, len,
6035       ipHdrParams, localIf, flags)
6036 CmInetFd        *sockFd;        /* socket file descriptor */ 
6037 CmInetAddr      *fromAddr;      /* sender Internet address/port */ 
6038 CmInetMemInfo   *info;          /* buffer allocation info */
6039 Buffer         **mPtr;          /* received buffer structure */
6040 MsgLen          *len;           /* number of octets to read */ 
6041 CmInetIpHdrParm *ipHdrParams;   /* IPv6 extensions headers */
6042 CmInetLocalInf  *localIf;       /* local interface on which pkt was recvd */
6043 S32              flags;         /* additional control flags */
6044 #else
6045 PUBLIC S16 cmInetRecvMsg(sockFd, fromAddr, info, mPtr, len, ipHdrParams, flags)
6046 CmInetFd        *sockFd;        /* socket file descriptor */ 
6047 CmInetAddr      *fromAddr;      /* sender Internet address/port */ 
6048 CmInetMemInfo   *info;          /* buffer allocation info */
6049 Buffer         **mPtr;          /* received buffer structure */
6050 MsgLen          *len;           /* number of octets to read */ 
6051 CmInetIpHdrParm *ipHdrParams;   /* IPv6 extensions headers */
6052 S32              flags;         /* additional control flags */
6053 #endif /* LOCAL_INTF */
6054 #else
6055 #ifdef LOCAL_INTF
6056 PUBLIC S16 cmInetRecvMsg(sockFd, fromAddr, info, mPtr, len, localIf, flags)
6057 CmInetFd        *sockFd;        /* socket file descriptor */ 
6058 CmInetAddr      *fromAddr;      /* sender Internet address/port */ 
6059 CmInetMemInfo   *info;          /* buffer allocation info */
6060 Buffer         **mPtr;          /* received buffer structure */
6061 MsgLen          *len;           /* number of octets to read */ 
6062 CmInetLocalInf  *localIf;       /* local interface on which pkt was recvd */
6063 S32              flags;         /* additional control flags */
6064 #else
6065 PUBLIC S16 cmInetRecvMsg(sockFd, fromAddr, info, mPtr, len, flags)
6066 CmInetFd        *sockFd;        /* socket file descriptor */ 
6067 CmInetAddr      *fromAddr;      /* sender Internet address/port */ 
6068 CmInetMemInfo   *info;          /* buffer allocation info */
6069 Buffer         **mPtr;          /* received buffer structure */
6070 MsgLen          *len;           /* number of octets to read */ 
6071 S32              flags;         /* additional control flags */
6072 #endif /* LOCAL_INTF */
6073 #endif /* IPV6_OPTS_SUPPORTED */
6074 #endif /* ANSI */
6075 {
6076 #if (defined(WIN32) || defined(CMINETFLATBUF))
6077    S32           ret;            /* temporary return value */
6078    U32           pendLen;        /* pending data length */
6079    S32           recvLen;        /* number of received octets by recvmsg() */
6080    MsgLen        bufLen;         /* entire number of received octets */
6081    MsgLen        curLen;         /* current number of octets in buffer */ 
6082    Data         *recvBuf;        /* receive buffer */
6083    Data         *bufPtr;         /* current buffer position */   
6084    Buffer       *mBuf;           /* received message */ 
6085    U32           remAddrLen;     /* length of remote address */
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 #else
6091    CmInetSockAddr  remSockAddr;     /* to get packet's source IP address */
6092 #endif /* IPV6_SUPPORTED */
6093 #else
6094    S32           ret;            /* temporary return value */
6095   /* cm_inet_c_001.main_58: Fix for g++ compilation warning */
6096    U16           i;              /* index */
6097    U32           pendLen;        /* pending data length */
6098    S32           numBuf;         /* number of allocated dBufs */
6099    S32           recvLen;        /* number of received octets by recvmsg() */
6100    MsgLen        bufLen;         /* entire number of received octets */
6101    struct msghdr msg;            /* message header */ 
6102    /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6103    Buffer       *tempMsg = NULLP;        /* temporary message */
6104    CmInetIovec  rxArr[CM_INET_MAX_DBUF]; /* dynamic gather array */
6105    Buffer      **dBufs = NULLP;   /* dynamic array with allocated dBufs */
6106    S16           numDBufs;       /* number of allocated dBufs */
6107
6108    /* cm_inet_c_001.main_55: As remAddrLen is only being used when
6109     * WIN32 or CMINETFLATBUF is defined, then Removed variable
6110     * in else part*/
6111    struct sockaddr_in *remAddr;  /* remote Internet address */       
6112 #ifdef IPV6_SUPPORTED 
6113    struct sockaddr_in6 *remAddr6;  /* remote Internet address */       
6114    struct sockaddr_in6 remSockAddr;/* to get packet's source IP address */
6115    /* added for IPv6 ext headers support */
6116 #ifdef IPV6_OPTS_SUPPORTED
6117    CmInetIpv6RtHdr0     rtHdr0;          /* type 0 route header */      
6118 #endif /* IPV6_OPTS_SUPPORTED */
6119
6120 #ifdef LOCAL_INTF
6121    struct in6_pktinfo  *pkt6Info;        /* IPv6 IP_PKTINFO */
6122 #endif /* LOCAL_INTF */   
6123
6124 #if (defined(SS_LINUX) || defined(_XPG4_2))
6125    U8                   ancillData[CM_INET_IPV6_ANCIL_DATA];
6126    /* from stack for IPv6 ancill data */
6127 #endif
6128 #else
6129    CmInetSockAddr       remSockAddr;     /* to get packet's src IP address */
6130 #if (defined(SS_LINUX) || defined(_XPG4_2))
6131    U8                   ancillData[CM_INET_IPV4_ANCIL_DATA];
6132    /* from stack for IPv4 ancill data */
6133 #endif
6134 #endif /* IPV6_SUPPORTED */
6135    /* added new definitions */
6136    Bool                 allocFlatBuf;    /* allocate a flat buffer */
6137    /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6138    Data                 *recvBuf = NULLP;        /* receive buffer */
6139 #ifdef SS_LINUX
6140 #ifdef LOCAL_INTF
6141    struct in_pktinfo    *pkt4Info;       /* IPv4 IP_PKTINFO */
6142 #endif
6143 #endif /* SS_LINUX */
6144 #if (defined(IPV6_OPTS_SUPPORTED) || defined(LOCAL_INTF))   
6145    struct               cmsghdr *cmsgptr;/* pointer to struct cmsghdr */
6146 #endif
6147 #endif /* WIN32 | CMINETFLATBUF */
6148    /* used by getsockopt */
6149
6150    /* cm_inet_c_001.main_55:Removed unused variables errValue and optLen */
6151
6152    TRC2(cmInetRecvMsg)
6153
6154 #if (ERRCLASS & ERRCLS_INT_PAR)
6155       /* error check on parameters */
6156       if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
6157             (info == NULLP) || (mPtr == NULLP) || (len == NULLP))
6158       {
6159          RETVALUE(RFAILED);
6160       }
6161 #endif /* ERRCLASS & ERRCLS_INT_PAR */
6162
6163    *mPtr = NULLP;
6164
6165    /*cm_inet_c_001.main_48 variables declaration */
6166 #if !((defined(WIN32) || defined(CMINETFLATBUF)))
6167    numBuf = 0;
6168    numDBufs = 0;
6169 #endif
6170
6171 #if (defined(WIN32) || defined(CMINETFLATBUF))
6172    remAddr = NULLP;  
6173 #ifdef IPV6_SUPPORTED 
6174    remAddr6 = NULLP;
6175 #endif /* IPV6_SUPPORTED */   
6176 #else
6177 #ifdef IPV6_SUPPORTED 
6178    remAddr = NULLP;
6179    remAddr6 = NULLP;
6180 #endif /* IPV6_SUPPORTED */  
6181
6182 #if (defined(SS_LINUX) || defined(_XPG4_2))
6183    cmMemset((U8*)ancillData, 0, sizeof(ancillData));
6184 #endif /* SS_LINUX || _XPG4_2 */
6185
6186 #endif /* (WIN32 | CMINETFLATBUF) */
6187
6188    /* clear the structure */   
6189    cmMemset((U8*)&remSockAddr, 0, sizeof(remSockAddr));
6190
6191    /* get number of pending data */
6192    /* removed 3rd arg memInfo. MemInfo is no longer
6193       needed as we call ioctl for all sockets */
6194
6195    /* cm_inet_c_001.main_48 : call ioctl only for STREAM 
6196     * sockets now. For Non-Stream sockets(Raw & UDP), fix
6197     * pending length to CM_INET_MAX_UDPRAW_MSGSIZE
6198     */
6199    if(sockFd->type == CM_INET_STREAM)
6200    {
6201       ret = cmInetGetNumRead(sockFd, &pendLen);
6202       if (ret != ROK)
6203       {
6204          /* ret may be RFAILED or ROUTRES */
6205          RETVALUE(ret);
6206       }
6207    }
6208    else 
6209    {  
6210       /* cm_inet_c_001.main_48 : pendLen is set 1 greater 
6211        * than the #defined value. If recvFrom/recvMsg 
6212        * returns the len == pendLen, we would drop the 
6213        * message as the msg len is larger than the largest 
6214        * msg we are willing to accept.
6215        */
6216       pendLen = CM_INET_MAX_UDPRAW_MSGSIZE+1;
6217    } 
6218
6219
6220    /* check if connection got closed */
6221    if (pendLen == 0)
6222    {
6223       if (sockFd->type == CM_INET_STREAM)
6224       {
6225          /* cm_inet_c_001.main_50: 
6226           * cm_inet_c_001.main_56: Removed comment for cm_inet_c_001.main_50 as
6227           * the current patch changes its functionality */
6228          U8  readBuf[1]; /* declaration of variable for Peek */
6229
6230          /* 
6231           * cm_inet_c_001.main_56:
6232           * We are peeking the socket buffer again with peek as on some machines
6233           * like solaris, there is a latency observed in ioctl. In such cases, 
6234           * ioctl may return 0, even though there are bytes available to read. 
6235           * We reconfirm through peek whether 0 means EOF or its ioctl latency
6236           * issue.
6237           */
6238          ret = cmInetPeekNew(sockFd, NULLP, info, 0, 1, readBuf);
6239          if (ret == RCLOSED)
6240          {
6241             RETVALUE(ret);
6242          }
6243          /* cm_inet_c_001.main_56:
6244           * Returning ROKDNA even cmInetPeekNew returns ROK. Because currently
6245           * we are not sure about pending length. Anyway socket FD already set,
6246           * we do another iteration to get exact pendLen value. We cannot call 
6247           * cmInetGetNumRead at this point because of latency between the ioctl
6248           * call and recvfrom call issues on some machines ioctl call may 
6249           * return ZERO even their a data to read.  */
6250          RETVALUE(ROKDNA);
6251       }
6252    } 
6253    /* cm_inet_c_001.main_52:  Support for partial reception */
6254    /* cm_inet_c_001.main_59: Fix for compilation warning */
6255    if ((sockFd->type == CM_INET_STREAM) && (*len > (MsgLen)pendLen)) 
6256    {
6257       /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6258       *len = (MsgLen)pendLen;
6259    }
6260
6261    /* check if there are enough pending data to read */
6262    if ((*len == CM_INET_READ_ANY) || ((U32)*len <= pendLen))
6263    {
6264       if (*len == CM_INET_READ_ANY)
6265       {
6266          /* added check for TCP socket. Pending data length in 
6267             the socket recv buffer is determined by ioctl call in 
6268             cmInetGetNumRead. 
6269             For TCP it can't be > CM_INET_MAX_MSG_LEN. */
6270          if (sockFd->type == CM_INET_STREAM) 
6271          {
6272             /* max message length is limited to control the memory usage */
6273             if (pendLen > CM_INET_MAX_MSG_LEN)
6274                pendLen = CM_INET_MAX_MSG_LEN;
6275          }
6276          /* cm_inet_c_001.main_48 : removed the check for 
6277           * Non Stream sockets (pendLen < MAX_UDPRAW_MSGSIZE)
6278           * as we are hardcoding pendLen for Non-Stream sockets.
6279           */
6280
6281          /* read all pending data */ 
6282          /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6283          bufLen = (MsgLen)pendLen;
6284          *len = (MsgLen)pendLen; 
6285       }
6286       else
6287       {
6288          /*  cm_inet_c_001.main_45- Returning  CM_INET_MAX_MSG_LEN when input is larger than
6289           * this */
6290 #ifdef LONG_MSG
6291          /* max message length is limited to control the memory usage */
6292          if ((*len) > CM_INET_MAX_MSG_LEN)
6293          {
6294             (*len) = CM_INET_MAX_MSG_LEN;
6295          }
6296 #endif
6297          /* read data length given by user */ 
6298          bufLen = *len;
6299       }
6300
6301 #if (defined(WIN32) || defined(CMINETFLATBUF))
6302
6303       /* set destination Internet address structure */
6304       if (fromAddr != NULLP)
6305       {
6306          remAddrLen = sizeof(remSockAddr); 
6307       }
6308       else
6309       {
6310          remAddrLen = 0;
6311       }
6312
6313       /* allocate flat receive buffer */
6314       ret = SGetSBuf(info->region, info->pool, &recvBuf, bufLen);
6315       if (ret != ROK)
6316       {
6317          RETVALUE(ROUTRES);
6318       }          
6319       curLen = bufLen;
6320       bufPtr = recvBuf;
6321
6322       /* 
6323        * maybe needs more than one recvfrom() call to read an entire 
6324        * message from a stream socket (TCP)
6325        */
6326       while (curLen > 0)
6327       {
6328          /* added separate recvfrom calls different OS */
6329
6330          /*cm_inet_c_001.main_42   1. In Vx-Works the 5th and 6th parameter of recvfrom
6331            system call are either NULL or should be valid pointer.*/
6332 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
6333          if (remAddrLen)
6334             recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0, 
6335                   (struct sockaddr *)&remSockAddr, (int *)&remAddrLen);
6336          else
6337             recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0, 
6338                   NULLP, (int *)&remAddrLen);
6339 #else         
6340 #if ( defined(SUNOS) || defined(SS_LINUX))
6341          if (remAddrLen)
6342             recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0, 
6343                   (struct sockaddr *)&remSockAddr, (socklen_t *)&remAddrLen);
6344          else
6345             recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0, 
6346                   NULLP, (socklen_t *)&remAddrLen); 
6347 #else
6348          if (remAddrLen)
6349             recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0, 
6350                   &remSockAddr, (S32 *)&remAddrLen);
6351          else
6352             recvLen = recvfrom(sockFd->fd, (S8 *)bufPtr, curLen, 0, 
6353                   NULLP, (S32 *)&remAddrLen); 
6354
6355 #endif /* defined(SUNOS) || defined(SS_LINUX) */
6356 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */ 
6357
6358          if (recvLen == INET_ERR)
6359          {
6360             /* cleanup */
6361             /* moved cleanup here */
6362             SPutSBuf(info->region, info->pool, recvBuf, bufLen); 
6363
6364             /*  added check ERR_WOULDBLOCK */
6365             if ((INET_ERR_CODE == ERR_AGAIN) ||
6366                   (INET_ERR_CODE == ERR_WOULDBLOCK))
6367             {
6368                *len = 0;
6369                RETVALUE(ROKDNA);
6370             }
6371
6372
6373             /*  In Windows the recvfrom function fails
6374              *  with error code which maps to either WSAECONNABORTED. If
6375              *  this happens then cmInetRecvMsg must return RCLOSED */
6376             if ((INET_ERR_CODE == ERR_CONNABORTED) || 
6377                   (INET_ERR_CODE == ERR_CONNRESET))
6378             {
6379                *len = 0;
6380                RETVALUE(RCLOSED);
6381             }
6382
6383 #ifdef CMINETDBG
6384 #ifndef ALIGN_64BIT
6385             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
6386             /* cm_inet_c_001.main_62:Warning fix */
6387             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() Failed : error(%d),"
6388                   " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
6389             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET034, 0, prntBuf);
6390 #else
6391             /* cm_inet_c_001.main_62:Warning fix */
6392             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() Failed : error(%d),"
6393                   " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
6394             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET034, 0, prntBuf);
6395 #endif /*ALIGN_64BIT*/
6396 #endif /* CMINETDBG */
6397
6398             RETVALUE(RFAILED);
6399          } 
6400          curLen -= recvLen;
6401          bufPtr += recvLen;
6402
6403          /* 
6404           * a message is always read atomically on a datagram socket,
6405           * therefore it's ok to read less than pending data!
6406           */
6407 #ifdef CM_INET2  
6408          if ((sockFd->type == CM_INET_RAW) || 
6409                (sockFd->type == CM_INET_DGRAM))
6410          {
6411             *len = recvLen;
6412             break; 
6413          }
6414 #else /* CM_INET2 */ 
6415          if (sockFd->type == CM_INET_DGRAM)
6416          {
6417             *len = recvLen;
6418             break; 
6419          }
6420 #endif /* CM_INET2 */ 
6421       } /* while (curLen > 0) (only for stream sockets) */ 
6422
6423       /* For UDP, it is possible to receive
6424        * a 0 byte datagram, in this case just return ROKDNA.
6425        */ 
6426 #ifdef CM_INET2
6427       if ((sockFd->type == CM_INET_DGRAM || sockFd->type == CM_INET_RAW) 
6428             && (*len == 0))
6429 #else
6430          if ((sockFd->type == CM_INET_DGRAM) && (*len == 0))
6431 #endif
6432          {
6433             SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6434             RETVALUE(ROKDNA);
6435          }
6436
6437       /* cm_inet_c_001.main_48 : If Received 
6438        * len == CM_INET_MAX_UDPRAW_MSGSIZE+1
6439        * Drop this message 
6440        */ 
6441 #ifdef CM_INET2
6442       if ((sockFd->type == CM_INET_DGRAM || sockFd->type == CM_INET_RAW) 
6443             && (*len == (CM_INET_MAX_UDPRAW_MSGSIZE+1)))
6444 #else
6445          if ((sockFd->type == CM_INET_DGRAM) 
6446                && (*len == (CM_INET_MAX_UDPRAW_MSGSIZE+1)))
6447 #endif
6448          {
6449 #ifdef CMINETDBG
6450 #ifndef ALIGN_64BIT
6451             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
6452             /* cm_inet_c_001.main_62:Warning fix */
6453             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg(),recevied a message"
6454                   " > than allowed(%lu), sockFd->fd(%ld) \n", 
6455                   CM_INET_MAX_UDPRAW_MSGSIZE, sockFd->fd);
6456             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET068, 0, prntBuf);
6457 #else
6458             /* cm_inet_c_001.main_62:Warning fix */
6459             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg(),recevied a message"
6460                   " > than allowed(%lu), sockFd->fd(%d) \n", 
6461                   CM_INET_MAX_UDPRAW_MSGSIZE, sockFd->fd);
6462             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET068, 0, prntBuf);
6463 #endif /*ALIGN_64BIT*/
6464 #endif
6465             SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6466             RETVALUE(ROKDNA);
6467          }
6468
6469       /* cm_inet_c_001.main_48 : copy data to a message structure */
6470       ret = SGetMsg(info->region, info->pool, &mBuf);
6471       if (ret != ROK)
6472       {
6473          /* cleanup */
6474          SPutSBuf(info->region, info->pool, recvBuf, bufLen);       
6475          RETVALUE(ret);
6476       }
6477
6478 #ifdef CM_INET2  
6479       if ((sockFd->type == CM_INET_DGRAM) ||
6480             (sockFd->type == CM_INET_RAW))
6481       {
6482          ret = SAddPstMsgMult(recvBuf, *len, mBuf);        
6483       }
6484       else
6485       {
6486          ret = SAddPstMsgMult(recvBuf, bufLen, mBuf);        
6487       }
6488
6489 #else /* CM_INET2 */ 
6490       if (sockFd->type == CM_INET_DGRAM)
6491       {
6492          ret = SAddPstMsgMult(recvBuf, *len, mBuf);        
6493       }
6494       else
6495       {
6496          ret = SAddPstMsgMult(recvBuf, bufLen, mBuf);        
6497       }
6498 #endif /* CM_INET2 */ 
6499
6500       if (ret != ROK)
6501       {
6502          SPutSBuf(info->region, info->pool, recvBuf, bufLen);    
6503          SPutMsg(mBuf); 
6504          RETVALUE(ret);
6505       }
6506       *mPtr = mBuf;
6507
6508       /* setup return destination Internet address */
6509       /* added the check of (remAddrLen > 0) */
6510       if ((fromAddr != NULLP) && (remAddrLen > 0))
6511       {
6512 #ifdef IPV6_SUPPORTED
6513          if (remAddrLen == sizeof(struct sockaddr_in6))
6514          {
6515             remAddr6 = (struct sockaddr_in6 *)&remSockAddr;
6516             fromAddr->type = CM_INET_IPV6ADDR_TYPE;
6517             fromAddr->u.ipv6Addr.port = CM_INET_NTOH_U16(remAddr6->sin6_port);
6518             CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr, 
6519                   &remAddr6->sin6_addr);
6520          }
6521          else
6522          {
6523             remAddr = (struct sockaddr_in *)&remSockAddr;
6524             fromAddr->type = CM_INET_IPV4ADDR_TYPE;
6525             fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(remAddr->sin_port);
6526             fromAddr->u.ipv4Addr.address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
6527          }
6528 #else
6529          remAddr = (struct sockaddr_in *)&remSockAddr;
6530          fromAddr->port    = CM_INET_NTOH_U16(remAddr->sin_port);
6531          fromAddr->address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
6532 #endif /* IPV6_SUPPORTED */
6533       }   
6534
6535       /* cleanup */
6536       SPutSBuf(info->region, info->pool, recvBuf, bufLen);      
6537
6538 #else  /* end of Win NT/flat buffer specific part */
6539
6540       /* Initialise variable */
6541       allocFlatBuf = FALSE;
6542
6543       /* 
6544        * maybe needs more than one recvmsg() call to read entire message 
6545        * on a stream socket 
6546        */
6547       while (bufLen > 0)
6548       {
6549          /* allocate gather vector, it's a dynamic array */    
6550          numDBufs =  CM_INET_MAX_DBUF;
6551
6552          ret = SGetSBuf(info->region, info->pool, (Data**)&dBufs, 
6553                numDBufs*sizeof(Buffer*));
6554          if (ret != ROK)
6555          {
6556             RETVALUE(ROUTRES);
6557          }                     
6558
6559          /* Allocate dBufs for gather read */ 
6560          /* allocate dBufs for gathering read */
6561          if (sockFd->type == CM_INET_STREAM)
6562             ret = buildRecvBuf(info, bufLen, rxArr, dBufs, numDBufs, &msg,
6563                   TRUE);
6564          else
6565             ret = buildRecvBuf(info, bufLen, rxArr, dBufs, numDBufs, &msg,
6566                   FALSE);
6567          if (ret != ROK)
6568          {
6569             /* check if the function returned RNA */ 
6570             if (ret == RNA)
6571             {
6572                /* Incase of UDP/RAW messages allocate a flat buffer. Incase
6573                 * of TCP ignore this error condition. The user will call 
6574                 * cmInetRecvMsg again */
6575                /* cm_inet_c_001.main_62:Warning fix */
6576                if (sockFd->type != (U8)CM_INET_STREAM)/* G++ */
6577                {
6578
6579 #ifdef T2K_MEM_LEAK_DBG
6580                        char * file = __FILE__;
6581                        U32  line   = __LINE__;
6582 #endif
6583
6584                   /* cleanup  the dBuf array */
6585                   for (i = 0; i < msg.msg_iovlen; i++)
6586                      SPutDBuf(info->region, info->pool, dBufs[i]);   
6587
6588                   SPutSBuf(info->region, info->pool, (Data*)dBufs, 
6589                         numDBufs * sizeof(Buffer*)); 
6590
6591                   /* allocate flat receive buffer */
6592                   ret = SGetSBuf(info->region, info->pool, &recvBuf, bufLen);
6593                   if (ret != ROK)
6594                      RETVALUE(ROUTRES);
6595
6596                   allocFlatBuf = TRUE;
6597
6598                   /* update the message structure */
6599 #ifdef SS_LINUX
6600                   rxArr[0].iov_base = (Void*)recvBuf;  
6601                   rxArr[0].iov_len = (U32)bufLen;    
6602 #else
6603                   rxArr[0].iov_base = (S8*)recvBuf;
6604                   rxArr[0].iov_len = bufLen;
6605 #endif /* SS_LINUX */
6606                   msg.msg_iov           = rxArr;
6607                   msg.msg_iovlen        = 1;
6608                }
6609             }
6610             else
6611             {
6612                SPutSBuf(info->region, info->pool, (Data*)dBufs, 
6613                      numDBufs*sizeof(Buffer*)); 
6614                RETVALUE(ret);
6615             }
6616          }
6617
6618          numBuf =  msg.msg_iovlen;
6619
6620          /* setup destination Internet address structure */
6621          if (fromAddr != NULLP)
6622          {
6623 #ifdef SS_LINUX
6624             msg.msg_name    = (Void*)&remSockAddr;
6625 #else
6626 #ifdef SS_PS
6627             msg.msg_name    = (char *)&remSockAddr;
6628 #else
6629             msg.msg_name    = (caddr_t)&remSockAddr;
6630 #endif /* SS_PS */
6631 #endif /* SS_LINUX */
6632             msg.msg_namelen = sizeof(remSockAddr);
6633          }
6634          else
6635          {
6636             msg.msg_name    = NULLP;
6637             msg.msg_namelen = 0;
6638          }
6639
6640          /* added defined(_XPG4_2). Also changed the
6641           * assignments */
6642 #if (defined(SS_LINUX) || defined(_XPG4_2))
6643          msg.msg_control      = ancillData;
6644          msg.msg_controllen   = sizeof(ancillData);
6645 #else
6646          msg.msg_accrights     = NULLP;
6647          msg.msg_accrightslen  = 0;
6648 #endif /* SS_LINUX */
6649
6650          recvLen = recvmsg(sockFd->fd, &msg, flags);
6651          if ((recvLen == INET_ERR) || (recvLen > CM_INET_MAX_MSG_LEN))
6652          {
6653             /* Moved up the cleanup precedures here before returning */
6654             /* Cleanup flat buffer if allocated */
6655             if (allocFlatBuf)
6656                SPutSBuf(info->region, info->pool, recvBuf, bufLen);
6657             else
6658             {
6659                /* cleanup */
6660                for (i = 0; i < numBuf; i++)
6661                { 
6662                 #ifdef T2K_MEM_LEAK_DBG
6663                    char * file = __FILE__;
6664                    U32  line   = __LINE__;
6665                 #endif
6666
6667                   SPutDBuf(info->region, info->pool, dBufs[i]);   
6668                }
6669                SPutSBuf(info->region, info->pool, (Data*)dBufs, 
6670                      numDBufs*sizeof(Buffer*)); 
6671             }
6672
6673             /* cm_inet_c_001.main_50 - Free the buffer only when valid, it might be that
6674              * it has partially received data
6675              */
6676             /* added check ERR_AGAIN when CMINETFLATBUF is not defined. 
6677                added check ERR_WOULDBLOCK */
6678             if ((INET_ERR_CODE == ERR_AGAIN) ||
6679                   (INET_ERR_CODE == ERR_WOULDBLOCK))
6680             {
6681                /* cm_inet_c_001.main_50 : If message is read partially then just return
6682                 * OK without freeing the mPtr. This will gaurd us
6683                 * against unexpected WOULDBLOCKS observed in solaris
6684                 */
6685                if (*mPtr != NULLP)
6686                   RETVALUE(ROK);
6687
6688                RETVALUE(ROKDNA);
6689             }
6690
6691             /* cm_inet_c_001.main_50 - Free the buffer only when valid, it might be that
6692              * it has partially received data
6693              */
6694             if (*mPtr != NULLP)
6695             {
6696                SPutMsg(*mPtr);
6697             }
6698 #ifdef CMINETDBG
6699 #ifndef ALIGN_64BIT
6700             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
6701             /* cm_inet_c_001.main_62:Warning fix */
6702             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() Failed : error(%d),"
6703                   " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
6704             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET035, 0, prntBuf);
6705 #else
6706             /* cm_inet_c_001.main_62:Warning fix */
6707             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() Failed : error(%d),"
6708                   " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
6709             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET035, 0, prntBuf);
6710 #endif /*ALIGN_64BIT*/
6711 #endif /* CMINETDBG */
6712
6713             /*  If this happens then cmInetRecvMsg must return RCLOSED. 
6714              *  Needed for getting icmp msgs */
6715             if (INET_ERR_CODE == ERR_CONNABORTED)
6716             {
6717                *len = 0;
6718                RETVALUE(RCLOSED);
6719             }
6720             RETVALUE(RFAILED); 
6721          } 
6722
6723          bufLen -= recvLen;
6724
6725          /* added for IPv6 extn headers */
6726 #if (defined(IPV6_OPTS_SUPPORTED) || defined(LOCAL_INTF))
6727
6728          /* check if ancillary data has been received. 
6729           * Return the allocated memory when no ancillary data received */
6730 #if (defined(SS_LINUX) || defined(_XPG4_2))         
6731          if (msg.msg_controllen)
6732          {   
6733             cmsgptr = CMSG_FIRSTHDR(&msg);
6734          }   
6735          else 
6736             cmsgptr = NULLP;
6737 #else
6738          cmsgptr = NULLP;         
6739 #endif  /* SS_LINUX || _XPG4_2 */        
6740
6741          if (cmsgptr != NULLP) 
6742          {
6743 #ifdef IPV6_OPTS_SUPPORTED            
6744             if(ipHdrParams != NULLP)
6745             {   
6746                ipHdrParams->u.ipv6HdrParm.ttl.pres = FALSE;
6747                ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhHdrPrsnt = FALSE;
6748                ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsPrsnt = FALSE;
6749                ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsPrsnt = FALSE;
6750
6751                /* get all ancillary data objects recvd one by one */
6752                for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULLP; 
6753                      cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
6754                {
6755                   if (cmsgptr->cmsg_level == IPPROTO_IPV6)
6756                   {
6757                      /* Initialise ipHdrParams properly */
6758                      ipHdrParams->type = CM_INET_IPV6ADDR_TYPE;   
6759
6760                      if (cmsgptr->cmsg_type == IPV6_HOPOPTS) 
6761                      {
6762                         /* build up HBH opt array from recvd ancillary data */
6763                         ret = cmInet6BuildRecvHopOptsArr(
6764                               (U8 *)CMSG_DATA(cmsgptr), cmsgptr->cmsg_len, 
6765                               &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhOptsArr,
6766                               0, info);
6767                         if (ret != ROK)
6768                            RETVALUE(ret);
6769                         ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.hbhHdrPrsnt = 
6770                            TRUE; 
6771                      }
6772 #ifdef SS_LINUX
6773                      else if(cmsgptr->cmsg_type == IPV6_DSTOPTS)
6774 #else
6775                      else if ((cmsgptr->cmsg_type == IPV6_DSTOPTS) ||
6776                            (cmsgptr->cmsg_type == IPV6_RTHDRDSTOPTS))
6777 #endif /* SS_LINUX */  
6778                      {
6779                         /* build up Dest opt array from recvd ancillary data */
6780                         ret = cmInet6BuildRecvDstOptsArr(
6781                               (U8 *)CMSG_DATA(cmsgptr), cmsgptr->cmsg_len, 
6782                               &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsArr,
6783                               1, info); 
6784                         if (ret != ROK)
6785                            RETVALUE(ret);
6786                         ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.destOptsPrsnt = 
6787                            TRUE;
6788                      }
6789                      else if (cmsgptr->cmsg_type == IPV6_RTHDR)
6790                      {
6791                         /* build up Route Hdr from recvd ancillary data */
6792                         ret = cmInet6BuildRecvRtHdr(
6793                               (U8 *)CMSG_DATA(cmsgptr), cmsgptr->cmsg_len, &rtHdr0,
6794                               &ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsArr, 
6795                               info);
6796                         if (ret != ROK)
6797                            RETVALUE(ret);
6798                         ipHdrParams->u.ipv6HdrParm.ipv6ExtHdr.rtOptsPrsnt = 
6799                            TRUE; 
6800                      }
6801                      else if(cmsgptr->cmsg_type == IPV6_HOPLIMIT)
6802                      {
6803                         /* get the received hoplimit */
6804                         ret = cmInet6GetHopLimitValue((U8 *)CMSG_DATA(cmsgptr),
6805                               cmsgptr->cmsg_len, &ipHdrParams->u.ipv6HdrParm);
6806                         if (ret != ROK)
6807                            RETVALUE(ret);
6808                      }
6809                   }
6810                }  /* for */            
6811             } /* ipHdrParams */
6812 #endif /* IPV6_OPTS_SUPPORTED */
6813
6814 #ifdef IPV6_SUPPORTED
6815 #ifdef LOCAL_INTF 
6816             for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULLP; 
6817                   cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
6818             {   
6819                if(cmsgptr->cmsg_type == IPV6_PKTINFO)
6820                {
6821                   pkt6Info = (struct in6_pktinfo *)CMSG_DATA(cmsgptr);
6822                   localIf->intfPrsnt = TRUE;
6823                   localIf->localIf = pkt6Info->ipi6_ifindex;
6824                   localIf->localIfAddr.type =  CM_INET_IPV6ADDR_TYPE;
6825                   cmMemcpy((U8 *)&localIf->localIfAddr.u.ipv6NetAddr,
6826                         (U8 *)(int *)&pkt6Info->ipi6_addr, 16);
6827                }
6828             }   
6829 #endif /* LOCAL_INTF */
6830 #endif            
6831
6832 #if (defined(SS_LINUX) && defined(LOCAL_INTF))
6833 #ifdef IPV6_SUPPORTED        
6834             if(sockFd->protType == AF_INET) 
6835             { 
6836 #endif               
6837                for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; 
6838                      cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
6839                {
6840                   if (cmsgptr->cmsg_level == IPPROTO_IP && 
6841                         cmsgptr->cmsg_type == IP_PKTINFO)
6842                   {
6843                      pkt4Info = (struct in_pktinfo *)CMSG_DATA(cmsgptr);
6844                      localIf->intfPrsnt = TRUE;
6845                      localIf->localIf = pkt4Info->ipi_ifindex;
6846                      localIf->localIfAddr.type =  CM_INET_IPV4ADDR_TYPE;
6847                      localIf->localIfAddr.u.ipv4NetAddr = 
6848                         ntohl(*(int *)&pkt4Info->ipi_addr);     
6849                   }
6850                }
6851 #ifdef IPV6_SUPPORTED               
6852             }
6853 #endif 
6854 #endif /* SS_LINUX */ 
6855          }
6856 #endif /* IPV6_OPTS_SUPPORTED || LOCAL_INTF */
6857
6858          /* setup return destination Internet address */
6859          if (fromAddr != NULLP)
6860          {
6861 #ifdef IPV6_SUPPORTED
6862             if (msg.msg_namelen == sizeof(struct sockaddr_in6))
6863             {
6864                remAddr6 = (struct sockaddr_in6 *)&remSockAddr;
6865                fromAddr->type = CM_INET_IPV6ADDR_TYPE;
6866                fromAddr->u.ipv6Addr.port = 
6867                   CM_INET_NTOH_U16(remAddr6->sin6_port);
6868                CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr, 
6869                      &remAddr6->sin6_addr);
6870             }
6871             else
6872             {
6873                remAddr = (struct sockaddr_in *)&remSockAddr;
6874                fromAddr->type = CM_INET_IPV4ADDR_TYPE;
6875                fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(remAddr->sin_port);
6876                fromAddr->u.ipv4Addr.address = 
6877                   CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
6878             }
6879 #else
6880             remAddr = (struct sockaddr_in *)&remSockAddr;
6881             fromAddr->port    = CM_INET_NTOH_U16(remAddr->sin_port);
6882             fromAddr->address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
6883 #endif /* IPV6_SUPPORTED */
6884          }
6885
6886          /* Incase a flat buffer was allocated get
6887           * a message to pass up */
6888          if (allocFlatBuf)
6889          {
6890             bufLen += recvLen;
6891
6892             /* Get a message */
6893             ret = SGetMsg(info->region, info->pool, &tempMsg);
6894             if (ret != ROK)
6895             {
6896                /* cleanup */
6897                SPutSBuf(info->region, info->pool, recvBuf, bufLen);       
6898                RETVALUE(ret);
6899             }
6900
6901             /* cm_inet_c_001.main_48 : A 0 len UDP packet could be received */
6902             if ( recvLen > 0)
6903             {
6904                ret = SAddPstMsgMult(recvBuf, recvLen, tempMsg);        
6905                if (ret != ROK)
6906                {
6907                   SPutSBuf(info->region, info->pool, recvBuf, bufLen);    
6908                   SPutMsg(tempMsg); 
6909                   RETVALUE(ret);
6910                }
6911             }
6912
6913             *mPtr = tempMsg;
6914
6915             SPutSBuf(info->region, info->pool, recvBuf, bufLen);    
6916             /* cm_inet_c_001.main_48 :flat buffers are allocated 
6917              * for non -TCP sockets. On these sockets we can receive 
6918              * only one message at a time 
6919              */
6920             /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6921             *len = (MsgLen)recvLen;
6922             break;
6923          }
6924          else
6925          {
6926             /* build message out of dBufs */
6927             ret = buildRecvMsg(info, rxArr, numBuf, recvLen, dBufs, &tempMsg);
6928             if (ret != ROK)
6929             {
6930                /* Deallocate previously allocated
6931                 * mBuf */
6932                if (*mPtr != NULLP)
6933                   SPutMsg(*mPtr);
6934                SPutSBuf(info->region, info->pool, (Data*)dBufs, 
6935                      numDBufs*sizeof(Buffer*)); 
6936                RETVALUE(ret);
6937             }
6938          }
6939
6940          if (*mPtr == NULLP)
6941          {
6942             /* it's first recvmsg() call */ 
6943             *mPtr = tempMsg;
6944          }
6945          else
6946          {
6947             /* concatenate messages */  
6948             ret = SCatMsg(*mPtr, tempMsg, M1M2);
6949             if (ret != ROK)
6950             {
6951                /* cleanup */
6952                SPutMsg(*mPtr);
6953                SPutMsg(tempMsg);
6954                SPutSBuf(info->region, info->pool, (Data*)dBufs, 
6955                      numDBufs*sizeof(Buffer*)); 
6956                RETVALUE(RFAILED);
6957             }
6958             SPutMsg(tempMsg);
6959          }
6960
6961          SPutSBuf(info->region, info->pool, (Data*)dBufs, 
6962                numDBufs*sizeof(Buffer*)); 
6963
6964          /* 
6965           * a message is always read atomically on a datagram socket,
6966           * therefore it's ok to read less than pending data!
6967           */
6968 #ifdef CM_INET2  
6969          if ((sockFd->type == CM_INET_DGRAM) ||
6970                (sockFd->type == CM_INET_RAW))
6971          {
6972             /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6973             *len = (MsgLen)recvLen;
6974             break; 
6975          }
6976 #else /* CM_INET2 */ 
6977          if (sockFd->type == CM_INET_DGRAM)
6978          {
6979             /* cm_inet_c_001.main_54: Fix for Klockworks issue */
6980             *len = (MsgLen)recvLen;
6981             break; 
6982          }
6983 #endif /* CM_INET2 */ 
6984       } /* while(bufLen > 0) (only for stream sockets) */
6985
6986       /* cm_inet_c_001.main_48 : For UDP, it is possible to receive
6987        * a 0 byte datagram, in this case just return ROKDNA 
6988        */
6989
6990 #ifdef CM_INET2
6991       if ((sockFd->type == CM_INET_DGRAM || sockFd->type == CM_INET_RAW)
6992             && (*len == 0))
6993 #else
6994          if ((sockFd->type == CM_INET_DGRAM) && (*len == 0))
6995 #endif
6996          {
6997             *len = 0;
6998             if (*mPtr != NULLP)
6999             {
7000                SPutMsg(*mPtr);
7001             }
7002             RETVALUE(ROKDNA);
7003
7004          }
7005
7006       /* Received len == CM_INET_MAX_UDPRAW_MSGSIZE+1
7007        * Drop this message 
7008        */
7009
7010 #ifdef CM_INET2
7011       if ((sockFd->type == CM_INET_DGRAM || sockFd->type == CM_INET_RAW)
7012             && (*len == (CM_INET_MAX_UDPRAW_MSGSIZE+1)))
7013 #else
7014          if ((sockFd->type == CM_INET_DGRAM) 
7015                && (*len == (CM_INET_MAX_UDPRAW_MSGSIZE+1)))
7016 #endif
7017          {
7018             *len = 0;
7019             if (*mPtr != NULLP)
7020             {
7021                SPutMsg(*mPtr);
7022             }
7023
7024 #ifdef CMINETDBG
7025 #ifndef ALIGN_64BIT
7026             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7027             /* cm_inet_c_001.main_62:Warning fix */
7028             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() recevied a message > than"
7029                   " allowed(%d),sockFd->fd(%ld)\n", 
7030                   CM_INET_MAX_UDPRAW_MSGSIZE, sockFd->fd);
7031             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET069, 0, prntBuf);
7032 #else
7033             /* cm_inet_c_001.main_62:Warning fix */
7034             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetRecvMsg() recevied a message > than"
7035                   " allowed(%d),sockFd->fd(%d)\n", 
7036                   CM_INET_MAX_UDPRAW_MSGSIZE, sockFd->fd);
7037             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET069, 0, prntBuf);
7038 #endif
7039 #endif
7040             RETVALUE(ROKDNA);
7041
7042          }
7043
7044 #endif /* WIN32 | CMINETFLATBUF  */
7045    }
7046    else
7047    {
7048       /* not enough data pending yet */
7049       RETVALUE(ROKDNA);
7050    }
7051
7052    RETVALUE(ROK);
7053 } /* end of cmInetRecvMsg */
7054
7055
7056 /* cm_inet_c_001.main_56: Added new function cmInetPeekNew() */
7057 \f
7058 /*
7059  *
7060  *      Fun:   cmInetPeekNew
7061  *
7062  *      Desc:  Reads some data from the socket without destroying the socket
7063  *             receive buffer.
7064  *             The data is specified by the byte positon (first byte is at
7065  *             position 0) and the length.  
7066  *
7067  *      Ret:   ROK     - successful
7068  *             ROKDNA  - ok, data not available
7069  *             RCLOSED - connection closed by peer
7070  *             RFAILED - failed
7071  *
7072  *      Notes: Following are the differences from the cmInetPeek to cmInetPeekNew.
7073  *       This primitive does not call the select function as this is already
7074  *       taken care by the called primitive. This primitive will not use any 
7075  *       ioctl calls, because on some machines due to latency in ioctl call 
7076  *       length may return as ZERO, even there is some data to be read from 
7077  *       the socket and this primitive only peek buffer using recvfrom. 
7078  *       
7079  *       Caller of this function need to allocate the sufficient memory to hold
7080  *       the data peeked from the socket i.e. dataPos + dataLen. Socket data 
7081  *       will be copied in the "data" starting from dataPos offset.
7082  *
7083  *       For example, caller passed the following values to this function. 
7084  *       dataPos = 2 and dataLen = 10,then size of data buffer received should
7085  *       be minimum of (dataPos + dataLen)12 bytes and socket data will be 
7086  *       copied in the data buffer from offset 2 (dataPos) onwards.   
7087  *
7088  *             
7089  *      File:  cm_inet.c
7090  */
7091
7092 #ifdef ANSI
7093 PUBLIC S16 cmInetPeekNew
7094 (
7095  CmInetFd        *sockFd,        /* socket file descriptor */ 
7096  CmInetAddr      *fromAddr,      /* sender Internet address/port */ 
7097  CmInetMemInfo   *info,          /* buffer allocation info */
7098  MsgLen           dataPos,       /* position of data */
7099  MsgLen           dataLen,       /* length of read data */
7100  Data            *data           /* read data */
7101  )
7102 #else
7103 PUBLIC S16 cmInetPeekNew(sockFd, fromAddr, info, dataPos, dataLen, data)
7104    CmInetFd        *sockFd;        /* socket file descriptor */ 
7105    CmInetAddr      *fromAddr;      /* sender Internet address/port */ 
7106    CmInetMemInfo   *info;          /* buffer allocation info */
7107    MsgLen           dataPos;       /* position of data */
7108    MsgLen           dataLen;       /* length of read data */
7109    Data            *data;          /* read data */
7110 #endif
7111 {
7112    /* cm_inet_c_001.main_57 - Fix for validation and compilation warning */
7113    S32          recvLen;           /* number of received octets */
7114    S32          remAddrLen;        /* length of remote address length */
7115    struct sockaddr_in  *remAddr;    /* remote Internet address */      
7116 #ifdef IPV6_SUPPORTED
7117    struct sockaddr_in6  *remAddr6;  /* remote Internet IPV6 address */      
7118    struct sockaddr_in6 remSockAddr; /* to get packet's source IP address */
7119 #else
7120    CmInetSockAddr  remSockAddr;     /* to get packet's source IP address */
7121 #endif /* IPV6_SUPPORTED */
7122
7123    TRC2(cmInetPeeknew);
7124
7125 #if (ERRCLASS & ERRCLS_INT_PAR)
7126    /* error check on parameters */
7127    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
7128          (info == NULLP) || (data == NULLP) ||
7129          (dataPos < 0) || (dataLen < 0))
7130    {
7131       RETVALUE(RFAILED);
7132    }
7133 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7134
7135    /* check if fromAddr is present or not */
7136    if (fromAddr != NULLP)
7137    {
7138       remAddrLen = sizeof(remSockAddr); 
7139    }
7140    else
7141    {
7142       remAddrLen = 0;
7143    }
7144
7145    /* added different recvfrom calls with different 6th arg for 
7146     * different OS If remAddrLen is 0, pass NULLP */
7147 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
7148    if(remAddrLen)
7149       recvLen = recvfrom(sockFd->fd,(S8*)(data + dataPos), (dataLen), 
7150             CM_INET_MSG_PEEK, &remSockAddr, (int*)&remAddrLen);
7151    else
7152       recvLen = recvfrom(sockFd->fd,(S8*)(data + dataPos), (dataLen), 
7153             CM_INET_MSG_PEEK, NULLP, (int*)&remAddrLen);
7154 #else
7155 #if ( defined(SUNOS) || defined(SS_LINUX))
7156    if(remAddrLen)
7157       recvLen = recvfrom(sockFd->fd, (S8*)(data + dataPos),(dataLen), 
7158             CM_INET_MSG_PEEK, (struct sockaddr *)&remSockAddr, 
7159             (socklen_t *)&remAddrLen);
7160    else
7161       recvLen = recvfrom(sockFd->fd, (S8*)(data + dataPos),(dataLen), 
7162             CM_INET_MSG_PEEK, NULLP, (socklen_t *)&remAddrLen);
7163 #else
7164    if(remAddrLen)
7165       recvLen = recvfrom(sockFd->fd,(S8*)(data + dataPos), (dataLen), 
7166             CM_INET_MSG_PEEK, &remSockAddr, (S32*)&remAddrLen);
7167    else
7168       recvLen = recvfrom(sockFd->fd,(S8*)(data + dataPos), (dataLen), 
7169             CM_INET_MSG_PEEK, NULLP, (S32*)&remAddrLen);
7170 #endif /* defined(SUNOS) || defined(SS_LINUX) */
7171 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */
7172
7173    /* removed the check of returned remAddrLen */ 
7174    if (recvLen == INET_ERR)
7175    {
7176       /* added check ERR_WOULDBLOCK */
7177       if ((INET_ERR_CODE == ERR_AGAIN) ||
7178             (INET_ERR_CODE == ERR_WOULDBLOCK))
7179       {
7180          recvLen = 0;
7181          RETVALUE(ROKDNA);
7182       }
7183       /* cm_inet_c_001.main_61: added host unreachable check */
7184       if ((INET_ERR_CODE == ERR_CONNABORTED) ||
7185             (INET_ERR_CODE == ERR_CONNRESET) ||
7186             (INET_ERR_CODE == ERR_HOSTUNREACH) ||
7187             (INET_ERR_CODE == ERR_CONNREFUSED))
7188       {
7189          recvLen = 0;
7190          RETVALUE(RCLOSED);
7191       }
7192 #ifdef CMINETDBG
7193 #ifndef ALIGN_64BIT
7194       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7195       /* cm_inet_c_001.main_62:Warning fix */
7196       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetPeekNew() Failed : error(%d), sockFd->fd(%ld)\n", 
7197             INET_ERR_CODE, sockFd->fd);
7198       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET070, 0, prntBuf);
7199 #else
7200       /* cm_inet_c_001.main_62:Warning fix */
7201       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetPeekNew() Failed : error(%d), sockFd->fd(%d)\n", 
7202             INET_ERR_CODE, sockFd->fd);
7203       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET070, 0, prntBuf);
7204 #endif
7205 #endif /* CMINETDBG */
7206
7207       RETVALUE(RFAILED);
7208    } 
7209    else if (recvLen == 0)
7210    {
7211       RETVALUE(RCLOSED);
7212    }
7213
7214    /* cm_inet_c_001.main_57 - Fix for validation */
7215    if (recvLen < (S32)dataLen)  /* maybe happen */
7216    {
7217       RETVALUE(ROKDNA);
7218    } 
7219
7220    /* setup return destination Internet address */
7221    /* added the check of (remAddLen > 0) */
7222    if ((fromAddr != NULLP) && (remAddrLen > 0))
7223    {
7224 #ifdef IPV6_SUPPORTED
7225       cmMemset((U8*)fromAddr, 0, sizeof(fromAddr));
7226       if (remAddrLen == sizeof(struct sockaddr_in6))
7227       {
7228          remAddr6 = (struct sockaddr_in6 *)&remSockAddr;
7229          fromAddr->type = CM_INET_IPV6ADDR_TYPE;
7230          fromAddr->u.ipv6Addr.port = 
7231             CM_INET_NTOH_U16(remAddr6->sin6_port);
7232          CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr, 
7233                &remAddr6->sin6_addr);
7234       }
7235       else
7236       {
7237          remAddr = (struct sockaddr_in *)&remSockAddr;
7238          fromAddr->type = CM_INET_IPV4ADDR_TYPE;
7239          fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(remAddr->sin_port);
7240          fromAddr->u.ipv4Addr.address = 
7241             CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
7242       } 
7243 #else
7244       remAddr = (struct sockaddr_in *)&remSockAddr;
7245       fromAddr->port    = CM_INET_NTOH_U16(remAddr->sin_port);
7246       fromAddr->address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
7247 #endif /* IPV6_SUPPORTED */
7248    }
7249
7250    RETVALUE(ROK);
7251 } /* end of cmInetPeeknew */
7252
7253 \f
7254 /*
7255 *
7256 *      Fun:   cmInetPeek
7257 *
7258 *      Desc:  Reads some data from the socket without destroying the socket
7259 *             receive buffer.
7260 *             The data is specified by the byte positon (first byte is at
7261 *             position 0) and the length.  
7262 *     
7263 *      Ret:   ROK     - successful
7264 *             ROKDNA  - ok, data not available
7265 *             RCLOSED - connection closed by peer
7266 *             RFAILED - failed
7267 *
7268 *      Notes: None.
7269 *
7270 *      File:  cm_inet.c
7271 *
7272 */
7273
7274 #ifdef ANSI
7275 PUBLIC S16 cmInetPeek
7276 (
7277 CmInetFd        *sockFd,        /* socket file descriptor */ 
7278 CmInetAddr      *fromAddr,      /* sender Internet address/port */ 
7279 CmInetMemInfo   *info,          /* buffer allocation info */
7280 MsgLen           dataPos,       /* position of data */
7281 MsgLen           dataLen,       /* length of read data */
7282 Data            *data           /* read data */
7283 )
7284 #else
7285 PUBLIC S16 cmInetPeek(sockFd, fromAddr, info, dataPos, dataLen, data)
7286 CmInetFd        *sockFd;        /* socket file descriptor */ 
7287 CmInetAddr      *fromAddr;      /* sender Internet address/port */ 
7288 CmInetMemInfo   *info;          /* buffer allocation info */
7289 MsgLen           dataPos;       /* position of data */
7290 MsgLen           dataLen;       /* length of read data */
7291 Data            *data;          /* read data */
7292 #endif
7293 {
7294    /* cm_inet_c_001.main_54: Fix for Klockworks issue */
7295    Data        *recvBuf = NULLP;   /* plain receive buffer */
7296    /* cm_inet_c_001.main_47: 102069 Changed from S32 to MsgLen for bufLen*/
7297    MsgLen       bufLen;            /* buffer length */ 
7298    MsgLen       i;                 /* index */
7299    MsgLen       j;                 /* index */
7300    S32          ret;               /* temporary return value */
7301    U32          timeout;           /* timeout for cmInetSelect() */ 
7302    U32         *timeoutPtr;        /* pointer to timeout */
7303    S16          numFdS;            /* number of ready descriptors */
7304    /* cm_inet_c_001.main_45 - fixing the UMR issue in 64bit linux */
7305    U32          pendLen = 0;           /* pending data length */
7306    S32          recvLen;           /* number of received octets */
7307    S32          remAddrLen;        /* length of remote address length */
7308    CmInetFdSet  readFdS;           /* socket file descriptor set */
7309    struct sockaddr_in  *remAddr;    /* remote Internet address */      
7310 #ifdef IPV6_SUPPORTED
7311    struct sockaddr_in6  *remAddr6;  /* remote Internet IPV6 address */      
7312    struct sockaddr_in6 remSockAddr; /* to get packet's source IP address */
7313 #else
7314    CmInetSockAddr  remSockAddr;     /* to get packet's source IP address */
7315 #endif /* IPV6_SUPPORTED */
7316
7317    TRC2(cmInetPeek);
7318
7319 #if (ERRCLASS & ERRCLS_INT_PAR)
7320    /* error check on parameters */
7321    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
7322          (info == NULLP) || (data == NULLP) ||
7323          (dataPos < 0) || (dataLen < 0))
7324    {
7325       RETVALUE(RFAILED);
7326    }
7327 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7328
7329    /* check if there are some datas */
7330    if (sockFd->blocking) 
7331    {
7332       /* blocking */ 
7333       timeoutPtr = NULLP;  
7334    } 
7335    else 
7336    {
7337       /* poll (non-blocking) */ 
7338       timeout = 0;
7339       timeoutPtr = &timeout;
7340    }
7341    CM_INET_FD_ZERO(&readFdS);
7342    CM_INET_FD_SET(sockFd, &readFdS);
7343
7344    ret = cmInetSelect(&readFdS, NULLP, timeoutPtr, &numFdS);
7345    if (CM_INET_FD_ISSET(sockFd, &readFdS))
7346    {
7347       /* get number of pending data */
7348       /* removed 3rd arg memInfo. MemInfo is no longer needed as we 
7349          call ioctl for all sockets */
7350       ret = cmInetGetNumRead(sockFd, &pendLen);
7351       if (ret != ROK)
7352       {
7353          /* cm_inet_c_001.main_50
7354           * Return RCLOSED if cmInetGetNumRead returns RCLOSED. For other
7355           * errors just return RFAILED.
7356           */
7357          if (ret == RCLOSED)
7358             RETVALUE(RCLOSED);
7359
7360          RETVALUE(RFAILED);
7361       }
7362
7363       /* check if connection got closed */
7364       if (pendLen == 0)
7365       {
7366
7367          /* cm_inet_c_001.main_50 
7368           * Due to latency (mostly in solaris) sometimes ioctl(FIONREAD)
7369           * (inside cmInetGetNumRead) returns pend length as 0 on a TCP 
7370           * socket that select says is ready to read. This should not be 
7371           * considered as connection closed. So return ROKDNA instead of 
7372           * RCLOSED even for TCP sockets
7373           */
7374          RETVALUE(ROKDNA);
7375       }
7376       /* added check for TCP/UDP socket. Pending data len in the socket 
7377          recv buffer is determined by ioctl call in cmInetGetNumRead. 
7378          For TCP it can't be > CM_INET_MAX_MSG_LEN. 
7379          For UDP it can't be > CM_INET_MAX_UDPRAW_MSGSIZE. */ 
7380       if (sockFd->type == CM_INET_STREAM) 
7381       {
7382          /* max message length is limited to control the memory usage */
7383          if (pendLen > CM_INET_MAX_MSG_LEN)
7384             pendLen = CM_INET_MAX_MSG_LEN;
7385          /* In STREAM remote address is not required */
7386          remAddrLen = 0;
7387       }
7388       else
7389       {
7390          if (pendLen > CM_INET_MAX_UDPRAW_MSGSIZE)
7391             pendLen = CM_INET_MAX_UDPRAW_MSGSIZE;
7392
7393          remAddrLen = sizeof(CmInetSockAddr);
7394       }
7395
7396       /* check if there are enough pending data to read */
7397       bufLen = dataPos + dataLen;
7398
7399       /* check if fromAddr is present or not */
7400       if (fromAddr != NULLP)
7401       {
7402          remAddrLen = sizeof(remSockAddr); 
7403       }
7404       else
7405       {
7406          remAddrLen = 0;
7407       }
7408
7409       /* cm_inet_c_001.main_58: Fix for g++ compilation warning */
7410       if ((MsgLen)pendLen >= bufLen)
7411       {        
7412          /* allocate receive buffer (flat structure) */
7413          ret = SGetSBuf(info->region, info->pool, &recvBuf, bufLen);                  
7414          if (ret != ROK)
7415          {
7416             RETVALUE(ROUTRES);
7417          }          
7418
7419          /* added different recvfrom calls with 
7420           * different 6th arg for different OS */
7421
7422          /* If remAddrLen is 0, pass NULLP */
7423 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
7424          if(remAddrLen)
7425             recvLen = recvfrom(sockFd->fd,(S8*)recvBuf, bufLen, 
7426                   CM_INET_MSG_PEEK, &remSockAddr, (int*)&remAddrLen);
7427          else
7428             recvLen = recvfrom(sockFd->fd,(S8*)recvBuf, bufLen, 
7429                   CM_INET_MSG_PEEK, NULLP, (int*)&remAddrLen);
7430 #else
7431 #if ( defined(SUNOS) || defined(SS_LINUX))
7432          if(remAddrLen)
7433             recvLen = recvfrom(sockFd->fd, (S8*)recvBuf,bufLen, 
7434                   CM_INET_MSG_PEEK, (struct sockaddr *)&remSockAddr, 
7435                   (socklen_t *)&remAddrLen);
7436          else
7437             recvLen = recvfrom(sockFd->fd, (S8*)recvBuf,bufLen, 
7438                   CM_INET_MSG_PEEK, NULLP, (socklen_t *)&remAddrLen);
7439 #else         
7440          if(remAddrLen)
7441             recvLen = recvfrom(sockFd->fd,(S8*)recvBuf, bufLen, 
7442                   CM_INET_MSG_PEEK, &remSockAddr, (S32*)&remAddrLen);
7443          else
7444             recvLen = recvfrom(sockFd->fd,(S8*)recvBuf, bufLen, 
7445                   CM_INET_MSG_PEEK, NULLP, (S32*)&remAddrLen);
7446 #endif /* defined(SUNOS) || defined(SS_LINUX) */
7447 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */
7448
7449          /* removed the check of returned remAddrLen */ 
7450          if (recvLen == INET_ERR)
7451          {
7452             /* cleanup */
7453             /* moved cleanup here */
7454             SPutSBuf(info->region, info->pool, recvBuf, bufLen); 
7455
7456             /* added check ERR_WOULDBLOCK */
7457             if ((INET_ERR_CODE == ERR_AGAIN) ||
7458                   (INET_ERR_CODE == ERR_WOULDBLOCK))
7459             {
7460                recvLen = 0;
7461                RETVALUE(ROKDNA);
7462             }
7463
7464             /* moved up the cleanup */
7465
7466 #ifdef CMINETDBG
7467 #ifndef ALIGN_64BIT
7468             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7469             /* cm_inet_c_001.main_62:Warning fix */
7470             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetPeek() Failed : error(%d), sockFd->fd(%ld)\n", 
7471                   INET_ERR_CODE, sockFd->fd);
7472             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET036, 0, prntBuf);
7473 #else
7474             /* cm_inet_c_001.main_62:Warning fix */
7475             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetPeek() Failed : error(%d), sockFd->fd(%d)\n", 
7476                   INET_ERR_CODE, sockFd->fd);
7477             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET036, 0, prntBuf);
7478 #endif
7479 #endif /* CMINETDBG */
7480
7481             if ((INET_ERR_CODE == ERR_CONNABORTED) ||
7482                   (INET_ERR_CODE == ERR_CONNRESET))
7483             {
7484                recvLen = 0;
7485                RETVALUE(RCLOSED);
7486             }
7487             RETVALUE(RFAILED);
7488          } 
7489
7490          if (recvLen < (S32)bufLen)  /* maybe happen */
7491          {
7492             /* cleanup */
7493             SPutSBuf(info->region, info->pool, recvBuf, bufLen);                            
7494             RETVALUE(ROKDNA);
7495          } 
7496
7497          /* copy data */
7498          for (j = 0, i = dataPos; i < bufLen; j++, i++)
7499             data[j] = recvBuf[i];             
7500
7501          /* setup return destination Internet address */
7502          /* added the check of (remAddLen > 0) */
7503          if ((fromAddr != NULLP) && (remAddrLen > 0))
7504          {
7505 #ifdef IPV6_SUPPORTED
7506             cmMemset((U8*)fromAddr, 0, sizeof(fromAddr));
7507             if (remAddrLen == sizeof(struct sockaddr_in6))
7508             {
7509                remAddr6 = (struct sockaddr_in6 *)&remSockAddr;
7510                fromAddr->type = CM_INET_IPV6ADDR_TYPE;
7511                fromAddr->u.ipv6Addr.port = 
7512                   CM_INET_NTOH_U16(remAddr6->sin6_port);
7513                CM_INET_COPY_IPV6ADDR(&fromAddr->u.ipv6Addr.ipv6NetAddr, 
7514                      &remAddr6->sin6_addr);
7515             }
7516             else
7517             {
7518                remAddr = (struct sockaddr_in *)&remSockAddr;
7519                fromAddr->type = CM_INET_IPV4ADDR_TYPE;
7520                fromAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(remAddr->sin_port);
7521                fromAddr->u.ipv4Addr.address = 
7522                   CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
7523             } 
7524 #else
7525             remAddr = (struct sockaddr_in *)&remSockAddr;
7526             fromAddr->port    = CM_INET_NTOH_U16(remAddr->sin_port);
7527             fromAddr->address = CM_INET_NTOH_U32(remAddr->sin_addr.s_addr);
7528 #endif /* IPV6_SUPPORTED */
7529          }   
7530
7531          /* cleanup */
7532          SPutSBuf(info->region, info->pool, recvBuf, bufLen);                            
7533       }
7534       else
7535       {
7536          /* not enough data pending yet */
7537          RETVALUE(ROKDNA);
7538       }
7539    }
7540    else
7541    {
7542       /* no data pending */ 
7543       RETVALUE(ROKDNA);
7544    }   
7545
7546    RETVALUE(ROK);
7547 } /* end of cmInetPeek */
7548
7549 \f
7550 /*
7551 *
7552 *      Fun:   cmInetClose 
7553 *
7554 *      Desc:  Close a socket gracefully. 
7555 *
7556 *      Ret:   ROK     - successful
7557 *             RFAILED - failed
7558 *
7559 *      Notes: None.
7560 *
7561 *      File:  cm_inet.c
7562 *
7563 */
7564
7565 #ifdef ANSI
7566 PUBLIC S16 cmInetClose
7567 (
7568 CmInetFd *sockFd                /* socket file descriptor */
7569 )
7570 #else
7571 PUBLIC S16 cmInetClose(sockFd)
7572 CmInetFd *sockFd;               /* socket file descriptor */
7573 #endif
7574 {
7575    S32 ret;                     /* temporary return value */
7576
7577    TRC2(cmInetClose);
7578
7579 #if (ERRCLASS & ERRCLS_INT_PAR)
7580    /* error check on parameters */
7581    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
7582    {
7583       RETVALUE(RFAILED);
7584    }
7585 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7586
7587 #ifdef WIN32
7588    ret = closesocket(sockFd->fd);
7589 #else
7590    ret = close(sockFd->fd);
7591 #endif /* WIN32 */
7592    if (ret == INET_ERR) 
7593    {
7594 #ifdef CMINETDBG
7595 #ifndef ALIGN_64BIT
7596       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7597       /* cm_inet_c_001.main_62:Warning fix */
7598       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetClose() Failed : error(%d), sockFd->fd(%ld)\n",
7599             INET_ERR_CODE, sockFd->fd);
7600       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET037, 0, prntBuf);
7601 #else
7602       /* cm_inet_c_001.main_62:Warning fix */
7603       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetClose() Failed : error(%d), sockFd->fd(%d)\n",
7604             INET_ERR_CODE, sockFd->fd);
7605       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET037, 0, prntBuf);
7606 #endif /*ALIGN_64BIT*/
7607 #endif /* CMINETDBG */
7608       RETVALUE(RFAILED);
7609    }
7610
7611    RETVALUE(ROK);
7612 } /* end of cmInetClose */
7613
7614 \f
7615 /*
7616 *
7617 *      Fun:   cmInetShutdown
7618 *
7619 *      Desc:  Close an Internet connection with more control over the data of 
7620 *             the full-duplex connection.
7621 *             Values for the howTo parameter:
7622 *
7623 *             CM_INET_SHTDWN_RECV - discard data in receive buffer
7624 *             CM_INET_SHTDWN_SEND - discard data in transmit buffer
7625 *             CM_INET_SHTDWN_BOTH - discard data in receive and transmit buffer      
7626 *
7627 *      Ret:   ROK     - successful
7628 *             RFAILED - failed
7629 *
7630 *      Notes: This function does not free the socket descriptor but only closes the 
7631 *             connection (cmInetClose() has to be called afterwards).
7632 *             No error is returned if the socket is not connected while calling
7633 *             this function. 
7634 *
7635 *      File:  cm_inet.c
7636 *
7637 */
7638
7639 #ifdef ANSI
7640 PUBLIC S16 cmInetShutdown
7641 (
7642 CmInetFd *sockFd,               /* socket file descriptor */
7643 S32       howTo                 /* operation flag */
7644 )
7645 #else
7646 PUBLIC S16 cmInetShutdown(sockFd, howTo)
7647 CmInetFd *sockFd;               /* socket file descriptor */
7648 S32       howTo;                /* operation flag */
7649 #endif
7650 {
7651    S32 ret;                     /* temporary return value */
7652
7653    TRC2(cmInetShutdown);
7654
7655 #if (ERRCLASS & ERRCLS_INT_PAR)
7656    /* error check on parameters */
7657    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
7658    {
7659       RETVALUE(RFAILED);
7660    }
7661 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7662
7663    ret = shutdown(sockFd->fd, howTo);
7664    if (ret == INET_ERR)
7665    {
7666       if (INET_ERR_CODE == ERR_NOTCONN)
7667       {
7668          /* socket is not connected */ 
7669          RETVALUE(ROK); 
7670       }
7671       else
7672       {
7673          /* real problem */ 
7674 #ifdef CMINETDBG
7675 #ifndef ALIGN_64BIT
7676          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7677          /* cm_inet_c_001.main_62:Warning fix */
7678          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetShutdown() Failed : error(%d),"
7679                " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
7680          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET038, 0, prntBuf);
7681 #else
7682          /* cm_inet_c_001.main_62:Warning fix */
7683          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetShutdown() Failed : error(%d),"
7684                " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
7685          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET038, 0, prntBuf);
7686 #endif /*ALIGN_64BIT*/
7687 #endif /* CMINETDBG */
7688          RETVALUE(RFAILED);
7689       }
7690    }   
7691
7692    RETVALUE(ROK);
7693 } /* end of cmInetShutdown */
7694
7695 \f
7696 /*
7697 *
7698 *      Fun:   cmInetSelect   
7699 *
7700 *      Desc:  Allows multiplex i/o requests among multiple sockets.
7701 *             If the parameter mSecTimeout points to a value of zero the 
7702 *             call immediatley returns (poll), if it is a null pointer, the
7703 *             timeout is set to infinit.
7704 *             numFdS returns the number of ready file  descriptors  contained  
7705 *             in  the  file  descriptor  sets 
7706 *
7707 *      Ret:   ROK      - successful
7708 *             RTIMEOUT - timout expired
7709 *             RFAILED  - failed
7710 *
7711 *      Notes: None.
7712 *
7713 *      File:  cm_inet.c
7714 *
7715 */
7716
7717 #ifdef ANSI
7718 PUBLIC S16 cmInetSelect
7719 (
7720 CmInetFdSet *readFdS,           /* read socket descriptor file set */  
7721 CmInetFdSet *writeFdS,          /* write socket descriptor file set */
7722 U32         *mSecTimeout,       /* timeout in msecs */
7723 S16         *numFdS             /* number of ready descriptors */
7724 )
7725 #else
7726 PUBLIC S16 cmInetSelect(readFdS, writeFdS, mSecTimeout, numFdS)
7727 CmInetFdSet *readFdS;           /* read socket descriptor file set */  
7728 CmInetFdSet *writeFdS;          /* write socket descriptor file set */
7729 U32         *mSecTimeout;       /* timeout in msecs */
7730 S16         *numFdS;            /* number of ready descriptors */
7731 #endif
7732 {
7733    S32 ret;                     /* temporary return value */
7734    struct timeval  timeout;     /* timeout structure */
7735    struct timeval *timeoutPtr;
7736    S32 errCode;
7737
7738 #if (ERRCLASS & ERRCLS_INT_PAR)
7739    /* error check on parameters */
7740    if (numFdS == NULLP)
7741    {
7742       RETVALUE(RFAILED);
7743    }
7744 #endif /* ERRCLASS & ERRCLS_INT_PAR */
7745
7746    *numFdS = 0;
7747
7748    if (mSecTimeout != NULLP)
7749    {
7750       timeout.tv_sec  = *mSecTimeout / 1000;
7751       timeout.tv_usec = (*mSecTimeout % 1000) * 1000;
7752       timeoutPtr      = &timeout;
7753    }
7754    else
7755    {
7756       /* infinite timeout */ 
7757       timeoutPtr = NULLP;
7758    }
7759
7760 #ifdef TUCL_TTI_RCV
7761    timeout.tv_sec  = 0;
7762    timeout.tv_usec = 1;
7763 #endif
7764
7765    /* cm_inet_c_001.main_53 - Removed do-while loop */
7766    ret = select(FD_SETSIZE, readFdS, writeFdS, (fd_set*)0, timeoutPtr);
7767
7768    /* cm_inet_c_001.main_53 -  Return ROKDNA in case select was interrupted */
7769    if ((ret == INET_ERR) && (INET_ERR_CODE == ERR_EINTR))
7770    {
7771       RETVALUE(ROKDNA);
7772    }
7773
7774    /* timeout occured */
7775    if (ret == 0)
7776    { 
7777       RETVALUE(RTIMEOUT);
7778    }
7779
7780    if (ret == INET_ERR)
7781    {
7782       /* asa: Added a check for ERR_INVAL to return ROK
7783        * readFdS and writeFdS may be passed as NULL to
7784        * cmInetSelect() call
7785        */
7786       switch(errCode = INET_ERR_CODE)
7787       {
7788          case ERR_INVAL:
7789             RETVALUE(ROK);
7790
7791          default:
7792 #ifdef CMINETDBG
7793             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
7794             /* cm_inet_c_001.main_62:Warning fix */
7795             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSelect() Failed : error(%d)\n",
7796                   INET_ERR_CODE);
7797             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET039, 0, prntBuf);
7798 #endif /* CMINETDBG */
7799             RETVALUE(RFAILED);
7800
7801       } /* end of switch */
7802    }
7803
7804    /* return number of ready file descriptors */
7805    /* cm_inet_c_001.main_54: Fix for Klockworks issue */
7806    *numFdS = (S16)ret;   
7807
7808    RETVALUE(ROK); 
7809 } /* end of  cmInetSelect */
7810
7811 \f
7812 /*
7813 *
7814 *      Fun:   cmInetSetOpt
7815 *
7816 *      Desc:  Sets a socket option.
7817 *             The function supports following options:
7818 *
7819 *             CM_INET_OPT_BLOCK:
7820 *                value: CM_INET_OPT_DISABLE  non-blocking
7821 *                value: CM_INET_OPT_ENABLE   blocking
7822 *
7823 *             CM_INET_OPT_REUSEADDR:   
7824 *                value: CM_INET_OPT_ENABLE   reuse address 
7825 *
7826 *             CM_INET_OPT_BROADCAST:
7827 *                value: CM_INET_OPT_DISABLE
7828 *                value: CM_INET_OPT_ENABLE
7829 *
7830 *             CM_INET_OPT_KEEPALIVE:
7831 *                value: CM_INET_OPT_DISABLE
7832 *                value: CM_INET_OPT_ENABLE
7833 *
7834 *             CM_INET_OPT_RX_BUF_SIZE:
7835 *                value: receive buffer size in bytes
7836 *
7837 *             CM_INET_OPT_TX_BUF_SIZE:
7838 *                value: transmitter buffer size in bytes
7839 *
7840 *             CM_INET_OPT_ADD_MCAST_MBR:
7841 *                value: address of CmInetMCastInf structure
7842 *
7843 *             CM_INET_OPT_DRP_MCAST_MBR:
7844 *                value: address of CmInetMCastInf structure
7845 *
7846 *             CM_INET_OPT_TCP_NODELAY:  
7847 *                value: CM_INET_OPT_DISABLE
7848 *                value: CM_INET_OPT_ENABLE
7849 *
7850 *             CM_INET_OPT_BSD_COMPAT: For Linux only
7851 *                value: CM_INET_OPT_ENABLE   
7852 *                value: CM_INET_OPT_DISABLE 
7853 *
7854 *             CM_INET_OPT_HDR_INCLD: 
7855 *                value: CM_INET_ENABLE
7856 *                value: CM_INET_DISABLE
7857 *
7858 *             CM_INET_OPT_DONT_FRAGMENT:
7859 *                value: CM_INET_OPT_ENABLE
7860 *                value: CM_INET_DISABLE
7861 *
7862 *             CM_INET_OPT_TOS:
7863 *                value: Type of Service.
7864
7865 *             CM_INET_OPT_TTL:
7866 *                value: Time To Live.
7867 *
7868 *             CM_INET_OPT_IP_OPTIONS:
7869 *                value: IPv4 header option value 
7870 *                ENABLE/DISABLE.
7871 *
7872 *             CM_INET_OPT_IP_ROUTER_ALERT:
7873 *                value: CM_INET_OPT_DISABLE
7874 *                value: CM_INET_OPT_ENABLE
7875 *
7876 *             CM_INET_OPT_IPV4_PKTINFO
7877 *                value: CM_INET_OPT_ENABLE
7878 *                value: CM_INET_OPT_DISABLE
7879 *
7880 *             CM_INET_OPT_MCAST_LOOP:  
7881 *                value: CM_INET_OPT_DISABLE
7882 *                value: CM_INET_OPT_ENABLE
7883 *
7884 *             CM_INET_OPT_MCAST_IF:
7885 *                value: Address of interface.
7886 *
7887 *             CM_INET_OPT_MCAST_TTL:
7888 *                value: TTL of the outgoing multicast packet.
7889 *
7890 *             The next  options are defined only if IPV6 is 
7891 *             supported.
7892 *
7893 *             CM_INET_OPT_ADD_MCAST6_MBR:
7894 *                value: address of CmInetMCastInf6 structure
7895 *
7896 *             CM_INET_OPT_DRP_MCAST6_MBR:
7897 *                value: address of CmInetMCastInf6 structure
7898 *
7899 *             CM_INET_OPT_MCAST6_LOOP:  
7900 *                value: CM_INET_OPT_DISABLE
7901 *                value: CM_INET_OPT_ENABLE
7902 *
7903 *             CM_INET_OPT_MCAST6_IF:
7904 *                value: Interface index
7905 *
7906 *             CM_INET_OPT_MCAST6_HOPS:  
7907 *                value: multicast hop limit 
7908 *
7909 *             CM_INET_OPT_RECVIPV6_HOPLIM:
7910 *                value: CM_INET_OPT_ENABLE   hop limit will be returned
7911 *                                            on the socket.
7912 *                value: CM_INET_OPT_DISABLE  hop limit wont be returned 
7913 *                                            on the socket.
7914 *
7915 *             CM_INET_OPT_RECVIPV6_HBHOPTS:
7916 *                value: CM_INET_OPT_ENABLE   HBH Options will be returned
7917 *                                            on the socket.
7918 *                value: CM_INET_OPT_DISABLE  HBH Options wont be returned 
7919 *                                            on the socket. 
7920 *                                            
7921 *             CM_INET_OPT_RECVIPV6_DSTOPTS:
7922 *                value: CM_INET_OPT_ENABLE   Dest Options will be returned
7923 *                                            on the socket.
7924 *                value: CM_INET_OPT_DISABLE  Dest Options wont be returned 
7925 *                                            on the socket.                     
7926 *                                            
7927 *             CM_INET_OPT_RECVIPV6_RTHDR:
7928 *                value: CM_INET_OPT_ENABLE   Route Hdr Opt will be turned
7929 *                                            ON on the socket.
7930 *                value: CM_INET_OPT_DISABLE  Route Hdr Opt will be turned 
7931 *                                            OFF on the socket.
7932 *
7933 *             CM_INET_OPT_IP_ROUTER_ALERT6  
7934 *                value: CM_INET_OPT_ENABLE
7935 *                value: CM_INET_OPT_DISABLE
7936
7937 *             CM_INET_OPT_IPV6_PKTINFO
7938 *                value: CM_INET_OPT_ENABLE   Enable sending and receiving
7939 *                                            of packet info
7940 *                value: CM_INET_OPT_DISABLE  Disable sending and receiving
7941 *                                            of packet info
7942
7943 *             CM_INET_OPT_LINGER
7944 *                value: address of CmInetSockLinger structure
7945 *
7946 *             CM_INET_OPT_SCTP_EVENTS
7947 *                value: address of CmInetSctpSockEvent structure
7948 *
7949 *             CM_INET_OPT_SCTP_PRIM_ADDR
7950 *                value: address of CmInetSctpPrimAddr structure
7951 *
7952 *             CM_INET_OPT_SCTP_PEERADDR_PARAMS
7953 *                value: address of CmInetSctpPeerAddrParams structure
7954 *
7955 *
7956 *      Ret:   ROK     - successful
7957 *             RFAILED - failed
7958 *             RNA     - failed, option not available
7959 *             (Only when CM_INET2 is defined)
7960 *
7961 *      Notes: The send and receive buffer size may be system
7962 *             specific. The cmInetSetOpt() call may return
7963 *             successfuly although not the entire buffer size 
7964 *             could be set!
7965 *
7966 *      File:  cm_inet.c
7967 *
7968 */
7969 #ifdef ANSI
7970 PUBLIC S16 cmInetSetOpt
7971 (
7972 CmInetFd *sockFd,               /* socket file descriptor */ 
7973 U32       level,                /* option level */
7974 U32       type,                 /* option type */
7975 Ptr       value                 /* option value */ 
7976
7977 #else
7978 PUBLIC S16 cmInetSetOpt(sockFd, level, type, value)
7979 CmInetFd *sockFd;               /* socket file descriptor */ 
7980 U32       level;                /* option level */
7981 U32       type;                 /* option type */
7982 Ptr       value;                /* option value */
7983 #endif
7984 {
7985    S32  ret = ROK;              /* temporary return value */
7986    U32  disable = 0;            /* disable option */
7987    U32  enable = 1;             /* enable option */
7988
7989    /* added for IPv4 options */
7990 #ifdef IPV4_OPTS_SUPPORTED
7991 #if((!defined (SS_VW)) && (!defined(SS_LINUX)))   
7992    TknStr64 *tempTknStr64;      /* points TknStr64 structure */
7993    /* which has value for IPv4 hdr options.*/
7994 #endif /* SS_VW && SS_LINUX */   
7995 #ifdef WIN32   
7996    int disableOpt = 0;
7997 #endif /* WIN32 */   
7998 #endif /* IPV4_OPTS_SUPPORTED */ 
7999
8000 #if (defined(SUNOS)|| defined(WIN32) || defined(SS_PS) || defined(SS_VW_MCAST)\
8001       || defined(HPOS))
8002    U8   lpEnable = 1;           /* multicast loop enable */
8003    U8   lpDisable = 0;          /* multicast loop disable */
8004 #endif /* SUNOS || WIN32 || SS_PS || SS_VW_MCAST || HPOS */
8005
8006 #ifdef WIN32
8007    BOOL boolEnable = TRUE;      /* enable option */
8008    BOOL boolDisable = FALSE;    /* disable option */
8009 #endif /* WIN32 */
8010
8011 #if (defined(SUNOS) || defined(WIN32) || defined(SS_PS) || \
8012       defined(SS_VW_MCAST) || defined(HPOS))
8013    struct ip_mreq stMreq;
8014    CmInetMCastInf *mCast;
8015 #endif /* SUNOS || WIN32  || SS_PS || SS_VW_MCAST || HPOS */
8016
8017 #ifdef IPV6_SUPPORTED
8018    U32    loopEna = 1;     /* IPv6 multicast loop enable */
8019    U32    loopDis = 0;     /* IPv6 multicast loop disable */
8020    struct ipv6_mreq     *stMreq6Ptr;
8021    /* cm_inet_c_001.main_44 : some operating system doesnt have icmp6_filter. so 
8022       this flag is gaurded under ICMPV6_FILTER_SUPPORTED. so if user want this 
8023       support he has to enable the above flag.*/
8024    /* cm_inet_c_001.main_58 : Protaected under flag CM_ICMP_FILTER_SUPPORT
8025     * to support filteration  of ICMP messages */
8026 #if (defined(ICMPV6_FILTER_SUPPORTED) || defined(CM_ICMP_FILTER_SUPPORT))
8027    struct icmp6_filter  *icmp6Filter; 
8028 #endif /* ICMPV6_FILTER_SUPPORTED */
8029 #endif /* IPV6_SUPPORTED */
8030
8031    /* cm_inet_c_001.main_58 : Added new local variables to support filteration 
8032     * of ICMP messages */
8033 #ifdef SS_LINUX
8034 #ifdef CM_ICMP_FILTER_SUPPORT
8035   struct icmp_filter icmpFilter; 
8036 #endif  
8037 #endif  
8038
8039    /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
8040 #ifdef CM_LKSCTP
8041    struct linger               lngr;
8042    struct sctp_event_subscribe event; 
8043    struct sctp_paddrparams     addrParams;
8044    struct sctp_setprim         setPrim;
8045    struct sockaddr_in         *pAddr;
8046    struct sctp_assocparams     assocParams;
8047    struct sctp_initmsg         initmsg;
8048    struct sctp_rtoinfo         rtoinfo;
8049 #ifdef IPV6_SUPPORTED
8050    struct sockaddr_in6        *pAddr6;
8051 #endif /* IPV6_SUPPORTED */
8052
8053    CmInetSockLinger           *pSockLinger;
8054    CmInetSctpSockEvent        *pSctpEvent;
8055    CmInetSctpPrimAddr         *pSctpPrimAddr;
8056    CmInetSctpPeerAddrParams   *pSctpPAddrParams;
8057    CmInetSctpRtoInfo          *pSctpRtoInfo;
8058    CmInetSctpInitMsg          *pSctpInitMsg;
8059    CmInetSctpAssocParams      *pSctpAssocParams;
8060 #endif
8061
8062    U32    *optVal;
8063
8064    TRC2(cmInetSetOpt);
8065
8066    /* cm_inet_c_001.main_58 : Added NULL check for value field */ 
8067    if(value == NULLP)
8068    {
8069       RETVALUE(RFAILED);
8070    }
8071
8072 #if (ERRCLASS & ERRCLS_INT_PAR)
8073    /* error check on parameters */
8074    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
8075    {
8076       RETVALUE(RFAILED);
8077    }
8078 #endif /* ERRCLASS & ERRCLS_INT_PAR */
8079
8080    switch (type)
8081    {
8082       case CM_INET_OPT_BLOCK:
8083          optVal = (U32*)value;
8084          switch(*optVal)
8085          {
8086             case CM_INET_OPT_ENABLE:
8087
8088 #ifdef WIN32
8089                /* cm_inet_c_001.main_59: Fix for compilation warning */
8090                ret = ioctlsocket(sockFd->fd, FIONBIO, (U32 *)&disable);
8091 #else
8092 #ifdef SS_PS
8093                ret = ioctl(sockFd->fd, FIONBIO, (char*)&disable);
8094 #else
8095 #ifdef SS_VW
8096                ret = ioctl(sockFd->fd, (S32)FIONBIO, (S32)&disable);
8097 #else
8098                ret = ioctl(sockFd->fd, (S32)FIONBIO, &disable);
8099
8100 #endif /* SS_VW */
8101 #endif /* SS_PS */
8102 #endif /* WIN32 */
8103                sockFd->blocking = 1;
8104                break;
8105
8106             case CM_INET_OPT_DISABLE:
8107 #ifdef WIN32
8108               /* cm_inet_c_001.main_59: Fix for compilation warning */
8109               ret = ioctlsocket(sockFd->fd, FIONBIO, (U32 *)&enable); 
8110 #else
8111 #ifdef SS_PS
8112                ret = ioctl(sockFd->fd, FIONBIO, (char*)&enable);
8113 #else
8114 #ifdef SS_VW
8115                ret = ioctl(sockFd->fd, (S32)FIONBIO, (S32)&enable);
8116 #else
8117                ret = ioctl(sockFd->fd, (S32)FIONBIO, &enable);
8118 #endif /* SS_VW */
8119 #endif /* SS_PS */
8120 #endif /* WIN32 */
8121                sockFd->blocking = 0;
8122                break;
8123
8124             default:
8125                /* wrong value */
8126                RETVALUE(RFAILED);
8127                break;
8128          }
8129          break;
8130
8131       case CM_INET_OPT_REUSEADDR:
8132          optVal = (U32*)value;
8133          if (*optVal == CM_INET_OPT_ENABLE)
8134          {
8135 #ifdef WIN32
8136             ret = setsockopt(sockFd->fd, level, SO_REUSEADDR,
8137                   (char*)&boolEnable, sizeof(boolEnable));
8138 #else
8139             ret = setsockopt(sockFd->fd, level, SO_REUSEADDR,
8140                   (char*)&enable, sizeof(enable));
8141 #ifdef SS_VW
8142             setsockopt(sockFd->fd, level, SO_REUSEPORT,
8143                   (char*)&enable, sizeof(enable));
8144 #endif /* SS_VW */
8145 #endif /* WIN32 */
8146          }
8147          else if (*optVal == CM_INET_OPT_DISABLE)
8148          {
8149 #ifdef WIN32
8150             ret = setsockopt(sockFd->fd, level, SO_REUSEADDR,
8151                   (char*)&boolDisable, sizeof(boolDisable));
8152 #else
8153             ret = setsockopt(sockFd->fd, level, SO_REUSEADDR,
8154                   (char*)&disable, sizeof(disable));
8155 #ifdef SS_VW
8156             ret = setsockopt(sockFd->fd, level, SO_REUSEPORT,
8157                   (char*)&disable, sizeof(disable));
8158 #endif /* SS_VW */
8159 #endif /* WIN32 */
8160          }
8161          break;
8162
8163       case CM_INET_OPT_BROADCAST:
8164          optVal = (U32*)value;
8165          if (*optVal == CM_INET_OPT_ENABLE)
8166          {
8167 #ifdef WIN32
8168             ret = setsockopt(sockFd->fd, level, SO_BROADCAST,
8169                   (char*)&boolEnable, sizeof(boolEnable));
8170 #else
8171             ret = setsockopt(sockFd->fd, level, SO_BROADCAST,
8172                   (char*)&enable, sizeof(enable));
8173 #endif /* WIN32 */
8174          }
8175          else if (*optVal == CM_INET_OPT_DISABLE)
8176          {
8177 #ifdef WIN32
8178             ret = setsockopt(sockFd->fd, level, SO_BROADCAST,
8179                   (char*)&boolDisable, sizeof(boolDisable));
8180 #else
8181             ret = setsockopt(sockFd->fd, level, SO_BROADCAST,
8182                   (char*)&disable, sizeof(disable));
8183 #endif /* WIN32 */
8184          }
8185          break; 
8186
8187       case CM_INET_OPT_KEEPALIVE:
8188          optVal = (U32*)value;
8189          if (*optVal == CM_INET_OPT_ENABLE)
8190          {
8191 #ifdef WIN32
8192             ret = setsockopt(sockFd->fd, level, SO_KEEPALIVE,
8193                   (char*)&boolEnable, sizeof(boolEnable));
8194 #else
8195             ret = setsockopt(sockFd->fd, level, SO_KEEPALIVE,
8196                   (char*)&enable, sizeof(enable));
8197 #endif /* WIN32 */
8198          }
8199          else if (*optVal == CM_INET_OPT_DISABLE)
8200          {
8201 #ifdef WIN32
8202             ret = setsockopt(sockFd->fd, level, SO_KEEPALIVE,
8203                   (char*)&boolDisable, sizeof(boolDisable));
8204 #else
8205             ret = setsockopt(sockFd->fd, level, SO_KEEPALIVE,
8206                   (char*)&disable, sizeof(disable));
8207 #endif /* WIN32 */
8208          }
8209          break;
8210
8211       case CM_INET_OPT_RX_BUF_SIZE:
8212          optVal = (U32*)value;
8213          ret = setsockopt(sockFd->fd, level, SO_RCVBUF, 
8214                (char*)optVal, sizeof(*optVal));
8215          break;
8216
8217       case CM_INET_OPT_TX_BUF_SIZE:
8218          optVal = (U32*)value;
8219          ret = setsockopt(sockFd->fd, level, SO_SNDBUF, 
8220                (char*)optVal, sizeof(*optVal));
8221          break;
8222
8223       case CM_INET_OPT_TCP_NODELAY:
8224          optVal = (U32*)value;
8225          if (*optVal == CM_INET_OPT_ENABLE)
8226          {
8227 #ifdef WIN32
8228 #ifndef SS_WINCE
8229             ret = setsockopt(sockFd->fd, level, TCP_NODELAY,
8230                   (char*)&boolEnable, sizeof(boolEnable));
8231 #endif /* SS_WINCE */
8232 #else
8233             ret = setsockopt(sockFd->fd, level, TCP_NODELAY,
8234                   (char*)&enable, sizeof(enable)); 
8235 #endif /* WIN32 */
8236          }
8237          else if (*optVal == CM_INET_OPT_DISABLE)
8238          {
8239 #ifdef WIN32
8240 #ifndef SS_WINCE
8241             ret = setsockopt(sockFd->fd, level, TCP_NODELAY,
8242                   (char*)&boolDisable, sizeof(boolDisable));
8243 #endif /* SS_WINCE */
8244 #else
8245             ret = setsockopt(sockFd->fd, level, TCP_NODELAY,
8246                   (char*)&disable, sizeof(disable));
8247 #endif /* WIN32 */
8248          }
8249          break;
8250
8251 #if (defined(SUNOS)|| defined(WIN32) || defined(SS_PS) || \
8252       defined(SS_VW_MCAST) || defined(HPOS))
8253
8254       case CM_INET_OPT_ADD_MCAST_MBR:
8255          mCast = (CmInetMCastInf*)value;
8256
8257          /* Copy the addresses to stMreq structure */
8258 #ifdef SS_PS
8259          stMreq.imr_mcastaddr.s_addr = CM_INET_HTON_U32(mCast->mCastAddr);
8260 #else
8261          stMreq.imr_multiaddr.s_addr = CM_INET_HTON_U32(mCast->mCastAddr);
8262 #endif
8263          stMreq.imr_interface.s_addr = CM_INET_HTON_U32(mCast->localAddr);
8264
8265          ret = setsockopt(sockFd->fd, level, IP_ADD_MEMBERSHIP,
8266                (char*)&stMreq, sizeof(stMreq));
8267          break;
8268
8269       case CM_INET_OPT_DRP_MCAST_MBR:
8270          mCast = (CmInetMCastInf*)value;
8271
8272          /* Copy the addresses to stMreq structure */
8273 #ifdef SS_PS
8274          stMreq.imr_mcastaddr.s_addr = CM_INET_HTON_U32(mCast->mCastAddr);
8275 #else
8276          stMreq.imr_multiaddr.s_addr = CM_INET_HTON_U32(mCast->mCastAddr);
8277 #endif
8278          stMreq.imr_interface.s_addr = CM_INET_HTON_U32(mCast->localAddr);
8279
8280          ret = setsockopt(sockFd->fd, level, IP_DROP_MEMBERSHIP,
8281                (char*)&stMreq, sizeof(stMreq));
8282          break;
8283
8284 #endif /* SUNOS || WIN32 || SS_PS || SS_VW_MCAST || HPOS */
8285
8286 #ifdef SS_LINUX
8287          /* cm_inet_c_001.main_37 - Enable CMINET_BSDCOMPAT flag if system doesnt
8288             support CM_INET_OPT_BSD_COMPAT */
8289 #ifndef CMINET_BSDCOMPAT
8290       case CM_INET_OPT_BSD_COMPAT:
8291          optVal = (U32*)value;
8292          if (*optVal == CM_INET_OPT_ENABLE)
8293          {
8294             ret = setsockopt(sockFd->fd, level, SO_BSDCOMPAT,
8295                   &enable, sizeof(enable));
8296          }
8297          else if (*optVal == CM_INET_OPT_DISABLE)
8298          {
8299             ret = setsockopt(sockFd->fd, level, SO_BSDCOMPAT,
8300                   &disable, sizeof(disable));
8301          }
8302          break;
8303 #endif /* CMINET_BSDCOMPAT */
8304 #endif /* SS_LINUX */
8305
8306 #ifdef CM_INET2  
8307          /* Added for support of Raw socket  modify according to the 
8308           * option available on different platform  */
8309 #if (defined(SUNOS)|| defined(WIN32) || defined(SS_PS) || defined(SS_VW) \
8310       || defined(HPOS))
8311       case CM_INET_OPT_HDR_INCLD:
8312          optVal = (U32*)value;
8313          if (*optVal == CM_INET_OPT_ENABLE)
8314          {
8315 #ifdef WIN32 
8316             RETVALUE(RNA);    
8317 #else
8318             ret = setsockopt(sockFd->fd, level, IP_HDRINCL,
8319                   (char*)&enable, sizeof(enable));
8320 #endif /* WIN32 */
8321          }
8322          else if (*optVal == CM_INET_OPT_DISABLE)
8323          {
8324 #ifdef WIN32
8325             RETVALUE(RNA);    
8326 #else
8327             ret = setsockopt(sockFd->fd, level, IP_HDRINCL,
8328                   (char*)&disable, sizeof(disable));
8329 #endif /* WIN32 */
8330          }
8331          break;
8332
8333          /* added new options */
8334 #ifdef IPV4_OPTS_SUPPORTED
8335 #ifdef SS_LINUX
8336          /* Linux: set Router Alert socket option to Intercept RAW RSVP 
8337             packets at the Intermediate node(Router) with Router Alert SET.
8338             This socket option is MUST be set (when this server is opened)
8339             if the RSVP server wants to intercept raw RSVP packets. */
8340       case CM_INET_OPT_IP_ROUTER_ALERT:
8341          optVal = (U32*)value;
8342          if (*optVal == CM_INET_OPT_ENABLE)
8343          {   
8344             ret = setsockopt(sockFd->fd, level, IP_ROUTER_ALERT,
8345                   (char*)&enable, sizeof(enable));
8346             if (ret != ROK)
8347                RETVALUE(RFAILED);
8348          }
8349          else if (*optVal == CM_INET_OPT_DISABLE)
8350          {   
8351             ret = setsockopt(sockFd->fd, level, IP_ROUTER_ALERT,
8352                   (char*)&disable, sizeof(disable));
8353             if (ret != ROK)
8354                RETVALUE(RFAILED);
8355          }   
8356          break;         
8357 #endif /* SS_LINUX */
8358
8359          /* set Router Alert socket option */
8360       case CM_INET_OPT_IP_OPTIONS:
8361 #if (defined (SS_VW) || defined(SS_LINUX))
8362          RETVALUE(RNA);
8363 #else  
8364          tempTknStr64=(TknStr64 *)value;
8365          if (tempTknStr64->pres == TRUE)
8366          {
8367             if (tempTknStr64->len == 0)
8368             {
8369                /* disable the IP_OPTIONS for Router Alert.  */
8370 #ifdef WIN32                          
8371                ret = setsockopt(sockFd->fd, level, IP_OPTIONS, 
8372                      (CONSTANT char *)&disableOpt, sizeof(int));
8373 #else
8374                ret = setsockopt(sockFd->fd, level, IP_OPTIONS, NULL, 0);
8375 #endif /* WIN32 */                  
8376             }  
8377             else
8378                /* enable the IP_OPTIONS for Router Alert */
8379                ret = setsockopt(sockFd->fd, level, IP_OPTIONS,
8380                      (char *)tempTknStr64->val, tempTknStr64->len);
8381          }
8382          else
8383             RETVALUE(RFAILED); /* Trying to set IPv4 Hdr option
8384                                 * without giving option values*/
8385 #endif /* SS_VW || SS_LINUX */
8386          break;
8387 #endif /* IPV4_OPTS_SUPPORTED */
8388
8389          /* added new options */
8390 #if (defined(SS_LINUX) && (!defined(SS_VW) && !defined(WIN32)))
8391 #ifdef LOCAL_INTF
8392       case CM_INET_OPT_IPV4_PKTINFO:
8393          optVal = (U32*)value;
8394          if (*optVal == CM_INET_OPT_ENABLE)
8395          {   
8396             /* set IP_PKTINFO option when IP_ROUTER_ALERT is set in linux */
8397             ret = setsockopt(sockFd->fd, level, IP_PKTINFO,
8398                   (char*)&enable, sizeof(enable));
8399
8400             if (ret != ROK)
8401                RETVALUE(RFAILED);
8402          }
8403          else if (*optVal == CM_INET_OPT_DISABLE)
8404          {   
8405             /* disable IP_PKTINFO when IP_ROUTER_ALERT is set in linux */ 
8406             ret = setsockopt(sockFd->fd, level, IP_PKTINFO,
8407                   (char*)&disable, sizeof(disable));
8408
8409             if (ret != ROK)
8410                RETVALUE(RFAILED);
8411          }   
8412          break;   
8413 #endif /* LOCAL_INTF */            
8414 #endif /* SS_LINUX */
8415
8416 #endif /* SUNOS || WIN32 || SS_PS || SS_VW || HPOS */
8417
8418       case CM_INET_OPT_DONTFRAGMENT:
8419          optVal = (U32*)value;
8420          if (*optVal == CM_INET_OPT_ENABLE)
8421          {
8422 #ifdef WIN32
8423             ret = setsockopt(sockFd->fd, level, IP_DONTFRAGMENT,
8424                   (char*)&boolEnable, sizeof(boolEnable));
8425 #endif /* WIN32 */
8426          }
8427          else if (*optVal == CM_INET_OPT_DISABLE)
8428          {
8429 #ifdef WIN32
8430             ret = setsockopt(sockFd->fd, level, IP_DONTFRAGMENT,
8431                   (char*)&boolDisable, sizeof(boolDisable));
8432 #endif /* WIN32 */
8433          }
8434          break;
8435
8436          /* also add these 2 options for VxWorks */         
8437 #if (defined(SUNOS)|| defined(WIN32) || defined(HPOS) || defined(SS_VW))
8438       case CM_INET_OPT_TOS:
8439          optVal = (U32*)value;
8440          ret = setsockopt(sockFd->fd, level, IP_TOS,
8441                (char*)optVal, sizeof(*optVal));
8442          break;
8443
8444       case CM_INET_OPT_TTL:
8445          optVal = (U32*)value;
8446          ret = setsockopt(sockFd->fd, level, IP_TTL,
8447                (char*)optVal, sizeof(*optVal));
8448          break;
8449 #endif /* SUNOS || WIN32 || HPOS || SS_VW */
8450 #endif  /* CM_INET2 */ 
8451
8452 #if (defined(SUNOS)|| defined(WIN32) || defined(SS_PS) || defined(SS_VW_MCAST) \
8453       || defined(HPOS))
8454       case CM_INET_OPT_MCAST_LOOP:
8455          optVal = (U32*)value;
8456          if (*optVal == CM_INET_OPT_ENABLE)
8457          {
8458 #ifdef SS_VW            
8459             ret = setsockopt(sockFd->fd, level, IP_MULTICAST_LOOP,
8460                   (char *)&lpEnable, sizeof(lpEnable));
8461 #else
8462             ret = setsockopt(sockFd->fd, level, IP_MULTICAST_LOOP,
8463                   (CONSTANT char *)&lpEnable, sizeof(lpEnable));
8464 #endif /* SS_VW */           
8465          }
8466          else
8467          {
8468 #ifdef SS_VW            
8469             ret = setsockopt(sockFd->fd, level, IP_MULTICAST_LOOP,
8470                   (char *)&lpDisable, sizeof(lpDisable));
8471 #else
8472             ret = setsockopt(sockFd->fd, level, IP_MULTICAST_LOOP,
8473                   (CONSTANT char *)&lpDisable, sizeof(lpDisable));
8474 #endif /* SS_VW */            
8475          }
8476          break;
8477
8478       case CM_INET_OPT_MCAST_IF:
8479          optVal = (U32*)value;
8480          *optVal = CM_INET_HTON_U32((U32)*optVal); 
8481          ret = setsockopt(sockFd->fd, level, IP_MULTICAST_IF,
8482                (char *)optVal, sizeof(struct in_addr));
8483          break;
8484
8485       case CM_INET_OPT_MCAST_TTL:
8486          optVal = (U32*)value;
8487          /* remove CONSTANT in setsockopt for VW */
8488 #ifdef SS_VW      
8489          ret = setsockopt(sockFd->fd, level, IP_MULTICAST_TTL,
8490                (char *)optVal, sizeof(U8));
8491 #else
8492          ret = setsockopt(sockFd->fd, level, IP_MULTICAST_TTL,
8493                (CONSTANT char *)optVal, sizeof(U8));
8494 #endif /* SS_VW */         
8495          break;
8496 #endif /* SUNOS || WIN32 || SS_PS || SS_VW_MCAST || HPOS */
8497
8498 #ifdef IPV6_SUPPORTED
8499       case CM_INET_OPT_IPV6_TTL:
8500          optVal = (U32*)value;
8501          ret = setsockopt(sockFd->fd, level, IPV6_UNICAST_HOPS,
8502                (char*)optVal, sizeof(*optVal));
8503          break;
8504
8505       case CM_INET_OPT_ADD_MCAST6_MBR:
8506          stMreq6Ptr = (struct ipv6_mreq *)value;
8507          ret = setsockopt(sockFd->fd, level, IPV6_JOIN_GROUP,
8508                (char*)stMreq6Ptr, sizeof(struct ipv6_mreq));
8509          break;
8510
8511       case CM_INET_OPT_DRP_MCAST6_MBR:
8512          stMreq6Ptr = (struct ipv6_mreq *)value;
8513          ret = setsockopt(sockFd->fd, level, IPV6_LEAVE_GROUP,
8514                (char*)stMreq6Ptr, sizeof(struct ipv6_mreq));
8515          break;
8516
8517       case CM_INET_OPT_MCAST6_LOOP:  
8518          optVal = (U32*)value;
8519          if (*optVal == CM_INET_OPT_ENABLE)
8520          {
8521             ret = setsockopt(sockFd->fd, level, IPV6_MULTICAST_LOOP,
8522                   &loopEna, sizeof(loopEna));
8523          }
8524          else
8525          {
8526             ret = setsockopt(sockFd->fd, level, IPV6_MULTICAST_LOOP,
8527                   &loopDis, sizeof(loopDis));
8528          }
8529          break;
8530
8531       case CM_INET_OPT_MCAST6_IF:
8532          ret = setsockopt(sockFd->fd, level, IPV6_MULTICAST_IF,
8533                (U32 *)value, sizeof(U32));
8534          break;
8535
8536       case CM_INET_OPT_MCAST6_HOPS:
8537          optVal = (U32*)value;
8538          ret = setsockopt(sockFd->fd, level, IPV6_MULTICAST_HOPS,
8539                (char *)optVal, sizeof(U32));
8540          break;
8541
8542          /* cm_inet_c_001.main_44 : some operating system doesnt have icmp6_filter. so 
8543             this flag is gaurded under ICMPV6_SUPPORTED. so if user want this 
8544             support he has to enable the above flag.*/
8545          /* cm_inet_c_001.main_58 : Protaected under flag CM_ICMP_FILTER_SUPPORT
8546           * to support filteration  of ICMP messages */
8547 #if (defined(ICMPV6_FILTER_SUPPORTED) || defined(CM_ICMP_FILTER_SUPPORT))
8548       case CM_INET_OPT_ICMP6_FILTER:  
8549          icmp6Filter = (struct icmp6_filter *)value;
8550          ret = setsockopt(sockFd->fd, level, ICMP6_FILTER,
8551                (char *)icmp6Filter, sizeof(struct icmp6_filter));
8552          break;
8553 #endif /* ICMPV6_FILTER_SUPPORTED */
8554
8555          /* added new options */
8556 #ifdef IPV6_OPTS_SUPPORTED
8557       case CM_INET_OPT_RECVIPV6_HOPLIM:
8558          optVal = (U32*)value;
8559 #ifdef SS_LINUX         
8560          ret = setsockopt(sockFd->fd, level, IPV6_HOPLIMIT,
8561                (char *)optVal, sizeof(U32)); 
8562 #else
8563          ret = setsockopt(sockFd->fd, level, IPV6_HOPLIMIT,
8564                (char *)optVal, sizeof(U32)); 
8565          /* enable the reception of IPv6 HopLimit value as ancillary data */
8566          ret = setsockopt(sockFd->fd, level, IPV6_RECVHOPLIMIT,
8567                (char*)&enable, sizeof(enable)); 
8568 #endif /* SS_LINUX */
8569
8570          break;
8571
8572       case CM_INET_OPT_RECVIPV6_HBHOPTS:
8573          optVal = (U32*)value;
8574 #ifdef SS_LINUX
8575          ret = setsockopt(sockFd->fd, level, IPV6_HOPOPTS,
8576                (char *)optVal, sizeof(U32));
8577 #else
8578          ret = setsockopt(sockFd->fd, level, IPV6_RECVHOPOPTS,
8579                (char *)optVal, sizeof(U32)); 
8580 #endif /* SS_LINUX */          
8581          break;
8582
8583       case CM_INET_OPT_RECVIPV6_DSTOPTS:
8584          optVal = (U32*)value;
8585 #ifdef SS_LINUX         
8586          ret = setsockopt(sockFd->fd, level, IPV6_DSTOPTS,
8587                (char *)optVal, sizeof(U32));
8588 #else         
8589          ret = setsockopt(sockFd->fd, level, IPV6_RECVDSTOPTS,
8590                (char *)optVal, sizeof(U32));
8591 #endif /* SS_LINUX */
8592          break;
8593
8594       case CM_INET_OPT_RECVIPV6_RTHDR:
8595          optVal = (U32*)value;
8596 #ifdef SS_LINUX         
8597          ret = setsockopt(sockFd->fd, level, IPV6_RTHDR,
8598                (char *)optVal, sizeof(U32));
8599 #else
8600          ret = setsockopt(sockFd->fd, level, IPV6_RECVRTHDR,
8601                (char *)optVal, sizeof(U32));
8602 #endif /* SS_LINUX */         
8603          break;      
8604
8605          /* works ONLY for IPPROTO_RAW type socket. so if it this socket
8606           * option is tried to set for IPPROTO_RSVP, then it is supposed
8607           * to fail with EINVAL according to net/ipv6/ipv6_sockglue.c 
8608           *
8609           * if HI_SRVC_RAW_RAW is not used during ServOpenReq as the server 
8610           * type, then it will fail here due to above reason */
8611 #ifdef SS_LINUX
8612       case CM_INET_OPT_IP_ROUTER_ALERT6:
8613          optVal = (U32*)value;
8614          if(*optVal == CM_INET_OPT_ENABLE)
8615             ret = setsockopt(sockFd->fd, IPPROTO_IPV6, IPV6_ROUTER_ALERT,
8616                   (char *)&enable, sizeof(enable));          
8617          else
8618             ret = setsockopt(sockFd->fd, level, IPV6_ROUTER_ALERT,
8619                   (char *)&disable, sizeof(disable));
8620
8621          break;
8622 #endif /* SS_LINUX */
8623 #endif /* IPV6_OPTS_SUPPORTED */
8624
8625 #ifdef LOCAL_INTF         
8626       case CM_INET_OPT_IPV6_PKTINFO:
8627          optVal = (U32*)value;
8628 #ifdef SS_LINUX         
8629          ret = setsockopt(sockFd->fd, level, IPV6_PKTINFO,
8630                (char *)optVal, sizeof(U32));
8631 #else         
8632          ret = setsockopt(sockFd->fd, level, IPV6_RECVPKTINFO,
8633                (char *)&enable, sizeof(enable));
8634 #endif /* SS_LINUX */
8635          break;
8636 #endif /* LOCAL_INTF */
8637
8638 #endif /* IPV6_SUPPORTED */
8639
8640          /*cm_inet_c_001.main_38 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
8641 #ifdef CM_LKSCTP
8642       case CM_INET_OPT_LINGER:
8643          pSockLinger = (CmInetSockLinger *)value;
8644
8645          cmMemset((U8*)&lngr, 0, sizeof(struct linger));
8646
8647          if (pSockLinger->enable == TRUE)
8648             lngr.l_onoff = 1;
8649          else 
8650             lngr.l_onoff = 0;
8651
8652          lngr.l_linger = pSockLinger->lingerTime;
8653          ret = setsockopt(sockFd->fd, level, SO_LINGER, &lngr, sizeof(lngr));
8654          break;
8655
8656       case CM_INET_OPT_SCTP_EVENTS:
8657          pSctpEvent = (CmInetSctpSockEvent *)value;
8658
8659          cmMemset((U8*)&event, 0, sizeof(struct sctp_event_subscribe));
8660
8661          if (pSctpEvent->dataIoEvent == TRUE)
8662             event.sctp_data_io_event = 1;
8663
8664          if (pSctpEvent->associationEvent == TRUE)
8665             event.sctp_association_event = 1;
8666
8667          if (pSctpEvent->addressEvent == TRUE)
8668             event.sctp_address_event = 1;
8669
8670          if (pSctpEvent->sendFailureEvent == TRUE)
8671             event.sctp_send_failure_event = 1;
8672
8673          if (pSctpEvent->peerErrorEvent == TRUE)
8674             event.sctp_peer_error_event = 1;
8675
8676          if (pSctpEvent->shutdownEvent == TRUE)
8677             event.sctp_shutdown_event = 1;
8678
8679          if (pSctpEvent->partialDeliveryEvent == TRUE)
8680             event.sctp_partial_delivery_event = 1;
8681
8682          if (pSctpEvent->adaptationLayerEvent == TRUE)
8683 #ifdef SUN_KSCTP
8684             event.sctp_adaption_layer_event = 1;
8685 #else
8686          event.sctp_adaptation_layer_event = 1;
8687 #endif
8688
8689          ret = setsockopt(sockFd->fd, level, SCTP_EVENTS, &event, sizeof(event));
8690          break;
8691
8692       case CM_INET_OPT_SCTP_PRIM_ADDR:
8693          pSctpPrimAddr = (CmInetSctpPrimAddr *)value;
8694
8695          cmMemset((U8*)&setPrim, 0, sizeof(struct sctp_setprim));
8696
8697 #ifdef IPV6_SUPPORTED 
8698          if (pSctpPrimAddr->addr.type == CM_INET_IPV6ADDR_TYPE)
8699          {
8700             if (sockFd->protType == AF_INET)
8701             {
8702 #ifdef CMINETDBG
8703 #ifndef ALIGN_64BIT
8704                /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
8705                /* cm_inet_c_001.main_62:Warning fix */
8706                snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid address: sockFd->protType(%d),"
8707                      " sockFd->fd(%ld)\n", sockFd->protType, sockFd->fd);
8708                CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET040, 0, prntBuf);
8709 #else
8710                /* cm_inet_c_001.main_62:Warning fix */
8711                snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid address: sockFd->protType(%d),"
8712                      " sockFd->fd(%d)\n", sockFd->protType, sockFd->fd);
8713                CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET040, 0, prntBuf);
8714 #endif /*ALIGN_64BIT*/
8715 #endif /* CMINETDBG */
8716                RETVALUE(RFAILED);
8717             }
8718
8719             pAddr6 = (struct sockaddr_in6*)&(setPrim.ssp_addr);
8720             pAddr6->sin6_family      = AF_INET6;
8721             pAddr6->sin6_port        = CM_INET_HTON_U16(pSctpPrimAddr->port);
8722             CM_INET_COPY_IPV6ADDR(&pAddr6->sin6_addr.s6_addr, &pSctpPrimAddr->addr.u.ipv6NetAddr); 
8723          }
8724          else 
8725          {
8726             pAddr = (struct sockaddr_in*)&(setPrim.ssp_addr);
8727             pAddr->sin_family      = AF_INET;
8728             pAddr->sin_port        = CM_INET_HTON_U16(pSctpPrimAddr->port);
8729             pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pSctpPrimAddr->addr.u.ipv4NetAddr);
8730          }
8731 #else 
8732          pAddr = (struct sockaddr_in*)&(setPrim.ssp_addr);
8733          pAddr->sin_family      = AF_INET;
8734          pAddr->sin_port        = CM_INET_HTON_U16(pSctpPrimAddr->port);
8735          pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pSctpPrimAddr->addr.u.ipv4NetAddr);
8736 #endif /* IPV6_SUPPORTED */
8737
8738          setPrim.ssp_assoc_id   = pSctpPrimAddr->assocId;
8739
8740          ret = setsockopt(sockFd->fd, level, SCTP_PRIMARY_ADDR, &setPrim, sizeof(setPrim));
8741          break;
8742
8743       case CM_INET_OPT_SCTP_PEERADDR_PARAMS:
8744          pSctpPAddrParams = (CmInetSctpPeerAddrParams *)value;
8745
8746          cmMemset((U8*)&addrParams, 0, sizeof(struct sctp_paddrparams));
8747
8748
8749          if (pSctpPAddrParams->s.addrPres == TRUE)
8750          {
8751 #ifdef IPV6_SUPPORTED 
8752             if (pSctpPAddrParams->s.addr.type == CM_INET_IPV6ADDR_TYPE)
8753             {
8754                if (sockFd->protType == AF_INET)
8755                {
8756 #ifdef CMINETDBG
8757 #ifndef ALIGN_64BIT
8758                   /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
8759                   /* cm_inet_c_001.main_62:Warning fix */
8760                   snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid address: sockFd->protType(%d),"
8761                         " sockFd->fd(%ld)\n", sockFd->protType, sockFd->fd);
8762                   CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET041, 0, prntBuf);
8763 #else
8764                   /* cm_inet_c_001.main_62:Warning fix */
8765                   snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "Invalid address: sockFd->protType(%d),"
8766                         " sockFd->fd(%d)\n", sockFd->protType, sockFd->fd);
8767                   CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET041, 0, prntBuf);
8768 #endif /*ALIGN_64BIT*/
8769 #endif /* CMINETDBG */
8770
8771                   RETVALUE(RFAILED);
8772                }
8773
8774                pAddr6 = (struct sockaddr_in6*)&(addrParams.spp_address);
8775                pAddr6->sin6_family      = AF_INET6;
8776                pAddr6->sin6_port        = CM_INET_HTON_U16(pSctpPAddrParams->s.port);
8777                CM_INET_COPY_IPV6ADDR(&pAddr6->sin6_addr.s6_addr, &pSctpPAddrParams->s.addr.u.ipv6NetAddr); 
8778             }
8779             else 
8780             {
8781                pAddr = (struct sockaddr_in*)&(addrParams.spp_address);
8782                pAddr->sin_family      = AF_INET;
8783                pAddr->sin_port        = CM_INET_HTON_U16(pSctpPAddrParams->s.port);
8784                pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pSctpPAddrParams->s.addr.u.ipv4NetAddr);
8785             }
8786 #else 
8787             pAddr = (struct sockaddr_in*)&(addrParams.spp_address);
8788             pAddr->sin_family      = AF_INET;
8789             pAddr->sin_port        = CM_INET_HTON_U16(pSctpPAddrParams->s.port);
8790             pAddr->sin_addr.s_addr = CM_INET_HTON_U32(pSctpPAddrParams->s.addr.u.ipv4NetAddr);
8791 #endif /* IPV6_SUPPORTED */
8792          }
8793          else
8794          {
8795 #ifdef IPV6_SUPPORTED 
8796             if (sockFd->protType == AF_INET6)
8797                addrParams.spp_address.ss_family = AF_INET6;
8798             else
8799                addrParams.spp_address.ss_family = AF_INET;
8800 #else
8801             addrParams.spp_address.ss_family = AF_INET;
8802 #endif
8803          }
8804
8805          /* Not validating the address, whether addr is a valid address or not */
8806
8807          addrParams.spp_assoc_id   = pSctpPAddrParams->assocId;
8808          /*cm_inet_c_001.main_58  : fix for klockwork issue */
8809          addrParams.spp_pathmaxrxt = (U16)pSctpPAddrParams->pathMaxRxt;
8810 #ifdef SUN_KSCTP
8811          if (pSctpPAddrParams->hbEnblFlag == CM_INET_OPT_ENABLE)
8812             addrParams.spp_hbinterval = pSctpPAddrParams->hbInterval;
8813          else
8814             addrParams.spp_hbinterval = 0;
8815 #else
8816          /* linux */
8817          addrParams.spp_flags = 0;
8818
8819          if (pSctpPAddrParams->pmtudFlag == CM_INET_OPT_ENABLE)
8820          {
8821             addrParams.spp_flags     |= SPP_PMTUD_ENABLE;
8822             addrParams.spp_pathmtu    = pSctpPAddrParams->pathMtu;
8823          }
8824          else if(pSctpPAddrParams->pmtudFlag == CM_INET_OPT_DISABLE)
8825             addrParams.spp_flags     |= SPP_PMTUD_DISABLE;
8826
8827          if (pSctpPAddrParams->sackDelayFlag == CM_INET_OPT_ENABLE)
8828          {
8829             addrParams.spp_flags     |= SPP_SACKDELAY_ENABLE;
8830             addrParams.spp_sackdelay  = pSctpPAddrParams->sackDelay;
8831          }
8832          else if(pSctpPAddrParams->sackDelayFlag == CM_INET_OPT_DISABLE)
8833             addrParams.spp_flags     |= SPP_SACKDELAY_DISABLE;
8834
8835          if (pSctpPAddrParams->hbEnblFlag == CM_INET_OPT_ENABLE)
8836          {
8837             addrParams.spp_flags     |= SPP_HB_ENABLE;
8838             addrParams.spp_hbinterval = pSctpPAddrParams->hbInterval;
8839          }
8840          else if(pSctpPAddrParams->hbEnblFlag == CM_INET_OPT_DISABLE)
8841             addrParams.spp_flags |= SPP_HB_DISABLE;
8842 #endif
8843          ret = setsockopt(sockFd->fd, level, SCTP_PEER_ADDR_PARAMS, &addrParams, sizeof(addrParams));
8844          break;
8845
8846       case CM_INET_OPT_SCTP_ASSOC_PARAMS:
8847          pSctpAssocParams = (CmInetSctpAssocParams *)value;
8848
8849          cmMemset((U8*)&assocParams, 0, sizeof(struct sctp_assocparams));
8850
8851          assocParams.sasoc_cookie_life              = pSctpAssocParams->cookieLife;
8852          assocParams.sasoc_asocmaxrxt               = pSctpAssocParams->assocMaxReTx;
8853          assocParams.sasoc_assoc_id                 = pSctpAssocParams->assocId;
8854          assocParams.sasoc_number_peer_destinations = pSctpAssocParams->numberOfPeerDest;
8855          assocParams.sasoc_peer_rwnd                = pSctpAssocParams->peerRwnd;
8856          assocParams.sasoc_local_rwnd               = pSctpAssocParams->localRwnd;
8857
8858          ret = setsockopt(sockFd->fd, level, SCTP_ASSOCINFO, &assocParams, sizeof(assocParams));
8859          break;
8860
8861       case CM_INET_OPT_SCTP_RTO_INFO:
8862          pSctpRtoInfo = (CmInetSctpRtoInfo *)value;
8863
8864          cmMemset((U8*)&rtoinfo, 0, sizeof(struct sctp_rtoinfo));
8865
8866          rtoinfo.srto_assoc_id = pSctpRtoInfo->assocId;
8867          rtoinfo.srto_initial  = pSctpRtoInfo->rtoInitial;
8868          rtoinfo.srto_max      = pSctpRtoInfo->rtoMax;
8869          rtoinfo.srto_min      = pSctpRtoInfo->rtoMin;
8870
8871          ret = setsockopt(sockFd->fd, level, SCTP_RTOINFO, &rtoinfo, sizeof(rtoinfo));
8872          break;
8873
8874       case CM_INET_OPT_SCTP_INIT_MSG:
8875          pSctpInitMsg = (CmInetSctpInitMsg *)value;
8876
8877          cmMemset((U8*)&initmsg, 0, sizeof(struct sctp_initmsg));
8878
8879          initmsg.sinit_max_attempts   = pSctpInitMsg->maxInitReTx;
8880          initmsg.sinit_max_init_timeo = pSctpInitMsg->maxInitTimeout;
8881          initmsg.sinit_num_ostreams   = pSctpInitMsg->numOstreams;
8882          initmsg.sinit_max_instreams  = pSctpInitMsg->maxInstreams;
8883
8884          ret = setsockopt(sockFd->fd, level, SCTP_INITMSG, &initmsg, sizeof(initmsg));
8885          break;
8886
8887 #endif /*CM_LKSCTP*/
8888
8889          /* cm_inet_c_001.main_58 : Added to support filteration  of ICMP 
8890           * messages and protected under CM_ICMP_FILTER_SUPPORT flag. Its a
8891           *  partial implementaion for icmp filter done for TUCL */
8892 #ifdef SS_LINUX
8893 #ifdef CM_ICMP_FILTER_SUPPORT
8894       case CM_INET_OPT_ICMP_FILTER:
8895          optVal = (U32*)value;
8896          ret = setsockopt(sockFd->fd, level, ICMP_FILTER,
8897                optVal, sizeof(icmpFilter));
8898          break;
8899 #endif
8900 #endif
8901
8902       default:  
8903          /* wrong socket option type */
8904          RETVALUE(RFAILED);
8905          break;
8906    }
8907
8908    if (ret == INET_ERR)
8909    {
8910 #ifdef CMINETDBG
8911 #ifndef ALIGN_64BIT
8912       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
8913       /* cm_inet_c_001.main_62:Warning fix */
8914       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSetOpt() Failed : error(%d), sockFd->fd(%ld)\n",
8915             INET_ERR_CODE, sockFd->fd);
8916       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET042, 0, prntBuf);
8917 #else
8918       /* cm_inet_c_001.main_62:Warning fix */
8919       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetSetOpt() Failed : error(%d), sockFd->fd(%d)\n",
8920             INET_ERR_CODE, sockFd->fd);
8921       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET042, 0, prntBuf);
8922 #endif /*ALIGN_64BIT*/
8923 #endif /* CMINETDBG */
8924       RETVALUE(RFAILED);
8925    }          
8926    RETVALUE(ROK);
8927 } /* end of cmInetSetOpt */
8928
8929
8930 \f
8931 /*
8932 *
8933 *      Fun:   cmInetGetNumRead
8934 *
8935 *      Desc:  Gives the number of pending octets in the socket receive buffer.
8936 *
8937 *      Ret:   ROK     - successful
8938 *             RFAILED - failed
8939 *             
8940 *      Notes: None.
8941 *
8942 *      File:  cm_inet.c
8943 *
8944 */
8945
8946 #ifdef ANSI
8947 PUBLIC S16 cmInetGetNumRead
8948 (
8949 CmInetFd *sockFd,               /* socket file descriptor */
8950 U32      *dataLen               /* number of pending octets */
8951 /* removed 3rd argument memInfo */
8952 )
8953 #else
8954 PUBLIC S16 cmInetGetNumRead(sockFd, dataLen)
8955 CmInetFd *sockFd;               /* socket file descriptor */
8956 U32      *dataLen;              /* number of pending octets */
8957 /* removed 3rd argument memInfo */
8958 #endif
8959 {
8960    S32 ret;                     /* temporary return value */
8961
8962    /* removed local variables added for recvfrom call */
8963
8964    TRC2(cmInetGetNumRead);   
8965
8966 #if (ERRCLASS & ERRCLS_INT_PAR)
8967    /* error check on parameters */
8968    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
8969          (dataLen == NULLP))
8970    {
8971       RETVALUE(RFAILED);
8972    }
8973 #endif
8974
8975    /* use ioctl call for all types of socket to get length of 
8976       pending data in the socket recv buffer */
8977 #ifdef WIN32
8978    /* cm_inet_c_001.main_59: Fix for compilation warning */
8979    ret = ioctlsocket(sockFd->fd, FIONREAD, (U32 *)dataLen);  
8980 #else 
8981 #ifdef SS_PS
8982    ret = ioctl(sockFd->fd, FIOREAD, (char*)dataLen);
8983 #else
8984 #ifdef SS_VW
8985    ret = ioctl(sockFd->fd, FIONREAD, (S32)dataLen);
8986 #else
8987    ret = ioctl(sockFd->fd, FIONREAD, dataLen);
8988 #endif /* SS_VW */
8989 #endif /* SS_PS */
8990 #endif /* WIN32 */
8991
8992    /* For UDP socket assign the length of pending data in the 
8993       socket recv buffer to largest datagram size. 
8994       Removed recvfrom call & necessary processing for it. */
8995
8996    if (ret == INET_ERR)
8997    {
8998       /* removed error check CONABORTED added for recvfrom call. 
8999          Also return value changed from RCLOSED to ROK */
9000       /*  Check for reset connection */
9001       /* cm_inet_c_001.main_45: Close the TCP connection only when err is one of these*/
9002       if ((INET_ERR_CODE == ERR_CONNREFUSED) ||
9003             (INET_ERR_CODE == ERR_CONNABORTED) ||
9004             (INET_ERR_CODE == ERR_TIMEDOUT))
9005       {
9006          *dataLen = 0;
9007
9008          /* cm_inet_c_001.main_50 
9009           * Return RCLOSED instead of ROK to initiate connection closure.
9010           * ROK will be returned only if the ioctl call above returns ROK.
9011           * The routines calling this function have been modified to not
9012           * return RCLOSED when this function returns ROK with pending data 
9013           * length value of 0. This modification is needed because:
9014           * Due to latency (mostly in solaris) sometimes ioctl(FIONREAD)
9015           * returns successfully with pend length as 0 on a TCP socket that 
9016           * select says is ready to read. This should not be considered as 
9017           * connection closed.
9018           */
9019          RETVALUE(RCLOSED);
9020       }
9021
9022       /* removed error check ERR_WOULDBLOCK */ 
9023       /* cm_inet_c_001.main_45: Dont close the connection in case of ERR_CONNRESET */
9024       if ((INET_ERR_CODE == ERR_AGAIN) ||
9025             (INET_ERR_CODE == ERR_CONNRESET))
9026       {
9027          *dataLen = 0;
9028          RETVALUE(ROKDNA);
9029       }
9030
9031 #ifdef SS_LINUX
9032       /* cm_inet_c_001.main_45: Change 2048 to CM_INET_MAX_UDPRAW_MSGSIZE */
9033       *dataLen = CM_INET_MAX_UDPRAW_MSGSIZE;
9034       RETVALUE(ROK);
9035 #endif /* SS_LINUX */
9036
9037       /* removed error debug printing added for recvfrom call. */
9038
9039 #ifdef CMINETDBG
9040 #ifndef ALIGN_64BIT
9041       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9042       /* cm_inet_c_001.main_62:Warning fix */
9043       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetNumRead() Failed : error(%d),"
9044             " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
9045       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET043, 0, prntBuf);
9046 #else
9047       /* cm_inet_c_001.main_62:Warning fix */
9048       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetNumRead() Failed : error(%d),"
9049             " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
9050       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET043, 0, prntBuf);
9051 #endif /*ALIGN_64BIT*/
9052 #endif /* CMINETDBG */
9053       RETVALUE(RFAILED);
9054    }
9055
9056    RETVALUE(ROK);
9057 } /* end of cmInetGetNumRead */
9058
9059 \f
9060 #ifndef SS_PS
9061 /*
9062 *
9063 *      Fun:   cmInetGetHostByName
9064 *
9065 *      Desc:  Resolves a host name into the appropriate 4 byte Internet 
9066 *             address.     
9067 *
9068 *      Ret:   ROK     - successful
9069 *             RFAILED - failed
9070 *
9071 *      Notes: None.
9072 *
9073 *      File:  cm_inet.c
9074 *
9075 */
9076  
9077 #ifdef ANSI
9078 PUBLIC S16 cmInetGetHostByName
9079 (
9080 S8              *hostName,         /* host name */  
9081 CmInetIpAddrTbl *addrTbl           /* Address Table of IPV4 Addresses */
9082 )
9083 #else
9084 PUBLIC S16 cmInetGetHostByName (hostName, addrTbl)
9085 S8              *hostName;         /* host name */  
9086 CmInetIpAddrTbl *addrTbl;          /* Address Table of IPV4 Addresses */
9087 #endif
9088 {
9089 #ifndef SS_VW
9090    U8            numAddrs;       /* Number of Addresses */
9091 #endif /* SS_VW */
9092
9093 #if (defined(WIN32) || defined(SS_LINUX) || defined(HPOS))
9094    struct hostent *hostid;       /* pointer to host information */
9095 #else
9096 #ifndef SS_VW
9097    struct hostent hostid;        /* host information */
9098    S8 infoBuf[CM_INET_MAX_INFO]; /* info buffer */
9099    S32 err;                      /* error code */
9100 #endif /* SS_VW */
9101 #endif /* WIN32 || SS_LINUX || HPOS  */
9102
9103    TRC2(cmInetGetHostByName)
9104
9105 #if (ERRCLASS & ERRCLS_INT_PAR)
9106       /* error check on parameters */
9107       if ((hostName == NULLP) || (addrTbl == NULLP))
9108       {
9109          RETVALUE(RFAILED);
9110       }
9111 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9112
9113    /* Initialise */
9114 #ifndef SS_VW
9115    numAddrs       = 0;
9116 #endif /* SS_VW */
9117
9118    addrTbl->count = 0;
9119
9120 #if (defined(WIN32) || defined(SS_LINUX) || defined(HPOS))
9121    hostid = gethostbyname(hostName);
9122    if (hostid == 0) 
9123    {
9124 #ifdef CMINETDBG
9125       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9126       /* cm_inet_c_001.main_62:Warning fix */
9127       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d),"
9128             " hostName(%p)\n", INET_ERR_CODE, hostName);
9129       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET044, 0, prntBuf);
9130 #endif /* CMINETDBG */
9131       RETVALUE(RFAILED);
9132    }
9133    if (hostid->h_addrtype != AF_INET)
9134    {
9135 #ifdef CMINETDBG
9136       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9137       /* cm_inet_c_001.main_62:Warning fix */
9138       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetHostByName() Failed : error(%d),"
9139             " hostName(%p), hostid->h_addrtype(%d)\n",
9140             INET_ERR_CODE, hostName, hostid->h_addrtype);
9141       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET045, 0, prntBuf);
9142 #endif /* CMINETDBG */
9143       RETVALUE(RFAILED);
9144    }
9145    else
9146    {
9147       while ((numAddrs < CM_INET_IPV4_NUM_ADDR) &&
9148             (hostid->h_addr_list[numAddrs] != NULLP))
9149       {
9150          addrTbl->netAddr[addrTbl->count++] = 
9151             CM_INET_NTOH_U32 (*((U32 *) hostid->h_addr_list[numAddrs]));
9152          numAddrs += 1;
9153       }
9154    }
9155 #else
9156
9157 #ifdef SS_VW
9158    {
9159       S32 vwIpAddr;
9160
9161       vwIpAddr = hostGetByName(hostName);
9162       if (vwIpAddr == INET_ERR)
9163       {
9164 #ifdef CMINETDBG
9165          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9166          /* cm_inet_c_001.main_62:Warning fix */
9167          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d),"
9168                " hostName(%p)\n", INET_ERR_CODE, hostName);
9169          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET046, 0, prntBuf);
9170 #endif /* CMINETDBG */
9171          RETVALUE(RFAILED);
9172       }
9173       CM_COPY_VWIPADDR(vwIpAddr, &(addrTbl->netAddr[addrTbl->count]));
9174       addrTbl->count++;
9175    }
9176 #else
9177
9178    err = 0;                     /* err is not reset by gethostnyname_r()! */
9179
9180    gethostbyname_r(hostName, &hostid, infoBuf, CM_INET_MAX_INFO, (int*)&err);
9181    if ((hostid.h_addrtype != AF_INET) || (err < 0))
9182    {
9183 #ifdef CMINETDBG
9184       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9185       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d), hostName(%p),"
9186             " hostid.h_addrtype(%d)\n",
9187             INET_ERR_CODE, hostName, hostid.h_addrtype);
9188       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET047, 0, prntBuf);
9189 #endif /* CMINETDBG */
9190       RETVALUE(RFAILED);
9191    }
9192    else
9193    {
9194       while ((numAddrs < CM_INET_IPV4_NUM_ADDR) &&
9195             (hostid.h_addr_list[numAddrs] != NULLP))
9196       {
9197          addrTbl->netAddr[addrTbl->count++] = 
9198             CM_INET_NTOH_U32 (*((U32 *) hostid.h_addr_list[numAddrs]));
9199          numAddrs += 1;
9200       }
9201    }
9202 #endif /* SS_VW */
9203
9204 #endif /* WIN32  || SS_LINUX || HPOS */
9205
9206    RETVALUE(ROK);
9207
9208 } /* end of cmInetGetHostByName */
9209
9210 \f
9211 /* The getipnodebyname is not supported on all the Solaris Operating system
9212  * versions. This has to be supported on operating systems that support IPV6
9213  * as per the RFC on the IPV6 socket interface. Hence this function is moved
9214  * under the IPV6_SUPPORTED flag */
9215
9216 /* This function now can be called for both IPv4 and IPv6. However, we will 
9217  * call cmInetGetHostByName inside for IPv4. Move all flag dependencies 
9218  * inside this function. */
9219 /*
9220 *
9221 *      Fun:   cmInetGetIpNodeByName
9222 *
9223 *      Desc:  Resolves a host name into the appropriate 4 byte Internet 
9224 *             address or into the appropriate 16 byte IPV6 address.
9225 *             This function is expected to be thread safe and should be used
9226 *             instead of the cmInetGetHostByName function.
9227 *
9228 *      Ret:   ROK     - successful
9229 *             RFAILED - failed
9230 *
9231 *      Notes: None.
9232 *
9233 *      File:  cm_inet.c
9234 *
9235 */
9236 #ifdef ANSI
9237 PUBLIC S16 cmInetGetIpNodeByName
9238 (
9239 S8              *hostName,         /* host name */  
9240 CmInetIpAddrArr *addrArr           /* Array of addressed filled in */
9241 )
9242 #else
9243 PUBLIC S16 cmInetGetIpNodeByName(hostName, addrArr)
9244 S8              *hostName;         /* host name */  
9245 CmInetIpAddrArr *addrArr;          /* Array of addressed filled in */
9246 #endif
9247 {
9248    /* for return value from cmInetGetHostByName */
9249 #ifndef IPV6_SUPPORTED   
9250    S16    ret; 
9251 #else   
9252 #ifdef SUNOS
9253 #ifndef SS_LINUX
9254    U8     numAddrs=0;              /* Number of addresses */
9255    int    err=0;                   /* error code */
9256    struct hostent *hostid;       /* host information */
9257 #endif /* SS_LINUX */
9258 #endif /* SUNOS */
9259 #endif /* IPV6_SUPPORTED */
9260
9261    TRC2(cmInetGetIpNodeByName)
9262
9263
9264 #if (ERRCLASS & ERRCLS_INT_PAR)
9265    /* error check on parameters */
9266    if ((hostName == NULLP) || (addrArr == NULLP))
9267    {
9268       RETVALUE(RFAILED);
9269    }
9270 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9271
9272 #ifdef IPV6_SUPPORTED
9273 #ifdef SUNOS
9274 #ifndef SS_LINUX
9275
9276 #ifdef IPV6_SUPPORTED
9277    if (addrArr->type == CM_INET_IPV6ADDR_TYPE)
9278       hostid = getipnodebyname(hostName, AF_INET6, 0, &err);
9279    else
9280 #endif /* IPV6_SUPPORTED */
9281       hostid = getipnodebyname(hostName, AF_INET, 0, &err);
9282    if (!hostid)
9283    {
9284 #ifdef CMINETDBG
9285       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9286       /* cm_inet_c_001.main_62:Warning fix */
9287       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetIpNodeByName() Failed : error(%d),"
9288             " hostName(%p), addrArr->type(%d)n", 
9289             err, hostName, addrArr->type);
9290       CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET048, 0, prntBuf);
9291 #endif /* CMINETDBG */
9292       RETVALUE(RFAILED);
9293    }
9294
9295 #ifdef IPV6_SUPPORTED
9296    if (addrArr->type == CM_INET_IPV6ADDR_TYPE)
9297    {
9298       if (hostid->h_addrtype == AF_INET6)
9299       {
9300          while ((numAddrs < CM_INET_IPV6_NUM_ADDR) &&
9301                (hostid->h_addr_list[numAddrs] != NULLP))
9302          {
9303             /* Use the cminet fill macro here */
9304             CM_INET_COPY_IPV6ADDR(&addrArr->u.ipv6AddrArr.netAddr[numAddrs],
9305                   hostid->h_addr_list[numAddrs]);
9306             addrArr->u.ipv6AddrArr.count++; 
9307             numAddrs += 1;
9308          }
9309       }
9310       else
9311       {
9312 #ifdef CMINETDBG
9313          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9314          /* cm_inet_c_001.main_62:Warning fix */
9315          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetIpNodeByName() Failed : error(%d),"
9316                " hostName(%p), addrArr->type(%d),hostid->h_addrtype(%d) \n",
9317                err, hostName, addrArr->type, hostid->h_addrtype);
9318          CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET049, 0, prntBuf);
9319 #endif /* CMINETDBG */
9320          RETVALUE(RFAILED);
9321       }
9322    }
9323    else
9324 #endif /* IPV6_SUPPORTED */
9325    {
9326       if (hostid->h_addrtype == AF_INET)
9327       {
9328          while ((numAddrs < CM_INET_IPV4_NUM_ADDR) &&
9329                (hostid->h_addr_list[numAddrs] != NULLP))
9330          {
9331             addrArr->u.ipv4AddrArr.count ++;
9332             addrArr->u.ipv4AddrArr.netAddr[numAddrs] =
9333                CM_INET_NTOH_U32 (*((U32 *) hostid->h_addr_list[numAddrs]));
9334             numAddrs += 1;
9335          }
9336       }
9337       else
9338       {
9339 #ifdef CMINETDBG
9340          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9341          /* cm_inet_c_001.main_62:Warning fix */
9342          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetIpNodeByName() Failed : error(%d),"
9343                " hostName(%p), hostid->h_addrtype(%d), addrArr->type(%d)\n",
9344                err, hostName, hostid->h_addrtype, addrArr->type);
9345          CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET050, 0, prntBuf);
9346 #endif /* CMINETDBG */
9347          RETVALUE(RFAILED);
9348       }
9349    }
9350 #endif /* SS_LINUX */
9351 #endif /* SUNOS */
9352
9353    RETVALUE(ROK);
9354 #else
9355    ret = cmInetGetHostByName(hostName, &addrArr->u.ipv4AddrArr); 
9356    RETVALUE(ret);
9357 #endif /* IPV6_SUPPORTED */
9358
9359 } /* end of cmInetGetIpNodeByName */
9360
9361 \f
9362 /*
9363 *
9364 *      Fun:   cmInetAddr
9365 *
9366 *      Desc:  Converts an ASCII string containig an internet address
9367 *             ("xxx.xxx.xxx.xxx") into a CmInetIpAddr (U32) format.
9368 *             This function is a wrapper for the inet_addr() call.
9369 *
9370 *      Ret:   ROK     - successful
9371 *             RFAILED - failed
9372 *
9373 *      Notes: None.
9374 *
9375 *      File:  cm_inet.c
9376 *
9377 */
9378
9379 #ifdef ANSI
9380 PUBLIC S16 cmInetAddr(
9381 S8           *asciiAddr,        /* ascii address representation */
9382 CmInetIpAddr *address           /* 4 byte interent address */
9383 )
9384 #else
9385 PUBLIC S16 cmInetAddr(asciiAddr, address)
9386 S8           *asciiAddr;        /* ascii address representation */
9387 CmInetIpAddr *address;          /* 4 byte interent address */
9388 #endif
9389 {
9390    TRC2(cmInetAddr); 
9391
9392 #if (ERRCLASS & ERRCLS_INT_PAR)
9393    /* error check on parameters */
9394    if (asciiAddr == NULLP)
9395    {
9396       RETVALUE(RFAILED);
9397    }
9398 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9399
9400    *address = inet_addr(asciiAddr);
9401    if (*address == (U32)ERR_INADDRNONE)
9402    {
9403       /* asciiAddr does not contain a valid internet address */ 
9404       RETVALUE(RFAILED);
9405    }
9406
9407    RETVALUE(ROK);
9408 }
9409
9410 \f
9411 /*
9412 *
9413 *      Fun:   cmInetNtoa
9414 *
9415 *      Desc:  Converts an CmInetIPAddr based IP address into a string 
9416 *             of the format "xxx.xxx.xxx.xxx".
9417 *             This function is a wrapper for the inet_ntoa() call.
9418 *
9419 *      Ret:   ROK     - successful
9420 *             RFAILED - failed
9421 *
9422 *      Notes: This function delivers a pointer to a static buffer 
9423 *             within the system. Therefore the string has to be copied 
9424 *             by the caller before another call is made!
9425 *
9426 *      File:  cm_inet.c
9427 *
9428 */
9429
9430 #ifdef ANSI
9431 PUBLIC S16 cmInetNtoa(
9432 CmInetIpAddr   address,         /* 4 byte interent address */
9433 S8           **asciiAddr        /* ascii address representation */
9434 )
9435 #else
9436 PUBLIC S16 cmInetNtoa(address, asciiAddr)
9437 CmInetIpAddr   address;         /* 4 byte interent address */
9438 S8           **asciiAddr;       /* ascii address representation */
9439 #endif
9440 {
9441    struct in_addr inetAddr;     /* internet address structure */
9442
9443    TRC2(cmInetNtoa); 
9444
9445 #if (ERRCLASS & ERRCLS_INT_PAR)
9446    /* error check on parameters */
9447    if (asciiAddr == NULLP)
9448    {
9449       RETVALUE(RFAILED);
9450    }
9451 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9452
9453    inetAddr.s_addr = address;
9454
9455    *asciiAddr = inet_ntoa(inetAddr);
9456    if (*asciiAddr == NULL)
9457    { 
9458       RETVALUE(RFAILED);
9459    }
9460
9461    RETVALUE(ROK);
9462 }
9463 /*
9464 *
9465 *      Fun:   cmInetNtop
9466 *
9467 *      Desc:  Converts an network address into a string. 
9468 *             This function is a wrapper for the inet_ntop() call.
9469 *
9470 *      Ret:   ROK     - successful
9471 *             RFAILED - failed
9472 *
9473 *      Notes: This function copies the resulting string to the buffer pointed to
9474 *              by asciiaddr,which must be a non NULL pointer.The caller specifies
9475 *              the number of bytes available in this buffer in the argument len.
9476 *     
9477 *      File:  cm_inet.c
9478 *
9479 */
9480
9481 #ifdef ANSI
9482 PUBLIC S16 cmInetNtop(
9483 U8             type,              /* ip address type */
9484 Void           *address,         /* 4/16 byte interent address */
9485 S8             *asciiAddr,      /* ascii adress representation */
9486 U32            len
9487 )
9488 #else
9489 PUBLIC S16 cmInetNtop(type,address, asciiAddr,len)
9490 U8             type;              /* ip address type */  
9491 Void           *address;         /* 4/16 byte interent address */
9492 S8             *asciiAddr;      /* ascii adress representation */
9493 U32            len;
9494 #endif
9495 {
9496                              
9497    S32  domain = 0;
9498    TRC2(cmInetNtop);
9499
9500 #if (ERRCLASS & ERRCLS_INT_PAR)
9501    /* error check on parameters */
9502    if (asciiAddr == NULLP || address == NULLP || len == 0 )
9503    {
9504       RETVALUE(RFAILED);
9505    }
9506    
9507 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9508    switch(type)
9509    {
9510       case CM_INET_IPV4ADDR_TYPE :
9511          domain = AF_INET;
9512          break;
9513       case CM_INET_IPV6ADDR_TYPE :
9514          domain = AF_INET6;
9515          break;     
9516    }
9517    if(inet_ntop(domain,address,asciiAddr,len) == NULL)
9518    {
9519       RETVALUE(RFAILED);
9520    }
9521
9522    RETVALUE(ROK);
9523 }
9524
9525
9526 /* The inet_pton is not supported on all the Solaris Operating system 
9527  * versions. This has to be supported on operating systems that support 
9528  * IPV6 as per the RFC on the IPV6 socket interface. Hence this function
9529  *is moved under the IPV6_SUPPORTED flag */
9530 #ifdef IPV6_SUPPORTED
9531 #ifdef SUNOS
9532 \f
9533 /*
9534 *
9535 *      Fun:   cmInetPton
9536 *
9537 *      Desc:  Converts a IP address string to address.
9538 *
9539 *      Ret:   ROK     - successful
9540 *             RFAILED - failed
9541 *
9542 *      Notes: 
9543 *
9544 *      File:  cm_inet.c
9545 *
9546 */
9547
9548 #ifdef ANSI
9549 PUBLIC S16 cmInetPton(
9550 CmInetIpAddr  *address,         /* 4 byte interent address */
9551 S8           *asciiAddr         /* ascii address representation */
9552 )
9553 #else
9554 PUBLIC S16 cmInetPton(address, asciiAddr)
9555 CmInetIpAddr  *address;         /* 4 byte interent address */
9556 S8            *asciiAddr;       /* ascii address representation */
9557 #endif
9558 {
9559    S16    ret;
9560
9561    TRC2(cmInetPton); 
9562
9563 #if (ERRCLASS & ERRCLS_INT_PAR)
9564    /* error check on parameters */
9565    if ((asciiAddr == NULLP) || (address == NULLP))
9566    {
9567       RETVALUE(RFAILED);
9568    }
9569 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9570
9571    ret = inet_pton(AF_INET, asciiAddr, (void *)address);
9572    if (ret != 1)
9573    { 
9574       RETVALUE(RFAILED);
9575    }
9576
9577    RETVALUE(ROK);
9578 } /* end of cmInetPton */
9579 #endif /* SUNOS */
9580 #endif /* IPV6_SUPPORTED */
9581
9582 #ifdef IPV6_SUPPORTED
9583 \f
9584 /*
9585 *
9586 *      Fun:   cmInetPton6
9587 *
9588 *      Desc:  Converts a IP address string to IPV6 address suitable 
9589 *             to be used in bind.
9590 *
9591 *      Ret:   ROK     - successful
9592 *             RFAILED - failed
9593 *
9594 *      Notes: 
9595 *
9596 *      File:  cm_inet.c
9597 *
9598 */
9599 #ifdef ANSI
9600 PUBLIC S16 cmInetPton6(
9601 CmInetIpAddr6  *address6,       /* 16 byte interent address */
9602 S8             *asciiAddr       /* ascii address representation */
9603 )
9604 #else 
9605 PUBLIC S16 cmInetPton6(address6, asciiAddr)
9606 CmInetIpAddr6 *address6;        /* 16 byte interent address */
9607 S8            *asciiAddr;       /* ascii address representation */
9608 #endif
9609 {
9610    S16    ret;
9611
9612 #ifdef WIN32
9613    struct sockaddr_storage ss;
9614    U32    sslen = sizeof(ss);
9615 #endif /* WIN32 */
9616    TRC2(cmInetPton); 
9617
9618 #if (ERRCLASS & ERRCLS_INT_PAR)
9619    /* error check on parameters */
9620    if ((asciiAddr == NULLP) || (address6 == NULLP))
9621    {
9622       RETVALUE(RFAILED);
9623    }
9624 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9625
9626 #ifndef WIN32 
9627    ret = inet_pton(AF_INET6, asciiAddr, (void *)address6);
9628    if (ret != 1)
9629    { 
9630       RETVALUE(RFAILED);
9631    }
9632 #else
9633    /* cm_inet_c_001.main_44 : In windows inet_pton is not implemented. so we are using the below function
9634     * to convert the ipv6 address string to appropriate form */
9635    WSAStringToAddressA((LPTSTR)asciiAddr, AF_INET6, NULL, (struct sockaddr*)&ss, &sslen);
9636    cmMemcpy((U8*)address6, (U8*)&(((struct sockaddr_in6 *)&ss)->sin6_addr), sizeof(CmInetIpAddr6));
9637 #endif /* WIN32 */
9638
9639    RETVALUE(ROK);
9640 } /* end of cmInetPton6 */
9641 #endif /* IPV6_SUPPORTED */
9642 #endif /* SS_PS */
9643
9644 \f
9645 /*
9646 *
9647 *      Fun:   cmInetGetMemSize
9648 *
9649 *      Desc:  This function gives the max number of static buffer space that
9650 *             the internet library will allocate. 
9651 *
9652 *      Ret:   ROK - successful
9653 *
9654 *      Notes: None.
9655 *
9656 *      File:  cm_inet.c
9657 *
9658 */
9659
9660 #ifdef ANSI
9661 PUBLIC S16 cmInetGetMemSize(
9662 S32 *size                       /* max used memory size */
9663 )
9664 #else
9665 PUBLIC S16 cmInetGetMemSize(size)
9666 S32 *size;                      /* max used memory size */
9667 #endif
9668 {
9669 #ifdef WIN32
9670    /* max static memory size depends on max flat buffer size */
9671    *size = CM_INET_MAX_MSG_LEN;
9672 #else   
9673    /* max static memory size depends on max flat buffer or iovect size */
9674    *size = CM_INET_MAX_MSG_LEN;
9675 #endif 
9676
9677    RETVALUE(ROK);
9678 }
9679
9680
9681 \f
9682 /*
9683 *
9684 *      Fun:   cmInetInit
9685 *
9686 *      Desc:  This function initializes the socket library.
9687 *
9688 *      Ret:   ROK - successful
9689 *
9690 *      Notes: Required only for Winsock and not for 4.3BSD
9691 *
9692 *      File:  cm_inet.c
9693 *
9694 */
9695  
9696 #ifdef ANSI
9697 PUBLIC S16 cmInetInit(
9698 Void
9699 )
9700 #else
9701 PUBLIC S16 cmInetInit(Void)
9702 #endif
9703 {
9704 #ifdef WIN32
9705    U16     version;
9706    S32     err;
9707    WSADATA data;
9708
9709    version = MAKEWORD(CM_INET_HIGH_VER, CM_INET_LOW_VER);
9710    err = WSAStartup(version, &data);
9711    if (err != 0)
9712    {
9713       RETVALUE(RFAILED);
9714    }
9715 #endif
9716
9717    RETVALUE(ROK);
9718 }
9719
9720 \f
9721 /*
9722 *
9723 *      Fun:   cmInetDeInit
9724 *
9725 *      Desc:  This function de initializes the socket library. The
9726 *             WINSOCK implementation de registers the application and
9727 *             releases any resources allocated on behalf of the
9728 *             application.
9729 *
9730 *      Ret:   ROK - successful
9731 *
9732 *      Notes: Required only for Winsock and not for 4.3BSD
9733 *
9734 *      File:  cm_inet.c
9735 *
9736 */
9737  
9738 #ifdef ANSI
9739 PUBLIC S16 cmInetDeInit(
9740 Void
9741 )
9742 #else
9743 PUBLIC S16 cmInetDeInit(Void)
9744 #endif
9745 {
9746 #ifdef WIN32
9747    S32     err;
9748
9749    err = WSACleanup();
9750    if (err != 0)
9751    {
9752       RETVALUE(RFAILED);
9753    }
9754 #endif
9755
9756    RETVALUE(ROK);
9757 }/* end of cmInetDeInit() */
9758
9759 \f
9760 /*
9761 *
9762 *      Fun:   cmInetGetSockName
9763 *
9764 *      Desc:  This function is used to retireve the current name 
9765 *             for the specified socket descriptor. It returns the 
9766 *             local association(address and port) for the socket.
9767
9768 *      Ret:   ROK     - successful
9769 *             RFAILED - failed
9770 *
9771 *      Notes: Please note if the socket was bound to CM_INET_INADDR_ANY
9772 *             cmInetGetSockName() will not necessarily return the local
9773 *             address information unless the socket has been connected.
9774 *
9775 *      File:  cm_inet.c
9776 *
9777 */
9778 \f
9779 #ifdef ANSI
9780 PUBLIC S16 cmInetGetSockName
9781 (
9782 CmInetFd *sockFd,               /* socket file descriptor */ 
9783 CmInetAddr *locAddr
9784
9785 #else
9786 PUBLIC S16 cmInetGetSockName(sockFd, locAddr)
9787 CmInetFd *sockFd;               /* socket file descriptor */ 
9788 CmInetAddr *locAddr;
9789 #endif
9790 {
9791    struct sockaddr_in *sockAddr; 
9792 #ifdef IPV6_SUPPORTED
9793    struct sockaddr_in6 *sockAddr6;
9794    struct sockaddr_in6 lclSockAddr;
9795 #else
9796    CmInetSockAddr lclSockAddr;
9797 #endif /* IPV6_SUPPORTED */
9798 #ifdef UNIX
9799    socklen_t size;
9800 #else
9801    U32  size;
9802 #endif /* SS_LINUX */
9803    S32  errCode;
9804    /*cm_inet_c_001.main_58  : fix for klockwork issue */
9805    S32  ret;
9806
9807    TRC2(cmInetGetSockName);
9808
9809 #if (ERRCLASS & ERRCLS_INT_PAR)
9810    /* error check on parameters */
9811    if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd) ||
9812          (locAddr == NULLP))
9813    {
9814       RETVALUE(RFAILED);
9815    }
9816 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9817
9818    cmMemset((U8*)&lclSockAddr, 0, sizeof(lclSockAddr));
9819    size = sizeof(lclSockAddr);
9820
9821 #ifdef UNIX
9822    ret = getsockname(sockFd->fd, (CmInetSockAddr*)&lclSockAddr, 
9823          (socklen_t *)&size);
9824 #else
9825    ret = getsockname(sockFd->fd, (CmInetSockAddr*)&lclSockAddr, (int*)&size);
9826 #endif /* SS_LINUX */
9827
9828    if(ret == INET_ERR)
9829    {
9830       switch(errCode = INET_ERR_CODE)
9831       {
9832          case ERR_INVAL:
9833             sockAddr = (struct sockaddr_in *)&lclSockAddr;
9834 #ifdef IPV6_SUPPORTED
9835             locAddr->type = CM_INET_IPV4ADDR_TYPE;
9836             locAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(sockAddr->sin_port);
9837 #else
9838             locAddr->port = CM_INET_NTOH_U16(sockAddr->sin_port);
9839 #endif /* IPV6_SUPPORTED */
9840             RETVALUE(ROK);
9841
9842          default:
9843 #ifdef CMINETDBG
9844 #ifndef ALIGN_64BIT
9845             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
9846             /* cm_inet_c_001.main_62:Warning fix */
9847             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d),"
9848                   " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
9849             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET051, 0, prntBuf);
9850 #else
9851             /* cm_inet_c_001.main_62:Warning fix */
9852             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetGetHostByName() Failed : error(%d),"
9853                   " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
9854             CMINETLOGERROR(ERRCLS_INT_PAR, ECMINET051, 0, prntBuf);
9855 #endif /* ALIGN_64BIT */
9856 #endif /* CMINETDBG */
9857             RETVALUE(RFAILED);
9858       }/* end of switch */
9859
9860    }/* end if */
9861
9862    /* Fill the returned address in to locAddr */
9863 #ifdef IPV6_SUPPORTED
9864    cmMemset((U8*)locAddr, 0, sizeof(CmInetAddr));
9865    if (size == sizeof(struct sockaddr_in6))
9866    {
9867       sockAddr6 = (struct sockaddr_in6 *)&lclSockAddr;
9868       locAddr->type = CM_INET_IPV6ADDR_TYPE;
9869       locAddr->u.ipv6Addr.port = CM_INET_NTOH_U16(sockAddr6->sin6_port);
9870       CM_INET_COPY_IPV6ADDR(&locAddr->u.ipv6Addr.ipv6NetAddr, 
9871             &sockAddr6->sin6_addr);
9872    }
9873    else
9874    {
9875       sockAddr = (struct sockaddr_in *)&lclSockAddr;
9876       locAddr->type = CM_INET_IPV4ADDR_TYPE;
9877       locAddr->u.ipv4Addr.port = CM_INET_NTOH_U16(sockAddr->sin_port);
9878       locAddr->u.ipv4Addr.address = 
9879          CM_INET_NTOH_U32(sockAddr->sin_addr.s_addr);
9880    }
9881 #else
9882    sockAddr = (struct sockaddr_in *)&lclSockAddr;
9883    locAddr->port    = CM_INET_NTOH_U16(sockAddr->sin_port);
9884    locAddr->address = CM_INET_NTOH_U32(sockAddr->sin_addr.s_addr);
9885 #endif /* IPV6_SUPPORTED */
9886    RETVALUE(ROK);
9887 }/* end of cmInetGetSockName() */
9888
9889 /*  New functions to peek into the file descriptor 
9890  * set */
9891 #if (defined(SUNOS) || defined(WIN32) || defined(SS_LINUX) || defined(SS_VW) \
9892       || defined(HPOS))
9893 \f
9894 /*
9895 *
9896 *      Fun:   cmInetFdSetInfoInit
9897 *
9898 *      Desc:  This function is used to initialise operating system specific
9899 *             data that will be used to peek into the file descriptor lists
9900 *             to get the sockets that are set 
9901
9902 *      Ret:   ROK     - successful
9903 *             RFAILED - failed
9904 *
9905 *      Notes: 
9906 *
9907 *      File:  cm_inet.c
9908 *
9909 */
9910 \f
9911 #ifdef ANSI
9912 PUBLIC S16 cmInetFdSetInfoInit
9913 (
9914 CmInetFdSetInfo *fdSetInfo
9915
9916 #else
9917 PUBLIC S16 cmInetFdSetInfoInit(fdSetInfo)
9918 CmInetFdSetInfo *fdSetInfo;
9919 #endif
9920 {
9921 #if (defined(SUNOS) || defined(SS_LINUX) || defined(SS_VW) || defined(HPOS))
9922    U16   arIdx;
9923    U8    curByte;
9924    U8    bitPos;
9925    CmInetFdSet *fdSet;
9926 #endif /* SUNOS || SS_LINUX || SS_VW */
9927
9928 #if (ERRCLASS & ERRCLS_INT_PAR)
9929    if (fdSetInfo == NULLP)
9930       RETVALUE(RFAILED);
9931 #endif /* ERRCLASS & ERRCLS_INT_PAR */
9932
9933    if (fdSetInfo->initDone == TRUE)
9934       RETVALUE(ROK);
9935
9936 #ifdef WIN32
9937    fdSetInfo->numFds = 0;
9938 #endif /* WIN32 */
9939
9940 #if (defined(SUNOS) || defined(SS_LINUX) || defined(SS_VW)|| defined(HPOS))
9941    /* Check if we are on a big endian machine */
9942    arIdx = 0x01;
9943    if (*(U8 *)&arIdx)
9944       fdSetInfo->bigEndian = FALSE;
9945    else
9946       fdSetInfo->bigEndian = TRUE;
9947
9948    fdSetInfo->arIdx = 0;
9949    fdSetInfo->ar[0] = 0xff;
9950
9951    /* Initialise the array */
9952    /* The array contains bit positions for the first bit 
9953     * for each integer from 1 to 2^8. 
9954     */
9955    for (arIdx = 1; arIdx < 256; arIdx++)
9956    {
9957       /* cm_inet_c_001.main_54: Fix for Klockworks issue */
9958       curByte = (U8)arIdx;
9959       bitPos = 0;
9960
9961       while(bitPos < 8)
9962       {
9963          if (curByte & 0x01)
9964          {
9965             fdSetInfo->ar[arIdx] = bitPos;
9966             break;
9967          }
9968          bitPos += 1;
9969          curByte = curByte >> 1;
9970       }
9971    }
9972    /* Calculate the number of array elements in this fd_set */
9973 #if (defined(SS_LINUX)  &&  !defined(_GNU_SOURCE))
9974    fdSetInfo->numArElems = sizeof(CmInetFdSet)/sizeof(fdSet->__fds_bits[0]);
9975 #else
9976    fdSetInfo->numArElems = sizeof(CmInetFdSet)/sizeof(fdSet->fds_bits[0]);
9977 #endif /* SS_LINUX */
9978 #endif /* SUNOS  || SS_LINUX || SS_VW || HPOS */   
9979
9980    fdSetInfo->initDone = TRUE;
9981    RETVALUE(ROK);
9982 }/* end of cmInetFdSetInfoInit() */
9983
9984 \f
9985 /*
9986 *
9987 *      Fun:   cmInetGetFd
9988 *
9989 *      Desc:  This function is used to get the file descriptor from the
9990 *             file descriptor set.
9991
9992 *      Ret:   ROK     - successful
9993 *             ROKDNA  - socket not found
9994 *             RFAILED - failed
9995 *             RNA     - failed, initialisation not done
9996 *
9997 *      Notes: If the application modifies fdSet between calls to this
9998 *             function then the results are undefined. This function should
9999 *             be called in a loop till either it returns - not ROK, or if 
10000 *             all sockets in the file descriptor set are processed. 
10001 *
10002 *      File:  cm_inet.c
10003 *
10004 */
10005 \f
10006 #ifdef ANSI
10007 PUBLIC S16 cmInetGetFd
10008 (
10009 CmInetFdSetInfo *fdSetInfo,
10010 CmInetFdSet     *fdSet,
10011 CmInetFdType    *sockFd
10012
10013 #else
10014 PUBLIC S16 cmInetGetFd(fdSetInfo, fdSet, sockFd)
10015 CmInetFdSetInfo *fdSetInfo;
10016 CmInetFdSet     *fdSet;
10017 CmInetFdType    *sockFd;
10018 #endif
10019 {
10020   /*cm_inet_c_001.main_58 : Fix for klockwork issue */
10021 #if (!defined (WIN32))
10022    U32 sizOfFdSetArElem;  
10023    U8 bytesScanned;
10024    Bool found;
10025    U32 curIdx;
10026    U8 *tempByte;
10027    U8 bitPos;
10028 #endif /* !defined (WIN32) */
10029
10030 #if (ERRCLASS & ERRCLS_INT_PAR)
10031    if ((fdSetInfo == NULLP) || (fdSet == NULLP) || (sockFd == NULLP))
10032       RETVALUE(RFAILED);
10033
10034    if (fdSetInfo->initDone != TRUE)
10035       RETVALUE(RNA);
10036 #endif /* ERRCLASS & ERRCLS_INT_PAR */
10037
10038 #ifdef WIN32
10039 #if (ERRCLASS & ERRCLS_DEBUG)
10040    if (fdSetInfo->numFds > FD_SETSIZE)
10041       RETVALUE(RFAILED);
10042 #endif /* ERRCLASS & ERRCLS_DEBUG */
10043    /* cm_inet_c_001.main_32 :  Corrected check for number of fd set in
10044       a fdset for WIN32*/
10045    if (fdSetInfo->numFds >= fdSet->fd_count)
10046       RETVALUE(ROKDNA);
10047
10048    *sockFd = fdSet->fd_array[fdSetInfo->numFds];
10049    fdSetInfo->numFds += 1;
10050    RETVALUE(ROK);
10051 #endif /* WIN32 */
10052
10053    /* cm_inet_c_001.main_59: Protected under if not defined WIN32 */
10054 #if (!defined (WIN32))
10055    /* Start with arIdx and continue upto number of array elements. */
10056    curIdx = fdSetInfo->arIdx;
10057    found = FALSE;
10058
10059 #if (defined(SS_LINUX)  &&  !defined(_GNU_SOURCE))
10060    sizOfFdSetArElem = sizeof(fdSet->__fds_bits[0]);
10061 #else
10062    sizOfFdSetArElem = sizeof(fdSet->fds_bits[0]);
10063 #endif /* SS_LINUX */
10064
10065    for (curIdx = fdSetInfo->arIdx; curIdx < fdSetInfo->numArElems;
10066          curIdx ++)
10067    {
10068 #if (defined(SS_LINUX)  &&  !defined(_GNU_SOURCE))
10069       if (fdSet->__fds_bits[curIdx])
10070 #else
10071          if (fdSet->fds_bits[curIdx])
10072 #endif /* SS_LINUX */
10073          {
10074             /* Walk through the bytes in this element */
10075 #if (defined(SS_LINUX)  &&  !defined(_GNU_SOURCE))
10076             tempByte = (U8 *)&fdSet->__fds_bits[curIdx];
10077 #else
10078             tempByte = (U8 *)&fdSet->fds_bits[curIdx];
10079 #endif /* SS_LINUX */
10080
10081             /* Set the starting byte offset */
10082             if (fdSetInfo->bigEndian)
10083                tempByte += sizOfFdSetArElem - 1;
10084
10085             for (bytesScanned = 0; bytesScanned < sizOfFdSetArElem; 
10086                   bytesScanned ++)
10087             {
10088                if (*tempByte)
10089                {
10090                   bitPos = fdSetInfo->ar[*tempByte];
10091                   /* cm_inet_c_001.main_54: Fix for Klockworks issue */
10092                   fdSetInfo->arIdx = (U16)curIdx;
10093                   /* Calculate fd depending on where we are */
10094                   *sockFd = ((bytesScanned << 3) + bitPos);
10095                   *sockFd += (curIdx  * (sizOfFdSetArElem << 3));
10096                   /* Clear the file descriptor */
10097                   *tempByte &= ~(1 << bitPos);
10098                   RETVALUE(ROK);
10099                }
10100                if (fdSetInfo->bigEndian)
10101                   tempByte -= 1;
10102                else
10103                   tempByte += 1;
10104             }
10105             break;
10106          }
10107    }
10108
10109    if (!found)
10110       RETVALUE(ROKDNA);
10111
10112    RETVALUE(ROK);
10113 #endif /* SUNOS || SS_LINUX || SS_VW || HPOS */
10114 } /* end of cmInetGetFd */
10115
10116 #endif /* SUNOS || WIN32  || SS_LINUX || SS_VW || HPOS  */ 
10117
10118 \f
10119 /* add cmInetConvertStrToIpAddr and
10120  * cmInetAsciiToIpv4 functions */
10121 /*
10122 *
10123 *       Fun:   cmInetConvertStrToIpAddr
10124 *
10125 *       Desc:  This function parses the input string for an IPV4/IPV6 address.
10126 *              formats:
10127 *              1) IPV4 in dot number format:
10128 *                    206.216.108.253
10129 *              2) IPV6, in uncompressed, compressed, and IPV4 embedded format 
10130 *                    10:20:30:40:502:610:70C:80ad
10131 *                    A5::34:45
10132 *                    45::AB:34:123.34.5.667
10133 *
10134 *       Ret:   ROK     - SUCCESS
10135 *              RFAILED - FAILURE
10136 *
10137 *       Notes: 
10138 *
10139 *       File:  cm_inet.c
10140 *
10141 */
10142
10143 #ifdef ANSI
10144 PUBLIC S16 cmInetConvertStrToIpAddr
10145 (
10146 U16                len,                /* Length of IP address */
10147 U8                 *val,               /* Domain Name String */
10148 CmInetNetAddr      *address            /* IP Address */
10149 )
10150 #else
10151 PUBLIC S16 cmInetConvertStrToIpAddr(len, val, address)
10152 U16                len;                /* Length of IP address */
10153 U8                 *val;               /* Domain Name String */
10154 CmInetNetAddr      *address;           /* IP Address */
10155 #endif
10156 {
10157    U8              idx;                /* Index for string*/
10158    U8              ipv4[CM_INET_IPV4ADDR_SIZE]; /* IPV4 Address bytes */
10159 #ifdef IPV6_SUPPORTED
10160    U16             *ipv6;                 /* IPV6 Address bytes */
10161    U16             ipv6Reg[8];           /* regular IPV6 Address bytes */
10162    U16             ipv6Cmp[8];           /* compressed IPV6 Address bytes */
10163    U8              numBlk;               /* number of blocks in IPV6 addr */
10164    Bool            compressed;           /* IPV6 in compressed format */
10165    U8              ipv6Idx;              /* counter for IPV6 */
10166    U8              blkBeginIdx;          /* IPV6, char index for the 
10167                                             beginning of the block */
10168    U8              i;                    /* counter for IPV6 */
10169    S16             retVal;               /* return value */
10170    Bool            embedIPV4 = FALSE;    /* IPV4 embedded in IPV6 ? */
10171 #endif /* IPV6_SUPPORTED*/
10172
10173    TRC2(cmInetConvertStrToIpAddr)
10174
10175       idx = 0;
10176 #ifdef IPV6_SUPPORTED
10177    numBlk = 0;
10178    ipv6Idx = 0;
10179    compressed = FALSE;
10180    embedIPV4 = FALSE;
10181    ipv6 = ipv6Reg; /* assign pointer to IPV6 regular, uncompressed */
10182    cmMemset((U8 *)ipv6Reg, 0, CM_INET_IPV6ADDR_SIZE);
10183    cmMemset((U8 *)ipv6Cmp, 0, CM_INET_IPV6ADDR_SIZE);
10184 #endif /* IPV6_SUPPORTED*/
10185
10186    cmMemset((U8 *)ipv4, 0, CM_INET_IPV4ADDR_SIZE);
10187
10188    /* Check for IP Address */
10189    while ((val[idx] != '.') && (val[idx] != ':') && 
10190          (idx < len))
10191    {
10192 #if (ERRCLASS & ERRCLS_DEBUG)
10193       if (((val[idx] < '0') || (val[idx] > '9')) &&
10194             ((val[idx] < 'a') || (val[idx] > 'f')) &&
10195             ((val[idx] < 'A') || (val[idx] > 'F')))
10196       {
10197          /* Not a digit */
10198          RETVALUE(RFAILED);
10199       }
10200 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10201
10202       /* Convert Ascii to integer */
10203       CM_INET_ATOI(ipv4[0], val[idx]);
10204
10205 #ifdef IPV6_SUPPORTED
10206       /* convert Ascii to hex */
10207       CM_INET_ATOH(ipv6[0], val[idx]);
10208 #endif /* IPV6_SUPPORTED */
10209
10210       idx++; /* move to the next character */
10211    } /* while, try to determine IPV4 or IPV6 */
10212
10213 #if (ERRCLASS & ERRCLS_DEBUG)
10214    if ((val[idx] != '.') && (val[idx] != ':'))
10215    {
10216       /* Not a digit */
10217       RETVALUE(RFAILED);
10218    } /* if, couldn't determine IPV4 or IPV6 */
10219 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10220
10221
10222    if (val[idx] == '.')
10223    {
10224       idx++;
10225       cmInetAsciiToIpv4(3, &(ipv4[1]), (U16)(len - idx), &(val[idx]));
10226
10227       address->type = CM_INET_IPV4ADDR_TYPE;
10228       CM_INET_GET_IPV4_ADDR_FRM_STRING(address->u.ipv4NetAddr, ipv4);
10229    } /* if, IPV4 */
10230 #ifdef IPV6_SUPPORTED
10231    else 
10232    {
10233       numBlk = 1; /* already converted the 1st block */
10234       ipv6Idx = 0;
10235       while ((val[idx] != '\0') && (idx < len) && (numBlk <= 8))
10236       {
10237          idx++; /* go to the next char, either a number or the 2nd : */
10238          if (val[idx] == ':')
10239          {
10240 #if (ERRCLASS & ERRCLS_DEBUG)
10241             if (compressed == TRUE)
10242             {
10243                /* can't have 2 :: */
10244                RETVALUE(RFAILED);
10245             } /* if, 2 :: */
10246 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10247
10248             compressed = TRUE;
10249             idx++; /* skip the : */
10250             ipv6 = ipv6Cmp;
10251             ipv6Idx = 0;
10252          } /* if, IPV6 in compressed format :: */
10253          else
10254          {
10255             ipv6Idx++;
10256          } /* else, uncompressed, convert next block */
10257
10258          numBlk++; /* increase number of blocks */
10259
10260          /* assign the index the beginning of the block */
10261          blkBeginIdx = idx;
10262
10263          while(val[idx] != ':' && val[idx] != '\0' && idx < len)
10264          {
10265             if (val[idx] == '.')
10266             {
10267                /* convert number to IPV4 */
10268                ipv6[ipv6Idx] = 0; /* clear out whatever we did */
10269                cmMemset((U8 *)ipv4, 0, CM_INET_IPV4ADDR_SIZE);
10270                retVal = cmInetAsciiToIpv4(4, ipv4, len - blkBeginIdx, 
10271                      &(val[blkBeginIdx]));
10272                /* stop the loop, embedded IPV4 is the last part of
10273                   an IPV6 address */
10274                if (retVal != ROK)
10275                {
10276                   RETVALUE(retVal);
10277                }
10278                embedIPV4 = TRUE;
10279                break;
10280             } /* if, '.' means IPV4 address embedded in IPV6 */
10281
10282 #if (ERRCLASS & ERRCLS_DEBUG)
10283             if (((val[idx] < '0') || (val[idx] > '9')) &&
10284                   ((val[idx] < 'a') || (val[idx] > 'f')) &&
10285                   ((val[idx] < 'A') || (val[idx] > 'F')))
10286             {
10287                /* Not a digit */
10288                RETVALUE(RFAILED);
10289             }
10290 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10291
10292             /* Convert Ascii to integer */
10293             CM_INET_ATOH(ipv6[ipv6Idx], val[idx]);
10294
10295             /* move to the next index */
10296             idx++;
10297          } /* while, convert a block of 16 bits Hex number */
10298          if (embedIPV4 == TRUE)
10299          {
10300             ipv6Idx--; /* deccrease in case of compressed IPV6 */
10301             break; /* stop the while look */
10302          } /* if, IPV4 embedded in IPV6 */
10303       } /* while, IPV6 parsing */
10304       if (compressed == TRUE)
10305       {
10306          if (embedIPV4 == TRUE)
10307          {
10308             numBlk = 5; /* the last 2 blocks are IPV4 */
10309          } /* if, IPV4 embedded */
10310          else
10311          {
10312             numBlk = 7; /* copy from the last block */
10313          } /* else, no embedded IPV4 */
10314
10315          /* type cast U8 over -1 becasue we want to copy the last block,
10316             ipv6Cmp[0]
10317             */
10318          for (i = ipv6Idx; i != (U8) (-1); i --)
10319          {
10320             ipv6Reg[numBlk] = ipv6Cmp[i];
10321             numBlk--;
10322          } /* for, copying compress IPV6 to regular IPV6 */
10323       } /* if, compressed format */
10324
10325       if (embedIPV4 == TRUE)
10326       {
10327          ipv6Reg[6] = PutHiByte(ipv6Reg[6], ipv4[0]);
10328          ipv6Reg[6] = PutLoByte(ipv6Reg[6], ipv4[1]);
10329          ipv6Reg[7] = PutHiByte(ipv6Reg[7], ipv4[2]);
10330          ipv6Reg[7] = PutLoByte(ipv6Reg[7], ipv4[3]);
10331       } /* if, IPV4 embedded */
10332
10333       /* convert IPV6 to cmInetIpv6 */
10334       address->type = CM_INET_IPV6ADDR_TYPE;
10335       cmMemcpy((U8 *)address->u.ipv6NetAddr,
10336             (CONSTANT U8 *) ipv6Reg,  CM_INET_IPV6ADDR_SIZE);
10337    } /* else, IPV6 */
10338 #endif /* IPV6_SUPPORTED */
10339
10340    RETVALUE(ROK);
10341 } /* cmInetConvertStrToIpAddr */
10342
10343 \f
10344 /*
10345 *
10346 *       Fun:   cmInetAsciiToIpv4
10347 *
10348 *       Desc:  This function parses the input string to an IPV4 address.
10349 *              The input string can be 
10350 *              - the whole IPV4 address, '123.43.45.56', or
10351 *              - a part of it. '34.56.454'
10352 *              numBytes: number of bytes needs to be converted, IPV4 has
10353 *                        4 bytes. If we are only converting the end of an
10354 *                        address, this number needs to be adjusted. For
10355 *                        example, when converting '34.56.454]', the number
10356 *                        is 3.
10357 *
10358 *       Ret:   ROK     - SUCCESS
10359 *              RFAILED - FAILURE
10360 *
10361 *       Notes: 
10362 *
10363 *       File:  cm_inet.c
10364 *
10365 */
10366 #ifdef ANSI 
10367 PUBLIC S16  cmInetAsciiToIpv4
10368 (
10369 U8                 numBytes,           /* number of Byte to convert */
10370 U8                 *ipv4Addr,          /* IPV4 Address */
10371 U16                len,                /* Length of IP address */
10372 U8                 *val                /* Domain Name String */
10373 )
10374 #else
10375 PUBLIC S16 cmInetAsciiToIpv4(numBytes, ipv4Addr, len, val)
10376 U8                 numBytes;           /* number of Byte to convert */
10377 U8                 *ipv4Addr;          /* IPV4 Address */
10378 U16                len;                /* Length of IP address */
10379 U8                 *val;               /* Domain Name String */
10380 #endif
10381 {
10382    U8              byteCount;          /* Byte Count */
10383    U8              idx;                /* Index for string*/
10384
10385    TRC2(cmInetAsciiToIpv4)
10386
10387       idx = 0;
10388    for (byteCount = 0; byteCount < numBytes; byteCount++)
10389    {
10390       while((val[idx] != '.') && (idx < len))
10391       {
10392 #if (ERRCLASS & ERRCLS_DEBUG)
10393          if (val[idx] < '0' || val[idx] > '9')
10394          {
10395             /* Not a digit */
10396             RETVALUE(RFAILED);
10397          }
10398 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
10399
10400          /* Convert Ascii to integer */
10401          CM_INET_ATOI(ipv4Addr[byteCount], val[idx]);
10402
10403          /* move to the next index */
10404          idx++;
10405       }
10406       idx++;
10407    }
10408
10409    RETVALUE(ROK);
10410 } /* cmInetAsciiToIpv4 */
10411
10412 /* cm_inet_c_001.main_34:Added wrapper function for getaddrinfo and freeaddrinfo */
10413 #if (!defined(SS_VW) && !defined(SS_PS) && !defined(WIN32))
10414 \f
10415 /*
10416 *
10417 *      Fun:   cmInetGetAddrInfo 
10418 *
10419 *      Desc:  a socket file descriptor to a local Internet 
10420 *             address/port.
10421 *
10422 *      Ret:   Value returned by getaddrinfo 
10423 *
10424 *      Notes: None.
10425 *
10426 *      File:  cm_inet.c
10427 *
10428 */
10429
10430 #ifdef ANSI
10431 PUBLIC S32 cmInetGetAddrInfo
10432 (
10433 CONSTANT S8              *node,          /* Network addr which has to be resolved */
10434 CONSTANT S8              *service,       /* Sets the port number in network addr */
10435 CONSTANT CmInetAddrInfo  *hints,         /* Specifies preferred socket type or protocol */
10436 CmInetAddrInfo           **res           /* Link list of addrInfo structure */
10437 )
10438 #else
10439 PUBLIC S32 cmInetGetAddrInfo(node,service,hints,res)
10440 CONSTANT S8              *node;          /* Network addr which has to be resolved */
10441 CONSTANT S8              *service;       /* Sets the port number in network addr */
10442 CONSTANT CmInetAddrInfo  *hints;         /* Specifies preferred socket type or protocol */
10443 CmInetAddrInfo           **res;          /* Link list of addrInfo structure */
10444 #endif
10445 {
10446    S32 ret;
10447    TRC2(cmInetGetAddrInfo);
10448    ret = ROK;
10449
10450 #if (ERRCLASS & ERRCLS_INT_PAR)
10451    /* error check on parameters */
10452    if ((node == NULLP) || (hints == NULLP))
10453    {
10454       RETVALUE(RFAILED);
10455    }
10456 #endif /* ERRCLASS & ERRCLS_INT_PAR */
10457
10458    ret = getaddrinfo(node,service,hints,res); 
10459    if (ret != ROK)
10460    {
10461 #ifdef CMINETDBG
10462 #ifndef ALIGN_64BIT
10463       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
10464       /* cm_inet_c_001.main_62:Warning fix */
10465       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetAddrInfo() Failed : error(%ld), node(%p),"
10466             " service(%p)\n",  ret, node, service);
10467       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET052, 0, prntBuf);
10468 #else
10469       /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
10470       /* cm_inet_c_001.main_62:Warning fix */
10471       snprintf(prntBuf, CMINET_PRNT_BUF_SIZE, "cmInetGetAddrInfo() Failed : error(%d), node(%p),"
10472             " service(%p)\n ", ret,  node, service);
10473       CMINETLOGERROR(ERRCLS_DEBUG, ECMINET053, 0, prntBuf);
10474 #endif /* ALIGN_64BIT */
10475 #endif /* CMINETDBG */
10476    }
10477    RETVALUE(ret); 
10478 } /* end of cmInetGetAddrInfo */
10479
10480 \f
10481 /*
10482 *
10483 *      Fun:   cmInetFreeAddrInfo 
10484 *
10485 *      Desc:  Free the dynamically allocated addrinfo structure 
10486 *
10487 *      Ret:   None 
10488 *
10489 *      Notes: None.
10490 *
10491 *      File:  cm_inet.c
10492 *
10493 */
10494
10495 #ifdef ANSI
10496 PUBLIC Void cmInetFreeAddrInfo
10497 (
10498 CmInetAddrInfo           *res           /* Link list of addrInfo structure */
10499 )
10500 #else
10501 PUBLIC Void cmInetFreeAddrInfo(res)
10502 CmInetAddrInfo           *res;          /* Link list of addrInfo structure */
10503 #endif
10504 {
10505    TRC2(cmInetFreeAddrInfo);
10506
10507 #if (ERRCLASS & ERRCLS_INT_PAR)
10508    /* error check on parameters */
10509    if (res == NULLP) 
10510       RETVOID;   
10511 #endif /* ERRCLASS & ERRCLS_INT_PAR */
10512
10513    freeaddrinfo(res); 
10514 } /* end of cmInetFreeAddrInfo */
10515
10516 #endif /* SS_VW | SS_PS | WIN32*/
10517
10518 /* cm_inet_c_001.main_36 : 1. Added new interface - cmInetFlushRecvBuf()
10519    to flush the data from socket receive buffer. */
10520 #ifdef CM_INET_FLUSH_RECV_BUF
10521 \f
10522 /*
10523 *
10524 *      Fun:   cmInetFlushRcvBuf
10525 *
10526 *      Desc:  Reads all the data from a socket and throw it!!
10527 *             The buffers for the receive buffer for recvfrom() are allocated from the stack. 
10528 *
10529 *      Ret:   ROK     - successful
10530 *             ROKDNA  - ok, data not available
10531 *             RCLOSED - connection closed by peer
10532 *             ROUTRES - failed, out of resources
10533 *             RFAILED - failed
10534 *
10535 *      Notes: None.
10536 *
10537 *      File:  cm_inet.c
10538 *
10539 */
10540 #ifdef ANSI
10541 PUBLIC S16 cmInetFlushRecvBuf
10542 (
10543 CmInetFd        *sockFd,        /* socket file descriptor */ 
10544 MsgLen          *len,           /* number of octects to be flushed */
10545 S32              flags          /* additional control flags */
10546 )
10547 #else
10548 PUBLIC S16 cmInetFlushRecvBuf(sockFd, len, flags)
10549 CmInetFd        *sockFd;        /* socket file descriptor */ 
10550 MsgLen          *len;           /* number of octects to be flushed */
10551 S32              flags;         /* additional control flags */
10552 #endif /* ANSI */
10553 {
10554
10555    Data recvTempBuf[CM_INET_MAX_BYTES_READ];
10556
10557 #if (defined(WIN32) || defined(CMINETFLATBUF))
10558    S32           ret;            /* temporary return value */
10559    U32           pendLen;        /* pending data length */
10560    S32           recvLen;        /* number of received octets by recvmsg() */
10561    MsgLen        curLen;         /* current number of octets in buffer */ 
10562    U32           remAddrLen;     /* length of remote address */
10563    struct sockaddr_in  *remAddr;    /* remote Internet address */       
10564 #ifdef IPV6_SUPPORTED 
10565    struct sockaddr_in6 remSockAddr; /* to get packet's source IP address */
10566 #else
10567    CmInetSockAddr  remSockAddr;     /* to get packet's source IP address */
10568 #endif /* IPV6_SUPPORTED */
10569 #else
10570    S32           ret;            /* temporary return value */
10571    MsgLen        curLen;         /* current number of octets in buffer */ 
10572    U32           pendLen;        /* pending data length */
10573    S32           recvLen;        /* number of received octets by recvmsg() */
10574    struct msghdr msg;            /* message header */ 
10575    CmInetIovec  rxArr[CM_INET_MAX_DBUF]; /* dynamic gather array */
10576    U32           remAddrLen;     /* length of remote address */
10577 #ifdef IPV6_SUPPORTED 
10578    struct sockaddr_in6 remSockAddr;/* to get packet's source IP address */
10579
10580 #if (defined(SS_LINUX) || defined(_XPG4_2))
10581    U8                   ancillData[CM_INET_IPV6_ANCIL_DATA];
10582    /* from stack for IPv6 ancill data */
10583 #endif
10584 #else
10585    CmInetSockAddr       remSockAddr;     /* to get packet's src IP address */
10586 #if (defined(SS_LINUX) || defined(_XPG4_2))
10587    U8                   ancillData[CM_INET_IPV4_ANCIL_DATA];
10588    /* from stack for IPv4 ancill data */
10589 #endif
10590 #endif /* IPV6_SUPPORTED */
10591 #endif /* WIN32 | CMINETFLATBUF */
10592
10593    /* used by getsockopt */
10594    U32          errValue;                /* error value */
10595    U32          optLen;                  /* option length */
10596
10597    TRC2(cmInetFlushRcvBuf)
10598
10599 #if (ERRCLASS & ERRCLS_INT_PAR)
10600       /* error check on parameters */
10601       if ((sockFd == NULLP) || CM_INET_INV_SOCK_FD(sockFd))
10602       {
10603          RETVALUE(RFAILED);
10604       }
10605 #endif /* ERRCLASS & ERRCLS_INT_PAR */
10606
10607
10608 #if (defined(WIN32) || defined(CMINETFLATBUF))
10609    remAddr = NULLP;  
10610 #endif /* (WIN32 | CMINETFLATBUF) */
10611
10612    /* clear the structure */   
10613    cmMemset((U8*)&remSockAddr, 0, sizeof(remSockAddr));
10614
10615    /* get number of pending data */
10616    ret = cmInetGetNumRead(sockFd, &pendLen);
10617    if (ret != ROK)
10618    {
10619       /* ret may be RFAILED or ROUTRES */
10620       RETVALUE(ret);
10621    }
10622
10623    /* check if connection got closed */
10624    if (pendLen == 0)
10625    {
10626       if (sockFd->type == CM_INET_STREAM)
10627       {
10628
10629          /* cm_inet_c_001.main_50 
10630           * Due to latency (mostly in solaris) sometimes ioctl(FIONREAD)
10631           * (inside cmInetGetNumRead) returns pend length as 0 on a TCP 
10632           * socket that select says is ready to read. This should not be 
10633           * considered as connection closed. So return ROKDNA instead of 
10634           * RCLOSED
10635           */
10636          RETVALUE(ROKDNA);
10637       }
10638       else
10639          /* clear error if there is any, because if there is internal error
10640           * here it will cause infinite loop in TUCL */
10641       {
10642          errValue = 0;
10643          optLen = sizeof(int);
10644 #ifdef UNIX
10645          ret = getsockopt(sockFd->fd, SOL_SOCKET, SO_ERROR,
10646                (char*)&errValue, (socklen_t *)&optLen);
10647 #else
10648 #if (defined(SS_VW) || defined(SS_PS))
10649          ret = getsockopt(sockFd->fd, SOL_SOCKET, SO_ERROR,
10650                (char*)&errValue, (int *)&optLen);
10651 #else
10652 #ifndef SS_WINCE
10653          ret = getsockopt(sockFd->fd, SOL_SOCKET, SO_ERROR,
10654                (char*)&errValue, (int *)&optLen);
10655 #endif /* SS_WINCE */
10656 #endif /* SS_VW */
10657 #endif /* SS_LINUX */
10658          if (ret == INET_ERR)
10659          {
10660 #ifdef CMINETDBG
10661 #ifndef ALIGN_64BIT
10662             /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
10663             /* cm_inet_c_001.main_62:Warning fix */
10664             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10665                   " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
10666             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET054, 0, prntBuf);
10667 #else
10668             /* cm_inet_c_001.main_62:Warning fix */
10669             snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10670                   " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
10671             CMINETLOGERROR(ERRCLS_DEBUG, ECMINET054, 0, prntBuf);
10672 #endif /*ALIGN_64BIT*/
10673 #endif /* CMINETDBG */
10674             RETVALUE(RFAILED);
10675          }
10676          else
10677          {
10678             U8 tempBuf;
10679             /* added separate recvfrom calls different OS */
10680 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
10681             recvLen = recvfrom(sockFd->fd, (S8 *)&tempBuf, pendLen, 0, 
10682                   (struct sockaddr *)&remSockAddr, (int *)&remAddrLen);
10683 #else
10684 #if ( defined(SUNOS) || defined(SS_LINUX))
10685             recvLen = recvfrom(sockFd->fd, (S8 *)&tempBuf, pendLen, 0,
10686                   NULLP, (socklen_t *)&remAddrLen);
10687 #else
10688             recvLen = recvfrom(sockFd->fd, (S8 *)&tempBuf, pendLen, 0,
10689                   NULLP, (S32 *)&remAddrLen);
10690
10691 #endif /* defined(SUNOS) || defined(SS_LINUX) */
10692 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */
10693
10694             RETVALUE(ROKDNA);
10695          }      
10696       }
10697    }/* if (pendLen == 0)*/
10698
10699
10700    if((*len == CM_INET_READ_THROW) || (*len >= CM_INET_MAX_BYTES_READ))
10701    {
10702       curLen = CM_INET_MAX_BYTES_READ;
10703    }
10704    else
10705    {
10706       curLen = *len; /*set to given number of messasges to be flushed */
10707    }
10708
10709    if((*len != CM_INET_READ_THROW) && (*len < pendLen))
10710    {
10711       pendLen = *len;
10712    }
10713
10714 #if (defined(WIN32) || defined(CMINETFLATBUF))
10715
10716    remAddrLen = 0;
10717    /* 
10718     * maybe needs more than one recvfrom() call to read an entire 
10719     * message 
10720     */
10721    while (curLen > 0)
10722    {
10723       cmMemset((U8*)recvTempBuf, 0, CM_INET_MAX_BYTES_READ);
10724       /* added separate recvfrom calls different OS */
10725
10726 #if( defined(SS_VW) || defined(HPOS) || defined(SS_PS))
10727       recvLen = recvfrom(sockFd->fd, (S8 *)recvTempBuf, curLen, 0, 
10728             (struct sockaddr *)&remSockAddr, (int *)&remAddrLen);
10729 #else         
10730 #if ( defined(SUNOS) || defined(SS_LINUX))
10731       recvLen = recvfrom(sockFd->fd, (S8 *)recvTempBuf, curLen, 0, 
10732             (struct sockaddr *)&remSockAddr, (socklen_t *)&remAddrLen); 
10733 #else
10734       recvLen = recvfrom(sockFd->fd, (S8 *)recvTempbuf, curLen, 0, 
10735             &remSockAddr, (S32 *)&remAddrLen); 
10736
10737 #endif /* defined(SUNOS) || defined(SS_LINUX) */
10738 #endif /* defined(SS_VW) || defined(HPOS) || defined(SS_PS) */ 
10739
10740       if (recvLen == INET_ERR)
10741       {
10742
10743          /*  added check ERR_WOULDBLOCK */
10744          if ((INET_ERR_CODE == ERR_AGAIN) ||
10745                (INET_ERR_CODE == ERR_WOULDBLOCK))
10746          {
10747             *len = 0; 
10748             RETVALUE(ROKDNA);
10749          }
10750
10751
10752          /*  In Windows the recvfrom function fails
10753           *  with error code which maps to either WSAECONNABORTED. If
10754           *  this happens then cmInetFlushRecvBuf must return RCLOSED */
10755          if ((INET_ERR_CODE == ERR_CONNABORTED) || 
10756                (INET_ERR_CODE == ERR_CONNRESET))
10757          {
10758             *len = 0;
10759             RETVALUE(RCLOSED);
10760          }
10761
10762 #ifdef CMINETDBG
10763 #ifndef ALIGN_64BIT
10764          /* cm_inet_c_001.main_54 : CMINETLOGERROR added insted of SDisp */
10765          /* cm_inet_c_001.main_62:Warning fix */
10766          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10767                " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
10768          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET055, 0, prntBuf);
10769 #else
10770          /* cm_inet_c_001.main_62:Warning fix */
10771          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10772                " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
10773          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET055, 0, prntBuf);
10774 #endif /*ALIGN_64BIT*/
10775 #endif /* CMINETDBG */
10776
10777          RETVALUE(RFAILED);
10778       } 
10779
10780       if(recvLen < curLen)
10781          break;
10782
10783       pendLen -= recvLen;
10784
10785       if(pendLen < curLen)
10786          curLen = pendLen;
10787
10788    } /* while (curLen > 0)  */ 
10789
10790 #else  /* end of Win NT/flat buffer specific part */
10791
10792    /* 
10793     * maybe needs more than one recvmsg() call to read entire message 
10794     * on a stream socket 
10795     */
10796    while (curLen > 0)
10797    {
10798       cmMemset((U8*)recvTempBuf, 0, CM_INET_MAX_BYTES_READ);
10799       /* update the message structure */
10800 #ifdef SS_LINUX
10801       rxArr[0].iov_base = (Void*)recvTempBuf;  
10802       rxArr[0].iov_len = (U32)curLen;    
10803 #else
10804       rxArr[0].iov_base = (S8*)recvTempBuf;
10805       rxArr[0].iov_len = curLen; 
10806 #endif /* SS_LINUX */
10807       msg.msg_iov           = rxArr;
10808       msg.msg_iovlen        = 1;
10809
10810       msg.msg_name    = NULLP;
10811       msg.msg_namelen = 0;
10812
10813       /* added defined(_XPG4_2). Also changed the
10814        * assignments */
10815 #if (defined(SS_LINUX) || defined(_XPG4_2))
10816       msg.msg_control      = ancillData;
10817       msg.msg_controllen   = sizeof(ancillData);
10818       msg.msg_flags   = 0; 
10819 #else
10820       msg.msg_accrights     = NULLP;
10821       msg.msg_accrightslen  = 0;
10822 #endif /* SS_LINUX */
10823
10824       recvLen = recvmsg(sockFd->fd, &msg, flags);
10825       if ((recvLen == INET_ERR) || (recvLen > CM_INET_MAX_MSG_LEN))
10826       {
10827          /* added check ERR_AGAIN when CMINETFLATBUF is not defined. 
10828             added check ERR_WOULDBLOCK */
10829          if ((INET_ERR_CODE == ERR_AGAIN) ||
10830                (INET_ERR_CODE == ERR_WOULDBLOCK))
10831          {
10832             *len = 0;  
10833             RETVALUE(ROKDNA);
10834          }
10835
10836 #ifdef CMINETDBG
10837 #ifndef ALIGN_64BIT
10838          /* cm_inet_c_001.main_54: CMINETLOGERROR added insted of SDisp */
10839          /* cm_inet_c_001.main_62:Warning fix */
10840          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10841                " sockFd->fd(%ld)\n", INET_ERR_CODE, sockFd->fd);
10842          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET056, 0, prntBuf);
10843 #else
10844          /* cm_inet_c_001.main_62:Warning fix */
10845          snprintf(prntBuf, CMINET_PRNT_BUF_SIZE,"cmInetFlushRecvBuf() Failed : error(%d),"
10846                " sockFd->fd(%d)\n", INET_ERR_CODE, sockFd->fd);
10847          CMINETLOGERROR(ERRCLS_DEBUG, ECMINET056, 0, prntBuf);
10848 #endif /*ALIGN_64BIT*/
10849 #endif /* CMINETDBG */
10850
10851          /*  If this happens then cmInetFlushRecvBuf must return RCLOSED. 
10852           *  Needed for getting icmp msgs */
10853          if (INET_ERR_CODE == ERR_CONNABORTED)
10854          {
10855             *len = 0;
10856             RETVALUE(RCLOSED);
10857          }
10858          RETVALUE(RFAILED); 
10859       }/* if ((recvLen == INET_ERR) || (recvLen > CM_INET_MAX_MSG_LEN))*/ 
10860
10861       if(recvLen < curLen)
10862          break;
10863
10864       pendLen -= recvLen;
10865
10866       if(pendLen < curLen)
10867          curLen = pendLen;
10868
10869    } /* while(curLen > 0) */
10870
10871 #endif /* WIN32 | CMINETFLATBUF  */
10872
10873
10874    RETVALUE(ROK);
10875 } /* end of cmInetFlushRecvBuf */
10876
10877 #endif /* CM_INET_FLUSH_RECV_BUF*/
10878
10879 /**********************************************************************
10880          End of file
10881 **********************************************************************/