Add implementations of uname() and gethost(). From Stavros Polymenis.
This commit is contained in:
parent
d6eacb3ab5
commit
701509f9bd
2
configs
2
configs
@ -1 +1 @@
|
||||
Subproject commit c406bbba6f45f9c783584f0a3b6a1a628f209fa3
|
||||
Subproject commit 93f51860e7fbeb984ce9424b878bf2e7235c1c5f
|
58
include/sys/uio.h
Normal file
58
include/sys/uio.h
Normal file
@ -0,0 +1,58 @@
|
||||
/****************************************************************************
|
||||
* include/sys/uio.h
|
||||
*
|
||||
* Copyright (C) 2015 Stavros Polymenis. All rights reserved.
|
||||
* Author: Stavros Polymenis <sp@orbitalfox.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_SYS_UIO_H
|
||||
#define __INCLUDE_SYS_UIO_H
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct iovec
|
||||
{
|
||||
FAR void *iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if 0 /* Not implemented */
|
||||
ssize_t readv(int, const struct iovec *, int);
|
||||
ssize_t writev(int, const struct iovec *, int);
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_SYS_UIO_H */
|
70
include/sys/utsname.h
Normal file
70
include/sys/utsname.h
Normal file
@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
* include/sys/utsname.h
|
||||
*
|
||||
* Copyright (C) 2015 Stavros Polymenis. All rights reserved.
|
||||
* Author: Stavros Polymenis <sp@orbitalfox.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_SYS_UTSNAME_H
|
||||
#define __INCLUDE_SYS_UTSNAME_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define SYS_NAMELEN 16
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct utsname
|
||||
{
|
||||
char sysname[SYS_NAMELEN]; /* Name of OS */
|
||||
char nodename[HOST_NAME_MAX]; /* Name of this network node */
|
||||
char release[SYS_NAMELEN]; /* Release level */
|
||||
char version[SYS_NAMELEN]; /* Version level */
|
||||
char machine[SYS_NAMELEN]; /* Hardware type */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
int uname(FAR struct utsname *name);
|
||||
|
||||
#endif /* __INCLUDE_SYS_UTSNAME_H */
|
@ -96,6 +96,8 @@
|
||||
|
||||
#define fdatasync(f) fsync(f)
|
||||
|
||||
#define HOST_NAME_MAX 32
|
||||
|
||||
/****************************************************************************
|
||||
* Global Variables
|
||||
****************************************************************************/
|
||||
@ -191,6 +193,10 @@ FAR char **getoptargp(void); /* Optional argument following option */
|
||||
int *getoptindp(void); /* Index into argv */
|
||||
int *getoptoptp(void); /* unrecognized option character */
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
int gethostname(char *name, size_t size);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
# Add the internal C files to the build
|
||||
|
||||
CSRCS += lib_stream.c lib_filesem.c
|
||||
CSRCS += lib_stream.c lib_filesem.c lib_utsname.c
|
||||
|
||||
# Add C files that depend on file OR socket descriptors
|
||||
|
||||
|
102
libc/misc/lib_utsname.c
Normal file
102
libc/misc/lib_utsname.c
Normal file
@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
* include/sys/utsname.c
|
||||
*
|
||||
* Copyright (C) 2015 Stavros Polymenis. All rights reserved.
|
||||
* Author: Stavros Polymenis <sp@orbitalfox.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/utsname.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/version.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uname
|
||||
*
|
||||
* Description:
|
||||
* The uname() function will store information identifying the current
|
||||
* system in the structure pointed to by name.
|
||||
*
|
||||
* The uname() function uses the utsname structure defined in
|
||||
* <sys/utsname.h>.
|
||||
*
|
||||
* The uname() function will return a string naming the current system in
|
||||
* the character array sysname. Similarly, nodename will contain the name
|
||||
* of this node within an implementation-defined communications network.
|
||||
* The arrays release and version will further identify the operating
|
||||
* system. The array machine will contain a name that identifies the
|
||||
* hardware that the system is running on.
|
||||
*
|
||||
* The format of each member is implementation-defined.
|
||||
*
|
||||
* Input Parameters:
|
||||
* name - The user-provided buffer to receive the system information.
|
||||
*
|
||||
* Returned Value:
|
||||
* Upon successful completion, a non-negative value will be returned.
|
||||
* Otherwise, -1 will be returned and errno set to indicate the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int uname(FAR struct utsname *name)
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
strcpy(name->sysname, "NuttX");
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
/* Get the hostname */
|
||||
|
||||
if (-1 == gethostname(name->nodename, HOST_NAME_MAX))
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
#else
|
||||
strcpy(name->nodename, "");
|
||||
#endif
|
||||
|
||||
strcpy(name->release, CONFIG_VERSION_STRING);
|
||||
strcpy(name->version, CONFIG_VERSION_BUILD);
|
||||
strcpy(name->machine, CONFIG_ARCH);
|
||||
|
||||
return ret;
|
||||
}
|
@ -52,6 +52,10 @@ ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
||||
CSRCS += lib_sleep.c lib_usleep.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
CSRCS += lib_gethostname.c
|
||||
endif
|
||||
|
||||
# Add the unistd directory to the build
|
||||
|
||||
DEPPATH += --dep-path unistd
|
||||
|
90
libc/unistd/lib_gethostname.c
Normal file
90
libc/unistd/lib_gethostname.c
Normal file
@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
* libc/unistd/lib_gethostname.c
|
||||
*
|
||||
* Copyright (C) 2015 Stavros Polymenis. All rights reserved.
|
||||
* Author: Stavros Polymenis <sp@orbitalfox.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Defintiions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NET_HOSTNAME
|
||||
# define CONFIG_NET_HOSTNAME ""
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: gethostname
|
||||
*
|
||||
* Description:
|
||||
* The gethostname() function will return the standard host name for the
|
||||
* current machine. The namelen argument will specify the size of the
|
||||
* array pointed to by the name argument. The returned name will be null-
|
||||
* terminated, except that if namelen is an insufficient length to hold the
|
||||
* host name, then the returned name will be truncated and it is
|
||||
* unspecified whether the returned name is null-terminated.
|
||||
*
|
||||
* Host names are limited to {HOST_NAME_MAX} bytes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* name - The user-provided buffer to receive the host name.
|
||||
* namelen - The size of the user provided buffer in bytes.
|
||||
*
|
||||
* Returned Value:
|
||||
* Upon successful completion, 0 will be returned; otherwise, -1 will be
|
||||
* returned. No errors are defined; errno variable is not set.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int gethostname(FAR char *name, size_t namelen)
|
||||
{
|
||||
/* Return the host name, truncating to fit into the user provided buffer */
|
||||
|
||||
strncpy(name, CONFIG_NET_HOSTNAME, namelen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
@ -262,4 +262,10 @@ config NET_MULTICAST
|
||||
---help---
|
||||
Outgoing multi-cast address support
|
||||
|
||||
config NET_HOSTNAME
|
||||
string "Host name for current machine"
|
||||
default ""
|
||||
---help---
|
||||
A unique name to identify device on the network
|
||||
|
||||
endif # NET
|
||||
|
Loading…
Reference in New Issue
Block a user