Commit 3618556a authored by Tomoyuki Sahara's avatar Tomoyuki Sahara

struct sockaddr_un can be shorter than struct sockaddr.

ref: https://github.com/iij/mruby-socket/issues/45
parent 97933665
......@@ -664,19 +664,15 @@ mrb_socket_listen(mrb_state *mrb, mrb_value klass)
static mrb_value
mrb_socket_sockaddr_family(mrb_state *mrb, mrb_value klass)
{
mrb_value sa;
const struct sockaddr *sa;
mrb_value str;
mrb_get_args(mrb, "S", &sa);
#ifdef __linux__
if ((size_t)RSTRING_LEN(sa) < offsetof(struct sockaddr, sa_family) + sizeof(sa_family_t)) {
mrb_raisef(mrb, E_SOCKET_ERROR, "invalid sockaddr (too short)");
}
#else
if ((size_t)RSTRING_LEN(sa) < sizeof(struct sockaddr)) {
mrb_get_args(mrb, "S", &str);
if ((size_t)RSTRING_LEN(str) < offsetof(struct sockaddr, sa_family) + sizeof(sa_family_t)) {
mrb_raisef(mrb, E_SOCKET_ERROR, "invalid sockaddr (too short)");
}
#endif
return mrb_fixnum_value(((struct sockaddr *)RSTRING_PTR(sa))->sa_family);
sa = (const struct sockaddr *)RSTRING_PTR(str);
return mrb_fixnum_value(sa->sa_family);
}
static mrb_value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment