Print this page
10108 libstmfproxy needs smatch fixes


   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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 




  26 #include <stdio.h>
  27 #include <stdlib.h>
  28 #include <string.h>
  29 #include <strings.h>
  30 #include <sys/types.h>
  31 #include <errno.h>
  32 #include <syslog.h>
  33 #include <unistd.h>
  34 #include <sys/types.h>
  35 #include <sys/socket.h>
  36 #include <sys/time.h>
  37 #include <netinet/in.h>
  38 #include <arpa/inet.h>
  39 #include <netdb.h>
  40 #include <sys/stat.h>
  41 #include <sys/sdt.h>
  42 #include <signal.h>
  43 #include <fcntl.h>
  44 #include <libstmfproxy.h>
  45 


 104 
 105                 if (bind(sfd, (struct sockaddr *)&serv_addr,
 106                     sizeof (serv_addr)) < 0) {
 107                         syslog(LOG_DAEMON|LOG_WARNING, "bind() call failed: %d",
 108                             errno);
 109                         goto serv_out;
 110                 }
 111 
 112                 (void) listen(sfd, 5);
 113 
 114                 new_sfd = accept(sfd, (struct sockaddr *)&cli_addr, &cliLen);
 115 
 116                 if (new_sfd < 0) {
 117                         syslog(LOG_DAEMON|LOG_WARNING, "accept failed: %d",
 118                             errno);
 119                         goto serv_out;
 120                 }
 121                 sh = malloc(sizeof (*sh));
 122                 sh->sockfd = new_sfd;
 123 serv_out:
 124                 close(sfd);
 125         } else {
 126                 struct  hostent *hp;
 127 
 128                 /*
 129                  * Assume IP dot notation or if that fails, gethostbyname()
 130                  * If that fails, return
 131                  */
 132                 if ((inet_aton(server, &sin.sin_addr)) == 0) {
 133                         if ((hp = gethostbyname(server)) != NULL) {
 134                                 memcpy(&sin.sin_addr.s_addr, hp->h_addr,
 135                                     hp->h_length);
 136                         } else {
 137                                 syslog(LOG_DAEMON|LOG_CRIT,
 138                                     "Cannot get IP address for %s", server);
 139                                 (void) close(sfd);
 140                                 return (NULL);
 141                         }
 142                 } else {
 143                         fprintf(stderr,
 144                             "Sorry, cannot use ip address format\n");
 145                         (void) close(sfd);
 146                         return (NULL);
 147                 }
 148                 sin.sin_family = AF_INET;
 149                 /* XXX pass in from smf */
 150                 sin.sin_port = htons(6543);
 151 
 152                 while (connect(sfd, (struct sockaddr *)&sin,
 153                     sizeof (sin)) < 0) {
 154                         close(sfd);
 155                         if (errno == ECONNREFUSED) {
 156                                 /* get a fresh socket and retry */
 157                                 sfd = socket(AF_INET, SOCK_STREAM, 0);
 158                                 if (sfd < 0) {
 159                                         syslog(LOG_DAEMON|LOG_WARNING,
 160                                             "socket() call failed: %d", errno);
 161                                         return (NULL);
 162                                 }
 163                                 sleep(2);
 164                         } else {
 165                                 syslog(LOG_DAEMON|LOG_CRIT,
 166                                     "Cannot connect %s - %d", server, errno);
 167                                 return (NULL);
 168                         }
 169                 }
 170                 sh = malloc(sizeof (*sh));
 171                 sh->sockfd = sfd;
 172         }
 173         return (sh);
 174 }
 175 
 176 pt_ops_t pt_socket_ops = {
 177         pt_socket_connect,
 178         pt_socket_send,
 179         pt_socket_recv
 180 };
 181 
 182 int
 183 stmf_proxy_transport_init(char *transport, pt_ops_t **pt_ops)


   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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2018, Joyent, Inc.
  28  */
  29 
  30 #include <stdio.h>
  31 #include <stdlib.h>
  32 #include <string.h>
  33 #include <strings.h>
  34 #include <sys/types.h>
  35 #include <errno.h>
  36 #include <syslog.h>
  37 #include <unistd.h>
  38 #include <sys/types.h>
  39 #include <sys/socket.h>
  40 #include <sys/time.h>
  41 #include <netinet/in.h>
  42 #include <arpa/inet.h>
  43 #include <netdb.h>
  44 #include <sys/stat.h>
  45 #include <sys/sdt.h>
  46 #include <signal.h>
  47 #include <fcntl.h>
  48 #include <libstmfproxy.h>
  49 


 108 
 109                 if (bind(sfd, (struct sockaddr *)&serv_addr,
 110                     sizeof (serv_addr)) < 0) {
 111                         syslog(LOG_DAEMON|LOG_WARNING, "bind() call failed: %d",
 112                             errno);
 113                         goto serv_out;
 114                 }
 115 
 116                 (void) listen(sfd, 5);
 117 
 118                 new_sfd = accept(sfd, (struct sockaddr *)&cli_addr, &cliLen);
 119 
 120                 if (new_sfd < 0) {
 121                         syslog(LOG_DAEMON|LOG_WARNING, "accept failed: %d",
 122                             errno);
 123                         goto serv_out;
 124                 }
 125                 sh = malloc(sizeof (*sh));
 126                 sh->sockfd = new_sfd;
 127 serv_out:
 128                 (void) close(sfd);
 129         } else {
 130                 struct  hostent *hp;
 131 
 132                 /*
 133                  * Assume IP dot notation or if that fails, gethostbyname()
 134                  * If that fails, return
 135                  */
 136                 if ((inet_aton(server, &sin.sin_addr)) == 0) {
 137                         if ((hp = gethostbyname(server)) != NULL) {
 138                                 memcpy(&sin.sin_addr.s_addr, hp->h_addr,
 139                                     hp->h_length);
 140                         } else {
 141                                 syslog(LOG_DAEMON|LOG_CRIT,
 142                                     "Cannot get IP address for %s", server);
 143                                 (void) close(sfd);
 144                                 return (NULL);
 145                         }
 146                 } else {
 147                         fprintf(stderr,
 148                             "Sorry, cannot use ip address format\n");
 149                         (void) close(sfd);
 150                         return (NULL);
 151                 }
 152                 sin.sin_family = AF_INET;
 153                 /* XXX pass in from smf */
 154                 sin.sin_port = htons(6543);
 155 
 156                 while (connect(sfd, (struct sockaddr *)&sin,
 157                     sizeof (sin)) < 0) {
 158                         (void) close(sfd);
 159                         if (errno == ECONNREFUSED) {
 160                                 /* get a fresh socket and retry */
 161                                 sfd = socket(AF_INET, SOCK_STREAM, 0);
 162                                 if (sfd < 0) {
 163                                         syslog(LOG_DAEMON|LOG_WARNING,
 164                                             "socket() call failed: %d", errno);
 165                                         return (NULL);
 166                                 }
 167                                 (void) sleep(2);
 168                         } else {
 169                                 syslog(LOG_DAEMON|LOG_CRIT,
 170                                     "Cannot connect %s - %d", server, errno);
 171                                 return (NULL);
 172                         }
 173                 }
 174                 sh = malloc(sizeof (*sh));
 175                 sh->sockfd = sfd;
 176         }
 177         return (sh);
 178 }
 179 
 180 pt_ops_t pt_socket_ops = {
 181         pt_socket_connect,
 182         pt_socket_send,
 183         pt_socket_recv
 184 };
 185 
 186 int
 187 stmf_proxy_transport_init(char *transport, pt_ops_t **pt_ops)