-- <li>ifindex = Interface Index (Linux, "packet"-family)</li>
-- </ul>
+--- Get protocol entry by name.
+-- @usage This function returns nil if the given protocol is unknown.
+-- @class function
+-- @name nixio.getprotobyname
+-- @param name protocol name to lookup
+-- @return Table containing the following fields: <ul>
+-- <li>name = Protocol Name</li>
+-- <li>proto = Protocol Number</li>
+-- <li>aliases = Table of alias names</li>
+-- </ul>
+
+--- Get protocol entry by number.
+-- @usage This function returns nil if the given protocol is unknown.
+-- @class function
+-- @name nixio.getprotobynumber
+-- @param proto protocol number to lookup
+-- @return Table containing the following fields: <ul>
+-- <li>name = Protocol Name</li>
+-- <li>proto = Protocol Number</li>
+-- <li>aliases = Table of alias names</li>
+-- </ul>
+
+--- Get all or a specifc proto entry.
+-- @class function
+-- @name nixio.getproto
+-- @param proto protocol number or name to lookup (optional)
+-- @return Table (or if no parameter is given, a table of tables)
+-- containing the following fields: <ul>
+-- <li>name = Protocol Name</li>
+-- <li>proto = Protocol Number</li>
+-- <li>aliases = Table of alias names</li>
+-- </ul>
+
--- Create a new socket and bind it to a network address.
-- This function is a shortcut for calling nixio.socket and then bind()
-- on the socket object.
-- @class function
-- @name nixio.tls
-- @param mode TLS-Mode ["client", "server"]
--- @return TLSContext Object
\ No newline at end of file
+-- @return TLSContext Object
}
#endif
+/**
+ * protoent conversion helper
+ */
+static int nixio__pushprotoent(lua_State *L, struct protoent *e) {
+ int i;
+ if (e) {
+ lua_newtable(L);
+
+ lua_pushstring(L, e->p_name);
+ lua_setfield(L, -2, "name");
+
+ lua_pushnumber(L, e->p_proto);
+ lua_setfield(L, -2, "proto");
+
+ lua_newtable(L);
+ for (i = 0; e->p_aliases[i]; i++) {
+ lua_pushstring(L, e->p_aliases[i]);
+ lua_rawseti(L, -2, i+1);
+ }
+ lua_setfield(L, -2, "aliases");
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * getprotobyname(name)
+ */
+static int nixio_getprotobyname(lua_State *L) {
+ const char *name = luaL_checkstring(L, 1);
+ struct protoent *res = getprotobyname(name);
+ return nixio__pushprotoent(L, res);
+}
+
+/**
+ * getprotobynumber(proto)
+ */
+static int nixio_getprotobynumber(lua_State *L) {
+ int proto = luaL_checkinteger(L, 1);
+ struct protoent *res = getprotobynumber(proto);
+ return nixio__pushprotoent(L, res);
+}
/* module table */
static const luaL_reg R[] = {
#if defined(__linux__) || defined(BSD)
- {"getifaddrs", nixio_getifaddrs},
+ {"getifaddrs", nixio_getifaddrs},
#endif
- {"getaddrinfo", nixio_getaddrinfo},
- {"getnameinfo", nixio_getnameinfo},
- {NULL, NULL}
+ {"getaddrinfo", nixio_getaddrinfo},
+ {"getnameinfo", nixio_getnameinfo},
+ {"getprotobyname", nixio_getprotobyname},
+ {"getprotobynumber", nixio_getprotobynumber},
+ {NULL, NULL}
};
/* object table */
static const luaL_reg M[] = {
- {"getsockname", nixio_sock_getsockname},
- {"getpeername", nixio_sock_getpeername},
- {NULL, NULL}
+ {"getsockname", nixio_sock_getsockname},
+ {"getpeername", nixio_sock_getpeername},
+ {NULL, NULL}
};
void nixio_open_address(lua_State *L) {