summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-27 15:21:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-27 15:21:23 +0000
commit5fb1faf2bfc87597dbbf1a6686bab6b36482529d (patch)
tree05ecf4363780e14bd42b26d179cc1bd37ffbf46b /ext/socket
parentd8c66c433393cb0ff97fcbd32f6a4fdc4d8f8b79 (diff)
* ext/socket/raddrinfo.c: suppress strict-aliasing warning with
gcc version 4.4.0 20090219 (Red Hat 4.4.0-0.21) on Fedora 11 Alpha. * ext/socket/socket.c: ditto. * ext/socket/unixsocket.c: ditto. * ext/socket/sockport.h (SS_LEN): defined. (SET_SS_LEN): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/raddrinfo.c13
-rw-r--r--ext/socket/socket.c2
-rw-r--r--ext/socket/sockport.h7
-rw-r--r--ext/socket/unixsocket.c7
4 files changed, 19 insertions, 10 deletions
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index eead911..ff39264 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -1255,15 +1255,16 @@ addrinfo_mload(VALUE self, VALUE ary)
#ifdef HAVE_SYS_UN_H
case AF_UNIX:
{
- struct sockaddr_un *su = (struct sockaddr_un *)&ss;
- memset(su, 0, sizeof(*su));
- su->sun_family = AF_UNIX;
+ struct sockaddr_un sun;
+ memset(&sun, 0, sizeof(sun));
+ sun.sun_family = AF_UNIX;
StringValue(v);
- if (sizeof(su->sun_path) <= RSTRING_LEN(v))
+ if (sizeof(sun.sun_path) <= RSTRING_LEN(v))
rb_raise(rb_eSocket, "too long AF_UNIX path");
- memcpy(su->sun_path, RSTRING_PTR(v), RSTRING_LEN(v));
- len = sizeof(*su);
+ memcpy(sun.sun_path, RSTRING_PTR(v), RSTRING_LEN(v));
+ len = sizeof(sun);
+ memcpy(&ss, &sun, len);
break;
}
#endif
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index a578006..7dfe02f 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1157,7 +1157,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
rb_raise(rb_eTypeError, "sockaddr length too big");
}
memcpy(&ss, RSTRING_PTR(sa), RSTRING_LEN(sa));
- if (RSTRING_LEN(sa) != SA_LEN((struct sockaddr*)&ss)) {
+ if (RSTRING_LEN(sa) != SS_LEN(&ss)) {
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
sap = (struct sockaddr*)&ss;
diff --git a/ext/socket/sockport.h b/ext/socket/sockport.h
index d536bbf..6d3344e 100644
--- a/ext/socket/sockport.h
+++ b/ext/socket/sockport.h
@@ -13,22 +13,29 @@
#ifndef SA_LEN
# ifdef HAVE_SA_LEN
# define SA_LEN(sa) (sa)->sa_len
+# define SS_LEN(ss) (ss)->ss_len
# else
# ifdef AF_INET6
# define SA_LEN(sa) \
(((sa)->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) \
: sizeof(struct sockaddr))
+# define SS_LEN(ss) \
+ (((ss)->ss_family == AF_INET6) ? sizeof(struct sockaddr_in6) \
+ : sizeof(struct sockaddr))
# else
/* by tradition, sizeof(struct sockaddr) covers most of the sockaddrs */
# define SA_LEN(sa) (sizeof(struct sockaddr))
+# define SS_LEN(ss) (sizeof(struct sockaddr))
# endif
# endif
#endif
#ifdef HAVE_SA_LEN
# define SET_SA_LEN(sa, len) (void)((sa)->sa_len = (len))
+# define SET_SS_LEN(ss, len) (void)((ss)->ss_len = (len))
#else
# define SET_SA_LEN(sa, len) (void)(len)
+# define SET_SS_LEN(ss, len) (void)(len)
#endif
#ifdef HAVE_SIN_LEN
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index 5f8b860..ae596d6 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -236,7 +236,7 @@ unix_send_io(VALUE sock, VALUE val)
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_RIGHTS;
- *(int *)CMSG_DATA(&cmsg.hdr) = fd;
+ memcpy(CMSG_DATA(&cmsg.hdr), &fd, sizeof(int));
#else
arg.msg.msg_accrights = (caddr_t)&fd;
arg.msg.msg_accrightslen = sizeof(fd);
@@ -321,7 +321,8 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_RIGHTS;
- *(int *)CMSG_DATA(&cmsg.hdr) = -1;
+ fd = -1;
+ memcpy(CMSG_DATA(&cmsg.hdr), &fd, sizeof(int));
#else
arg.msg.msg_accrights = (caddr_t)&fd;
arg.msg.msg_accrightslen = sizeof(fd);
@@ -374,7 +375,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
#endif
#if FD_PASSING_BY_MSG_CONTROL
- fd = *(int *)CMSG_DATA(&cmsg.hdr);
+ memcpy(&fd, CMSG_DATA(&cmsg.hdr), sizeof(int));
#endif
if (klass == Qnil)