BUG#: 4691
[tpot/pegasus/.git] / src / slp / slp_client / src / cmd-utils / slp_client / lslp-nucleus.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 nucleus RTOS
33  *
34  *  Originated: December 17, 2001 
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/Attic/lslp-nucleus.h,v 1.4 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
67 #ifndef _LSLP_NUCLEUS_INCL_
68 #define LSLP_NUCLEUS_INCL_
69
70 #ifdef  __cplusplus
71 extern "C" {
72 #endif
73
74
75 #include "time.h"
76
77 #include <ctype.h>
78 #include <stdio.h>
79 #include <stdlib.h>
80 #include <string.h>
81 #include "sp_cmn.hc"
82 #include "tcpsprt.h" //define for net version
83 #include "net\target.h"
84 #include "net\inc\nu_net.h"
85 #include "net\inc\arp.h"
86 #include "net\inc\socketd.h"
87 #include "net\inc\sockdefs.h"
88 //#include "tcpst.hc"
89 UINT32  tcpst_inet_addr(char *);
90
91   /* DELETE these lines after you are ready to proceed ! */
92 //jeb#error "Remember to define the correct BYTE ORDER in the file endian.h"
93 //jeb#error "Check to ensure there is a nucleus implementation of inet_addr(char *) - I can write one if you need it"
94 //jeb#error "Check to ensure there is a nucleus implementation of htons(short int) - I can write one if you need it"
95 //jeb#error "Check to ensure there is a nucleus implementation of inet_ntoa(unsigned int) - I can write one if you need it"
96 //jeb#error "Need a gethostname function (returns a string holding the hostname of the management module)"
97 //jeb#error "prototype is int gethostname(char *buffer, int buffer_size) ; return zero upon success "
98 //jeb#error "need to define _LSLP_STRTOK( char *string, char *delimitors, char **state), which is a thread-safe version of strtok"
99 /* #error "errno is a global variable holding the code for the most recent failure" */
100
101 /*** nucleus include files ***/
102
103 /** below are posix include files that may or may not be appropriate to Nucleus ***/
104 /*** modify to include the correct files for the nucleus runtimes ***/
105 //jeb#include <signal.h>
106 //jeb#include <stdio.h>
107 //jeb#include <stdlib.h>
108 //jeb#include <stdarg.h>
109 //jeb#include <unistd.h> 
110 //jeb#include <time.h>
111 //jeb#include <sys/types.h>
112 //jeb#include <sys/time.h>
113 //jeb#include <netinet/in.h>
114 //jeb#include <arpa/inet.h>
115 //jeb#include <sys/ioctl.h>
116 //jeb#include <sys/socket.h>
117 //jeb#include <sys/select.h>
118 //jeb#include <netdb.h>
119 //jeb#include <assert.h>
120 //jeb#include <memory.h>
121 //jeb#include <string.h>
122 //jeb#include <ctype.h>
123   
124   
125   /*** typedefs ***/
126   typedef char int8;
127   typedef CHAR int8;
128   typedef INT8 int8;
129   
130
131   typedef unsigned char uint8;
132   typedef unsigned char byte;
133   typedef UINT8 uint8;
134
135   typedef short int16;
136   typedef INT16 int16;
137   
138   typedef unsigned short uint16;
139   typedef UINT16 uint16;
140
141   typedef int int32;
142   typedef unsigned long uint32;
143
144 //jeb chg  typedef int INT;
145   typedef int SOCKETD;
146   typedef int SOCKET;
147   
148   
149 /* ATTN << Thu Dec 20 11:35:36 2001 mdd >> */
150
151 #ifdef BOOL   //jeb 
152 #undef BOOL
153   typedef uint32 BOOL;
154 #endif  
155   
156   
157   /* ATTN << Tue Dec 18 09:40:43 2001 mdd >> */
158   /* this is a variable structure that probably has an option
159      id and then a variable sized buffer to hold the results */
160 /*   typedef unsigned int SCK_IOCTL_OPTION ; */
161   
162   /* probably don't need long longs  */
163   /**  typedef __int64 int64; **/
164   /**  typedef unsigned __int64 uint64; **/  //jeb fix
165   
166   typedef int STATUS;
167   
168   struct in_addr 
169   {
170     uint32 s_addr;
171   };
172   
173   typedef struct sockaddr
174   {
175     uint8 sa_len;
176     uint8 sa_family;
177     char sa_data[14];
178   } SOCKADDR ;
179   
180                  
181   typedef struct sockaddr_in     
182   {
183 //jeb    uint8 sin_len;
184     int16 sin_family;
185     uint16 sin_port;
186     struct in_addr sin_addr;
187     char   *sin_zero;
188 //    char sin_zero[8];
189   } SOCKADDR_IN ;
190   
191   struct hostent
192   {
193     char *h_name;
194     char **h_alias;
195     INT16 h_addrtype;
196     INT16 h_length;
197 //    char *h_addr;               //jeb
198     char        **h_addr_list;
199   };
200   
201 //jeb  extern NU_Host_Ent * nucleus_gethostbyname(const char *name);
202 //jeb   extern NU_Host_Ent * nucleus_gethostbyaddr( const void *addr, int len, int type);
203   extern NU_HOSTENT * nucleus_gethostbyname(const char *name);
204   extern NU_HOSTENT * nucleus_gethostbyaddr( const void *addr, int len, int type);
205 #ifndef FALSE
206 #define FALSE 0
207 #endif
208
209 #ifndef TRUE
210 #define TRUE 1
211 #endif
212
213 #define SOCK_DGRAM NU_TYPE_DGRAM
214 #define SOCK_STREAM NU_TYPE_STREAM
215 #define UNUSED_NU_PARM 0
216
217 #define INVALID_SOCKET NU_INVALID_SOCKET 
218 #define SOCKET_ERROR NU_INVALID_SOCKET  
219 //jeb strt add
220 #define AF_INET SK_FAM_IP 
221 #define INADDR_NONE 0 
222 #define INADDR_ANY INADDR_NONE 
223 //jeb end add
224
225 /* ATTN need to define these error constants for nucleus << Tue Dec 18 16:22:28 2001 mdd >> */
226
227 #define EINTR     /* call was interrupted */
228 #define ENOTSOCK INVALID_SOCKET
229 #define EADDRNOTAVAIL 
230 #define EAFNOSUPPORT 
231 #define EISCONN 
232 #define ETIMEDOUT 
233 #define ECONNREFUSED 
234 #define ENETUNREACH 
235 #define EADDRINUSE 
236 #define EINPROGRESS 
237 #define EALREADY 
238 #define EWOULDBLOCK 
239
240
241     /*** function macros ***/
242
243   /*** << Mon Dec 17 17:28:24 2001 mdd >> 
244
245        NOTE: Many of these calls require unused or null values for parameters. 
246        I've substituted (hardcoded) these parameters where I could find them. 
247        This is not very portable nor maintainable; perhaps you will find a better solution !
248
249   ***/
250
251 #define _LSLP_CLOSESOCKET(a)  NU_Close_Socket((int)(a)) 
252 #define _LSLP_SOCKET(a, b, c) NU_Socket( NU_FAMILY_IP, ((INT16)(b)), NU_NONE )
253 //jeb
254 #define _LSLP_BIND(a, b, c) \
255            NU_Bind ((INT)(a),((struct addr_struct *)(b)),UNUSED_NU_PARM )
256 #define _LSLP_CONNECT(a, b, c ) \
257            NU_Connect ((INT)(a), \
258               ((struct addr_struct *)(b)), \
259                     UNUSED_NU_PARM)
260 #define _LSLP_LISTEN(a, b) NU_Listen ((INT)(a), (UINT16)(b))
261 #define _LSLP_ACCEPT(a, b, c) \
262            NU_Accept ((INT)(a), \
263                       ((struct addr_struct *)(b)), \
264                       UNUSED_NU_PARM )
265 #define _LSLP_SEND(a, b, c, d) NU_Send ((INT)(a), (CHAR *)(b), (UINT16)(c), UNUSED_NU_PARM)
266 #define _LSLP_SENDTO(a, b, c, d, e, f) \
267              NU_Send_To ((INT)(a), (char *)(b), (UINT16)(c), (UNUSED_NU_PARM), \
268                          ((struct addr_struct *)(e)), \
269                          UNUSED_NU_PARM )
270 #define _LSLP_RECV(a, b, c, d)  NU_Recv ((INT)(a), (char *)(b), (UINT16)(c), UNUSED_NU_PARM )
271 #define _LSLP_RECV_FROM(a, b, c, d, e, f) \
272              NU_Recv_From ((INT)(a), (char *)(b), (INT16)(c), (UNUSED_NU_PARM), \
273              ((struct addr_struct *)(e)), \
274              UNUSED_NU_PARM)
275
276 /* << Tue Dec 18 07:53:12 2001 mdd >> ATTN need to redefine these gethost functions   */
277 /* for all platforms  */
278
279 #define _LSLP_GETHOSTBYNAME(a) \
280          (struct hostent *) nucleus_gethostbyname((const char *)(a))
281 #define _LSLP_GETHOSTBYADDR(a, b, c ) \
282            (struct hostent *) nucleus_gethostbyaddr( (const void *)(a), (int)(b), (int)(c))
283
284 #define _LSLP_SETSOCKOPT(a, b, c, d, e) \
285              NU_Setsockopt(((INT)(a)), ((INT)(b)), ((INT)(c)), ((void *)(d)), ((INT)(e))) 
286 #define _LSLP_GETSOCKOPT(a, b, c, d, e) \
287              NU_Getsockopt(((INT)(a)), ((INT)(b)), ((INT)(c)), ((void *)(d)), ((INT *)(e)))
288
289 #define _LSLP_SET_TTL(s, t)  NU_Setsockopt((s), IPPROTO_IP, IP_MULTICAST_TTL, (void *)&(t), sizeof((t)))      //jeb
290
291 /* << Tue Dec 18 08:16:59 2001 mdd >> ATTN need to redefine abort to be shutdown & close */
292 #define _LSLP_ABORT(a) NU_Abort(((INT)(a))) 
293
294 #define _LSLP_SLEEP(a) _sleep((int)(a))
295
296 //jeb strtok
297 #define _LSLP_STRTOK(s, d, x) strtok(((char*)(s)),((const char *)(d)))  
298 //jeb assert
299
300 #define SLPDBG
301 //#ifdef SLPDBG
302 //void assert(int);
303 #define assert(a) _system_info((!(a)),"ASSERT:%s/%d", __FILE__, __LINE__)
304 //#else
305 //#define assert(a) ((void)0)
306 //#endif
307
308 #define htons(x)        INTSWAP((unsigned short)(x))
309 #define ntohs(x)    INTSWAP((unsigned short)(x))
310 #define ntohl(x)        LONGSWAP((unsigned long)(x))
311 #define inet_addr(x) tcpst_inet_addr((char *)(x))
312
313 #define _itoa(a,b,c) itoa(((int)(a)),((char*)(b)),((int)(c)))
314 //end jeb
315
316 /* << Tue Dec 18 09:54:25 2001 mdd >> ATTN the final parameter is a pointer on windows */
317 /* and unix, but is an integer on Nucleus that specifies timer ticks */
318
319   struct _lslp_timeval 
320   {
321     uint32 tv_sec;
322     uint32 tv_usec;
323   } ;
324 //jeb 
325   struct timeval 
326   {
327     uint32 tv_sec;
328     uint32 tv_usec;
329   } ;
330 //jeb 
331
332 //jeb  typedef TIMEVAL timeval;
333   
334 #ifdef PLUS
335 #define _LSLP_SELECT(a, b, c, d, e ) \
336              NU_Select(((INT)(a)), ((FD_SET *)(b)), ((FD_SET *)(c)), ((FD_SET *)(d)), \
337                        ((UNSIGNED)(((struct _lslp_timeval *)(e))->tv_usec)))
338 #else 
339 #define _LSLP_SELECT(a, b, c, d, e ) \
340              NU_Select(((INT)(a)), ((FD_SET *)(b)), ((FD_SET *)(c)), ((FD_SET *)(d)), \ 
341                        (sint)((((struct _lslp_timeval *)(e))->tv_usec) & 0x7fffffff  ) )
342 #endif 
343 #define LSLP_FD_SET FD_SET
344 #define _LSLP_FD_ISSET(a, b) NU_FD_Check(((INT)(a)), ((FD_SET *)(b)))
345 #define _LSLP_FD_SET(a, b)  NU_FD_Set(((INT)(a)), ((FD_SET *)(b)))
346 #define _LSLP_FD_ZERO(a) NU_FD_Init(((FD_SET *)(a)))
347 #define _LSLP_FD_CLR(a, b)  NU_FD_Reset(((INT)(a)), ((FD_SET *)(b)))
348
349        
350 /* ATTN << Tue Dec 18 10:42:19 2001 mdd >> */
351
352 //jeb #define _LSLP_IOCTLSOCKET(a, b, c) #error "See Nucleus NET Reference Manual for limitations on usage of ioctl\n"
353
354 /* ATTN << Tue Dec 18 12:54:40 2001 mdd >> */
355 #define _LSLP_GETLASTERROR() 
356
357
358   /***** 
359
360   We probably don't need these to be defined << Tue Dec 18 16:21:23 2001 mdd >> 
361
362   STATUS NU_Send_To_Raw(INT socketd, char *buff, UINT16 nbytes, INT16 flags,
363   struct addr_struct *to, INT16 addrlen);
364   
365   INT16  NU_Get_IPRaw_PCB(INT socketd, struct sock_struct *);
366   
367   jeb start add
368   STATUS NU_Recv_From_No_Suspend (INT16, char *, INT16, INT16, struct addr_struct *, INT16 *);
369   STATUS NU_Find_Open_Sckts_For_Dev (UINT8 sck_type, INT skt, DV_DEVICE_ENTRY *dev_ptr);
370   jeb end add
371   
372   STATUS NU_Recv_From_Raw (INT, char *, INT16, INT16, struct addr_struct *, INT16 *);
373   
374   STATUS NU_Push (INT);
375   STATUS NU_Is_Connected (INT);
376   INT16  NU_GetPnum (struct sock_struct *);
377   INT16  NU_Get_UDP_Pnum (struct sock_struct *);
378   STATUS NU_Fcntl (INT socketd, INT16 command, INT16 arguement);
379   STATUS NU_Get_Peer_Name(INT, struct sockaddr_struct *, INT16 *);
380     
381   *****/
382
383 //prototypes  //jeb
384 char *inet_ntoa(struct in_addr in);
385
386
387
388 #ifdef  __cplusplus
389 }
390 #endif
391
392 #endif /* nucleus include */