3 Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice (including the next
13 paragraph) shall be included in all copies or substantial portions of the
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
27 Copyright 1993, 1998 The Open Group
29 Permission to use, copy, modify, distribute, and sell this software and its
30 documentation for any purpose is hereby granted without fee, provided that
31 the above copyright notice appear in all copies and that both that
32 copyright notice and this permission notice appear in supporting
35 The above copyright notice and this permission notice shall be included in
36 all copies or substantial portions of the Software.
38 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
42 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 Except as contained in this notice, the name of The Open Group shall not be
46 used in advertising or otherwise to promote the sale, use or other dealings
47 in this Software without prior written authorization from The Open Group.
52 * Author: Ralph Mor, X Consortium
61 #include <X11/SM/SMlib.h>
64 #include <X11/Xthreads.h>
73 #if defined(TCPCONN) || defined(STREAMSCONN)
75 #include <sys/socket.h>
79 #include <netinet/in.h>
80 #include <arpa/inet.h>
81 #define XOS_USE_NO_LOCKING
82 #define X_INCLUDE_NETDB_H
83 #include <X11/Xos_r.h>
88 #include <X11/Xwinsock.h>
89 #include <X11/Xw32defs.h>
90 #define X_INCLUDE_NETDB_H
91 #define XOS_USE_MTSAFE_NETDBAPI
92 #include <X11/Xos_r.h>
97 #include <net/gen/netdb.h>
102 #if defined(HAVE_UUID_CREATE)
104 #elif defined(HAVE_LIBUUID)
105 #include <uuid/uuid.h>
110 SmsGenerateClientID(SmsConn smsConn)
112 #if defined(HAVE_UUID_CREATE)
118 uuid_create(&uuid, &status);
120 uuid_to_string(&uuid, &temp, &status);
122 if ((id = malloc (strlen (temp) + 2)) != NULL)
131 #elif defined(HAVE_LIBUUID)
140 uuid_unparse_lower(uuid, &temp[1]);
142 if ((id = malloc (strlen (temp) + 1)) != NULL)
147 #if defined(TCPCONN) || defined(STREAMSCONN)
148 static const char hex[] = "0123456789abcdef";
150 char address[64], *addr_ptr = address;
153 static int sequence = 0;
155 if (gethostname (hostname, sizeof (hostname)))
160 char temp[4], *ptr1, *ptr2;
161 unsigned char decimal[4];
163 struct in_addr *haddr = NULL;
164 #if defined(IPv6) && defined(AF_INET6)
165 struct addrinfo *ai, *first_ai;
166 if (getaddrinfo(hostname,NULL,NULL,&ai) != 0)
169 for (first_ai = ai; ai != NULL; ai = ai->ai_next) {
170 if ( (ai->ai_family == AF_INET) || (ai->ai_family == AF_INET6) )
174 freeaddrinfo(first_ai);
178 if (ai->ai_family == AF_INET6) {
179 unsigned char *cp = (unsigned char *) &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr.s6_addr;
181 *addr_ptr++ = '6'; /* IPv6 address code */
183 for (i = 0 ; i < 16 ; i++) {
184 *addr_ptr++ = hex[cp[i] >> 4];
185 *addr_ptr++ = hex[cp[i] & 0x0f];
190 } else { /* Fall through to IPv4 address handling */
191 haddr = &((struct sockaddr_in *)ai->ai_addr)->sin_addr;
193 #ifdef XTHREADS_NEEDS_BYNAMEPARAMS
194 _Xgethostbynameparams hparams;
196 struct hostent *hostp;
198 if ((hostp = _XGethostbyname (hostname,hparams)) != NULL)
199 haddr = (struct in_addr *)(hostp->h_addr);
204 inet_addr = inet_ntoa (*haddr);
205 for (i = 0, ptr1 = inet_addr; i < 3; i++)
207 ptr2 = strchr (ptr1, '.');
209 if (!ptr2 || len > 3) {
210 #if defined(IPv6) && defined(AF_INET6)
211 freeaddrinfo(first_ai);
215 strncpy (temp, ptr1, len);
217 decimal[i] = atoi (temp);
221 decimal[3] = atoi (ptr1);
225 for (i = 0; i < 4; i++) {
226 *addr_ptr++ = hex[decimal[i] >> 4];
227 *addr_ptr++ = hex[decimal[i] & 0x0f];
232 #if defined(IPv6) && defined(AF_INET6)
234 freeaddrinfo(first_ai);
238 sprintf (temp, "1%s%.13ld%.10ld%.4d", address, (long)time((Time_t*)0),
239 (long)getpid(), sequence);
241 if (++sequence > 9999)
244 if ((id = malloc (strlen (temp) + 1)) != NULL)