-
Notifications
You must be signed in to change notification settings - Fork 1
/
mtools.h
129 lines (105 loc) · 3.64 KB
/
mtools.h
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
#ifndef MTOOLS_MTOOLS_H
#define MTOOLS_MTOOLS_H
/*
*
* Author: [email protected] (heavily modified by 29West/Informatica)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted without restriction.
*
* Note: this program is based on the sd_listen program by Tom Pusateri
* ([email protected]) and developed by Jon Knight ([email protected]).
*
THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE
UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES,
BE LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR
INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE
TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF
THE LIKELIHOOD OF SUCH DAMAGES.
*/
/*
* modified by Aviad Rozenhek [[email protected]] for open-mtools
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
/* Many of the following definitions are intended to make it easier to write
* portable code between windows and unix. */
/* use our own form of getopt */
extern int toptind;
extern int toptreset;
extern char *toptarg;
extern int tgetopt(int nargc, char * const *nargv, const char *ostr);
#define mprintf(opts, format, ...) \
fprintf(stderr, format, __VA_ARGS__); fflush(stderr); \
if(opts && opts->o_output) { fprintf(opts->o_output, format, __VA_ARGS__); fflush(opts->o_output); }
#if defined(_MSC_VER)
// Windows-only includes
#define HAVE_WINSOCK2_H 1
#define SLEEP_SEC(s) Sleep((s) * 1000)
#define SLEEP_MSEC(s) Sleep(s)
#define CLOSESOCKET closesocket
#define TLONGLONG signed __int64
#else
// Unix-only includes
#define HAVE_PTHREAD_H
#include <signal.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
#include <pthread.h>
#define SLEEP_SEC(s) sleep(s)
#define SLEEP_MSEC(s) usleep((s) * 1000)
#define CLOSESOCKET close
#define SOCKET int
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define TLONGLONG signed long long
#endif
#if defined(_WIN32)
# include <ws2tcpip.h>
# include <sys\types.h>
# include <sys\timeb.h>
# define perror(opts, x) mprintf(opts, "%s: %d\n",x,GetLastError())
#else
# include <sys/time.h>
#endif
#include <string.h>
#include <time.h>
#define MAXPDU 65536
#if HAVE_WINSOCK2_H
#include <winsock2.h>
#include <ws2tcpip.h>
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT WSAETIMEDOUT
#endif
#ifndef ECONNREFUSED
#define ECONNREFUSED WSAECONNREFUSED
#endif
#ifndef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS
#endif
#define getsockopt(a, b, c, d, e) getsockopt(a, b, c, (char*) d, e)
#define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
#pragma comment(lib, "Ws2_32.lib")
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#endif
extern int udp_set_url(struct sockaddr_storage *addr, const char *hostname, int port);
extern struct addrinfo* udp_resolve_host(const char *hostname, int port, int type, int family, int flags);
extern int udp_join_multicast_group(int sockfd, struct sockaddr *addr);
extern int udp_set_multicast_sources(int sockfd, struct sockaddr *addr,
int addr_len, char **sources,
int nb_sources, int include);
#endif