Remove useless comparison
[pidgin-git.git] / libpurple / protocols / gg / lib / network.h
blob330a6700bb1061ac49ae08fc260618dcd167cb4f
1 /* $Id$ */
3 /*
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,
19 * USA.
22 /**
23 * \file network.h
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
31 #ifdef _WIN32
32 # include <ws2tcpip.h>
33 # include <winsock2.h>
34 # include <stdlib.h>
35 # include <stdio.h>
36 # include <errno.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
39 * ifdefów. */
40 # ifndef ECONNRESET
41 # define ECONNRESET WSAECONNRESET
42 # endif
43 # ifndef EINPROGRESS
44 # define EINPROGRESS WSAEINPROGRESS
45 # endif
46 # ifndef ENOTCONN
47 # define ENOTCONN WSAENOTCONN
48 # endif
49 # ifndef ETIMEDOUT
50 # define ETIMEDOUT WSAETIMEDOUT
51 # endif
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)
83 WSADATA wsaData;
85 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
86 perror("WSAStartup");
87 exit(1);
91 #else
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>
97 # include <netdb.h>
98 # include <unistd.h>
99 # ifndef FIONBIO
100 # include <fcntl.h>
101 # endif
102 #endif
104 #ifndef INADDR_NONE
105 # define INADDR_NONE ((in_addr_t) 0xffffffff)
106 #endif
108 #ifndef AF_LOCAL
109 # define AF_LOCAL AF_UNIX
110 #endif
112 static inline int gg_fd_set_nonblocking(int fd)
114 int success;
115 #ifdef FIONBIO
116 int one = 1;
117 success = (ioctl(fd, FIONBIO, &one) == 0);
118 #else
119 success = (fcntl(fd, F_SETFL, O_NONBLOCK) == 0);
120 #endif
122 return success;
125 #endif /* LIBGADU_NETWORK_H */