4 * (C) Copyright 2001-2002 Wojtek Kaniewski <wojtekka@irc.pl>
5 * Robert J. Woźny <speedy@ziew.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License Version
9 * 2.1 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
25 * \brief Makra zapewniające kompatybilność API do obsługi sieci na różnych systemach
28 #ifndef LIBGADU_NETWORK_H
29 #define LIBGADU_NETWORK_H
32 # include <ws2tcpip.h>
33 # include <winsock2.h>
37 /* Obecnie na Win32 tylko MSVC definiuje te typy błędów. Na wypadek, gdyby
38 * jednak Cygwin bądź MinGW zaczęły je definiować, używamy bardziej ogólnych
41 # define ECONNRESET WSAECONNRESET
44 # define EINPROGRESS WSAEINPROGRESS
47 # define ENOTCONN WSAENOTCONN
50 # define ETIMEDOUT WSAETIMEDOUT
52 # define accept gg_win32_accept
53 # define bind gg_win32_bind
54 # define close gg_win32_close
55 # define connect gg_win32_connect
56 # define gethostbyname gg_win32_gethostbyname
57 # define getsockname gg_win32_getsockname
58 # define getsockopt gg_win32_getsockopt
59 # define ioctl gg_win32_ioctl
60 # define listen gg_win32_listen
61 # define recv gg_win32_recv
62 # define send gg_win32_send
63 # define setsockopt gg_win32_setsockopt
64 # define socket gg_win32_socket
65 # define socketpair(a, b, c, d) gg_win32_socketpair(d)
66 int gg_win32_accept(int sockfd
, struct sockaddr
*addr
, socklen_t
*addrlen
);
67 int gg_win32_bind(int sockfd
, const struct sockaddr
*addr
, socklen_t addrlen
);
68 int gg_win32_close(int sockfd
);
69 int gg_win32_connect(int sockfd
, const struct sockaddr
*addr
, socklen_t addrlen
);
70 struct hostent
*gg_win32_gethostbyname(const char *name
);
71 int gg_win32_getsockname(int sockfd
, struct sockaddr
*addr
, socklen_t
*addrlen
);
72 int gg_win32_getsockopt(int sockfd
, int level
, int optname
, void *optval
, socklen_t
*optlen
);
73 int gg_win32_ioctl(int d
, int request
, int *argp
);
74 int gg_win32_listen(int sockfd
, int backlog
);
75 int gg_win32_recv(int sockfd
, void *buf
, size_t len
, int flags
);
76 int gg_win32_send(int sockfd
, const void *buf
, size_t len
, int flags
);
77 int gg_win32_setsockopt(int sockfd
, int level
, int optname
, const void *optval
, socklen_t optlen
);
78 int gg_win32_socket(int domain
, int type
, int protocol
);
79 int gg_win32_socketpair(int sv
[2]);
81 static inline void gg_win32_init_network(void)
85 if (WSAStartup(MAKEWORD(2, 2), &wsaData
) != 0) {
92 # include <sys/ioctl.h>
93 # include <sys/types.h>
94 # include <sys/socket.h>
95 # include <netinet/in.h>
96 # include <arpa/inet.h>
105 # define INADDR_NONE ((in_addr_t) 0xffffffff)
109 # define AF_LOCAL AF_UNIX
112 static inline int gg_fd_set_nonblocking(int fd
)
117 success
= (ioctl(fd
, FIONBIO
, &one
) == 0);
119 success
= (fcntl(fd
, F_SETFL
, O_NONBLOCK
) == 0);
125 #endif /* LIBGADU_NETWORK_H */