-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptp.h
More file actions
511 lines (433 loc) · 12.2 KB
/
Copy pathptp.h
File metadata and controls
511 lines (433 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
/* CMS REPLACEMENT HISTORY, Element PTP.H*/
/* *4 15-SEP-2003 14:26:30 RD2JK "Reverted back to CRTL"*/
/* *3 15-SEP-2003 12:11:54 RD2JK "Replaced CRTL file i/o for windows with win32 api calls"*/
/* *2 29-JUL-2003 10:14:20 RD2JK ""*/
/* *1 25-JUL-2003 15:58:05 RD2JK "POINTTPOINT API HEADER FILE"*/
/* CMS REPLACEMENT HISTORY, Element PTP.H*/
/**************************************************************
* Point to Point API
*
* Written : James Kyburz 13-Feb-2002
* Function : API for sending and receiveing TCP/IP
* stream data.
* includes TCP/IP server ( gatekeeper )
* Version : 1.0
* Modifications :
*
*************************************************************/
#ifndef PTP_H
#define PTP_H
#define PTP_VER "1.0"
#ifdef WIN32
#define V_M_S 0
#define L_I_N_U_X 0
#define W_I_N 1
#define U_N_I_X 0
#define M_A_C 0
#endif
#ifdef _MAC
#define V_M_S 0
#define L_I_N_U_X 0
#define W_I_N 0
#define U_N_I_X 0
#define M_A_C 1
#endif
#ifdef __VMS_VER
#define V_M_S 1
#define L_I_N_U_X 0
#define W_I_N 0
#define U_N_I_X 0
#define M_A_C 0
#endif
#ifdef linux
#define V_M_S 0
#define L_I_N_U_X 1
#define W_I_N 0
#define U_N_I_X 0
#define M_A_C 0
#endif
#ifdef UNIX
#define V_M_S 0
#define L_I_N_U_X 0
#define W_I_N 0
#define U_N_I_X 1
#define M_A_C 0
#endif
#if V_M_S
#elif W_I_N
#elif L_I_N_U_X
#elif U_N_I_X
#elif M_A_C
#else #error "Platform not supported"
#endif
#if W_I_N
#define PTP_IOCTL ioctlsocket
#define PTPINPROGRESS WSAEINPROGRESS
#define PTP_SET_ERROR(x) WSASetLastError(x)
#ifndef PTP_IMANAGER
#define PTP_IMANAGER 0x00
#endif
#define PTP_ERROR WSAGetLastError()
#define PTP_STARTUP_LOG "C:/PTPStartupLog"
#elif V_M_S
#define PTP_IOCTL ioctl
#define PTPINPROGRESS EINPROGRESS
#define PTP_IMANAGER 0x00
#define PTP_STARTUP_LOG "SYS$LOGIN:PTPStartupLog"
#define PTP_ERROR errno
#define PTP_SET_ERROR(x) errno = x
#else
#define PTP_IOCTL ioctl
#define PTPINPROGRESS EINPROGRESS
#define PTP_IMANAGER 0x00
#define PTP_STARTUP_LOG "PTPStartupLog.TXT"
#define PTP_ERROR errno
#define PTP_SET_ERROR(x) errno = x
#endif
/* Windows compilation using VS 6.0 / VS.NET Link with wsock32.lib */
/* define error constants for all platforms */
#if W_I_N
#define PTPECONNRESET WSAECONNRESET
#define PTPEINTR WSAEINTR
#define PTPEWOULDBLOCK WSAEWOULDBLOCK
#define PTPEPERM EPERM
#define PTPEMFILE WSAEMFILE
#define PTPENFILE ENFILE
#define PTPENOMEM ENOMEM
#define PTPENOBUFS WSAENOBUFS
#else
#define PTPECONNRESET ECONNRESET
#define PTPEINTR EINTR
#define PTPEWOULDBLOCK EWOULDBLOCK
#define PTPEPERM EPERM
#define PTPEMFILE EMFILE
#define PTPENFILE ENFILE
#define PTPENOMEM ENOMEM
#define PTPENOBUFS ENOBUFS
#endif
#define PTP_OWN_HOST 0x0100007F /* 127.0.0.1 */
#define PTP_LOG_LEVEL_ERROR 0x00
#define PTP_LOG_LEVEL_INFORMATION 0x01
#define PTP_LOG_CODE 0x00
#define PTP_LOG_LEVEL_NOTHING 0x05
#define PTP_PARAM_LINE 0xFF
#define PTP_TAB 0x09
#define PTP_SERV_BACKLOG 0x01
#define PTP_MAX_MESSAGE_SIZE 0xFFFF
#define PTP_MAX_LOG_MESSAGE_SIZE 0x6D60
#define PTP_SD_BOTH 0x02
#define PTP_EXIT_SUCCESS 0x00
#define PTP_EXIT_FAILURE 0x01
#define PTP_INTERFACE_TIMEOUT 0x02
#define PTP_INTERFACE_FAILURE 0x00
#define PTP_INTERFACE_SUCCESS 0xFFFFFFFF
#define PTP_MSG_FUNC_REPLIER 0x01
#define PTP_MSG_FUNC_REQUESTER 0x02
#define PTP_MSG_FUNC_SHUTDOWN 0x05
#define PTP_MSG_FUNC_SHUTDOWN_WAIT 0x06
#define PTP_ACK 'Y'
#if PTP_IMANAGER
#define PTP_CONSOLE NULL
#else
#define PTP_CONSOLE stdout
#endif
#if W_I_N
#include <process.h> /* define getpid() */
#include <winsock2.h> /* define BSD 4.x socket api */
#include <winbase.h> /* define winbase */
#elif V_M_S
#include <unistd.h> /* define getpid() */
#include <starlet.h> /* define SYS$ routines */
#include <in.h> /* define internet constants, */
#include <stropts.h> /* define IOCTL non blocking */
#include <inet.h> /* define network address info */
#include <netdb.h> /* define network database lib */
#include <socket.h> /* define BSD 4.x socket api */
#include <unixio.h> /* define unix i/o */
#include <tcp.h> /* define tcp contants */
#else
# include <netinet/in.h> /* */
# include <netinet/tcp.h> /* */
# include <arpa/inet.h> /* */
# include <sys/types.h> /* */
# include <sys/socket.h> /* */
#endif
#include <math.h> /* define math functions */
#include <time.h> /* define time */
#include <signal.h> /* define signal handling */
#include <stdarg.h> /* define variable arguments */
#include <stdio.h> /* define standard i/o */
#include <stdlib.h> /* define standard library */
#include <string.h> /* define string handling */
#include <errno.h> /* define global error number */
#include <ctype.h> /* define character handling */
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;
typedef void privateVoid;
typedef short privateRtn;
typedef void PTPAPI;
#if W_I_N
typedef unsigned int PTP_SOCKET;
typedef int PTP_ADDRLEN;
typedef const char PTP_OPTVAL;
#else
typedef int PTP_SOCKET;
typedef unsigned int PTP_ADDRLEN;
typedef const int PTP_OPTVAL;
#endif
typedef struct sockaddr SOCKADDR;
typedef struct sockaddr_in ISOCKET;
typedef struct hostent HOSTENT;
typedef struct in_addr INADDR;
typedef struct message PTP_MESSAGE;
typedef struct tm TM;
enum sendType
{
PTP_SEND,
PTP_RECEIVE
};
typedef enum sendType SEND_TYPE;
enum messageType
{
PTP_NONE,
PTP_REPLIER,
PTP_REQUESTER
};
typedef enum messageType MESSAGE_TYPE;
enum messageStatus
{
PTP_IDLE,
PTP_BUSY
};
typedef enum messageStatus MESSAGE_STATUS;
/* Any amendments in ptpHeader will mean the API
must be released everywhere and function
zCreateHeader will have to be amended along
with all the calls to it.
*/
union ptpHeader
{
struct uHeader
{
uchar ptpIdentifier;
uchar function;
char cSize[0x08];
uchar language;
uchar encrypt;
uchar nullTerminator;
} u ;
char cHeader[sizeof( struct uHeader )];
};
struct message
{
PTP_MESSAGE *nextQ;
PTP_MESSAGE *prevQ;
PTP_MESSAGE *pairQ;
union ptpHeader header;
MESSAGE_TYPE type;
MESSAGE_STATUS status;
short deleteFlag : 0x01;
short validated : 0x01;
short noSize : 0x01;
short processedQuestion : 0x01;
uint size;
char *p;
uint bytesReceived;
int getSize;
PTP_SOCKET channel;
};
long zPutGetData(
long *,
FILE *,
PTP_SOCKET *,
char *,
long *,
const struct timeval *,
const long ,
const SEND_TYPE,
const char * );
PTP_MESSAGE *zAddQ(
PTP_MESSAGE **,
PTP_SOCKET );
privateVoid zWriteToLogger(
const char *,
const int,
va_list );
privateVoid zPTPLog(
FILE *,
const char,
const char *,
const int,
const int,
const char *,
... );
privateVoid zCleanup(
FILE *,
const char,
const char,
PTP_SOCKET *,
const char );
privateVoid zTime(
char *,
const char );
privateVoid zDelQ(
PTP_MESSAGE **,
PTP_MESSAGE * );
privateVoid zReceiveAnswer(
long *,
PTP_SOCKET *,
char *,
long *,
const long *,
const long *,
long * );
privateVoid zEncrypt(
uchar *,
int );
privateVoid zDecrypt(
uchar *,
int );
privateVoid zSend(
long *,
PTP_SOCKET *,
const char *,
const long *,
const long *,
const long *,
const long *,
const uchar );
privateVoid zWriteMessageToDisk(
long *,
const char *,
const char *,
const long *,
const long *,
const long * );
privateVoid zRecv(
long *,
PTP_SOCKET *,
char *,
long *,
const long *,
const long *,
long * );
privateVoid zSendFunction(
long *,
const char *,
const long *,
const long *,
const uchar,
const uchar );
#if W_I_N && !PTP_IMANAGER
static void zCleanupWinSock();
#endif
privateRtn zCreateHeader(
union ptpHeader *,
const long ,
const uchar,
const long ,
const long );
privateRtn zConnect(
long *,
const char *,
const long *,
const char *,
const long *,
PTP_SOCKET *,
const long *,
long * );
privateRtn zGetServAddr(
void *,
const char * );
privateRtn zConfig(
const char,
const char *,
... );
privateRtn zGetParam(
FILE *,
FILE *,
char *,
char *,
const uchar );
privateRtn zPutGetStream(
long *,
FILE *,
PTP_SOCKET *,
char *,
long *,
const long *,
const long,
const SEND_TYPE,
const char * );
PTPAPI PTP_Connect(
long *,
const char *,
const long *,
const char *,
const long *,
PTP_SOCKET *,
const long *,
long * );
PTPAPI PTP_ReceiveRequest(
long *,
PTP_SOCKET *,
char *,
long *,
const long *,
const long *,
long * );
PTPAPI PTP_SendReply(
long *,
PTP_SOCKET *,
const char *,
const long *,
const long *,
const long *,
const long * );
PTPAPI PTP_SendRequest(
long *,
PTP_SOCKET *,
const char *,
const long *,
const long *,
const long *,
const long * );
PTPAPI PTP_SendSafeRequest(
long *,
PTP_SOCKET *,
const char *,
const char *,
const long *,
const long *,
const long *,
const long * );
PTPAPI PTP_ReceiveReply(
long *,
PTP_SOCKET *,
char *,
long *,
const long *,
const long *,
long * );
PTPAPI PTP_Shutdown(
long *,
const long *,
const char * );
PTPAPI PTP_Server(
long *,
const char * );
PTPAPI PTP_Cleanup(
PTP_SOCKET * );
PTPAPI PTP_ParseFileHeader(
long *,
const char *,
long *,
long *,
long *,
long *,
long * );
PTPAPI PTP_GetHeaderSize(
long * );
#endif