From 4822d20cc55d54d0c3cb190fdcb343976db64901 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 28 Apr 2010 08:14:13 +0000 Subject: [PATCH] * ext/socket: fixed types. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/ancdata.c | 25 +++++++++++++------------ ext/socket/basicsocket.c | 14 +++++++------- ext/socket/constants.c | 2 +- ext/socket/init.c | 14 +++++++------- ext/socket/ipsocket.c | 6 +++--- ext/socket/mkconstants.rb | 6 +++--- ext/socket/raddrinfo.c | 37 +++++++++++++++++++------------------ ext/socket/socket.c | 30 +++++++++++++++--------------- ext/socket/tcpserver.c | 6 +++--- ext/socket/unixserver.c | 6 +++--- ext/socket/unixsocket.c | 24 ++++++++++++------------ 11 files changed, 86 insertions(+), 84 deletions(-) diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index 95a47b06e8..4d299ec334 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -606,7 +606,7 @@ ancillary_ipv6_pktinfo(VALUE self) VALUE v_addr; extract_ipv6_pktinfo(self, &pktinfo, &sa); - v_addr = rsock_addrinfo_new((struct sockaddr *)&sa, sizeof(sa), PF_INET6, 0, 0, Qnil, Qnil); + v_addr = rsock_addrinfo_new((struct sockaddr *)&sa, (socklen_t)sizeof(sa), PF_INET6, 0, 0, Qnil, Qnil); return rb_ary_new3(2, v_addr, UINT2NUM(pktinfo.ipi6_ifindex)); } #else @@ -634,7 +634,7 @@ ancillary_ipv6_pktinfo_addr(VALUE self) struct in6_pktinfo pktinfo; struct sockaddr_in6 sa; extract_ipv6_pktinfo(self, &pktinfo, &sa); - return rsock_addrinfo_new((struct sockaddr *)&sa, sizeof(sa), PF_INET6, 0, 0, Qnil, Qnil); + return rsock_addrinfo_new((struct sockaddr *)&sa, (socklen_t)sizeof(sa), PF_INET6, 0, 0, Qnil, Qnil); } #else #define ancillary_ipv6_pktinfo_addr rb_f_notimplement @@ -781,7 +781,7 @@ anc_inspect_ip_recvdstaddr(int level, int type, VALUE data, VALUE ret) struct in_addr addr; char addrbuf[INET_ADDRSTRLEN]; memcpy(&addr, RSTRING_PTR(data), sizeof(addr)); - if (inet_ntop(AF_INET, &addr, addrbuf, sizeof(addrbuf)) == NULL) + if (inet_ntop(AF_INET, &addr, addrbuf, (socklen_t)sizeof(addrbuf)) == NULL) rb_str_cat2(ret, " invalid-address"); else rb_str_catf(ret, " %s", addrbuf); @@ -834,7 +834,7 @@ anc_inspect_ipv6_pktinfo(int level, int type, VALUE data, VALUE ret) char addrbuf[INET6_ADDRSTRLEN], ifbuf[IFNAMSIZ]; memcpy(&addr, &pktinfo->ipi6_addr, sizeof(addr)); memcpy(&ifindex, &pktinfo->ipi6_ifindex, sizeof(ifindex)); - if (inet_ntop(AF_INET6, &addr, addrbuf, sizeof(addrbuf)) == NULL) + if (inet_ntop(AF_INET6, &addr, addrbuf, (socklen_t)sizeof(addrbuf)) == NULL) rb_str_cat2(ret, " invalid-address"); else rb_str_catf(ret, " %s", addrbuf); @@ -1163,7 +1163,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) if (controls_num) { #if defined(HAVE_ST_MSG_CONTROL) int i; - int last_pad = 0; + size_t last_pad = 0; int last_level = 0; int last_type = 0; controls_str = rb_str_tmp_new(0); @@ -1201,7 +1201,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) memset((char *)&cmh, 0, sizeof(cmh)); cmh.cmsg_level = level; cmh.cmsg_type = type; - cmh.cmsg_len = CMSG_LEN(RSTRING_LEN(cdata)); + cmh.cmsg_len = (socklen_t)CMSG_LEN(RSTRING_LEN(cdata)); MEMCPY(cmsg, &cmh, char, sizeof(cmh)); MEMCPY(cmsg+((char*)CMSG_DATA(&cmh)-(char*)&cmh), RSTRING_PTR(cdata), char, RSTRING_LEN(cdata)); last_level = cmh.cmsg_level; @@ -1254,7 +1254,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) memset(&mh, 0, sizeof(mh)); if (!NIL_P(dest_sockaddr)) { mh.msg_name = RSTRING_PTR(dest_sockaddr); - mh.msg_namelen = RSTRING_LEN(dest_sockaddr); + mh.msg_namelen = RSTRING_LENINT(dest_sockaddr); } mh.msg_iovlen = 1; mh.msg_iov = &iov; @@ -1263,7 +1263,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) #if defined(HAVE_ST_MSG_CONTROL) if (controls_str) { mh.msg_control = RSTRING_PTR(controls_str); - mh.msg_controllen = RSTRING_LEN(controls_str); + mh.msg_controllen = RSTRING_LENINT(controls_str); } else { mh.msg_control = NULL; @@ -1503,7 +1503,8 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) #if !defined(HAVE_ST_MSG_CONTROL) if (grow_buffer) { - int socktype, optlen = sizeof(socktype); + int socktype; + socklen_t optlen = (socklen_t)sizeof(socktype); if (getsockopt(fptr->fd, SOL_SOCKET, SO_TYPE, (void*)&socktype, &optlen) == -1) { rb_sys_fail("getsockopt(SO_TYPE)"); } @@ -1539,7 +1540,7 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) memset(&namebuf, 0, sizeof(namebuf)); mh.msg_name = (struct sockaddr *)&namebuf; - mh.msg_namelen = sizeof(namebuf); + mh.msg_namelen = (socklen_t)sizeof(namebuf); mh.msg_iov = &iov; mh.msg_iovlen = 1; @@ -1548,7 +1549,7 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) #if defined(HAVE_ST_MSG_CONTROL) mh.msg_control = ctlbuf; - mh.msg_controllen = maxctllen; + mh.msg_controllen = (socklen_t)maxctllen; #endif if (grow_buffer) @@ -1614,7 +1615,7 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) #undef BIG_ENOUGH_SPACE } #else - if (NIL_P(vmaxdatlen) && ss != -1 && ss == iov.iov_len) { + if (NIL_P(vmaxdatlen) && ss != -1 && ss == (ssize_t)iov.iov_len) { if (SIZE_MAX/2 < maxdatlen) rb_raise(rb_eArgError, "max data length too big"); maxdatlen *= 2; diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c index 0316f9965a..e744ad27d3 100644 --- a/ext/socket/basicsocket.c +++ b/ext/socket/basicsocket.c @@ -238,12 +238,12 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock) case T_TRUE: i = 1; numval: - v = (char*)&i; vlen = sizeof(i); + v = (char*)&i; vlen = (int)sizeof(i); break; default: StringValue(val); v = RSTRING_PTR(val); - vlen = RSTRING_LEN(val); + vlen = RSTRING_LENINT(val); break; } @@ -357,7 +357,7 @@ static VALUE bsock_getsockname(VALUE sock) { struct sockaddr_storage buf; - socklen_t len = sizeof buf; + socklen_t len = (socklen_t)sizeof buf; rb_io_t *fptr; GetOpenFile(sock, fptr); @@ -386,7 +386,7 @@ static VALUE bsock_getpeername(VALUE sock) { struct sockaddr_storage buf; - socklen_t len = sizeof buf; + socklen_t len = (socklen_t)sizeof buf; rb_io_t *fptr; GetOpenFile(sock, fptr); @@ -474,7 +474,7 @@ static VALUE bsock_local_address(VALUE sock) { struct sockaddr_storage buf; - socklen_t len = sizeof buf; + socklen_t len = (socklen_t)sizeof buf; rb_io_t *fptr; GetOpenFile(sock, fptr); @@ -506,7 +506,7 @@ static VALUE bsock_remote_address(VALUE sock) { struct sockaddr_storage buf; - socklen_t len = sizeof buf; + socklen_t len = (socklen_t)sizeof buf; rb_io_t *fptr; GetOpenFile(sock, fptr); @@ -549,7 +549,7 @@ rsock_bsock_send(int argc, VALUE *argv, VALUE sock) SockAddrStringValue(to); to = rb_str_new4(to); arg.to = (struct sockaddr *)RSTRING_PTR(to); - arg.tolen = RSTRING_LEN(to); + arg.tolen = (socklen_t)RSTRING_LENINT(to); func = rsock_sendto_blocking; } else { diff --git a/ext/socket/constants.c b/ext/socket/constants.c index c765d75ee6..39f985b316 100644 --- a/ext/socket/constants.c +++ b/ext/socket/constants.c @@ -15,7 +15,7 @@ static VALUE rb_mSockConst; #include "constdefs.c" static int -constant_arg(VALUE arg, int (*str_to_int)(const char*, int, int*), const char *errmsg) +constant_arg(VALUE arg, int (*str_to_int)(const char*, long, int*), const char *errmsg) { VALUE tmp; char *ptr; diff --git a/ext/socket/init.c b/ext/socket/init.c index 4c7926b945..ffd1c72895 100644 --- a/ext/socket/init.c +++ b/ext/socket/init.c @@ -121,7 +121,7 @@ rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from) rb_raise(rb_eIOError, "recv for buffered IO"); } arg.fd = fptr->fd; - arg.alen = sizeof(arg.buf); + arg.alen = (socklen_t)sizeof(arg.buf); arg.str = str = rb_tainted_str_new(0, buflen); klass = RBASIC(str)->klass; @@ -174,7 +174,7 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type rb_io_t *fptr; VALUE str; struct sockaddr_storage buf; - socklen_t alen = sizeof buf; + socklen_t alen = (socklen_t)sizeof buf; VALUE len, flg; long buflen; long slen; @@ -272,7 +272,7 @@ wait_connectable0(int fd, rb_fdset_t *fds_w, rb_fdset_t *fds_e) return 0; } else if (rb_fd_isset(fd, fds_e)) { - sockerrlen = sizeof(sockerr); + sockerrlen = (socklen_t)sizeof(sockerr); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen) == 0) { if (sockerr == 0) @@ -388,7 +388,7 @@ rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks) case EINPROGRESS: #endif #if WAIT_IN_PROGRESS > 0 - sockerrlen = sizeof(sockerr); + sockerrlen = (socklen_t)sizeof(sockerr); status = getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen); if (status) break; if (sockerr) { @@ -418,7 +418,7 @@ rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks) * some platforms, need to check true error * status. */ - sockerrlen = sizeof(sockerr); + sockerrlen = (socklen_t)sizeof(sockerr); status = getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen); if (!status && !sockerr) { struct timeval tv = {0, 100000}; @@ -515,7 +515,7 @@ rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len) arg.len = len; retry: rb_thread_wait_fd(fd); - fd2 = BLOCKING_REGION(accept_blocking, &arg); + fd2 = (int)BLOCKING_REGION(accept_blocking, &arg); if (fd2 < 0) { switch (errno) { case EMFILE: @@ -539,7 +539,7 @@ int rsock_getfamily(int sockfd) { struct sockaddr_storage ss; - socklen_t sslen = sizeof(ss); + socklen_t sslen = (socklen_t)sizeof(ss); ss.ss_family = AF_UNSPEC; if (getsockname(sockfd, (struct sockaddr*)&ss, &sslen) < 0) diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c index 68ff5a1301..dd7eb80b55 100644 --- a/ext/socket/ipsocket.c +++ b/ext/socket/ipsocket.c @@ -73,7 +73,7 @@ init_inetsock_internal(struct inetsock_arg *arg) #if !defined(_WIN32) && !defined(__CYGWIN__) status = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, - (char*)&status, sizeof(status)); + (char*)&status, (socklen_t)sizeof(status)); #endif status = bind(fd, res->ai_addr, res->ai_addrlen); syscall = "bind(2)"; @@ -185,7 +185,7 @@ ip_addr(int argc, VALUE *argv, VALUE sock) { rb_io_t *fptr; struct sockaddr_storage addr; - socklen_t len = sizeof addr; + socklen_t len = (socklen_t)sizeof addr; int norevlookup; GetOpenFile(sock, fptr); @@ -226,7 +226,7 @@ ip_peeraddr(int argc, VALUE *argv, VALUE sock) { rb_io_t *fptr; struct sockaddr_storage addr; - socklen_t len = sizeof addr; + socklen_t len = (socklen_t)sizeof addr; int norevlookup; GetOpenFile(sock, fptr); diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb index f2ba136f9c..c796cb4870 100644 --- a/ext/socket/mkconstants.rb +++ b/ext/socket/mkconstants.rb @@ -143,16 +143,16 @@ end ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_decl(funcname, pat, prefix_optional, guard=nil)") %if guard #ifdef <%=guard%> -int <%=funcname%>(const char *str, int len, int *valp); +int <%=funcname%>(const char *str, long len, int *valp); #endif %else -int <%=funcname%>(const char *str, int len, int *valp); +int <%=funcname%>(const char *str, long len, int *valp); %end EOS ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard=nil)") int -<%=funcname%>(const char *str, int len, int *valp) +<%=funcname%>(const char *str, long len, int *valp) { switch (len) { % each_names_with_len(pat, prefix_optional) {|pairs, len| diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index 8f89240f45..5478d1006c 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -129,7 +129,7 @@ rb_getaddrinfo(const char *node, const char *service, arg.service = service; arg.hints = hints; arg.res = res; - ret = BLOCKING_REGION(nogvl_getaddrinfo, &arg); + ret = (int)BLOCKING_REGION(nogvl_getaddrinfo, &arg); return ret; #endif } @@ -151,8 +151,8 @@ nogvl_getnameinfo(void *arg) { struct getnameinfo_arg *ptr = arg; return getnameinfo(ptr->sa, ptr->salen, - ptr->host, ptr->hostlen, - ptr->serv, ptr->servlen, + ptr->host, (socklen_t)ptr->hostlen, + ptr->serv, (socklen_t)ptr->servlen, ptr->flags); } #endif @@ -174,7 +174,7 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen, arg.serv = serv; arg.servlen = servlen; arg.flags = flags; - ret = BLOCKING_REGION(nogvl_getnameinfo, &arg); + ret = (int)BLOCKING_REGION(nogvl_getnameinfo, &arg); return ret; #endif } @@ -200,7 +200,7 @@ rsock_make_ipaddr(struct sockaddr *addr) } static void -make_inetaddr(long host, char *buf, size_t len) +make_inetaddr(unsigned int host, char *buf, size_t len) { struct sockaddr_in sin; @@ -233,7 +233,7 @@ host_str(VALUE host, char *hbuf, size_t len, int *flags_ptr) return NULL; } else if (rb_obj_is_kind_of(host, rb_cInteger)) { - unsigned long i = NUM2ULONG(host); + unsigned int i = NUM2UINT(host); make_inetaddr(htonl(i), hbuf, len); if (flags_ptr) *flags_ptr |= AI_NUMERICHOST; @@ -481,7 +481,7 @@ typedef struct { int pfamily; int socktype; int protocol; - size_t sockaddr_len; + socklen_t sockaddr_len; struct sockaddr_storage addr; } rb_addrinfo_t; @@ -544,7 +544,7 @@ alloc_addrinfo() } static void -init_addrinfo(rb_addrinfo_t *rai, struct sockaddr *sa, size_t len, +init_addrinfo(rb_addrinfo_t *rai, struct sockaddr *sa, socklen_t len, int pfamily, int socktype, int protocol, VALUE canonname, VALUE inspectname) { @@ -744,7 +744,8 @@ init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path, int socktype) un.sun_family = AF_UNIX; memcpy((void*)&un.sun_path, RSTRING_PTR(path), RSTRING_LEN(path)); - init_addrinfo(rai, (struct sockaddr *)&un, sizeof(un), PF_UNIX, socktype, 0, Qnil, Qnil); + init_addrinfo(rai, (struct sockaddr *)&un, (socklen_t)sizeof(un), + PF_UNIX, socktype, 0, Qnil, Qnil); } #endif @@ -801,7 +802,7 @@ addrinfo_initialize(int argc, VALUE *argv, VALUE self) VALUE sockaddr_arg, sockaddr_ary, pfamily, socktype, protocol; int i_pfamily, i_socktype, i_protocol; struct sockaddr *sockaddr_ptr; - size_t sockaddr_len; + socklen_t sockaddr_len; VALUE canonname = Qnil, inspectname = Qnil; if (check_addrinfo(self)) @@ -865,7 +866,7 @@ addrinfo_initialize(int argc, VALUE *argv, VALUE self) else { StringValue(sockaddr_arg); sockaddr_ptr = (struct sockaddr *)RSTRING_PTR(sockaddr_arg); - sockaddr_len = RSTRING_LEN(sockaddr_arg); + sockaddr_len = RSTRING_LENINT(sockaddr_arg); init_addrinfo(rai, sockaddr_ptr, sockaddr_len, i_pfamily, i_socktype, i_protocol, canonname, inspectname); @@ -941,7 +942,7 @@ inspect_sockaddr(VALUE addrinfo, VALUE ret) * draft-ietf-ipv6-scope-api-00.txt: Scoped Address Extensions to the IPv6 Basic Socket API */ error = getnameinfo((struct sockaddr *)&rai->addr, rai->sockaddr_len, - hbuf, sizeof(hbuf), NULL, 0, + hbuf, (socklen_t)sizeof(hbuf), NULL, 0, NI_NUMERICHOST|NI_NUMERICSERV); if (error) { rsock_raise_socket_error("getnameinfo", error); @@ -1182,7 +1183,7 @@ addrinfo_mdump(VALUE self) char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV]; int error; error = getnameinfo((struct sockaddr *)&rai->addr, rai->sockaddr_len, - hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), + hbuf, (socklen_t)sizeof(hbuf), pbuf, (socklen_t)sizeof(pbuf), NI_NUMERICHOST|NI_NUMERICSERV); if (error) { rsock_raise_socket_error("getnameinfo", error); @@ -1203,7 +1204,7 @@ addrinfo_mload(VALUE self, VALUE ary) VALUE canonname, inspectname; int afamily, pfamily, socktype, protocol; struct sockaddr_storage ss; - size_t len; + socklen_t len; rb_addrinfo_t *rai; if (check_addrinfo(self)) @@ -1273,7 +1274,7 @@ addrinfo_mload(VALUE self, VALUE ary) if (sizeof(uaddr.sun_path) <= (size_t)RSTRING_LEN(v)) rb_raise(rb_eSocket, "too long AF_UNIX path"); memcpy(uaddr.sun_path, RSTRING_PTR(v), RSTRING_LEN(v)); - len = sizeof(uaddr); + len = (socklen_t)sizeof(uaddr); memcpy(&ss, &uaddr, len); break; } @@ -1526,7 +1527,7 @@ addrinfo_getnameinfo(int argc, VALUE *argv, VALUE self) flags |= NI_DGRAM; error = getnameinfo((struct sockaddr *)&rai->addr, rai->sockaddr_len, - hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), + hbuf, (socklen_t)sizeof(hbuf), pbuf, (socklen_t)sizeof(pbuf), flags); if (error) { rsock_raise_socket_error("getnameinfo", error); @@ -1867,7 +1868,7 @@ addrinfo_ipv6_to_ipv4(VALUE self) sin4.sin_family = AF_INET; SET_SIN_LEN(&sin4, sizeof(sin4)); memcpy(&sin4.sin_addr, (char*)addr + sizeof(*addr) - sizeof(sin4.sin_addr), sizeof(sin4.sin_addr)); - return rsock_addrinfo_new((struct sockaddr *)&sin4, sizeof(sin4), + return rsock_addrinfo_new((struct sockaddr *)&sin4, (socklen_t)sizeof(sin4), PF_INET, rai->socktype, rai->protocol, rai->canonname, rai->inspectname); } @@ -2078,7 +2079,7 @@ rsock_fd_socket_addrinfo(int fd, struct sockaddr *addr, socklen_t len) int family; int socktype; int ret; - socklen_t optlen = sizeof(socktype); + socklen_t optlen = (socklen_t)sizeof(socktype); /* assumes protocol family and address family are identical */ family = get_afamily(addr, len); diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 1c499d9f08..63586fc002 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -253,7 +253,7 @@ sock_connect(VALUE sock, VALUE addr) addr = rb_str_new4(addr); GetOpenFile(sock, fptr); fd = fptr->fd; - n = rsock_connect(fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr), 0); + n = rsock_connect(fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr), 0); if (n < 0) { rb_sys_fail("connect(2)"); } @@ -313,7 +313,7 @@ sock_connect_nonblock(VALUE sock, VALUE addr) addr = rb_str_new4(addr); GetOpenFile(sock, fptr); rb_io_set_nonblock(fptr); - n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr)); + n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr)); if (n < 0) { if (errno == EINPROGRESS) rb_mod_sys_fail(rb_mWaitWritable, "connect(2) would block"); @@ -416,7 +416,7 @@ sock_bind(VALUE sock, VALUE addr) SockAddrStringValue(addr); GetOpenFile(sock, fptr); - if (bind(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr)) < 0) + if (bind(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr)) < 0) rb_sys_fail("bind(2)"); return INT2FIX(0); @@ -706,7 +706,7 @@ sock_accept(VALUE sock) rb_io_t *fptr; VALUE sock2; struct sockaddr_storage buf; - socklen_t len = sizeof buf; + socklen_t len = (socklen_t)sizeof buf; GetOpenFile(sock, fptr); sock2 = rsock_s_accept(rb_cSocket,fptr->fd,(struct sockaddr*)&buf,&len); @@ -771,7 +771,7 @@ sock_accept_nonblock(VALUE sock) rb_io_t *fptr; VALUE sock2; struct sockaddr_storage buf; - socklen_t len = sizeof buf; + socklen_t len = (socklen_t)sizeof buf; GetOpenFile(sock, fptr); sock2 = rsock_s_accept_nonblock(rb_cSocket, fptr, (struct sockaddr *)&buf, &len); @@ -822,7 +822,7 @@ sock_sysaccept(VALUE sock) rb_io_t *fptr; VALUE sock2; struct sockaddr_storage buf; - socklen_t len = sizeof buf; + socklen_t len = (socklen_t)sizeof buf; GetOpenFile(sock, fptr); sock2 = rsock_s_accept(0,fptr->fd,(struct sockaddr*)&buf,&len); @@ -967,7 +967,7 @@ sock_s_gethostbyaddr(int argc, VALUE *argv) t = AF_INET6; } #endif - h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_LEN(addr), t); + h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_LENINT(addr), t); if (h == NULL) { #ifdef HAVE_HSTRERROR extern int h_errno; @@ -1015,7 +1015,7 @@ sock_s_getservbyname(int argc, VALUE *argv) { VALUE service, proto; struct servent *sp; - int port; + long port; const char *servicename, *protoname = "tcp"; rb_scan_args(argc, argv, "11", &service, &proto); @@ -1418,7 +1418,7 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr) rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d", RSTRING_LEN(addr), (int)sizeof(struct sockaddr_un)); } - sun_path = rsock_unixpath(sockaddr, RSTRING_LEN(addr)); + sun_path = rsock_unixpath(sockaddr, RSTRING_LENINT(addr)); if (sizeof(struct sockaddr_un) == RSTRING_LEN(addr) && sun_path == sockaddr->sun_path && sun_path + strlen(sun_path) == RSTRING_PTR(addr) + RSTRING_LEN(addr)) { @@ -1434,7 +1434,7 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr) static VALUE sockaddr_obj(struct sockaddr *addr) { - size_t len; + socklen_t len; #if defined(AF_INET6) && defined(__KAME__) struct sockaddr_in6 addr6; #endif @@ -1444,12 +1444,12 @@ sockaddr_obj(struct sockaddr *addr) switch (addr->sa_family) { case AF_INET: - len = sizeof(struct sockaddr_in); + len = (socklen_t)sizeof(struct sockaddr_in); break; #ifdef AF_INET6 case AF_INET6: - len = sizeof(struct sockaddr_in6); + len = (socklen_t)sizeof(struct sockaddr_in6); # ifdef __KAME__ /* KAME uses the 2nd 16bit word of link local IPv6 address as interface index internally */ /* http://orange.kame.net/dev/cvsweb.cgi/kame/IMPLEMENTATION */ @@ -1469,17 +1469,17 @@ sockaddr_obj(struct sockaddr *addr) #ifdef HAVE_SYS_UN_H case AF_UNIX: - len = sizeof(struct sockaddr_un); + len = (socklen_t)sizeof(struct sockaddr_un); break; #endif default: - len = sizeof(struct sockaddr_in); + len = (socklen_t)sizeof(struct sockaddr_in); break; } #ifdef SA_LEN if (len < (socklen_t)SA_LEN(addr)) - len = SA_LEN(addr); + len = (socklen_t)SA_LEN(addr); #endif return rsock_addrinfo_new(addr, len, addr->sa_family, 0, 0, Qnil, Qnil); diff --git a/ext/socket/tcpserver.c b/ext/socket/tcpserver.c index 282bd60b30..7bb02d91f0 100644 --- a/ext/socket/tcpserver.c +++ b/ext/socket/tcpserver.c @@ -51,7 +51,7 @@ tcp_accept(VALUE sock) socklen_t fromlen; GetOpenFile(sock, fptr); - fromlen = sizeof(from); + fromlen = (socklen_t)sizeof(from); return rsock_s_accept(rb_cTCPSocket, fptr->fd, (struct sockaddr*)&from, &fromlen); } @@ -97,7 +97,7 @@ tcp_accept_nonblock(VALUE sock) socklen_t fromlen; GetOpenFile(sock, fptr); - fromlen = sizeof(from); + fromlen = (socklen_t)sizeof(from); return rsock_s_accept_nonblock(rb_cTCPSocket, fptr, (struct sockaddr *)&from, &fromlen); } @@ -124,7 +124,7 @@ tcp_sysaccept(VALUE sock) socklen_t fromlen; GetOpenFile(sock, fptr); - fromlen = sizeof(from); + fromlen = (socklen_t)sizeof(from); return rsock_s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen); } diff --git a/ext/socket/unixserver.c b/ext/socket/unixserver.c index a6379eb364..4fdc1d709d 100644 --- a/ext/socket/unixserver.c +++ b/ext/socket/unixserver.c @@ -52,7 +52,7 @@ unix_accept(VALUE sock) socklen_t fromlen; GetOpenFile(sock, fptr); - fromlen = sizeof(struct sockaddr_un); + fromlen = (socklen_t)sizeof(struct sockaddr_un); return rsock_s_accept(rb_cUNIXSocket, fptr->fd, (struct sockaddr*)&from, &fromlen); } @@ -98,7 +98,7 @@ unix_accept_nonblock(VALUE sock) socklen_t fromlen; GetOpenFile(sock, fptr); - fromlen = sizeof(from); + fromlen = (socklen_t)sizeof(from); return rsock_s_accept_nonblock(rb_cUNIXSocket, fptr, (struct sockaddr *)&from, &fromlen); } @@ -129,7 +129,7 @@ unix_sysaccept(VALUE sock) socklen_t fromlen; GetOpenFile(sock, fptr); - fromlen = sizeof(struct sockaddr_un); + fromlen = (socklen_t)sizeof(struct sockaddr_un); return rsock_s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen); } diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c index 1e3fb0784f..6bdaa94620 100644 --- a/ext/socket/unixsocket.c +++ b/ext/socket/unixsocket.c @@ -17,10 +17,11 @@ struct unixsock_arg { }; static VALUE -unixsock_connect_internal(struct unixsock_arg *arg) +unixsock_connect_internal(VALUE a) { + struct unixsock_arg *arg = (struct unixsock_arg *)a; return (VALUE)rsock_connect(arg->fd, (struct sockaddr*)arg->sockaddr, - sizeof(*arg->sockaddr), 0); + (socklen_t)sizeof(*arg->sockaddr), 0); } VALUE @@ -45,15 +46,14 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server) memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path)); if (server) { - status = bind(fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)); + status = bind(fd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr)); } else { int prot; struct unixsock_arg arg; arg.sockaddr = &sockaddr; arg.fd = fd; - status = rb_protect((VALUE(*)(VALUE))unixsock_connect_internal, - (VALUE)&arg, &prot); + status = (int)rb_protect(unixsock_connect_internal, (VALUE)&arg, &prot); if (prot) { close(fd); rb_jump_tag(prot); @@ -115,7 +115,7 @@ unix_path(VALUE sock) GetOpenFile(sock, fptr); if (NIL_P(fptr->pathv)) { struct sockaddr_un addr; - socklen_t len = sizeof(addr); + socklen_t len = (socklen_t)sizeof(addr); if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0) rb_sys_fail(0); fptr->pathv = rb_obj_freeze(rb_str_new_cstr(rsock_unixpath(&addr, len))); @@ -235,10 +235,10 @@ unix_send_io(VALUE sock, VALUE val) #if FD_PASSING_BY_MSG_CONTROL arg.msg.msg_control = (caddr_t)&cmsg; - arg.msg.msg_controllen = CMSG_LEN(sizeof(int)); + arg.msg.msg_controllen = (socklen_t)CMSG_LEN(sizeof(int)); arg.msg.msg_flags = 0; MEMZERO((char*)&cmsg, char, sizeof(cmsg)); - cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int)); + cmsg.hdr.cmsg_len = (socklen_t)CMSG_LEN(sizeof(int)); cmsg.hdr.cmsg_level = SOL_SOCKET; cmsg.hdr.cmsg_type = SCM_RIGHTS; memcpy(CMSG_DATA(&cmsg.hdr), &fd, sizeof(int)); @@ -320,9 +320,9 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock) #if FD_PASSING_BY_MSG_CONTROL arg.msg.msg_control = (caddr_t)&cmsg; - arg.msg.msg_controllen = CMSG_SPACE(sizeof(int)); + arg.msg.msg_controllen = (socklen_t)CMSG_SPACE(sizeof(int)); arg.msg.msg_flags = 0; - cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int)); + cmsg.hdr.cmsg_len = (socklen_t)CMSG_LEN(sizeof(int)); cmsg.hdr.cmsg_level = SOL_SOCKET; cmsg.hdr.cmsg_type = SCM_RIGHTS; fd = -1; @@ -415,7 +415,7 @@ unix_addr(VALUE sock) { rb_io_t *fptr; struct sockaddr_un addr; - socklen_t len = sizeof addr; + socklen_t len = (socklen_t)sizeof addr; GetOpenFile(sock, fptr); @@ -441,7 +441,7 @@ unix_peeraddr(VALUE sock) { rb_io_t *fptr; struct sockaddr_un addr; - socklen_t len = sizeof addr; + socklen_t len = (socklen_t)sizeof addr; GetOpenFile(sock, fptr);