diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-22 18:36:46 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-22 18:36:46 +0000 |
commit | c5148ad9e5d0c44c891f843bc7927bdcce0aee1a (patch) | |
tree | 6f54ddc25051c52d0ce5226bfac63c0054137b7c /nuttx/net/socket.c | |
parent | 7d4b2f6253d8ac898def6839b2ccc2ae61e24135 (diff) | |
download | px4-nuttx-c5148ad9e5d0c44c891f843bc7927bdcce0aee1a.tar.gz px4-nuttx-c5148ad9e5d0c44c891f843bc7927bdcce0aee1a.tar.bz2 px4-nuttx-c5148ad9e5d0c44c891f843bc7927bdcce0aee1a.zip |
TCP and ICMP protocols may now be disabled
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@398 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/socket.c')
-rw-r--r-- | nuttx/net/socket.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/nuttx/net/socket.c b/nuttx/net/socket.c index d7c21d01b..644f5a8c2 100644 --- a/nuttx/net/socket.c +++ b/nuttx/net/socket.c @@ -43,6 +43,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <errno.h> +#include <debug.h> #include "net-internal.h" @@ -106,10 +107,12 @@ int socket(int domain, int type, int protocol) /* Only SOCK_STREAM and possible SOCK_DRAM are supported */ -#ifdef CONFIG_NET_UDP +#if defined(CONFIG_NET_UDP) && defined(CONFIG_NET_TCP) if (protocol != 0 || (type != SOCK_STREAM && type != SOCK_DGRAM)) -#else +#elif defined(CONFIG_NET_TCP) if (protocol != 0 || type != SOCK_STREAM) +#elif defined(CONFIG_NET_UDP) + if (protocol != 0 || type != SOCK_DGRAM) #endif { err = EPROTONOSUPPORT; @@ -128,43 +131,49 @@ int socket(int domain, int type, int protocol) /* Initialize the socket structure */ psock = sockfd_socket(sockfd); - if (psock) + if (!psock) { - /* Save the protocol type */ + err = ENOSYS; /* should not happen */ + goto errout; + } + + /* Save the protocol type */ - psock->s_type = type; - psock->s_conn = NULL; + psock->s_type = type; + psock->s_conn = NULL; - /* Allocate the appropriate connection structure. This reserves the - * the connection structure is is unallocated at this point. It will - * not actually be initialized until the socket is connected. - */ + /* Allocate the appropriate connection structure. This reserves the + * the connection structure is is unallocated at this point. It will + * not actually be initialized until the socket is connected. + */ - switch (type) - { - case SOCK_STREAM: - psock->s_conn = uip_tcpalloc(); - break; + switch (type) + { +#ifdef CONFIG_NET_TCP + case SOCK_STREAM: + psock->s_conn = uip_tcpalloc(); + break; +#endif #ifdef CONFIG_NET_UDP - case SOCK_DGRAM: - psock->s_conn = uip_udpalloc(); - break; + case SOCK_DGRAM: + psock->s_conn = uip_udpalloc(); + break; #endif - default: - break; - } - /* Did we succesfully allocate some kind of connection structure? */ + default: + break; + } + + /* Did we succesfully allocate some kind of connection structure? */ - if (!psock->s_conn) - { - /* Failed to reserve a connection structure */ + if (!psock->s_conn) + { + /* Failed to reserve a connection structure */ - sockfd_release(sockfd); - err = ENFILE; - goto errout; - } + sockfd_release(sockfd); + err = ENFILE; + goto errout; } return sockfd; |