-------------------------------------------------------------------------*\ * Turns a master object into a server object \*-------------------------------------------------------------------------*/
| 432 | * Turns a master object into a server object |
| 433 | \*-------------------------------------------------------------------------*/ |
| 434 | static int meth_setsockname(lua_State *L) { |
| 435 | p_udp udp = (p_udp) auxiliar_checkclass(L, "udp{unconnected}", 1); |
| 436 | const char *address = luaL_checkstring(L, 2); |
| 437 | const char *port = luaL_checkstring(L, 3); |
| 438 | const char *err; |
| 439 | struct addrinfo bindhints; |
| 440 | memset(&bindhints, 0, sizeof(bindhints)); |
| 441 | bindhints.ai_socktype = SOCK_DGRAM; |
| 442 | bindhints.ai_family = udp->family; |
| 443 | bindhints.ai_flags = AI_PASSIVE; |
| 444 | err = inet_trybind(&udp->sock, &udp->family, address, port, &bindhints); |
| 445 | if (err) { |
| 446 | lua_pushnil(L); |
| 447 | lua_pushstring(L, err); |
| 448 | return 2; |
| 449 | } |
| 450 | lua_pushnumber(L, 1); |
| 451 | return 1; |
| 452 | } |
| 453 | |
| 454 | /*=========================================================================*\ |
| 455 | * Library functions |
nothing calls this directly
no test coverage detected