From 2eeac910988d9fa4b4e0f19992e8ce3be1d768e9 Mon Sep 17 00:00:00 2001 From: Tomoyuki Sahara Date: Thu, 14 Jun 2018 13:36:01 +0900 Subject: set sockaddr_un.sun_len on the systems that have sockaddr.sa_len. If your system has sa_len but is not BSD-derived, define HAVE_SA_LEN=1 on mrbgem.rake or build_config.rb. --- mrbgems/mruby-socket/mrbgem.rake | 1 + mrbgems/mruby-socket/src/socket.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'mrbgems/mruby-socket') diff --git a/mrbgems/mruby-socket/mrbgem.rake b/mrbgems/mruby-socket/mrbgem.rake index 8096815eb..b0894e095 100644 --- a/mrbgems/mruby-socket/mrbgem.rake +++ b/mrbgems/mruby-socket/mrbgem.rake @@ -4,6 +4,7 @@ MRuby::Gem::Specification.new('mruby-socket') do |spec| spec.summary = 'standard socket class' spec.cc.include_paths << "#{build.root}/src" + #spec.cc.defines << "HAVE_SA_LEN=0" # If Windows, use winsock if ( /mswin|mingw|win32/ =~ RUBY_PLATFORM ) then diff --git a/mrbgems/mruby-socket/src/socket.c b/mrbgems/mruby-socket/src/socket.c index 33c8d4455..951bece75 100644 --- a/mrbgems/mruby-socket/src/socket.c +++ b/mrbgems/mruby-socket/src/socket.c @@ -19,6 +19,7 @@ #else #include #include + #include #include #include #include @@ -42,6 +43,14 @@ #include "mruby/ext/io.h" +#if !defined(HAVE_SA_LEN) +#if (defined(BSD) && (BSD >= 199006)) +#define HAVE_SA_LEN 1 +#else +#define HAVE_SA_LEN 0 +#endif +#endif + #define E_SOCKET_ERROR (mrb_class_get(mrb, "SocketError")) #if !defined(mrb_cptr) @@ -695,6 +704,9 @@ mrb_socket_sockaddr_un(mrb_state *mrb, mrb_value klass) } s = mrb_str_buf_new(mrb, sizeof(struct sockaddr_un)); sunp = (struct sockaddr_un *)RSTRING_PTR(s); +#if HAVE_SA_LEN + sunp->sun_len = sizeof(struct sockaddr_un); +#endif sunp->sun_family = AF_UNIX; memcpy(sunp->sun_path, RSTRING_PTR(path), RSTRING_LEN(path)); sunp->sun_path[RSTRING_LEN(path)] = '\0'; -- cgit v1.2.3