summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-14 23:30:25 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-15 00:02:54 -0600
commitc13e6ac24f4139a354e068de8472eb6c831a7a23 (patch)
treebb6e7c5b61c02d47386aa6804cd9b18be5008811
parent509d6ec7c860e9c327cc9e2860a276787b4bb23f (diff)
downloadgcompat-c13e6ac24f4139a354e068de8472eb6c831a7a23.tar.gz
gcompat-c13e6ac24f4139a354e068de8472eb6c831a7a23.tar.bz2
gcompat-c13e6ac24f4139a354e068de8472eb6c831a7a23.tar.xz
gcompat-c13e6ac24f4139a354e068de8472eb6c831a7a23.zip
netdb: Add protocol and service functions from LSB
These take advantage of the musl implementation for simplicity. Signed-off-by: Samuel Holland <samuel@sholland.org>
-rw-r--r--Makefile1
-rw-r--r--libgcompat/netdb.c79
2 files changed, 80 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 5e6406d..37c7a70 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,7 @@ LIBGCOMPAT_SRC = \
libgcompat/malloc.c \
libgcompat/math.c \
libgcompat/misc.c \
+ libgcompat/netdb.c \
libgcompat/pthread.c \
libgcompat/pwd.c \
libgcompat/resolv.c \
diff --git a/libgcompat/netdb.c b/libgcompat/netdb.c
new file mode 100644
index 0000000..ae7713a
--- /dev/null
+++ b/libgcompat/netdb.c
@@ -0,0 +1,79 @@
+#include <errno.h> /* ENOENT */
+#include <netdb.h> /* getproto* */
+#include <stddef.h> /* NULL, size_t */
+#include <string.h> /* memcpy */
+
+/**
+ * Retrieve information from the network protocol database by protocol name,
+ * reentrantly.
+ *
+ * LSB 5.0: LSB-Core-generic/baselib-getprotobyname-r.html
+ */
+int getprotobyname_r(const char *name, struct protoent *result_buf, char *buf,
+ size_t buflen, struct protoent **result)
+{
+ struct protoent *prototmp = getprotobyname(name);
+
+ /* musl does not reuse static storage, so no race is possible. */
+ if (prototmp == NULL) {
+ *result = NULL;
+ return ENOENT;
+ }
+ *result = memcpy(result_buf, prototmp, sizeof(*result_buf));
+
+ return 0;
+}
+
+/**
+ * Retrieve information from the network protocol database by protocol number,
+ * reentrantly.
+ *
+ * LSB 5.0: LSB-Core-generic/baselib-getprotobynumber-r.html
+ */
+int getprotobynumber_r(int proto, struct protoent *result_buf, char *buf,
+ size_t buflen, struct protoent **result)
+{
+ struct protoent *prototmp = getprotobynumber(proto);
+
+ /* musl does not reuse static storage, so no race is possible. */
+ if (prototmp == NULL) {
+ *result = NULL;
+ return ENOENT;
+ }
+ *result = memcpy(result_buf, prototmp, sizeof(*result_buf));
+
+ return 0;
+}
+
+/**
+ * Read the next entry of the protocol database, reentrantly.
+ *
+ * LSB 5.0: LSB-Core-generic/baselib-getprotoent-r.html
+ */
+int getprotoent_r(struct protoent *result_buf, char *buf, size_t buflen,
+ struct protoent **result)
+{
+ struct protoent *prototmp = getprotoent();
+
+ /* musl does not reuse static storage, so no race is possible. */
+ if (prototmp == NULL) {
+ *result = NULL;
+ return ENOENT;
+ }
+ *result = memcpy(result_buf, prototmp, sizeof(*result_buf));
+
+ return 0;
+}
+
+/**
+ * Read the next entry of the network services database, reentrantly.
+ *
+ * LSB 5.0: LSB-Core-generic/baselib-getservent-r.html
+ */
+int getservent_r(struct servent *result_buf, char *buf, size_t buflen,
+ struct servent **result)
+{
+ /* musl does not implement getservent(). */
+ *result = NULL;
+ return ENOENT;
+}