diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 |
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 |
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /soxwrap | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'soxwrap')
| -rw-r--r-- | soxwrap/.gitignore | 4 | ||||
| -rw-r--r-- | soxwrap/Makefile.am | 22 | ||||
| -rw-r--r-- | soxwrap/configure.in | 195 | ||||
| -rw-r--r-- | soxwrap/mksocket.c | 426 | ||||
| -rw-r--r-- | soxwrap/mksocket.h | 45 | ||||
| -rw-r--r-- | soxwrap/sconnect.c | 98 | ||||
| -rw-r--r-- | soxwrap/sconnect.h | 32 | ||||
| -rw-r--r-- | soxwrap/soxwrap.h | 79 | ||||
| -rw-r--r-- | soxwrap/testprog.c | 34 |
9 files changed, 935 insertions, 0 deletions
diff --git a/soxwrap/.gitignore b/soxwrap/.gitignore new file mode 100644 index 0000000..e4a99ed --- /dev/null +++ b/soxwrap/.gitignore @@ -0,0 +1,4 @@ +/soxlibs.dep +/soxwrap_config.h +/soxwrap_config.h.in +/testprog diff --git a/soxwrap/Makefile.am b/soxwrap/Makefile.am new file mode 100644 index 0000000..4ade876 --- /dev/null +++ b/soxwrap/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 2000-2004 Double Precision, Inc. See COPYING for +# distribution information. + + +DISTCLEANFILES=soxlibs.dep + +noinst_LIBRARIES=libsoxwrap.a libmksocket.a + +libsoxwrap_a_SOURCES=soxwrap.h \ + sconnect.c sconnect.h + +libmksocket_a_SOURCES=mksocket.c mksocket.h + +noinst_PROGRAMS=testprog + +testprog_SOURCES=testprog.c +testprog_DEPENDENCIES=libsoxwrap.a config.status +testprog_LDADD=libsoxwrap.a @SOCKLIBS@ + +check-am: + ./testprog diff --git a/soxwrap/configure.in b/soxwrap/configure.in new file mode 100644 index 0000000..e096ad5 --- /dev/null +++ b/soxwrap/configure.in @@ -0,0 +1,195 @@ +dnl Process this file with autoconf to produce a configure script. + +dnl Copyright 2000-2009 Double Precision, Inc. See COPYING for +dnl distribution information. + +AC_INIT(soxwrap, 0.50, [courier-users@lists.sourceforge.net]) + +>confdefs.h # Kill PACKAGE_ macros + +AC_CONFIG_SRCDIR(soxwrap.h) +AC_CONFIG_AUX_DIR(../..) +AM_INIT_AUTOMAKE([foreign no-define]) + +AM_CONFIG_HEADER(soxwrap_config.h) + +>confdefs.h # Nuke PACKAGE_ macros. + +dnl Checks for programs. +AC_PROG_AWK +AC_PROG_INSTALL +AC_PROG_RANLIB +AC_PROG_LN_S +AC_PROG_CC + +dnl Check for options + +AC_CACHE_CHECK([for the Courier Socks library], + ac_cv_courier_socks, + +AC_COMPILE_IFELSE([ + AC_LANG_SOURCE([ +#include <socks.h> + +#ifndef courier_socks_h +#error Not a Courier socks header file +#endif +],[ int x=0; ])], [ac_cv_courier_socks=yes],[ac_cv_courier_socks=no]) + +) + +AC_ARG_WITH(socks, +[--without-socks - Do not use the Courier Socks library +--with-socks - Use Courier Socks library], +[ + if test "$withval" = "yes" + then + if test "$ac_cv_courier_socks" = "no" + then + AC_MSG_ERROR([Courier Socks header files not found]) + fi + else + ac_cv_courier_socks=no + fi +]) + +dnl Checks for libraries. + +saveLIBS="$LIBS" +NETLIBS="" +USENSL=no + +AC_CHECK_LIB(socket,socket,result=yes,result=no) +if test $result = yes; then + NETLIBS="-lsocket" +else + AC_CHECK_LIB(socket,socket,result=yes,result=no,-lnsl) + if test $result = yes; then + NETLIBS = "-lsocket -lnsl" + USENSL=yes + else + AC_CHECK_LIB(socket,connect,result=yes,result=no) + if test $result = yes; then + NETLIBS="-lsocket" + else + AC_CHECK_LIB(socket,connect,result=yes,result=no,-lnsl) + if test $result = yes; then + NETLIBS="-lsocket -lnsl" + USENSL=yes + fi + fi + fi +fi + +if test $USENSL != yes; then + LIBS="$LIBS $NETLIBS" + AC_TRY_LINK_FUNC(inet_addr, [ : ], + [ + AC_CHECK_LIB(nsl,inet_addr,result=yes,result=no) + if test $result = yes; then + NETLIBS="$NETLIBS -lnsl" + fi + ]) +fi + +LIBS="$saveLIBS" + +if test "$ac_cv_courier_socks" = "yes" +then + SOCKLIBS="-lsocks" + DOSOCKS=1 +else + SOCKLIBS=$NETLIBS + DOSOCKS=0 +fi + +AC_DEFINE_UNQUOTED(HAVE_SOCKS, $DOSOCKS, [ Whether to use the Courier Socks library ]) + +AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/select.h sys/poll.h pthread.h sys/stat.h fcntl.h sys/select.h sys/poll.h]) +AC_HEADER_TIME +AC_SYS_LARGEFILE +AC_SUBST(SOCKLIBS) + + +echo $SOCKLIBS >soxlibs.dep +CPPFLAGS="-I.. -I$srcdir/.. $CPPFLAGS" +dnl Checks for typedefs, structures, and compiler characteristics. + +AC_CACHE_CHECK([for structs in6_addr, sockaddr_in6, and sockaddr_storage], + soxwrap_cv_hasipv6structs, + +AC_TRY_COMPILE( [ +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + + ], [ +struct in6_addr in6a; +struct sockaddr_in6 sain6; +struct sockaddr_storage soas; +int x=PF_INET6; + + ], soxwrap_cv_hasipv6structs=yes, + soxwrap_cv_hasipv6structs=no ) +) + +AC_ARG_WITH(ipv6, [ --without-ipv6 Disable IPv6 support], +[ +case $withval in +y*|Y*) + if test "$soxwrap_cv_hasipv6structs" = no + then + AC_MSG_ERROR(IPv6 support not available) + fi + ;; +*) + soxwrap_cv_hasipv6structs=no + ;; +esac +] +) + +storage="struct sockaddr" +storage_family="sa_family" + +if test "$soxwrap_cv_hasipv6structs" = "yes" +then + AC_DEFINE_UNQUOTED(HAVE_SOXWRAP_IPV6,1,[Whether IPv6 is available]) + storage="struct sockaddr_storage" + storage_family="ss_family" +fi +AC_DEFINE_UNQUOTED(SOCKADDR_STORAGE, $storage, [ Whether sockaddr_storage is available ]) +AC_DEFINE_UNQUOTED(SS_family, $storage_family, [ The address family field in SOCKADDR_STORAGE]) + +dnl Check for socklen_t + +AC_CACHE_CHECK([for socklen_t], + sox_cv_hassocklen_t, + +AC_COMPILE_IFELSE([ +AC_LANG_SOURCE( [ +#include <sys/types.h> +#include <sys/socket.h> + +socklen_t sl_t; +],[ + accept(0, 0, &sl_t); +])], + sox_cv_hassocklen_t=yes, + sox_cv_hassocklen_t=no) +) + +socklen_t="int" + +if test $sox_cv_hassocklen_t = yes +then + : +else + AC_DEFINE_UNQUOTED(socklen_t, int, [ Default definition for socklen_t ]) +fi + + + +AC_CHECK_FUNCS(inet_pton poll) +AC_OUTPUT(Makefile) diff --git a/soxwrap/mksocket.c b/soxwrap/mksocket.c new file mode 100644 index 0000000..f375917 --- /dev/null +++ b/soxwrap/mksocket.c @@ -0,0 +1,426 @@ +/* +** Copyright 2004-2009 Double Precision, Inc. +** See COPYING for distribution information. +*/ + +#include "mksocket.h" + +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#if HAVE_FCNTL_H +#include <fcntl.h> +#endif +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include "soxwrap.h" + + +#define MKS_USEAFINET4 1 +#define MKS_ERROK 2 + +#if HAVE_SOXWRAP_IPV6 +typedef struct in6_addr NET_ADDR; +typedef struct sockaddr_in6 NET_SOCKADDR; +typedef struct sockaddr_storage NET_NETADDR; +#define NET_ADDRANY in6addr_any +#else +typedef struct in_addr NET_ADDR; +typedef struct sockaddr_in NET_SOCKADDR; +typedef struct sockaddr NET_NETADDR; + +extern struct in_addr rfc1035_addr_any; +#define NET_ADDRANY rfc1035_addr_any +#endif + +struct recycle_info { + const struct sockaddr *sin; + socklen_t sin_len; + int found_socket; +}; + +/* +** If caller already has a socket listening on this address, recycle it. +*/ + +static int try_recycle_socket(int fd, void *voidarg) +{ + struct recycle_info *ri=(struct recycle_info *)voidarg; + + union { + SOCKADDR_STORAGE ss; + struct sockaddr_in sin; +#if HAVE_SOXWRAP_IPV6 + struct sockaddr_in6 sin6; +#endif + } sa; + + socklen_t salen=sizeof(sa); + + if (getsockname(fd, (struct sockaddr *)&sa, &salen) < 0) + return 0; + + if (ri->sin->sa_family != sa.ss.SS_family) + return 0; + + switch (ri->sin->sa_family) { + case AF_INET: + { + struct sockaddr_in ri_sin; + + memcpy(&ri_sin, ri->sin, sizeof(ri_sin)); + + if (ri_sin.sin_addr.s_addr != sa.sin.sin_addr.s_addr + || ri_sin.sin_port != sa.sin.sin_port) + return 0; + } + break; + +#if HAVE_SOXWRAP_IPV6 + case AF_INET6: + { + struct sockaddr_in6 ri_sin; + + memcpy(&ri_sin, ri->sin, sizeof(ri_sin)); + + if (memcmp(&ri_sin.sin6_addr, &sa.sin6.sin6_addr, + sizeof(sa.sin6.sin6_addr)) || + ri_sin.sin6_port != sa.sin6.sin6_port) + return 0; + } + break; +#endif + default: + return 0; + } + ri->found_socket=fd; + return 1; +} + +static int mksocket2(const char *ipaddrarg, /* Host/IP address */ + const char *servname, /* Service/port */ + int socktype, /* SOCKS_STREAM */ + int flags, + int (*recycle_fd_func) + ( int(*)(int, void *), void *, void *), + void *voidarg) +{ + struct servent *servptr; + int port; + int fd; + struct recycle_info ri; + const struct sockaddr *sinaddr; + int sinaddrlen; + +#if HAVE_SOXWRAP_IPV6 + struct sockaddr_in6 sin6; +#endif + + struct sockaddr_in sin4; + + int af; + + servptr=getservbyname(servname, "tcp"); + if (servptr) + port=servptr->s_port; + else + { + port=atoi(servname); + if (port <= 0 || port > 65535) + { + fprintf(stderr, "Invalid port: %s\n", servname); + return (-1); + } + port=htons(port); + } + + /* Create an IPv6 or an IPv4 socket */ + +#if HAVE_SOXWRAP_IPV6 + if (flags & MKS_USEAFINET4) + { + fd=sox_socket(PF_INET, socktype, 0); + af=AF_INET; + } + else +#endif + { +#if HAVE_SOXWRAP_IPV6 + + if ((fd=sox_socket(PF_INET6, socktype, 0)) >= 0) + af=AF_INET6; + else +#endif + { + af=AF_INET; + fd=sox_socket(PF_INET, socktype, 0); + } + } + + if (fd < 0) + return (-1); + + /* Figure out what to bind based on what socket we created */ + + if (ipaddrarg && strcmp(ipaddrarg, "0")) + { + +#if HAVE_SOXWRAP_IPV6 + if (af == AF_INET6) + { + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family=af; + if (inet_pton(af, ipaddrarg, &sin6.sin6_addr) <= 0) + { + errno=EINVAL; + close(fd); + return -1; + } + sin6.sin6_port=port; + + sinaddr=(const struct sockaddr *)&sin6; + sinaddrlen=sizeof(sin6); + } + else +#endif + if (af == AF_INET) + { + memset(&sin4, 0, sizeof(sin4)); + sin4.sin_family=AF_INET; + if (inet_aton(ipaddrarg, &sin4.sin_addr) == 0) + { + errno=EINVAL; + close(fd); + return -1; + } + sin4.sin_port=port; + sinaddr=(const struct sockaddr *)&sin4; + sinaddrlen=sizeof(sin4); + } + else + { + errno=EAFNOSUPPORT; + close(fd); + return (-1); + } + } + else /* Bind default address */ + { +#if HAVE_SOXWRAP_IPV6 + if (af == AF_INET6) + { + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family=AF_INET6; + sin6.sin6_addr=in6addr_any; + sin6.sin6_port=port; + sinaddr=(const struct sockaddr *)&sin6; + sinaddrlen=sizeof(sin6); + } + else +#endif + if (af == AF_INET) + { + sin4.sin_family=AF_INET; + sin4.sin_addr.s_addr=INADDR_ANY; + sin4.sin_port=port; + sinaddr=(const struct sockaddr *)&sin4; + sinaddrlen=sizeof(sin4); + } + else + { + errno=EAFNOSUPPORT; + close(fd); + return (-1); + } + } + + ri.found_socket= -1; + ri.sin=sinaddr; + ri.sin_len=sinaddrlen; + + if (recycle_fd_func && + (*recycle_fd_func)(&try_recycle_socket, &ri, voidarg) > 0 && + ri.found_socket >= 0) + { + close(fd); + return dup(ri.found_socket); + } + + { + int dummy=1; + + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, + (const char *)&dummy, sizeof(dummy)); + } + + if (fcntl(fd, F_SETFD, FD_CLOEXEC)) + { + close(fd); + return (-1); + } + + if (fcntl(fd, F_SETFL, O_NONBLOCK)) + { + close(fd); + return (-1); + } + { + int dummy=1; + + setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, + (const char *)&dummy, sizeof(dummy)); + } + + if (sox_bind(fd, sinaddr, sinaddrlen) < 0) + { + if (flags & MKS_ERROK) + { + close(fd); + return (-2); + } + close(fd); + return (-1); + } + + if (sox_listen(fd, +#ifdef SOMAXCONN + SOMAXCONN +#else + 5 +#endif + )) + { + if (flags && MKS_ERROK) + { + close(fd); + return (-2); + } + close(fd); + return (-1); + } + return (fd); +} + + +int mksocket(const char *address, + const char *service, + int socktype, + int *fd1, + int *fd2, + int recycle_fd_func( int(*)(int, void *), void *, void *), + void *voidarg) +{ + int fd_flag=0; + + *fd1= -1; + *fd2= -1; + + if (address && strcmp(address, "0")) + { +#if HAVE_INET_PTON + SOCKADDR_STORAGE ina; + + if (inet_pton(AF_INET, address, &ina) > 0) + fd_flag=MKS_USEAFINET4; +#else + struct in_addr ina; + + if (inet_aton(address, &ina)) + fd_flag=MKS_USEAFINET4; +#endif + + } + + + *fd1=mksocket2(address, service, socktype, fd_flag, + recycle_fd_func, voidarg); + + /* BSD requires both an IPv6 and an IPv4 socket */ + +#if HAVE_SOXWRAP_IPV6 + + if (address == 0 || strcmp(address, "0") == 0) + { + int fd=mksocket2(address, service, socktype, + (MKS_USEAFINET4|MKS_ERROK), + recycle_fd_func, voidarg); + + if (fd < 0) + { + if (fd != -2) + { + if (*fd1 >= 0) + close(*fd1); + return -1; + } + } + + *fd2=fd; + } +#endif + if (*fd1 < 0 && *fd2 < 0) + return -1; + + if (*fd1 < 0) + { + *fd1=*fd2; + *fd2=-1; + } + return 0; +} + +#if HAVE_SYS_POLL_H + +#else + +int poll(struct pollfd *pfd, unsigned int n, int timeout) +{ + fd_set r, w, e; + int maxfd=-1; + unsigned int i; + struct timeval tv; + int cnt=0; + + FD_ZERO(&r); + FD_ZERO(&w); + FD_ZERO(&e); + + for (i=0; i<n; i++) + { + if (pfd[i].fd >= maxfd) + maxfd=pfd[i].fd; + + pfd[i].revents=0; + if (pfd[i].events & (POLLIN|POLLPRI)) + FD_SET(pfd[i].fd, &r); + if (pfd[i].events & POLLOUT) + FD_SET(pfd[i].fd, &w); + if (pfd[i].events & POLLPRI) + FD_SET(pfd[i].fd, &e); + } + + tv.tv_sec=timeout/1000; + tv.tv_usec=(timeout % 1000) * 1000; + + if (select(maxfd+1, &r, &w, &e, timeout < 0 ?NULL:&tv) < 0) + return -1; + + for (i=0; i<n; i++) + { + if (FD_ISSET(pfd[i].fd, &r)) + pfd[i].revents |= POLLIN; + if (FD_ISSET(pfd[i].fd, &w)) + pfd[i].revents |= POLLOUT; + if (FD_ISSET(pfd[i].fd, &e)) + pfd[i].revents |= POLLIN|POLLHUP; + + if (pfd[i].revents) + ++cnt; + } + + return cnt; +} + +#endif diff --git a/soxwrap/mksocket.h b/soxwrap/mksocket.h new file mode 100644 index 0000000..2b74b04 --- /dev/null +++ b/soxwrap/mksocket.h @@ -0,0 +1,45 @@ +#ifndef mksocket_h +#define mksocket_h + +#if HAVE_CONFIG_H +#include "soxwrap/soxwrap_config.h" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +extern int mksocket(const char *address, + const char *service, + int socktype, + int *fd1, + int *fd2, + int recycle_fd_func( int(*)(int, void *), void *, void *), + void *voidarg); + +#if HAVE_SYS_POLL_H +#include <sys/poll.h> +#else + +#define POLLIN 1 +#define POLLPRI 2 +#define POLLOUT 4 +#define POLLERR 8 +#define POLLHUP 16 +#define POLLNVAL 32 + +struct pollfd { + int fd; + short events, revents; +}; + +extern int poll(struct pollfd *pfd, unsigned int n, int timeout); + +#endif + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/soxwrap/sconnect.c b/soxwrap/sconnect.c new file mode 100644 index 0000000..7d933bf --- /dev/null +++ b/soxwrap/sconnect.c @@ -0,0 +1,98 @@ +/* +** Copyright 2001 Double Precision, Inc. +** See COPYING for distribution information. +*/ + +#include "sconnect.h" + +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#if HAVE_FCNTL_H +#include <fcntl.h> +#endif +#include <stdio.h> +#include <errno.h> +#include <string.h> + +#include "soxwrap.h" + + +int s_connect(int sockfd, const struct sockaddr *addr, size_t addr_s, + time_t connect_timeout) +{ + fd_set fdr; + struct timeval tv; + int rc; + +#ifdef SOL_KEEPALIVE + setsockopt(sockfd, SOL_SOCKET, SOL_KEEPALIVE, + (const char *)&dummy, sizeof(dummy)); +#endif + +#ifdef SOL_LINGER + { + struct linger l; + + l.l_onoff=0; + l.l_linger=0; + + setsockopt(sockfd, SOL_SOCKET, SOL_LINGER, + (const char *)&l, sizeof(l)); + } +#endif + + /* + ** If configuration says to use the kernel's timeout settings, + ** just call connect, and be done with it. + */ + + if (connect_timeout == 0) + return ( sox_connect(sockfd, addr, addr_s)); + + /* Asynchronous connect with timeout. */ + + if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) return (-1); + + if ( sox_connect(sockfd, addr, addr_s) == 0) + { + /* That was easy, we're done. */ + + if (fcntl(sockfd, F_SETFL, 0) < 0) return (-1); + return (0); + } + else + if (errno != EINPROGRESS) return (-1); + + /* Wait for the connection to go through, until the timeout expires */ + + FD_ZERO(&fdr); + FD_SET(sockfd, &fdr); + tv.tv_sec=connect_timeout; + tv.tv_usec=0; + + rc=sox_select(sockfd+1, 0, &fdr, 0, &tv); + if (rc < 0) return (-1); + + if (!FD_ISSET(sockfd, &fdr)) + { + errno=ETIMEDOUT; + return (-1); + } + + { + int gserr; + socklen_t gslen = sizeof(gserr); + + if (sox_getsockopt(sockfd, SOL_SOCKET, + SO_ERROR, + (char *)&gserr, &gslen)==0) + { + if (gserr == 0) + return 0; + + errno=gserr; + } + } + return (-1); +} diff --git a/soxwrap/sconnect.h b/soxwrap/sconnect.h new file mode 100644 index 0000000..750a812 --- /dev/null +++ b/soxwrap/sconnect.h @@ -0,0 +1,32 @@ +#ifndef sconnect_h +#define sconnect_h + +#if HAVE_CONFIG_H +#include "soxwrap/soxwrap_config.h" +#endif + +#if TIME_WITH_SYS_TIME +#include <sys/time.h> +#include <time.h> +#else +#if HAVE_SYS_TIME_H +#include <sys/time.h> +#else +#include <time.h> +#endif +#endif +#include <sys/types.h> +#include <sys/socket.h> + +/* +** Copyright 2001 Double Precision, Inc. +** See COPYING for distribution information. +*/ + + +#ifdef __cplusplus +extern "C" +#endif +int s_connect(int, const struct sockaddr *, size_t, time_t); + +#endif diff --git a/soxwrap/soxwrap.h b/soxwrap/soxwrap.h new file mode 100644 index 0000000..a6ba26c --- /dev/null +++ b/soxwrap/soxwrap.h @@ -0,0 +1,79 @@ +#ifndef soxwrap_h +#define soxwrap_h + +/* +** Copyright 2000 Double Precision, Inc. +** See COPYING for distribution information. +*/ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "soxwrap/soxwrap_config.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#if HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif +#if HAVE_SYS_POLL_H +#include <sys/poll.h> +#endif +#include <netinet/in.h> +#include <arpa/inet.h> +#include <fcntl.h> +#include <netdb.h> +#include <unistd.h> + +#define sox_init(s) 0 +#define sox_socket socket + +#if HAVE_SOCKS + +#include <socks.h> + +#define sox_getpeername Rgetpeername +#define sox_getsockname Rgetsockname +#define sox_accept Raccept +#define sox_connect Rconnect +#define sox_bind Rbind +#define sox_listen Rlisten +#define sox_recvfrom Rrecvfrom +#define sox_sendto Rsendto +#define sox_read Rread +#define sox_write Rwrite +#define sox_close Rclose +#define sox_dup Rdup +#define sox_dup2 Rdup2 +#define sox_select Rselect +#define sox_poll Rpoll +#define sox_getsockopt Rgetsockopt + +#else + +#define sox_getpeername getpeername +#define sox_getsockname getsockname +#define sox_accept accept +#define sox_connect connect +#define sox_bind bind +#define sox_listen listen +#define sox_recvfrom recvfrom +#define sox_sendto sendto +#define sox_read read +#define sox_write write +#define sox_close close +#define sox_dup dup +#define sox_dup2 dup2 +#define sox_select select +#define sox_poll poll +#define sox_getsockopt getsockopt +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/soxwrap/testprog.c b/soxwrap/testprog.c new file mode 100644 index 0000000..4396d56 --- /dev/null +++ b/soxwrap/testprog.c @@ -0,0 +1,34 @@ +/* +** Copyright 2000-2006 Double Precision, Inc. +** See COPYING for distribution information. +*/ + +#include "soxwrap.h" +#include <stdlib.h> +#include <stdio.h> + + +int main(int argc, char **argv) +{ +int fd=sox_socket(PF_INET, SOCK_STREAM, 0); +struct sockaddr addr; +socklen_t addr_len; + + if (fd < 0) + { + perror("socket"); + exit(1); + } + + addr_len=sizeof(addr); + + if (sox_getsockname(fd, &addr, &addr_len)) + { + perror("getsockname"); + exit(1); + } + + sox_close(fd); + exit(0); + return (0); +} |
