1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
thread safe version of some common functions:
20
This file is also used to make handling of sockets and ioctl()
21
portable accross systems.
30
#ifdef HAVE_SYS_SOCKET_H
31
#include <sys/socket.h>
33
#ifdef HAVE_NETINET_IN_H
34
#include <netinet/in.h>
36
#ifdef HAVE_ARPA_INET_H
37
#include <arpa/inet.h>
42
#ifdef HAVE_SYS_IOCTL_H
43
#include <sys/ioctl.h>
46
#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) && !defined(__NETWARE__)
47
#include <netinet/in_systm.h>
48
#include <netinet/in.h>
49
#include <netinet/ip.h>
50
#if !defined(alpha_linux_port)
51
#include <netinet/tcp.h>
56
#include <sys/ioctl.h>
57
#define ioctlsocket(A,B,C) ioctl((A),(B),(void *)(C),sizeof(*(C)))
59
#endif /* defined(__EMX__) */
61
#if defined(MSDOS) || defined(__WIN__)
62
#define O_NONBLOCK 1 /* For emulation of fcntl() */
65
SHUT_RDWR is called SD_BOTH in windows and
66
is defined to 2 in winsock2.h
69
#define SHUT_RDWR 0x02
74
On OSes which don't have the in_addr_t, we guess that using uint32 is the best
75
possible choice. We guess this from the fact that on HP-UX64bit & FreeBSD64bit
76
& Solaris64bit, in_addr_t is equivalent to uint32. And on Linux32bit too.
78
#ifndef HAVE_IN_ADDR_T
79
#define in_addr_t uint32
82
/* On some operating systems (e.g. Solaris) INADDR_NONE is not defined */
84
#define INADDR_NONE -1 /* Error value from inet_addr */
87
/* Thread safe or portable version of some functions */
89
void my_inet_ntoa(struct in_addr in, char *buf);
92
Handling of gethostbyname_r()
98
#if !defined(HAVE_GETHOSTBYNAME_R)
99
struct hostent *my_gethostbyname_r(const char *name,
100
struct hostent *result, char *buffer,
101
int buflen, int *h_errnop);
102
void my_gethostbyname_r_free();
103
#elif defined(HAVE_PTHREAD_ATTR_CREATE) || defined(_AIX) || defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
104
struct hostent *my_gethostbyname_r(const char *name,
105
struct hostent *result, char *buffer,
106
int buflen, int *h_errnop);
107
#define my_gethostbyname_r_free()
108
#if !defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) && !defined(HPUX10)
109
#define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
110
#endif /* !defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) */
112
#elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT)
113
#define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
114
struct hostent *my_gethostbyname_r(const char *name,
115
struct hostent *result, char *buffer,
116
int buflen, int *h_errnop);
117
#define my_gethostbyname_r_free()
119
#define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E))
120
#define my_gethostbyname_r_free()
121
#endif /* !defined(HAVE_GETHOSTBYNAME_R) */
123
#ifndef GETHOSTBYNAME_BUFF_SIZE
124
#define GETHOSTBYNAME_BUFF_SIZE 2048
127
/* On SCO you get a link error when refering to h_errno */
130
#define h_errno errno