mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
libreplace: replace inet_ntoa() when it is missing
...not only replace it when it is broken. This moves the defintion of rep_inet_ntoa from replace.c to inet_ntoa.c and adds configure checks for existence of inet_ntoa(). Checks are moved to an include file of its own. NOTE: The original rep_inet_ntoa in replace.c was wrapped into a "#ifndef WITH_PTHREADS" but the prototype in replace.h and the define in system/network.h were not. I removed that ifndef since the inet_ntoa() function is usually not thread safe anyways, since it returns a pointer to a static buffer. So whoever calls inet_ntoa() should be aware that it is not thread safe anyways. Michael (cherry picked from commit974c0c45ad
) (This used to be commitedcf2712bc
)
This commit is contained in:
parent
a4d7cbcb2f
commit
5c73dabd49
39
source3/lib/replace/inet_ntoa.c
Normal file
39
source3/lib/replace/inet_ntoa.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Unix SMB/CIFS implementation.
|
||||||
|
* replacement routines for broken systems
|
||||||
|
* Copyright (C) Andrew Tridgell 2003
|
||||||
|
* Copyright (C) Michael Adam 2008
|
||||||
|
*
|
||||||
|
* ** NOTE! The following LGPL license applies to the replace
|
||||||
|
* ** library. This does NOT imply that all of Samba is released
|
||||||
|
* ** under the LGPL
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "replace.h"
|
||||||
|
#include "system/network.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOTE: this is not thread safe, but it can't be, either
|
||||||
|
* since it returns a pointer to static memory.
|
||||||
|
*/
|
||||||
|
char *rep_inet_ntoa(struct in_addr ip)
|
||||||
|
{
|
||||||
|
uint8_t *p = (uint8_t *)&ip.s_addr;
|
||||||
|
static char buf[18];
|
||||||
|
slprintf(buf, 17, "%d.%d.%d.%d",
|
||||||
|
(int)p[0], (int)p[1], (int)p[2], (int)p[3]);
|
||||||
|
return buf;
|
||||||
|
}
|
19
source3/lib/replace/inet_ntoa.m4
Normal file
19
source3/lib/replace/inet_ntoa.m4
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
AC_CHECK_FUNCS(inet_ntoa,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} inet_ntoa.o"])
|
||||||
|
|
||||||
|
AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
|
||||||
|
AC_TRY_RUN([
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#ifdef HAVE_ARPA_INET_H
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
main() { struct in_addr ip; ip.s_addr = 0x12345678;
|
||||||
|
if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
|
||||||
|
strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
|
||||||
|
exit(1);}],
|
||||||
|
libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
|
||||||
|
if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
|
||||||
|
AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
|
||||||
|
fi
|
@ -120,24 +120,6 @@ if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
|
|||||||
AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
|
AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
|
|
||||||
AC_TRY_RUN([
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#ifdef HAVE_ARPA_INET_H
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
main() { struct in_addr ip; ip.s_addr = 0x12345678;
|
|
||||||
if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
|
|
||||||
strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
|
|
||||||
exit(1);}],
|
|
||||||
libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
|
|
||||||
if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
|
|
||||||
AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
|
AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
|
||||||
AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
|
AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
|
||||||
AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
|
AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
|
||||||
@ -348,6 +330,7 @@ m4_include(socket.m4)
|
|||||||
m4_include(inet_ntop.m4)
|
m4_include(inet_ntop.m4)
|
||||||
m4_include(inet_pton.m4)
|
m4_include(inet_pton.m4)
|
||||||
m4_include(inet_aton.m4)
|
m4_include(inet_aton.m4)
|
||||||
|
m4_include(inet_ntoa.m4)
|
||||||
m4_include(getaddrinfo.m4)
|
m4_include(getaddrinfo.m4)
|
||||||
m4_include(repdir.m4)
|
m4_include(repdir.m4)
|
||||||
m4_include(getifaddrs.m4)
|
m4_include(getifaddrs.m4)
|
||||||
|
@ -295,20 +295,6 @@ char *rep_strdup(const char *s)
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_STRDUP */
|
#endif /* HAVE_STRDUP */
|
||||||
|
|
||||||
#ifndef WITH_PTHREADS
|
|
||||||
/* REWRITE: not thread safe */
|
|
||||||
#ifdef REPLACE_INET_NTOA
|
|
||||||
char *rep_inet_ntoa(struct in_addr ip)
|
|
||||||
{
|
|
||||||
uint8_t *p = (uint8_t *)&ip.s_addr;
|
|
||||||
static char buf[18];
|
|
||||||
slprintf(buf, 17, "%d.%d.%d.%d",
|
|
||||||
(int)p[0], (int)p[1], (int)p[2], (int)p[3]);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
#endif /* REPLACE_INET_NTOA */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef HAVE_SETLINEBUF
|
#ifndef HAVE_SETLINEBUF
|
||||||
void rep_setlinebuf(FILE *stream)
|
void rep_setlinebuf(FILE *stream)
|
||||||
{
|
{
|
||||||
|
@ -325,7 +325,7 @@ ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset);
|
|||||||
ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset);
|
ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef REPLACE_INET_NTOA
|
#if !defined(HAVE_INET_NTOA) || defined(REPLACE_INET_NTOA)
|
||||||
#define inet_ntoa rep_inet_ntoa
|
#define inet_ntoa rep_inet_ntoa
|
||||||
/* prototype is in "system/network.h" */
|
/* prototype is in "system/network.h" */
|
||||||
#endif
|
#endif
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef REPLACE_INET_NTOA
|
#if !defined (HAVE_INET_NTOA) || defined(REPLACE_INET_NTOA)
|
||||||
/* define is in "replace.h" */
|
/* define is in "replace.h" */
|
||||||
char *rep_inet_ntoa(struct in_addr ip);
|
char *rep_inet_ntoa(struct in_addr ip);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user