diff --git a/client/gui_rpc_server.C b/client/gui_rpc_server.C index 64b2db18fa..90187acd53 100644 --- a/client/gui_rpc_server.C +++ b/client/gui_rpc_server.C @@ -702,10 +702,10 @@ int GUI_RPC_CONN_SET::init() { int one = 1; setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (char*)&one, 4); - retval = bind(lsock, (const sockaddr*)(&addr), (socklen_t)sizeof(addr)); + retval = bind(lsock, (const sockaddr*)(&addr), (boinc_socklen_t)sizeof(addr)); if (retval) { addr.sin_port = htons(GUI_RPC_PORT_ALT); - retval = bind(lsock, (const sockaddr*)(&addr), (socklen_t)sizeof(addr)); + retval = bind(lsock, (const sockaddr*)(&addr), (boinc_socklen_t)sizeof(addr)); if (retval) { msg_printf(NULL, MSG_ERROR, "GUI RPC bind failed: %d\n", retval); boinc_close_socket(lsock); @@ -778,7 +778,7 @@ bool GUI_RPC_CONN_SET::poll(double) { if (FD_ISSET(lsock, &read_fds)) { struct sockaddr_in addr; - socklen_t addr_len = sizeof(addr); + boinc_socklen_t addr_len = sizeof(addr); sock = accept(lsock, (struct sockaddr*)&addr, &addr_len); int peer_ip = (int) ntohl(addr.sin_addr.s_addr); diff --git a/client/ssl_net_xfer.C b/client/ssl_net_xfer.C index 7630f28fc3..490ae21249 100644 --- a/client/ssl_net_xfer.C +++ b/client/ssl_net_xfer.C @@ -77,13 +77,11 @@ #include "client_msgs.h" #if defined(_WIN32) -typedef int socklen_t; +typedef int boinc_socklen_t; #elif defined ( __APPLE__) -typedef int32_t socklen_t; -#elif !GETSOCKOPT_SOCKLEN_T -#ifndef socklen_t -typedef size_t socklen_t; -#endif +typedef int32_t boinc_socklen_t; +#else +typedef BOINC_SOCKLEN_T boinc_socklen_t; #endif // if an active transfer doesn't get any activity @@ -91,7 +89,7 @@ typedef size_t socklen_t; #define NET_XFER_TIMEOUT 600 int get_socket_error(int fd) { - socklen_t intsize = sizeof(int); + boinc_socklen_t intsize = sizeof(int); int n; #ifdef WIN32 getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&n, &intsize); diff --git a/lib/network.C b/lib/network.C index 4b558bd475..ba9c1d1ecf 100644 --- a/lib/network.C +++ b/lib/network.C @@ -162,7 +162,7 @@ void boinc_close_socket(int sock) { } int get_socket_error(int fd) { - socklen_t intsize = sizeof(int); + boinc_socklen_t intsize = sizeof(int); int n; #ifdef WIN32 getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&n, &intsize); diff --git a/lib/network.h b/lib/network.h index ebfe3fade5..cf91e3a146 100644 --- a/lib/network.h +++ b/lib/network.h @@ -16,6 +16,8 @@ // http://www.gnu.org/copyleft/lesser.html // or write to the Free Software Foundation, Inc., // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#ifndef _BOINC_NETWORK_H_ +#define _BOINC_NETWORK_H_ extern int resolve_hostname(char* hostname, int& ip_addr, char* msg); extern int boinc_socket(int& sock); @@ -24,12 +26,12 @@ extern void boinc_close_socket(int sock); extern int get_socket_error(int fd); #if defined(_WIN32) -typedef int socklen_t; +typedef int boinc_socklen_t; #define SHUT_WR SD_SEND #elif defined( __APPLE__) -typedef int32_t socklen_t; -#elif !defined(GETSOCKOPT_SOCKLEN_T) && !defined(_SOCKLEN_T_DECLARED) && !defined(socklen_t) -typedef size_t socklen_t; +typedef int32_t boinc_socklen_t; +#else +typedef BOINC_SOCKLEN_T boinc_socklen_t; #endif #define CONNECTED_STATE_NOT_CONNECTED 0 @@ -45,3 +47,4 @@ extern int NetOpen(); extern void NetClose(); extern void NetCheck(bool hangup_if_dialed); #endif +#endif diff --git a/m4/boinc_getsockopt.m4 b/m4/boinc_getsockopt.m4 index c03a145dde..a7f8646128 100644 --- a/m4/boinc_getsockopt.m4 +++ b/m4/boinc_getsockopt.m4 @@ -1,16 +1,66 @@ AC_DEFUN([BOINC_GETSOCKOPT_TYPE],[ -dnl TODO: use compiler to test these; there probably exists an autoconf macro already! -AC_MSG_CHECKING(type of getsockopt() parameter four) -case "$target" in -*-linux* | *solaris* | *openbsd* ) - AC_DEFINE(GETSOCKOPT_SOCKLEN_T, 1, [getsockopt uses socklen_t]) - AC_MSG_RESULT(socklen_t) - ;; -*sysv5OpenUNIX8* | *hpux* | i*86*cygwin* ) - AC_DEFINE(GETSOCKOPT_SIZE_T, 1, [getsockopt uses size_t]) - AC_MSG_RESULT(size_t) - ;; -esac +AC_LANG_PUSH(C) +AC_CHECK_HEADERS([sys/socket.h]) +if test "${ac_cv_header_sys_socket_h}" = "yes" ; then + ac_includes_default="${ac_includes_default} +#include +" +fi +AC_CHECK_TYPES([socklen_t]) +B_SV_CFLAGS="${CFLAGS}" +if test "${ac_cv_c_compiler_gnu}" = "yes" ; then + CFLAGS="${CFLAGS} -Werror -pedantic" +fi +AC_CACHE_CHECK([type of getsockopt() parameter five], +[boinc_cv_getsockopt_type], +[ + if test "${ac_cv_type_socklen_t}" = "yes" ; then + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ +#define CONFIG_TEST +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + ]], + [ + socklen_t l; + return getsockopt(0,0,0,(void *)0,&l); + ])], + [ + boinc_cv_getsockopt_type="socklen_t" + ] + ) + fi + if test -z "${boinc_cv_getsockopt_type}"; then + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ +#define CONFIG_TEST +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + ]], + [ + size_t l; + return getsockopt(0,0,0,(void *)0,&l); + ])], + [ + boinc_cv_getsockopt_type="size_t" + ], + [ + boinc_cv_getsockopt_type="int" + ] + ) + fi +]) +CFLAGS="${B_SV_CFLAGS}" +AC_DEFINE_UNQUOTED([BOINC_SOCKLEN_T],[${boinc_cv_getsockopt_type}],[Define to the type pointed to by the 5th parameter of getsockopt]) +AC_LANG_POP(C) ])