my_net.h 3.68 KB
Newer Older
unknown's avatar
unknown committed
1 2 3 4 5 6 7 8
/* Copyright (C) 2000 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
unknown's avatar
unknown committed
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
unknown's avatar
unknown committed
10 11 12 13 14 15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
unknown's avatar
unknown committed
16

17 18 19
/*
  thread safe version of some common functions:
  my_inet_ntoa
unknown's avatar
unknown committed
20

21 22
  This file is also used to make handling of sockets and ioctl()
  portable accross systems.
unknown's avatar
unknown committed
23

24 25 26 27 28 29 30
*/

#ifndef _my_net_h
#define _my_net_h
C_MODE_START

#include <errno.h>
unknown's avatar
unknown committed
31 32 33 34 35 36 37 38 39
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
40 41 42 43 44 45 46
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif

unknown's avatar
unknown committed
47
#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) && !defined(__NETWARE__)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#if !defined(alpha_linux_port)
#include <netinet/tcp.h>
#endif
#endif

#if defined(__EMX__)
#include <sys/ioctl.h>
#define ioctlsocket(A,B,C) ioctl((A),(B),(void *)(C),sizeof(*(C)))
#undef HAVE_FCNTL
#endif	/* defined(__EMX__) */

#if defined(MSDOS) || defined(__WIN__)
#define O_NONBLOCK 1    /* For emulation of fcntl() */
#endif

unknown's avatar
unknown committed
66 67 68 69 70 71 72 73 74
/*
  On OSes which don't have the in_addr_t, we guess that using uint32 is the best
  possible choice. We guess this from the fact that on HP-UX64bit & FreeBSD64bit
  & Solaris64bit, in_addr_t is equivalent to uint32. And on Linux32bit too.
*/
#ifndef HAVE_IN_ADDR_T
#define in_addr_t uint32
#endif

75 76 77 78 79
/* On some operating systems (e.g. Solaris) INADDR_NONE is not defined */
#ifndef INADDR_NONE
#define INADDR_NONE -1                          /* Error value from inet_addr */
#endif

80
/* Thread safe or portable version of some functions */
unknown's avatar
unknown committed
81 82

void my_inet_ntoa(struct in_addr in, char *buf);
unknown's avatar
unknown committed
83

unknown's avatar
unknown committed
84 85 86 87
/*
  Handling of gethostbyname_r()
*/

88
#if !defined(HPUX10)
unknown's avatar
unknown committed
89 90
struct hostent;
#endif /* HPUX */
unknown's avatar
unknown committed
91 92 93 94 95 96
#if !defined(HAVE_GETHOSTBYNAME_R)
struct hostent *my_gethostbyname_r(const char *name,
				   struct hostent *result, char *buffer,
				   int buflen, int *h_errnop);
void my_gethostbyname_r_free();
#elif defined(HAVE_PTHREAD_ATTR_CREATE) || defined(_AIX) || defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
unknown's avatar
unknown committed
97 98 99 100
struct hostent *my_gethostbyname_r(const char *name,
				   struct hostent *result, char *buffer,
				   int buflen, int *h_errnop);
#define my_gethostbyname_r_free()
101
#if !defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) && !defined(HPUX10)
unknown's avatar
unknown committed
102
#define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
unknown's avatar
unknown committed
103
#endif /* !defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) */
unknown's avatar
unknown committed
104 105 106 107 108 109 110 111 112 113

#elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT)
#define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
struct hostent *my_gethostbyname_r(const char *name,
				   struct hostent *result, char *buffer,
				   int buflen, int *h_errnop);
#define my_gethostbyname_r_free()
#else
#define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E))
#define my_gethostbyname_r_free()
unknown's avatar
unknown committed
114 115 116 117 118
#endif /* !defined(HAVE_GETHOSTBYNAME_R) */

#ifndef GETHOSTBYNAME_BUFF_SIZE
#define GETHOSTBYNAME_BUFF_SIZE 2048
#endif
unknown's avatar
unknown committed
119

120 121 122 123 124
/* On SCO you get a link error when refering to h_errno */
#ifdef SCO
#undef h_errno
#define h_errno errno
#endif
unknown's avatar
unknown committed
125

126
C_MODE_END
unknown's avatar
unknown committed
127
#endif