Print this page
inet_pton


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   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  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */



  24 
  25 #include <sys/time.h>
  26 
  27 #if defined(_KERNEL)
  28 #include <sys/ddi.h>
  29 #include <sys/types.h>
  30 #include <sys/sunddi.h>
  31 #include <sys/socket.h>
  32 #include <inet/tcp.h>

  33 #else
  34 #include <stdio.h>
  35 #include <strings.h>
  36 #include <stdlib.h>
  37 #include <errno.h>
  38 #include <sys/types.h>
  39 #include <sys/socket.h>
  40 #include <netinet/in.h>
  41 #include <arpa/inet.h>
  42 #endif
  43 
  44 #include <sys/iscsit/iscsit_common.h>
  45 #include <sys/iscsi_protocol.h>
  46 #include <sys/iscsit/isns_protocol.h>
  47 
  48 void *
  49 iscsit_zalloc(size_t size)
  50 {
  51 #if defined(_KERNEL)
  52         return (kmem_zalloc(size, KM_SLEEP));


 144                         return (NULL);
 145                 }
 146 #else
 147                 tmp_port = strtol(port_str, &errchr, 10);
 148 #endif
 149                 if (tmp_port < 0 || tmp_port > 65535) {
 150                         return (NULL);
 151                 }
 152         } else {
 153                 tmp_port = default_port;
 154         }
 155 
 156         sa->ss_family = af;
 157 
 158         sin = (struct sockaddr_in *)sa;
 159         if (af == AF_INET) {
 160                 if (inet_pton(af, addr_str,
 161                     (void *)&(sin->sin_addr.s_addr)) != 1) {
 162                         return (NULL);
 163                 }
 164                 /*
 165                  * intet_pton does not seem to convert to network
 166                  * order in kernel. This is a workaround until the
 167                  * inet_pton works or we have our own inet_pton function.
 168                  */
 169 #ifdef _KERNEL
 170                 sin->sin_addr.s_addr = ntohl((uint32_t)sin->sin_addr.s_addr);
 171 #endif
 172                 sin->sin_port = htons(tmp_port);
 173         } else {
 174                 sin6 = (struct sockaddr_in6 *)sa;
 175                 if (inet_pton(af, addr_str,
 176                     (void *)&(sin6->sin6_addr.s6_addr)) != 1) {
 177                         return (NULL);
 178                 }
 179                 sin6->sin6_port = htons(tmp_port);
 180         }
 181 
 182         /* successful */
 183         return (sa);
 184 }
 185 
 186 
 187 /*  Functions to convert iSCSI target structures to/from nvlists. */
 188 
 189 #ifndef _KERNEL
 190 int
 191 it_config_to_nv(it_config_t *cfg, nvlist_t **nvl)




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   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  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 /*
  25  * Copyright (c) 2012, Nexenta Systems, Inc. All rights reserved.
  26  */
  27 
  28 #include <sys/time.h>
  29 
  30 #if defined(_KERNEL)
  31 #include <sys/ddi.h>
  32 #include <sys/types.h>
  33 #include <sys/sunddi.h>
  34 #include <sys/socket.h>
  35 #include <inet/tcp.h>
  36 #include <inet/ip.h>
  37 #else
  38 #include <stdio.h>
  39 #include <strings.h>
  40 #include <stdlib.h>
  41 #include <errno.h>
  42 #include <sys/types.h>
  43 #include <sys/socket.h>
  44 #include <netinet/in.h>
  45 #include <arpa/inet.h>
  46 #endif
  47 
  48 #include <sys/iscsit/iscsit_common.h>
  49 #include <sys/iscsi_protocol.h>
  50 #include <sys/iscsit/isns_protocol.h>
  51 
  52 void *
  53 iscsit_zalloc(size_t size)
  54 {
  55 #if defined(_KERNEL)
  56         return (kmem_zalloc(size, KM_SLEEP));


 148                         return (NULL);
 149                 }
 150 #else
 151                 tmp_port = strtol(port_str, &errchr, 10);
 152 #endif
 153                 if (tmp_port < 0 || tmp_port > 65535) {
 154                         return (NULL);
 155                 }
 156         } else {
 157                 tmp_port = default_port;
 158         }
 159 
 160         sa->ss_family = af;
 161 
 162         sin = (struct sockaddr_in *)sa;
 163         if (af == AF_INET) {
 164                 if (inet_pton(af, addr_str,
 165                     (void *)&(sin->sin_addr.s_addr)) != 1) {
 166                         return (NULL);
 167                 }








 168                 sin->sin_port = htons(tmp_port);
 169         } else {
 170                 sin6 = (struct sockaddr_in6 *)sa;
 171                 if (inet_pton(af, addr_str,
 172                     (void *)&(sin6->sin6_addr.s6_addr)) != 1) {
 173                         return (NULL);
 174                 }
 175                 sin6->sin6_port = htons(tmp_port);
 176         }
 177 
 178         /* successful */
 179         return (sa);
 180 }
 181 
 182 
 183 /*  Functions to convert iSCSI target structures to/from nvlists. */
 184 
 185 #ifndef _KERNEL
 186 int
 187 it_config_to_nv(it_config_t *cfg, nvlist_t **nvl)