sockwrap.h 4.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* sockwrap.h */

/* Berkley/WinSock socket API wrappers */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright 2002 Rob Swindell - http://www.synchro.net/copyright.html		*
12
 *																			*
13
14
 * This library is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU Lesser General Public License		*
15
16
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
17
18
 * See the GNU Lesser General Public License for more details: lgpl.txt or	*
 * http://www.fsf.org/copyleft/lesser.html									*
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#ifndef _SOCKWRAP_H
#define _SOCKWRAP_H

41
42
#include "gen_defs.h"	/* BOOL */

43
44
45
/***************/
/* OS-specific */
/***************/
46
#if defined(_WIN32)		/* Use WinSock */
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

#include <winsock.h>	/* socket/bind/etc. */

/* Let's agree on a standard WinSock symbol here, people */
#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_	
#endif

#elif defined __unix__	/* Unix-variant */

#include <netdb.h>		/* gethostbyname */
#include <sys/types.h>  /* For u_int32_t on FreeBSD */
#include <netinet/in.h>	/* IPPROTO_IP */
#include <sys/socket.h>	/* socket/bind/etc. */
#include <sys/time.h>	/* struct timeval */
#include <arpa/inet.h>	/* inet_ntoa */
#include <unistd.h>		/* close */
64
65
66
67
68
#if defined(__solaris__)
	#include <sys/filio.h>  /* FIONBIO */
#else
	#include <sys/ioctl.h>	/* FIONBIO */
#endif
69
70
71
72
73
74
75
76

#endif

#include <errno.h>		/* errno */

/**********************************/
/* Socket Implementation-specific */
/**********************************/
77
#if defined(_WINSOCKAPI_)
78
79
80
81
82

#undef  EINTR
#define EINTR			(WSAEINTR-WSABASEERR)
#undef  ENOTSOCK
#define ENOTSOCK		(WSAENOTSOCK-WSABASEERR)
83
84
#undef  EMSGSIZE
#define EMSGSIZE		(WSAEMSGSIZE-WSABASEERR)
85
86
87
88
89
90
91
92
#undef  EWOULDBLOCK
#define EWOULDBLOCK		(WSAEWOULDBLOCK-WSABASEERR)
#undef  ECONNRESET
#define ECONNRESET		(WSAECONNRESET-WSABASEERR)
#undef  ESHUTDOWN
#define ESHUTDOWN		(WSAESHUTDOWN-WSABASEERR)
#undef  ECONNABORTED
#define ECONNABORTED	(WSAECONNABORTED-WSABASEERR)
93
94
#undef	EINPROGRESS
#define EINPROGRESS		(WSAEINPROGRESS-WSABASEERR)
95
96
97
98
99
100
101
102
103
104
105
106
107

#define s_addr			S_un.S_addr

#define socklen_t		int

static  wsa_error;
#define ERROR_VALUE		((wsa_error=WSAGetLastError())>0 ? wsa_error-WSABASEERR : wsa_error)
#define sendsocket(s,b,l)	send(s,b,l,0)

#else	/* BSD sockets */

/* WinSock-isms */
#define HOSTENT			struct hostent
108
#define IN_ADDR			struct in_addr
109
#define SOCKADDR		struct sockaddr
110
111
112
113
114
115
116
117
118
119
120
121
#define SOCKADDR_IN		struct sockaddr_in
#define LINGER			struct linger
#define SOCKET			int
#define SOCKET_ERROR	-1
#define INVALID_SOCKET  (SOCKET)(~0)
#define closesocket		close
#define ioctlsocket		ioctl
#define ERROR_VALUE		errno
#define sendsocket		write		// FreeBSD send() is broken

#endif	/* __unix__ */

122
123
124
125
126
#ifdef __cplusplus
extern "C" {
#endif

int		sendfilesocket(int sock, int file, long *offset, long count);
127
int		recvfilesocket(int sock, int file, long *offset, long count);
128
BOOL	socket_check(SOCKET sock, BOOL* rd_p, DWORD timeout);
129
130
131
132

#ifdef __cplusplus
}
#endif
133

134
135
136
137
#ifndef SHUT_RDWR
#define SHUT_RDWR		2	/* for shutdown() */
#endif

138
139
140
#ifndef IPPORT_HTTP
#define IPPORT_HTTP		80
#endif
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef IPPORT_FTP
#define IPPORT_FTP		21
#endif
#ifndef IPPORT_TELNET
#define IPPORT_TELNET	23
#endif
#ifndef IPPORT_SMTP
#define IPPORT_SMTP		25
#endif
#ifndef IPPORT_POP3
#define IPPORT_POP3		110
#endif

#endif	/* Don't add anything after this line */