blob: e3f68b5d5afc133c17fa3d0bbae6090d9a3fc970 [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 */
Benny Prijonoace00932006-02-14 21:04:47 +000079#if (defined(PJ_WIN32) && PJ_WIN32!=0) || \
80 (defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0)
Benny Prijono5dcb38d2005-11-21 01:55:47 +000081# define OSERR_EWOULDBLOCK WSAEWOULDBLOCK
82# define OSERR_EINPROGRESS WSAEINPROGRESS
Benny Prijonofa73e3e2006-01-05 23:35:46 +000083# define OSERR_ECONNRESET WSAECONNRESET
Benny Prijono5dcb38d2005-11-21 01:55:47 +000084#else
85# define OSERR_EWOULDBLOCK EWOULDBLOCK
86# define OSERR_EINPROGRESS EINPROGRESS
Benny Prijonofa73e3e2006-01-05 23:35:46 +000087# define OSERR_ECONNRESET ECONNRESET
Benny Prijono5dcb38d2005-11-21 01:55:47 +000088#endif
89
90
91/*
92 * And undefine this..
93 */
94#undef s_addr
95
96/*
97 * Linux kernel specifics
98 */
Benny Prijono9cf138e2006-01-19 03:58:29 +000099#if defined(PJ_LINUX_KERNEL)
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000100# include <linux/net.h>
101# include <asm/ioctls.h> /* FIONBIO */
102# include <linux/syscalls.h> /* sys_select() */
103# include <asm/uaccess.h> /* set/get_fs() */
104
105 typedef int socklen_t;
106# define getsockopt sys_getsockopt
107
108 /*
109 * Wrapper for select() in Linux kernel.
110 */
111 PJ_INLINE(int) select(int n, fd_set *inp, fd_set *outp, fd_set *exp,
112 struct timeval *tvp)
113 {
114 int count;
115 mm_segment_t oldfs = get_fs();
116 set_fs(KERNEL_DS);
117 count = sys_select(n, inp, outp, exp, tvp);
118 set_fs(oldfs);
119 return count;
120 }
121#endif /* PJ_LINUX_KERNEL */
122
123
124/*
125 * Windows specific
126 */
Benny Prijono9cf138e2006-01-19 03:58:29 +0000127#if defined(PJ_WIN32) || defined(PJ_WIN32_WINCE)
128 typedef int socklen_t;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000129#endif
130
131
132#endif /* __PJ_COMPAT_SOCKET_H__ */
133