BUG#: 4691
[tpot/pegasus/.git] / src / slp / slp_client / src / cmd-utils / slp_client / lslp-windows.h
1 //%2006////////////////////////////////////////////////////////////////////////
2 //
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.
13 //
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:
20 // 
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.
29 //
30 //==============================================================================
31 /*****************************************************************************
32  *  Description:   portability routines for WINDOZE
33  *
34  *  Originated: December 31, 1999 
35  *      Original Author: Mike Day md@soft-hackle.net
36  *                                mdday@us.ibm.com 
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 $                                                              
38  *                                                                          
39  *  Copyright (c) 2001 - 2003  IBM                                          
40  *  Copyright (c) 2000 - 2003 Michael Day                                    
41  *                                                                           
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:       
48  * 
49  *  The above copyright notice and this permission notice shall be included in 
50  *  all copies or substantial portions of the Software.
51  * 
52  * 
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.
60  *
61  *****************************************************************************/
62
63
64
65
66 #ifndef _LSLP_WINDOWS_INCL_
67 #define _LSLP_WINDOWS_INCL_
68
69 #ifdef _WIN32 
70 #ifndef _MT
71 #define _MT
72 #endif
73
74 #define WIN32_LEAN_AND_MEAN
75
76 #include <winsock2.h>
77 #include <ws2tcpip.h>
78 #include <stdio.h>
79 #include <stdlib.h>
80 #include <process.h>    /* _beginthread, _endthread */
81 #include <winbase.h>
82 #include <tchar.h>
83 #include <sys/types.h> 
84 #include <sys/timeb.h> 
85 #include <assert.h>
86 #include <errno.h>
87
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91
92 typedef unsigned char uint8;
93 typedef uint8 byte;
94 typedef short int16;
95 typedef unsigned short uint16;
96 typedef int int32;
97 typedef unsigned int uint32;
98 typedef __int64 int64;
99 typedef unsigned __int64 uint64;
100 typedef SOCKET SOCKETD;
101   
102 typedef struct socket_address {
103   struct sockaddr_in *address;
104   int address_len;
105 } socket_addr ;
106
107 typedef struct socket_address_list {
108   int count;
109   socket_addr *list;
110 } socket_addr_list; 
111
112 void WindowsStartNetwork(void);
113 /* int32 gettimeofday(struct timeval *tv, struct timezone *tz); */
114
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) \
128         if ((h) != 0)            \
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;}}
140
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
147
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))) 
151
152 /* void *(*start)(void *), ustacksize, void *arg           */
153 #define _LSLP_BEGINTHREAD(start, stacksize, arg) _beginthread((start), (stacksize), (arg)) 
154 #define _LSLP_ENDTHREAD  _endthread 
155
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)
161
162 #define strncasecmp strnicmp
163
164 /* maximum path length */
165 #define LSLP_MAXPATH _MAX_PATH
166 #define LSLP_NEWLINE \r\n
167 #endif   /* WIN 32 */
168
169
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
181
182 #define _LSLP_GETLASTERROR() WSAGetLastError()
183
184 #define _LSLP_INIT_NETWORK WindowsStartNetwork
185 #define _LSLP_DEINIT_NETWORK WSACleanup
186
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)))
201
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 >> */
204
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)))
217
218 #define _LSLP_IOCTLSOCKET ioctlsocket
219 #define LSLP_MTU 4096
220
221 #define LSLP_FD_SET fd_set
222 #define strcasecmp _stricmp
223
224 /* ascii and char tests and conversions */
225
226 #define _LSLP_ISASCII(a) __isascii(a)
227
228 #ifdef  __cplusplus
229 }
230 #endif
231
232 #endif /*_LSLP_WINDOWS_INCL_*/
233