1 //%2006////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //==============================================================================
31 /*****************************************************************************
32 * Description: portability routines for WINDOZE
34 * Originated: December 31, 1999
35 * Original Author: Mike Day md@soft-hackle.net
37 * $Header: /cvs/MSB/pegasus/src/slp/slp_client/src/cmd-utils/slp_client/lslp-windows.h,v 1.10 2006/01/31 14:50:42 karl Exp $
39 * Copyright (c) 2001 - 2003 IBM
40 * Copyright (c) 2000 - 2003 Michael Day
42 * Permission is hereby granted, free of charge, to any person obtaining a
43 * copy of this software and associated documentation files (the "Software"),
44 * to deal in the Software without restriction, including without limitation
45 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
46 * and/or sell copies of the Software, and to permit persons to whom the
47 * Software is furnished to do so, subject to the following conditions:
49 * The above copyright notice and this permission notice shall be included in
50 * all copies or substantial portions of the Software.
53 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
56 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
58 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
59 * DEALINGS IN THE SOFTWARE.
61 *****************************************************************************/
66 #ifndef _LSLP_WINDOWS_INCL_
67 #define _LSLP_WINDOWS_INCL_
74 #define WIN32_LEAN_AND_MEAN
80 #include <process.h> /* _beginthread, _endthread */
83 #include <sys/types.h>
84 #include <sys/timeb.h>
92 typedef unsigned char uint8;
95 typedef unsigned short uint16;
97 typedef unsigned int uint32;
98 typedef __int64 int64;
99 typedef unsigned __int64 uint64;
100 typedef SOCKET SOCKETD;
102 typedef struct socket_address {
103 struct sockaddr_in *address;
107 typedef struct socket_address_list {
112 void WindowsStartNetwork(void);
113 /* int32 gettimeofday(struct timeval *tv, struct timezone *tz); */
115 /* WIN 32 macros for mutex semaphore */
116 #define _LSLP_CREATE_MUTEX(h) \
117 (((h) = CreateMutex(NULL, FALSE, NULL)) ? 0 : -1)
118 #define _LSLP_CLOSE_MUTEX(h) \
119 if((h) != 0){ReleaseMutex((HANDLE)(h));CloseHandle((HANDLE)(h)); (h) = 0;}
120 #define LSLP_DEFAULT_WAIT 100
121 #define LSLP_EXTRA_WAIT 250
122 /* h = handle, m = milliseconds, c = pointer to completion code */
123 #define _LSLP_WAIT_MUTEX(h, m, c) \
124 if((h) != 0){(*(c)) = WaitForSingleObject((HANDLE)(h), (m));}
125 #define _LSLP_RELEASE_MUTEX(h) \
126 if((h) != 0) {ReleaseMutex((HANDLE)(h));}
127 #define _LSLP_DUP_MUTEX(h, n) \
129 {DuplicateHandle(GetCurrentProcess(), (h), GetCurrentProcess(), (n), \
130 0, TRUE, DUPLICATE_SAME_ACCESS | MUTEX_ALL_ACCESS | SYNCHRONIZE);}
131 #define _LSLP_CREATE_SEM(h, i) \
132 (((h) = (uint32)CreateSemaphore(NULL, (i), 0x0000ffff, NULL)) ? 0 : -1)
133 /* h = handle, m = milliseconds, c = pointer to completion code */
134 #define _LSLP_WAIT_SEM(h, m, c) \
135 if((h) != 0){(*(c)) = WaitForSingleObject((HANDLE)(h), (m));}
136 #define _LSLP_SIGNAL_SEM(h) \
137 ReleaseSemaphore((HANDLE)(h), 1, NULL)
138 #define _LSLP_CLOSE_SEM(h) \
139 {if((h) != 0){ReleaseSemaphore((HANDLE)(h), 0x0000fff0, NULL); CloseHandle((HANDLE)(h)); (h) = 0;}}
141 #define LSLP_SEM_T HANDLE
142 #define LSLP_THREAD_T HANDLE
143 #define LSLP_WAIT_FAILED WAIT_FAILED
144 #define LSLP_WAIT_OK WAIT_OBJECT_0
145 #define LSLP_WAIT_TIMEOUT WAIT_TIMEOUT
146 #define LSLP_WAIT_ABANDONDED WAIT_ABANDONED
148 /* void SLEEP(int32 milliseconds) */
149 #define _LSLP_SLEEP Sleep
150 #define _LSLP_SET_TTL(s, t) setsockopt((s), IPPROTO_IP, IP_MULTICAST_TTL, (const char *)&(t), sizeof((t)))
152 /* void *(*start)(void *), ustacksize, void *arg */
153 #define _LSLP_BEGINTHREAD(start, stacksize, arg) _beginthread((start), (stacksize), (arg))
154 #define _LSLP_ENDTHREAD _endthread
156 #define _LSLP_STRTOK(n, d, s) strtok((n), (d) )
157 #define _LSLP_SIG_ACTION()
158 #define _LSLP_SIG_ACTION_THREAD()
159 #define _LSLP_PUSH_HANDLER(a, b)
160 #define _LSLP_POP_HANDLER(a, b)
162 #define strncasecmp strnicmp
164 /* maximum path length */
165 #define LSLP_MAXPATH _MAX_PATH
166 #define LSLP_NEWLINE \r\n
170 #define ENOTSOCK WSAENOTSOCK
171 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
172 #define EAFNOSUPPORT WSAEAFNOSUPPORT
173 #define EISCONN WSAEISCONN
174 #define ETIMEDOUT WSAETIMEDOUT
175 #define ECONNREFUSED WSAECONNREFUSED
176 #define ENETUNREACH WSAENETUNREACH
177 #define EADDRINUSE WSAEADDRINUSE
178 #define EINPROGRESS WSAEINPROGRESS
179 #define EALREADY WSAEALREADY
180 #define EWOULDBLOCK WSAEWOULDBLOCK
182 #define _LSLP_GETLASTERROR() WSAGetLastError()
184 #define _LSLP_INIT_NETWORK WindowsStartNetwork
185 #define _LSLP_DEINIT_NETWORK WSACleanup
187 #define _LSLP_SOCKET(a, b, c) socket(((int)(a)), ((int)(b)), ((int)(c)))
188 #define _LSLP_CLOSESOCKET closesocket
189 #define _LSLP_BIND(a, b, c) bind(((SOCKET)(a)), ((const struct sockaddr *)(b)), ((int)(c)))
190 #define _LSLP_CONNECT(a, b, c) connect(((SOCKET)(a)), ((const struct sockaddr *)(b)), ((int)(c)))
191 #define _LSLP_LISTEN(a, b) listen(((SOCKET)(a)), ((int)(b)))
192 #define _LSLP_ACCEPT(a, b, c) accept(((SOCKET)(a)), ((struct sockaddr *)(b)), ((int *)(c)))
193 #define _LSLP_SEND(a, b, c, d) send(((SOCKET)(a)), ((const char *)(b)), ((int)(c)), ((int)(d)))
194 #define _LSLP_SENDTO(a, b, c, d, e, f) \
195 sendto(((SOCKET)(a)), ((const char *)(b)), ((int)(c)), ((int)(d)), \
196 ((const struct sockaddr *)(e)), ((int)(f)))
197 #define _LSLP_RECV(a, b, c, d) recv(((SOCKET)(a)), ((const char *)(b)), ((int)(c)), ((int)(d)))
198 #define _LSLP_RECV_FROM(a, b, c, d, e, f) \
199 recvfrom(((SOCKET)(a)), ((char *)(b)), ((int)(c)), ((int)(d)), \
200 ((struct sockaddr *)(e)), ((int *)(f)))
202 #define _LSLP_GETHOSTBYNAME(a, b) /* ATTN << Tue Dec 18 13:26:09 2001 mdd >> */
203 #define _LSLP_GETHOSTBYADDR(a, b, c, d) /* ATTN << Tue Dec 18 13:26:49 2001 mdd >> */
205 #define _LSLP_SETSOCKOPT(a, b, c, d, e) \
206 setsockopt(((SOCKET)(a)), ((int)(b)), ((int)(c)), ((const char *)(d)), ((int)(e)))
207 #define _LSLP_GETSOCKOPT(a, b, c, d, e) \
208 getsockopt(((SOCKET)(a)), ((int)(b)), ((int)(c)), ((char *)(d)), ((int *)(e)))
209 #define _LSLP_ABORT(a) { shutdown(((SOCKET)(a)), SD_BOTH ) ; closesocket((SOCKET)(a)) }
210 #define _LSLP_SELECT(a, b, c, d, e) \
211 select(((int)(a)), ((fd_set *)(b)), ((fd_set *)(c)), \
212 ((fd_set *)(d)), ((const struct timeval *)(e)))
213 #define _LSLP_FD_ISSET(a, b) FD_ISSET(((SOCKET)(a)), ((fd_set *)(b)))
214 #define _LSLP_FD_SET(a, b) FD_SET(((SOCKET)(a)), ((fd_set *)(b)))
215 #define _LSLP_FD_ZERO(a) FD_ZERO((fd_set *)(a))
216 #define _LSLP_FD_CLR(a, b) FD_CLR(((SOCKET)(a)), ((fd_set *)(b)))
218 #define _LSLP_IOCTLSOCKET ioctlsocket
219 #define LSLP_MTU 4096
221 #define LSLP_FD_SET fd_set
222 #define strcasecmp _stricmp
224 /* ascii and char tests and conversions */
226 #define _LSLP_ISASCII(a) __isascii(a)
232 #endif /*_LSLP_WINDOWS_INCL_*/