Print this page
10085 sctp_getpeeraddrs() doesn't need to check for a NULL primary


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 




  26 #include <sys/types.h>
  27 #include <sys/stream.h>
  28 #define _SUN_TPI_VERSION 2
  29 #include <sys/tihdr.h>
  30 #include <sys/socket.h>
  31 #include <sys/xti_inet.h>
  32 #include <sys/systm.h>
  33 #include <sys/ddi.h>
  34 #include <sys/sunddi.h>
  35 #include <sys/kmem.h>
  36 #include <sys/strsubr.h>
  37 #include <sys/strsun.h>
  38 #include <sys/policy.h>
  39 
  40 #include <inet/common.h>
  41 #include <netinet/ip6.h>
  42 #include <inet/ip.h>
  43 #include <inet/ip_ire.h>
  44 #include <inet/ip_if.h>
  45 #include <inet/proto_set.h>


1476         max = *addrcnt;
1477 
1478         /* If we want only one, give the primary */
1479         if (max == 1) {
1480                 addr = sctp->sctp_primary->sf_faddr;
1481                 switch (family) {
1482                 case AF_INET:
1483                         sin4 = paddrs;
1484                         IN6_V4MAPPED_TO_INADDR(&addr, &sin4->sin_addr);
1485                         sin4->sin_port = connp->conn_fport;
1486                         sin4->sin_family = AF_INET;
1487                         break;
1488 
1489                 case AF_INET6:
1490                         sin6 = paddrs;
1491                         sin6->sin6_addr = addr;
1492                         sin6->sin6_port = connp->conn_fport;
1493                         sin6->sin6_family = AF_INET6;
1494                         sin6->sin6_flowinfo = connp->conn_flowinfo;
1495                         if (IN6_IS_ADDR_LINKSCOPE(&addr) &&
1496                             sctp->sctp_primary != NULL &&
1497                             (sctp->sctp_primary->sf_ixa->ixa_flags &
1498                             IXAF_SCOPEID_SET)) {
1499                                 sin6->sin6_scope_id =
1500                                     sctp->sctp_primary->sf_ixa->ixa_scopeid;
1501                         } else {
1502                                 sin6->sin6_scope_id = 0;
1503                         }
1504                         sin6->__sin6_src_id = 0;
1505                         break;
1506                 }
1507                 return (0);
1508         }
1509 
1510         for (cnt = 0; cnt < max && fp != NULL; cnt++, fp = fp->sf_next) {
1511                 addr = fp->sf_faddr;
1512                 switch (family) {
1513                 case AF_INET:
1514                         ASSERT(IN6_IS_ADDR_V4MAPPED(&addr));
1515                         sin4 = (struct sockaddr_in *)paddrs + cnt;
1516                         IN6_V4MAPPED_TO_INADDR(&addr, &sin4->sin_addr);




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2018, Joyent, Inc.
  28  */
  29 
  30 #include <sys/types.h>
  31 #include <sys/stream.h>
  32 #define _SUN_TPI_VERSION 2
  33 #include <sys/tihdr.h>
  34 #include <sys/socket.h>
  35 #include <sys/xti_inet.h>
  36 #include <sys/systm.h>
  37 #include <sys/ddi.h>
  38 #include <sys/sunddi.h>
  39 #include <sys/kmem.h>
  40 #include <sys/strsubr.h>
  41 #include <sys/strsun.h>
  42 #include <sys/policy.h>
  43 
  44 #include <inet/common.h>
  45 #include <netinet/ip6.h>
  46 #include <inet/ip.h>
  47 #include <inet/ip_ire.h>
  48 #include <inet/ip_if.h>
  49 #include <inet/proto_set.h>


1480         max = *addrcnt;
1481 
1482         /* If we want only one, give the primary */
1483         if (max == 1) {
1484                 addr = sctp->sctp_primary->sf_faddr;
1485                 switch (family) {
1486                 case AF_INET:
1487                         sin4 = paddrs;
1488                         IN6_V4MAPPED_TO_INADDR(&addr, &sin4->sin_addr);
1489                         sin4->sin_port = connp->conn_fport;
1490                         sin4->sin_family = AF_INET;
1491                         break;
1492 
1493                 case AF_INET6:
1494                         sin6 = paddrs;
1495                         sin6->sin6_addr = addr;
1496                         sin6->sin6_port = connp->conn_fport;
1497                         sin6->sin6_family = AF_INET6;
1498                         sin6->sin6_flowinfo = connp->conn_flowinfo;
1499                         if (IN6_IS_ADDR_LINKSCOPE(&addr) &&

1500                             (sctp->sctp_primary->sf_ixa->ixa_flags &
1501                             IXAF_SCOPEID_SET)) {
1502                                 sin6->sin6_scope_id =
1503                                     sctp->sctp_primary->sf_ixa->ixa_scopeid;
1504                         } else {
1505                                 sin6->sin6_scope_id = 0;
1506                         }
1507                         sin6->__sin6_src_id = 0;
1508                         break;
1509                 }
1510                 return (0);
1511         }
1512 
1513         for (cnt = 0; cnt < max && fp != NULL; cnt++, fp = fp->sf_next) {
1514                 addr = fp->sf_faddr;
1515                 switch (family) {
1516                 case AF_INET:
1517                         ASSERT(IN6_IS_ADDR_V4MAPPED(&addr));
1518                         sin4 = (struct sockaddr_in *)paddrs + cnt;
1519                         IN6_V4MAPPED_TO_INADDR(&addr, &sin4->sin_addr);