5
Last change
on this file since cb68253 was
cb68253,
checked in by Sebastian Huber <sebastian.huber@…>, on 09/07/18 at 04:19:02
|
network: Use kernel/user space header files
Add and use <machine/rtems-bsd-kernel-space.h> and
<machine/rtems-bsd-user-space.h> similar to the libbsd to avoid command
line defines and defines scattered throught the code base.
Simplify cpukit/libnetworking/Makefile.am.
Update #3375.
|
-
Property mode set to
100644
|
File size:
895 bytes
|
Line | |
---|
1 | #include <machine/rtems-bsd-kernel-space.h> |
---|
2 | |
---|
3 | /* |
---|
4 | * RTEMS versions of hostname functions |
---|
5 | * FIXME: Not thread-safe |
---|
6 | */ |
---|
7 | |
---|
8 | #if HAVE_CONFIG_H |
---|
9 | #include "config.h" |
---|
10 | #endif |
---|
11 | |
---|
12 | #include <string.h> |
---|
13 | #include <errno.h> |
---|
14 | #include <unistd.h> |
---|
15 | #include <rtems/rtems_bsdnet.h> |
---|
16 | #include <sys/param.h> |
---|
17 | #include <sys/malloc.h> |
---|
18 | #include <sys/kernel.h> |
---|
19 | |
---|
20 | static char *rtems_hostname; |
---|
21 | |
---|
22 | int |
---|
23 | gethostname (char *name, size_t namelen) |
---|
24 | { |
---|
25 | char *cp = rtems_hostname; |
---|
26 | |
---|
27 | if (cp == NULL) |
---|
28 | cp = ""; |
---|
29 | strncpy (name, cp, namelen); |
---|
30 | return 0; |
---|
31 | } |
---|
32 | |
---|
33 | int |
---|
34 | sethostname (const char *name, size_t namelen) |
---|
35 | { |
---|
36 | char *old, *new; |
---|
37 | |
---|
38 | if (namelen >= MAXHOSTNAMELEN) { |
---|
39 | errno = EINVAL; |
---|
40 | return -1; |
---|
41 | } |
---|
42 | new = malloc (namelen + 1, M_HTABLE, M_NOWAIT); |
---|
43 | if (new == NULL) { |
---|
44 | errno = ENOMEM; |
---|
45 | return -1; |
---|
46 | } |
---|
47 | strncpy (new, name, namelen); |
---|
48 | new[namelen] = '\0'; |
---|
49 | old = rtems_hostname; |
---|
50 | rtems_hostname = new; |
---|
51 | if (old) |
---|
52 | free (old, M_HTABLE); |
---|
53 | return 0; |
---|
54 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.