File: winstub.h

package info (click to toggle)
tcpreen 1.4.4-2.1
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,316 kB
  • sloc: sh: 4,324; cpp: 2,142; ansic: 1,870; makefile: 34; sed: 16
file content (225 lines) | stat: -rw-r--r-- 6,730 bytes parent folder | download | duplicates (2)
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
/*
 * winstub.h - MS-Windows compatiblity hacks
 * $Id: winstub.h 172 2005-06-16 20:08:53Z rdenisc $
 */

/***********************************************************************
 *  Copyright (C) 2002-2004 Remi Denis-Courmont.                       *
 *  This program is free software; you can redistribute and/or modify  *
 *  it under the terms of the GNU General Public License as published  *
 *  by the Free Software Foundation; version 2 of the license.         *
 *                                                                     *
 *  This program is distributed in the hope that it will be useful,    *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               *
 *  See the GNU General Public License for more details.               *
 *                                                                     *
 *  You should have received a copy of the GNU General Public License  *
 *  along with this program; if not, you can get it from:              *
 *  http://www.gnu.org/copyleft/gpl.html                               *
 ***********************************************************************/

#ifndef __RDC_WINSTUB_H
# define __RDC_WINSTUB_H

/* gai functions do not link properly with my version of Mingw */

# include <winsock2.h> /* struct sockaddr & all the predefined constants */
# include <ws2tcpip.h> /* struct sockaddr_in and the like */
# include <io.h> /* prevents close() name mangling */
# include <stdint.h>

#ifndef HAVE_GAI_STRERROR
# undef gai_strerror // broken on my Mingw32
#endif

/* <ws2tcpip.h> breaks RFC2553 by not defining EAI_SYSTEM.
 * Give it a bogus value that should never happen in getaddrinfo(). */
# ifndef EAI_SYSTEM
#  define EAI_SYSTEM WSAEINPROGRESS
# endif

/* Winsock does not define these constants */
# ifndef SHUT_RD
#  define SHUT_RD	SD_RECEIVE
#  define SHUT_WR	SD_SEND
#  define SHUT_RDWR	SD_BOTH
# endif

# ifndef EINPROGRESS
#  define EINPROGRESS	WSAEINPROGRESS
#endif

# define main winstub_main

# ifdef __cplusplus
extern "C"
{
# endif
	void winsock_perror (const char *str);
# define perror winsock_perror

	const char *winsock_strerror (int errnum);
# define strerror winsock_strerror

	int winsock_close (int fd);
# define close winsock_close

	size_t winsock_recvfrom (int fd, void *buf, size_t len, int flags,
				 struct sockaddr *addr, socklen_t *alen);
# define recvfrom winsock_recvfrom

	size_t winsock_sendto (int fd, const void *buf, size_t len, int flags,
				const struct sockaddr *addr, socklen_t alen);
# define sendto winsock_sendto
	
	size_t winsock_read (int fd, void *buf, size_t len);
# define read winsock_read

	size_t winsock_write (int fd, const void *buf, size_t len);
# define write winsock_write

	size_t winsock_recv (int fd, void *buf, size_t len, int flags);
# define recv winsock_recv

	size_t winsock_send (int fd, const void *buf, size_t len, int flags);
# define send winsock_send

	int winsock_socket (int pf, int type, int proto);
# define socket winsock_socket

	int winsock_bind (int fd, struct sockaddr *addr, socklen_t addrlen);
# define bind winsock_bind

	int winsock_listen (int fd, int max);
# define listen winsock_listen

	int winsock_accept (int fd, struct sockaddr *addr, socklen_t *len);
# define accept winsock_accept

	int winsock_connect (int fd, struct sockaddr *addr, socklen_t len);
# define connect winsock_connect

	int winsock_shutdown (int fd, int how);
# define shutdown winsock_shutdown

	int winsock_setsockopt (int fd, int lvl, int opt, const void *data,
				socklen_t len);
# define setsockopt winsock_setsockopt

	int winsock_getsockopt (int fd, int lvl, int opt, void *data,
				socklen_t *len);
# define getsockopt winsock_getsockopt

	struct hostent *winsock_gethostbyaddr (const char *addr, int len,
						int type);
# define gethostbyaddr winsock_gethostbyaddr

	struct hostent *winsock_gethostbyname (const char *name);
# define gethostbyname winsock_gethostbyname

	int winsock_getpeername (int fd, struct sockaddr *addr,
					socklen_t *len);
# define getpeername winsock_getpeername

	int winsock_getsockname (int fd, struct sockaddr *addr,
					socklen_t *len);
# define getsockname winsock_getsockname

	char *winsock_inet_ntoa (struct in_addr in);
# define inet_ntoa winsock_inet_ntoa

	unsigned long winsock_inet_addr (const char *dotip);
# define inet_addr winsock_inet_addr

	struct servent *winsock_getservbyport (int port, const char *proto);
# define getservbyport winsock_getservbyport

	struct servent *winsock_getservbyname (const char *name,
						const char *proto);
# define getservbyname winsock_getservbyname

	uint16_t winsock_ntohs (uint16_t s);
# define ntohs winsock_ntohs

	uint16_t winsock_htons (uint16_t s);
# define htons winsock_htons

	uint32_t winsock_ntohl (uint32_t l);
# define ntohl winsock_ntohl

	uint32_t winsock_htonl (uint32_t l);
# define htonl winsock_htonl

	int winsock_getaddrinfo (const char *node, const char *service,
	                         const struct addrinfo *hints,
	                         struct addrinfo **res);
# define getaddrinfo winsock_getaddrinfo

	void winsock_freeaddrinfo (struct addrinfo *infos);
# define freeaddrinfo winsock_freeaddrinfo

	int winsock_getnameinfo (const struct sockaddr *sa, int salen, char *host,
	                         int hostlen, char *serv, int servlen, int flags);
# define getnameinfo winsock_getnameinfo

/*
 * POSIX functions which do not exists on Windows
 */
	unsigned int sleep (unsigned int s);
	int setuid (uid_t uid);
	int seteuid (uid_t uid);
	uid_t getuid (void);
	uid_t geteuid (void);

	struct passwd
	{
		uid_t pw_uid;
	};
	struct passwd *getpwnam (const char *username);
	struct passwd *getpwuid (uid_t uid);

	void openlog (const char *ident, int option, int facility);
	void syslog (int priority, const char *fmt, ...);
	void closelog (void);

# define LOG_CONS	0x02
# define LOG_NDELAY	0x08
# define LOG_NOWAIT	0x10
# define LOG_ODELAY	0x04
# define LOG_PERROR	0x20
# define LOG_PID	0x01

# define LOG_AUTH	0040
# define LOG_AUTHPRIV	0120
# define LOG_CRON	0110
# define LOG_DAEMON	0030
# define LOG_FTP	0130
# define LOG_LOCAL0	0200
# define LOG_LOCAL1	0210
# define LOG_LOCAL2	0220
# define LOG_LOCAL3	0230
# define LOG_LOCAL4	0240
# define LOG_LOCAL5	0250
# define LOG_LOCAL6	0260
# define LOG_LOCAL7	0270
# define LOG_LPR	0060
# define LOG_MAIL	0020
# define LOG_NEWS	0070
# define LOG_SYSLOG	0050
# define LOG_USER	0010
# define LOG_UUCP	0100

# define LOG_EMERG	0
# define LOG_ALERT	1
# define LOG_CRIT	2
# define LOG_ERR	3
# define LOG_WARNING	4
# define LOG_NOTICE	5
# define LOG_INFO	6
# define LOG_DEBUG	7

# ifdef __cplusplus
}
# endif
#endif /* not __RDC_WINSTUB_H */