summaryrefslogtreecommitdiffstats
path: root/c/src/libnetworking/rtems/sghostname.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-08-19 21:32:28 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-08-19 21:32:28 +0000
commit39e6e65a2c5a3312f365d59f23c469641e049c82 (patch)
treec0d6000a18918db140589a84596a8dfc215a4ced /c/src/libnetworking/rtems/sghostname.c
parentFirst version produced. (diff)
downloadrtems-39e6e65a2c5a3312f365d59f23c469641e049c82.tar.bz2
Base files
Diffstat (limited to 'c/src/libnetworking/rtems/sghostname.c')
-rw-r--r--c/src/libnetworking/rtems/sghostname.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/c/src/libnetworking/rtems/sghostname.c b/c/src/libnetworking/rtems/sghostname.c
new file mode 100644
index 0000000000..ec9753649b
--- /dev/null
+++ b/c/src/libnetworking/rtems/sghostname.c
@@ -0,0 +1,47 @@
+/*
+ * RTEMS versions of hostname functions
+ * FIXME: Not thread-safe
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <rtems/rtems_bsdnet.h>
+#include <sys/param.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+
+static char *rtems_hostname;
+
+int
+gethostname (char *name, int namelen)
+{
+ char *cp = rtems_hostname;
+
+ if (cp == NULL)
+ cp = "";
+ strncpy (name, cp, namelen);
+ return 0;
+}
+
+int
+sethostname (char *name, int namelen)
+{
+ char *old, *new;
+
+ if (namelen >= MAXHOSTNAMELEN) {
+ errno = EINVAL;
+ return -1;
+ }
+ new = malloc (namelen + 1, M_HTABLE, M_NOWAIT);
+ if (new == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ strncpy (new, name, namelen);
+ new[namelen] = '\0';
+ old = rtems_hostname;
+ rtems_hostname = new;
+ if (old)
+ free (old, M_HTABLE);
+ return 0;
+}