Skip to content

Commit e774fd7

Browse files
committed
feat(socket): add support set address for socket option packet_add_membership
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
1 parent 074d1a1 commit e774fd7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

socket.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,20 @@ static int sockopt_set_packet_membership(struct eco_socket *sock, lua_State *L,
837837
}
838838

839839
lua_getfield(L, 3, "type");
840-
mreq.mr_type = luaL_checkinteger(L, -1);
840+
mreq.mr_type = luaL_optinteger(L, -1, 0);
841+
lua_pop(L, 1);
842+
843+
lua_getfield(L, 3, "address");
844+
if (!lua_isnil(L, -1)) {
845+
size_t alen;
846+
const char *address = luaL_checklstring(L, -1, &alen);
847+
848+
if (alen > sizeof(mreq.mr_address))
849+
return luaL_argerror(L, 3, "address too long");
850+
851+
mreq.mr_alen = alen;
852+
memcpy(mreq.mr_address, address, alen);
853+
}
841854
lua_pop(L, 1);
842855

843856
return sockopt_set(sock, L, o, &mreq, sizeof(mreq));
@@ -1143,7 +1156,10 @@ int luaopen_eco_core_socket(lua_State *L)
11431156
lua_add_constant(L, "ARPOP_REQUEST", ARPOP_REQUEST);
11441157
lua_add_constant(L, "ARPOP_REPLY", ARPOP_REPLY);
11451158

1159+
lua_add_constant(L, "PACKET_MR_MULTICAST", PACKET_MR_MULTICAST);
11461160
lua_add_constant(L, "PACKET_MR_PROMISC", PACKET_MR_PROMISC);
1161+
lua_add_constant(L, "PACKET_MR_ALLMULTI", PACKET_MR_ALLMULTI);
1162+
lua_add_constant(L, "PACKET_MR_UNICAST", PACKET_MR_UNICAST);
11471163

11481164
lua_add_constant(L, "ICMP_ECHOREPLY", ICMP_ECHOREPLY);
11491165
lua_add_constant(L, "ICMP_ECHO", ICMP_ECHO);

0 commit comments

Comments
 (0)