Add socklen_t check with substitution, use socklen_t as needed

master
Pavel Roskin 8 years ago
parent 49ae93130a
commit 5465b8c85e

@ -332,13 +332,8 @@ int APP_CC
g_tcp_set_no_delay(int sck) g_tcp_set_no_delay(int sck)
{ {
int ret = 1; /* error */ int ret = 1; /* error */
#if defined(_WIN32)
int option_value;
int option_len;
#else
int option_value; int option_value;
unsigned int option_len; socklen_t option_len;
#endif
option_len = sizeof(option_value); option_len = sizeof(option_value);
@ -376,13 +371,8 @@ int APP_CC
g_tcp_set_keepalive(int sck) g_tcp_set_keepalive(int sck)
{ {
int ret = 1; /* error */ int ret = 1; /* error */
#if defined(_WIN32)
int option_value; int option_value;
int option_len; socklen_t option_len;
#else
int option_value;
unsigned int option_len;
#endif
option_len = sizeof(option_value); option_len = sizeof(option_value);
@ -422,11 +412,7 @@ g_tcp_socket(void)
{ {
int rv; int rv;
int option_value; int option_value;
#if defined(_WIN32) socklen_t option_len;
int option_len;
#else
unsigned int option_len;
#endif
#if defined(XRDP_ENABLE_IPV6) #if defined(XRDP_ENABLE_IPV6)
rv = (int)socket(AF_INET6, SOCK_STREAM, 0); rv = (int)socket(AF_INET6, SOCK_STREAM, 0);
@ -500,11 +486,7 @@ int APP_CC
g_sck_set_send_buffer_bytes(int sck, int bytes) g_sck_set_send_buffer_bytes(int sck, int bytes)
{ {
int option_value; int option_value;
#if defined(_WIN32) socklen_t option_len;
int option_len;
#else
unsigned int option_len;
#endif
option_value = bytes; option_value = bytes;
option_len = sizeof(option_value); option_len = sizeof(option_value);
@ -522,11 +504,7 @@ int APP_CC
g_sck_get_send_buffer_bytes(int sck, int *bytes) g_sck_get_send_buffer_bytes(int sck, int *bytes)
{ {
int option_value; int option_value;
#if defined(_WIN32) socklen_t option_len;
int option_len;
#else
unsigned int option_len;
#endif
option_value = 0; option_value = 0;
option_len = sizeof(option_value); option_len = sizeof(option_value);
@ -545,11 +523,7 @@ int APP_CC
g_sck_set_recv_buffer_bytes(int sck, int bytes) g_sck_set_recv_buffer_bytes(int sck, int bytes)
{ {
int option_value; int option_value;
#if defined(_WIN32) socklen_t option_len;
int option_len;
#else
unsigned int option_len;
#endif
option_value = bytes; option_value = bytes;
option_len = sizeof(option_value); option_len = sizeof(option_value);
@ -567,11 +541,7 @@ int APP_CC
g_sck_get_recv_buffer_bytes(int sck, int *bytes) g_sck_get_recv_buffer_bytes(int sck, int *bytes)
{ {
int option_value; int option_value;
#if defined(_WIN32) socklen_t option_len;
int option_len;
#else
unsigned int option_len;
#endif
option_value = 0; option_value = 0;
option_len = sizeof(option_value); option_len = sizeof(option_value);
@ -601,11 +571,7 @@ int APP_CC
g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid)
{ {
#if defined(SO_PEERCRED) #if defined(SO_PEERCRED)
#if defined(_WIN32) socklen_t ucred_length;
int ucred_length;
#else
unsigned int ucred_length;
#endif
struct myucred struct myucred
{ {
pid_t pid; pid_t pid;
@ -1056,11 +1022,7 @@ g_tcp_accept(int sck)
int ret ; int ret ;
char ipAddr[256] ; char ipAddr[256] ;
struct sockaddr_in s; struct sockaddr_in s;
#if defined(_WIN32) socklen_t i;
signed int i;
#else
unsigned int i;
#endif
i = sizeof(struct sockaddr_in); i = sizeof(struct sockaddr_in);
memset(&s, 0, i); memset(&s, 0, i);
@ -1081,11 +1043,7 @@ g_sck_accept(int sck, char *addr, int addr_bytes, char *port, int port_bytes)
int ret; int ret;
char ipAddr[256]; char ipAddr[256];
struct sockaddr_in s; struct sockaddr_in s;
#if defined(_WIN32) socklen_t i;
signed int i;
#else
unsigned int i;
#endif
i = sizeof(struct sockaddr_in); i = sizeof(struct sockaddr_in);
memset(&s, 0, i); memset(&s, 0, i);
@ -1115,11 +1073,7 @@ g_write_ip_address(int rcv_sck, char *ip_address, int bytes)
{ {
struct sockaddr_in s; struct sockaddr_in s;
struct in_addr in; struct in_addr in;
#if defined(_WIN32) socklen_t len;
int len;
#else
unsigned int len;
#endif
int ip_port; int ip_port;
int ok; int ok;
@ -1196,13 +1150,8 @@ g_sck_send(int sck, const void *ptr, int len, int flags)
int APP_CC int APP_CC
g_sck_socket_ok(int sck) g_sck_socket_ok(int sck)
{ {
#if defined(_WIN32)
int opt; int opt;
int opt_len; socklen_t opt_len;
#else
int opt;
unsigned int opt_len;
#endif
opt_len = sizeof(opt); opt_len = sizeof(opt);

@ -16,6 +16,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AX_CFLAGS_WARN_ALL AX_CFLAGS_WARN_ALL
AX_APPEND_COMPILE_FLAGS([-Wwrite-strings]) AX_APPEND_COMPILE_FLAGS([-Wwrite-strings])
AX_GCC_FUNC_ATTRIBUTE([format]) AX_GCC_FUNC_ATTRIBUTE([format])
AX_TYPE_SOCKLEN_T
case $host_os in case $host_os in
*linux*) *linux*)

@ -0,0 +1,61 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_type_socklen_t.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_TYPE_SOCKLEN_T
#
# DESCRIPTION
#
# Check whether sys/socket.h defines type socklen_t. Please note that some
# systems require sys/types.h to be included before sys/socket.h can be
# compiled.
#
# LICENSE
#
# Copyright (c) 2008 Lars Brinkhoff <lars@nocrew.org>
#
# 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, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# 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, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 5
AU_ALIAS([TYPE_SOCKLEN_T], [AX_TYPE_SOCKLEN_T])
AC_DEFUN([AX_TYPE_SOCKLEN_T],
[AC_CACHE_CHECK([for socklen_t], ac_cv_ax_type_socklen_t,
[
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/socket.h>],
[socklen_t len = 42; return 0;],
ac_cv_ax_type_socklen_t=yes,
ac_cv_ax_type_socklen_t=no)
])
if test $ac_cv_ax_type_socklen_t != yes; then
AC_DEFINE(socklen_t, int, [Substitute for socklen_t])
fi
])

@ -26,12 +26,7 @@ int tcp_socket_create(void)
{ {
int rv; int rv;
int option_value; int option_value;
socklen_t option_len;
#if defined(_WIN32)
int option_len;
#else
unsigned int option_len;
#endif
/* in win32 a socket is an unsigned int, in linux, it's an int */ /* in win32 a socket is an unsigned int, in linux, it's an int */
if ((rv = (int) socket(PF_INET, SOCK_STREAM, 0)) < 0) if ((rv = (int) socket(PF_INET, SOCK_STREAM, 0)) < 0)
@ -133,12 +128,7 @@ int tcp_accept(int skt)
int ret ; int ret ;
char ipAddr[256] ; char ipAddr[256] ;
struct sockaddr_in s; struct sockaddr_in s;
socklen_t i;
#if defined(_WIN32)
int i;
#else
unsigned int i;
#endif
i = sizeof(struct sockaddr_in); i = sizeof(struct sockaddr_in);
memset(&s, 0, i); memset(&s, 0, i);
@ -186,12 +176,7 @@ int tcp_socket(void)
{ {
int rv; int rv;
int option_value; int option_value;
socklen_t option_len;
#if defined(_WIN32)
int option_len;
#else
unsigned int option_len;
#endif
/* in win32 a socket is an unsigned int, in linux, it's an int */ /* in win32 a socket is an unsigned int, in linux, it's an int */
if ((rv = (int) socket(PF_INET, SOCK_STREAM, 0)) < 0) if ((rv = (int) socket(PF_INET, SOCK_STREAM, 0)) < 0)
@ -305,14 +290,7 @@ int tcp_can_send(int skt, int millis)
int tcp_socket_ok(int skt) int tcp_socket_ok(int skt)
{ {
int opt; int opt;
socklen_t opt_len = sizeof(opt);
#if defined(_WIN32)
int opt_len;
#else
unsigned int opt_len;
#endif
opt_len = sizeof(opt);
if (getsockopt(skt, SOL_SOCKET, SO_ERROR, (char *) (&opt), &opt_len) == 0) if (getsockopt(skt, SOL_SOCKET, SO_ERROR, (char *) (&opt), &opt_len) == 0)
{ {

@ -121,7 +121,7 @@ g_tcp_socket(void)
{ {
int rv; int rv;
int option_value; int option_value;
unsigned int option_len; socklen_t option_len;
rv = (int)socket(AF_INET, SOCK_STREAM, 0); rv = (int)socket(AF_INET, SOCK_STREAM, 0);
if (rv < 0) if (rv < 0)
@ -336,9 +336,7 @@ static int APP_CC
g_tcp_socket_ok(int sck) g_tcp_socket_ok(int sck)
{ {
int opt; int opt;
unsigned int opt_len; socklen_t opt_len = sizeof(opt);
opt_len = sizeof(opt);
if (getsockopt(sck, SOL_SOCKET, SO_ERROR, (char *)(&opt), &opt_len) == 0) if (getsockopt(sck, SOL_SOCKET, SO_ERROR, (char *)(&opt), &opt_len) == 0)
{ {

Loading…
Cancel
Save