summaryrefslogtreecommitdiff
path: root/nuttx/net/bind.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-09-01 20:56:19 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-09-01 20:56:19 +0000
commit279136fd239ad7bb378b0dae01fe8f109e463c4f (patch)
tree637beec01acf76a0c8926d8de422b642c11bfe89 /nuttx/net/bind.c
parent5d303ec17efc511d8cfe0919a790b44e24a8aad9 (diff)
downloadpx4-nuttx-279136fd239ad7bb378b0dae01fe8f109e463c4f.tar.gz
px4-nuttx-279136fd239ad7bb378b0dae01fe8f109e463c4f.tar.bz2
px4-nuttx-279136fd239ad7bb378b0dae01fe8f109e463c4f.zip
Adding socket(), bind() logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@319 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/bind.c')
-rw-r--r--nuttx/net/bind.c58
1 files changed, 53 insertions, 5 deletions
diff --git a/nuttx/net/bind.c b/nuttx/net/bind.c
index 56d96bb4c..daeb70a87 100644
--- a/nuttx/net/bind.c
+++ b/nuttx/net/bind.c
@@ -38,10 +38,14 @@
****************************************************************************/
#include <nuttx/config.h>
+#ifdef CONFIG_NET
+
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
+#include "net_internal.h"
+
/****************************************************************************
* Global Functions
****************************************************************************/
@@ -50,10 +54,10 @@
* Function: bind
*
* Description:
- * bind() gives the socket sockfd the local address my_addr. my_addr is
- * addrlen bytes long. Traditionally, this is called “assigning a name to a
- * socket.” When a socket is created with socket(2), it exists in a name space
- * (address family) but has no name assigned.
+ * bind() gives the socket sockfd the local address my_addr. my_addr is
+ * addrlen bytes long. Traditionally, this is called “assigning a name to
+ * a socket.” When a socket is created with socket(2), it exists in a name
+ * space (address family) but has no name assigned.
*
* Parameters:
* sockfd Socket descriptor from socket
@@ -63,13 +67,57 @@
* Returned Value:
* 0 on success; -1 on error with errno set appropriately
*
+ * EACCES
+ * The address is protected, and the user is not the superuser.
+ * EADDRINUSE
+ * The given address is already in use.
+ * EBADF
+ * sockfd is not a valid descriptor.
+ * EINVAL
+ * The socket is already bound to an address.
+ * ENOTSOCK
+ * sockfd is a descriptor for a file, not a socket.
+ *
* Assumptions:
*
****************************************************************************/
int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen)
{
- *get_errno_ptr() = ENOSYS;
+ FAR struct socket *psock = sockfd_socket(sockfd);
+ int err;
+
+ /* Verify that the sockfd corresponds to valid, allocated socket */
+
+ if (!psock || psock->s_crefs <= 0)
+ {
+ err = EBADF;
+ goto errout;
+ }
+
+ /* Perform the binding depending on the protocol type */
+ switch (psock->s_type)
+ {
+ case SOCK_STREAM:
+ /* Put TCP/IP binding logic here */
+ break;
+
+#ifdef CONFIG_NET_UDP
+ case SOCK_DGRAM:
+ /* Put UDP binding logic here */
+ break;
+#endif
+ default:
+ err = EBADF;
+ goto errout;
+ }
+
+ err = ENOSYS;
+ /*return OK;*/
+
+errout:
+ *get_errno_ptr() = err;
return ERROR;
}
+#endif /* CONFIG_NET */