blob: ee4f3a6e9cadcc6dd43bc56dfcc9e6a6b6e26a69 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_COMPAT_SOCKET_H__
20#define __PJ_COMPAT_SOCKET_H__
21
22/**
23 * @file socket.h
24 * @brief Provides all socket related functions,data types, error codes, etc.
25 */
26
27#if defined(PJ_HAS_WINSOCK_H) && PJ_HAS_WINSOCK_H != 0
28# include <winsock.h>
29#endif
30
31#if defined(PJ_HAS_WINSOCK2_H) && PJ_HAS_WINSOCK2_H != 0
32# include <winsock2.h>
33#endif
34
35#if defined(PJ_HAS_SYS_TYPES_H) && PJ_HAS_SYS_TYPES_H != 0
36# include <sys/types.h>
37#endif
38
39#if defined(PJ_HAS_SYS_SOCKET_H) && PJ_HAS_SYS_SOCKET_H != 0
40# include <sys/socket.h>
41#endif
42
43#if defined(PJ_HAS_LINUX_SOCKET_H) && PJ_HAS_LINUX_SOCKET_H != 0
44# include <linux/socket.h>
45#endif
46
47#if defined(PJ_HAS_SYS_SELECT_H) && PJ_HAS_SYS_SELECT_H != 0
48# include <sys/select.h>
49#endif
50
51#if defined(PJ_HAS_NETINET_IN_H) && PJ_HAS_NETINET_IN_H != 0
52# include <netinet/in.h>
53#endif
54
55#if defined(PJ_HAS_ARPA_INET_H) && PJ_HAS_ARPA_INET_H != 0
56# include <arpa/inet.h>
57#endif
58
59#if defined(PJ_HAS_SYS_IOCTL_H) && PJ_HAS_SYS_IOCTL_H != 0
60# include <sys/ioctl.h> /* FBIONBIO */
61#endif
62
63#if defined(PJ_HAS_ERRNO_H) && PJ_HAS_ERRNO_H != 0
64# include <errno.h>
65#endif
66
67#if defined(PJ_HAS_NETDB_H) && PJ_HAS_NETDB_H != 0
68# include <netdb.h>
69#endif
70
71#if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H != 0
72# include <unistd.h>
73#endif
74
75
76/*
77 * Define common errors.
78 */
79#ifdef PJ_WIN32
80# define OSERR_EWOULDBLOCK WSAEWOULDBLOCK
81# define OSERR_EINPROGRESS WSAEINPROGRESS
Benny Prijonofa73e3e2006-01-05 23:35:46 +000082# define OSERR_ECONNRESET WSAECONNRESET
Benny Prijono5dcb38d2005-11-21 01:55:47 +000083#else
84# define OSERR_EWOULDBLOCK EWOULDBLOCK
85# define OSERR_EINPROGRESS EINPROGRESS
Benny Prijonofa73e3e2006-01-05 23:35:46 +000086# define OSERR_ECONNRESET ECONNRESET
Benny Prijono5dcb38d2005-11-21 01:55:47 +000087#endif
88
89
90/*
91 * And undefine this..
92 */
93#undef s_addr
94
95/*
96 * Linux kernel specifics
97 */
Benny Prijono9cf138e2006-01-19 03:58:29 +000098#if defined(PJ_LINUX_KERNEL)
Benny Prijono5dcb38d2005-11-21 01:55:47 +000099# include <linux/net.h>
100# include <asm/ioctls.h> /* FIONBIO */
101# include <linux/syscalls.h> /* sys_select() */
102# include <asm/uaccess.h> /* set/get_fs() */
103
104 typedef int socklen_t;
105# define getsockopt sys_getsockopt
106
107 /*
108 * Wrapper for select() in Linux kernel.
109 */
110 PJ_INLINE(int) select(int n, fd_set *inp, fd_set *outp, fd_set *exp,
111 struct timeval *tvp)
112 {
113 int count;
114 mm_segment_t oldfs = get_fs();
115 set_fs(KERNEL_DS);
116 count = sys_select(n, inp, outp, exp, tvp);
117 set_fs(oldfs);
118 return count;
119 }
120#endif /* PJ_LINUX_KERNEL */
121
122
123/*
124 * Windows specific
125 */
Benny Prijono9cf138e2006-01-19 03:58:29 +0000126#if defined(PJ_WIN32) || defined(PJ_WIN32_WINCE)
127 typedef int socklen_t;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000128#endif
129
130
131#endif /* __PJ_COMPAT_SOCKET_H__ */
132