port to Android

This commit is contained in:
Gerhard Rieger 2012-07-22 18:52:38 +02:00
parent 5d052c84e1
commit 93e12161a3
10 changed files with 84 additions and 3 deletions

View file

@ -102,6 +102,9 @@ porting:
on some 64bit systems a compiler warning "cast from pointer to integer on some 64bit systems a compiler warning "cast from pointer to integer
of different size" was issued on some option definitions of different size" was issued on some option definitions
Cedril Priscal ported socat to Android (using Googles cross compiler).
The port includes the socat_buildscript_for_android.sh script
####################### V 2.0.0-b7: ####################### V 2.0.0-b7:
security: security:

View file

@ -477,6 +477,10 @@
/* Define if you have the /proc/$$/fd directories */ /* Define if you have the /proc/$$/fd directories */
#undef HAVE_PROC_DIR_FD #undef HAVE_PROC_DIR_FD
#undef HAVE_SETGRENT
#undef HAVE_GETGRENT
#undef HAVE_ENDGRENT
#undef WITH_HELP #undef WITH_HELP
#undef WITH_NOP #undef WITH_NOP
#undef WITH_TEST #undef WITH_TEST

View file

@ -80,6 +80,8 @@ AC_CHECK_HEADERS(sys/utsname.h sys/select.h sys/file.h)
AC_CHECK_HEADERS(util.h libutil.h sys/stropts.h regex.h) AC_CHECK_HEADERS(util.h libutil.h sys/stropts.h regex.h)
AC_CHECK_HEADERS(linux/fs.h linux/ext2_fs.h) AC_CHECK_HEADERS(linux/fs.h linux/ext2_fs.h)
dnl Checks for setgrent, getgrent and endgrent.
AC_CHECK_FUNCS(setgrent getgrent endgrent)
dnl Link libresolv if necessary (for Mac OS X) dnl Link libresolv if necessary (for Mac OS X)
AC_SEARCH_LIBS([res_9_init], [resolv]) AC_SEARCH_LIBS([res_9_init], [resolv])

View file

@ -0,0 +1,56 @@
#!/bin/sh
# Customize these parameters according to your environment
ANDROID_NDK="${HOME}/bin/android-ndk-r6b"
# Check for parameters
if [ ! -d "${ANDROID_NDK}" ]; then
echo "Android NDK not found in ${ANDROID_NDK}, please edit $0 to fix it."
exit 1
fi
if [ ! -e "${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh" ]; then
echo "Your Android NDK is not compatible (make-standalone-toolchain.sh not found)."
echo "Android NDK r6b is known to work."
exit 1
fi
# Extract the Android toolchain from NDK
ANDROID_PLATFORM="android-3"
ROOT="`pwd`"
OUT="${ROOT}/out"
${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \
--ndk-dir="${ANDROID_NDK}" \
--platform="${ANDROID_PLATFORM}" \
--install-dir="${OUT}/toolchain" \
|| exit 1
# Remove resolv.h because it is quite unusable as is
rm ${OUT}/toolchain/sysroot/usr/include/resolv.h
# Create configure script
cd ${ROOT}
autoconf || exit 1
# Create config.h and Makefile
cd ${OUT}
${ROOT}/configure \
--host \
--disable-openssl \
--disable-unix \
CC="${OUT}/toolchain/bin/arm-linux-androideabi-gcc" \
|| exit 1
# Replace misconfigured values in config.h
mv config.h config.old
cat config.old \
| sed 's/CRDLY_SHIFT/CRDLY_SHIFT 9/' \
| sed 's/TABDLY_SHIFT/TABDLY_SHIFT 11/' \
| sed 's/CSIZE_SHIFT/CSIZE_SHIFT 4/' \
> config.h
# Compile
make socat || exit 1
# Done
echo "Build finished, socat has been generated successfuly in out/socat"

View file

@ -412,6 +412,7 @@ char *sockaddr_inet6_info(const struct sockaddr_in6 *sa, char *buff, size_t blen
} }
#endif /* WITH_IP6 */ #endif /* WITH_IP6 */
#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
/* fill the list with the supplementary group ids of user. /* fill the list with the supplementary group ids of user.
caller passes size of list in ngroups, function returns number of groups in caller passes size of list in ngroups, function returns number of groups in
ngroups. ngroups.
@ -438,6 +439,7 @@ int getusergroups(const char *user, gid_t *list, size_t *ngroups) {
*ngroups = i; *ngroups = i;
return 0; return 0;
} }
#endif
#if !HAVE_HSTRERROR #if !HAVE_HSTRERROR
const char *hstrerror(int err) { const char *hstrerror(int err) {

View file

@ -74,7 +74,9 @@ extern const char *inet_ntop(int pf, const void *binaddr,
char *addrtext, socklen_t textlen); char *addrtext, socklen_t textlen);
#endif #endif
#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
extern int getusergroups(const char *user, gid_t *list, size_t *ngroups); extern int getusergroups(const char *user, gid_t *list, size_t *ngroups);
#endif
#if !HAVE_HSTRERROR #if !HAVE_HSTRERROR
extern const char *hstrerror(int err); extern const char *hstrerror(int err);

View file

@ -1,5 +1,5 @@
/* source: xio-process.c */ /* source: xio-process.c */
/* Copyright Gerhard Rieger 2001-2009 */ /* Copyright Gerhard Rieger 2001-2012 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
/* this file handles process related addresses options */ /* this file handles process related addresses options */
@ -16,7 +16,9 @@ const struct optdesc opt_setuid_early= { "setuid-early",NULL, OPT_SETUID_EARLY,
const struct optdesc opt_setuid = { "setuid", NULL, OPT_SETUID, GROUP_PROCESS, PH_LATE2, TYPE_UIDT, OFUNC_SPEC }; const struct optdesc opt_setuid = { "setuid", NULL, OPT_SETUID, GROUP_PROCESS, PH_LATE2, TYPE_UIDT, OFUNC_SPEC };
const struct optdesc opt_substuser_early = { "substuser-early", "su-e", OPT_SUBSTUSER_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_UIDT, OFUNC_SPEC }; const struct optdesc opt_substuser_early = { "substuser-early", "su-e", OPT_SUBSTUSER_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_UIDT, OFUNC_SPEC };
const struct optdesc opt_substuser = { "substuser", "su", OPT_SUBSTUSER, GROUP_PROCESS, PH_LATE2, TYPE_UIDT, OFUNC_SPEC }; const struct optdesc opt_substuser = { "substuser", "su", OPT_SUBSTUSER, GROUP_PROCESS, PH_LATE2, TYPE_UIDT, OFUNC_SPEC };
#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
const struct optdesc opt_substuser_delayed = { "substuser-delayed", "su-d", OPT_SUBSTUSER_DELAYED, GROUP_PROCESS, PH_INIT, TYPE_UIDT, OFUNC_SPEC }; const struct optdesc opt_substuser_delayed = { "substuser-delayed", "su-d", OPT_SUBSTUSER_DELAYED, GROUP_PROCESS, PH_INIT, TYPE_UIDT, OFUNC_SPEC };
#endif
const struct optdesc opt_chroot_early = { "chroot-early", NULL, OPT_CHROOT_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_STRING, OFUNC_SPEC }; const struct optdesc opt_chroot_early = { "chroot-early", NULL, OPT_CHROOT_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_STRING, OFUNC_SPEC };
const struct optdesc opt_chroot = { "chroot", NULL, OPT_CHROOT, GROUP_PROCESS, PH_LATE, TYPE_STRING, OFUNC_SPEC }; const struct optdesc opt_chroot = { "chroot", NULL, OPT_CHROOT, GROUP_PROCESS, PH_LATE, TYPE_STRING, OFUNC_SPEC };
const struct optdesc opt_setsid = { "setsid", "sid", OPT_SETSID, GROUP_PROCESS, PH_LATE, TYPE_BOOL, OFUNC_SPEC }; const struct optdesc opt_setsid = { "setsid", "sid", OPT_SETSID, GROUP_PROCESS, PH_LATE, TYPE_BOOL, OFUNC_SPEC };

View file

@ -1,5 +1,5 @@
/* source: xio-process.h */ /* source: xio-process.h */
/* Copyright Gerhard Rieger 2001-2009 */ /* Copyright Gerhard Rieger 2001-2012 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
#ifndef __xio_process_h_included #ifndef __xio_process_h_included
@ -11,7 +11,9 @@ extern const struct optdesc opt_setuid_early;
extern const struct optdesc opt_setuid; extern const struct optdesc opt_setuid;
extern const struct optdesc opt_substuser_early; extern const struct optdesc opt_substuser_early;
extern const struct optdesc opt_substuser; extern const struct optdesc opt_substuser;
#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
extern const struct optdesc opt_substuser_delayed; extern const struct optdesc opt_substuser_delayed;
#endif
extern const struct optdesc opt_chroot_early; extern const struct optdesc opt_chroot_early;
extern const struct optdesc opt_chroot; extern const struct optdesc opt_chroot;
extern const struct optdesc opt_setsid; extern const struct optdesc opt_setsid;

View file

@ -91,7 +91,9 @@ static int xioopen_pty(const char *linkname, struct opt *opts, int xioflags, xio
useptmx = true; useptmx = true;
# endif /* !HAVE_OPENPTY */ # endif /* !HAVE_OPENPTY */
#else #else
# if HAVE_OPENPTY
useopenpty = true; useopenpty = true;
#endif /* HAVE_OPENPTY */
#endif /* ! (defined(HAVE_DEV_PTMX) || defined(HAVE_DEV_PTC)) */ #endif /* ! (defined(HAVE_DEV_PTMX) || defined(HAVE_DEV_PTC)) */
#if HAVE_POLL #if HAVE_POLL

View file

@ -1430,10 +1430,14 @@ const struct optname optionnames[] = {
IF_ANY ("streams-i-push", &opt_streams_i_push) IF_ANY ("streams-i-push", &opt_streams_i_push)
#endif #endif
IF_ANY ("su", &opt_substuser) IF_ANY ("su", &opt_substuser)
#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
IF_ANY ("su-d", &opt_substuser_delayed) IF_ANY ("su-d", &opt_substuser_delayed)
#endif
IF_ANY ("su-e", &opt_substuser_early) IF_ANY ("su-e", &opt_substuser_early)
IF_ANY ("substuser", &opt_substuser) IF_ANY ("substuser", &opt_substuser)
#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
IF_ANY ("substuser-delayed", &opt_substuser_delayed) IF_ANY ("substuser-delayed", &opt_substuser_delayed)
#endif
IF_ANY ("substuser-early", &opt_substuser_early) IF_ANY ("substuser-early", &opt_substuser_early)
IF_TERMIOS("susp", &opt_vsusp) IF_TERMIOS("susp", &opt_vsusp)
#ifdef VSWTC #ifdef VSWTC
@ -3323,6 +3327,7 @@ int applyopts(int fd, struct opt *opts, enum e_phase phase) {
#endif #endif
} }
break; break;
#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
case OPT_SUBSTUSER_DELAYED: case OPT_SUBSTUSER_DELAYED:
{ {
struct passwd *pwd; struct passwd *pwd;
@ -3356,6 +3361,7 @@ int applyopts(int fd, struct opt *opts, enum e_phase phase) {
delayeduser = true; delayeduser = true;
} }
break; break;
#endif
case OPT_CHROOT_EARLY: case OPT_CHROOT_EARLY:
case OPT_CHROOT: case OPT_CHROOT:
if (Chroot(opt->value.u_string) < 0) { if (Chroot(opt->value.u_string) < 0) {