Print this page
8485 Remove set but unused variables in usr/src/cmd
   1 /*

   2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Licensed under the Academic Free License version 2.1
   5  */
   6 
   7 #include <stdio.h>
   8 #include <stdlib.h>
   9 #include <unistd.h>
  10 #include <signal.h>
  11 #include <string.h>
  12 #include <sys/types.h>
  13 #include <sys/socket.h>
  14 #include <sys/ioctl.h>
  15 #include <sys/sockio.h>
  16 #include <net/if.h>
  17 #include <net/if_arp.h>
  18 #include <netinet/in.h>
  19 #include <arpa/inet.h>
  20 #include <netdb.h>
  21 


  96         return (test_socket_access(ipv6addr, port));
  97 }
  98 
  99 static char *
 100 addr_to_string(char *prefix, uchar_t *mac, int mac_len, char *buf, int buf_len)
 101 {
 102         int i, n = 0;
 103 
 104         buf[0] = '\0';
 105         if (prefix != NULL)
 106                 n = sprintf(buf, prefix);
 107         for (i = 0; ((i < (mac_len)) && (n < buf_len)); i++)
 108                 n += sprintf(buf + n, "%2.2X", *mac++);
 109 
 110         return (buf);
 111 }
 112 
 113 static char *
 114 pseudo_serialno_from_addr(char *name)
 115 {
 116         int sd, rc, errnum;
 117         char buf[128];
 118         struct hostent *hp;
 119         struct xarpreq ar;
 120 
 121         if (name == NULL)
 122                 return (NULL);
 123 
 124         memset(&ar, 0, sizeof (ar));
 125 
 126         hp = getipnodebyname(name, AF_INET6, AI_ADDRCONFIG, &errnum);
 127         if (hp != NULL) {
 128                 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ar.xarp_pa;
 129 
 130                 sin6->sin6_family = AF_INET6;
 131                 (void) memcpy(&sin6->sin6_addr, hp->h_addr_list[0],
 132                                 hp->h_length);
 133         } else {
 134                 struct sockaddr_in *sin = (struct sockaddr_in *)&ar.xarp_pa;
 135 
 136                 sin->sin_family = AF_INET;
 137                 sin->sin_addr.s_addr = inet_addr(name);
 138         }
 139 
 140         sd = socket(AF_INET, SOCK_DGRAM, 0);
 141 
 142         ar.xarp_ha.sdl_family = AF_LINK;
 143         rc = ioctl(sd, SIOCGXARP, (caddr_t)&ar);
 144 
 145         close(sd);
 146 
 147         if (ar.xarp_flags & ATF_COM) {  /* use the MAC address */
 148                 uchar_t *ea = (uchar_t *)LLADDR(&ar.xarp_ha);
 149 
 150                 addr_to_string("LLADDR-", ea, ar.xarp_ha.sdl_alen,
 151                                         buf, sizeof (buf));
 152 
 153         } else if (hp != NULL) {          /* use the IPv6 address */
 154                 addr_to_string("IPV6ADDR-", (uchar_t *)&hp->h_addr_list[0],
 155                                         hp->h_length, buf, sizeof (buf));
 156         } else {                          /* use the IPv4 address */
 157                 struct sockaddr_in *sin = (struct sockaddr_in *)&ar.xarp_pa;
 158 
 159                 addr_to_string("IPV4ADDR-", (uchar_t *)&sin->sin_addr.s_addr, 4,
 160                                         buf, sizeof (buf));
 161         }
 162 
 163         return (strdup(buf));


   1 /*
   2  * Copyright 2017 Gary Mills
   3  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Licensed under the Academic Free License version 2.1
   6  */
   7 
   8 #include <stdio.h>
   9 #include <stdlib.h>
  10 #include <unistd.h>
  11 #include <signal.h>
  12 #include <string.h>
  13 #include <sys/types.h>
  14 #include <sys/socket.h>
  15 #include <sys/ioctl.h>
  16 #include <sys/sockio.h>
  17 #include <net/if.h>
  18 #include <net/if_arp.h>
  19 #include <netinet/in.h>
  20 #include <arpa/inet.h>
  21 #include <netdb.h>
  22 


  97         return (test_socket_access(ipv6addr, port));
  98 }
  99 
 100 static char *
 101 addr_to_string(char *prefix, uchar_t *mac, int mac_len, char *buf, int buf_len)
 102 {
 103         int i, n = 0;
 104 
 105         buf[0] = '\0';
 106         if (prefix != NULL)
 107                 n = sprintf(buf, prefix);
 108         for (i = 0; ((i < (mac_len)) && (n < buf_len)); i++)
 109                 n += sprintf(buf + n, "%2.2X", *mac++);
 110 
 111         return (buf);
 112 }
 113 
 114 static char *
 115 pseudo_serialno_from_addr(char *name)
 116 {
 117         int sd, errnum;
 118         char buf[128];
 119         struct hostent *hp;
 120         struct xarpreq ar;
 121 
 122         if (name == NULL)
 123                 return (NULL);
 124 
 125         memset(&ar, 0, sizeof (ar));
 126 
 127         hp = getipnodebyname(name, AF_INET6, AI_ADDRCONFIG, &errnum);
 128         if (hp != NULL) {
 129                 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ar.xarp_pa;
 130 
 131                 sin6->sin6_family = AF_INET6;
 132                 (void) memcpy(&sin6->sin6_addr, hp->h_addr_list[0],
 133                                 hp->h_length);
 134         } else {
 135                 struct sockaddr_in *sin = (struct sockaddr_in *)&ar.xarp_pa;
 136 
 137                 sin->sin_family = AF_INET;
 138                 sin->sin_addr.s_addr = inet_addr(name);
 139         }
 140 
 141         sd = socket(AF_INET, SOCK_DGRAM, 0);
 142 
 143         ar.xarp_ha.sdl_family = AF_LINK;
 144         (void) ioctl(sd, SIOCGXARP, (caddr_t)&ar);
 145 
 146         close(sd);
 147 
 148         if (ar.xarp_flags & ATF_COM) {  /* use the MAC address */
 149                 uchar_t *ea = (uchar_t *)LLADDR(&ar.xarp_ha);
 150 
 151                 addr_to_string("LLADDR-", ea, ar.xarp_ha.sdl_alen,
 152                                         buf, sizeof (buf));
 153 
 154         } else if (hp != NULL) {          /* use the IPv6 address */
 155                 addr_to_string("IPV6ADDR-", (uchar_t *)&hp->h_addr_list[0],
 156                                         hp->h_length, buf, sizeof (buf));
 157         } else {                          /* use the IPv4 address */
 158                 struct sockaddr_in *sin = (struct sockaddr_in *)&ar.xarp_pa;
 159 
 160                 addr_to_string("IPV4ADDR-", (uchar_t *)&sin->sin_addr.s_addr, 4,
 161                                         buf, sizeof (buf));
 162         }
 163 
 164         return (strdup(buf));