summaryrefslogtreecommitdiff
path: root/nuttx/include
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-09-03 20:34:44 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-09-03 20:34:44 +0000
commitc96d656001914b495f54e7a25d54079e41af86ce (patch)
treedabdb9c5fded41355669eccebd630d33b106689a /nuttx/include
parent0792c58515fae8507fcd6de41ca7db89fd2734d4 (diff)
downloadpx4-nuttx-c96d656001914b495f54e7a25d54079e41af86ce.tar.gz
px4-nuttx-c96d656001914b495f54e7a25d54079e41af86ce.tar.bz2
px4-nuttx-c96d656001914b495f54e7a25d54079e41af86ce.zip
Add send, sendto, rec, recvfrom
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@328 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include')
-rw-r--r--nuttx/include/net/uip/resolv.h40
-rw-r--r--nuttx/include/net/uip/uip.h100
-rw-r--r--nuttx/include/nuttx/net.h4
-rw-r--r--nuttx/include/sys/socket.h32
4 files changed, 110 insertions, 66 deletions
diff --git a/nuttx/include/net/uip/resolv.h b/nuttx/include/net/uip/resolv.h
index 3411966ea..9ab900978 100644
--- a/nuttx/include/net/uip/resolv.h
+++ b/nuttx/include/net/uip/resolv.h
@@ -36,25 +36,31 @@
#include <sys/types.h>
#include <net/uip/uipopt.h>
-/* Callback function which is called when a hostname is found.
- *
- * This function must be implemented by the module that uses the DNS
- * resolver. It is called when a hostname is found, or when a hostname
- * was not found.
- *
- * name A pointer to the name that was looked up. \param
- * ipaddr A pointer to a 4-byte array containing the IP address of the
- * hostname, or NULL if the hostname could not be found.
- */
-
-extern void resolv_found(char *name, uint16 *ipaddr);
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
/* Functions. */
-extern void resolv_conf(uint16 *dnsserver);
-extern uint16 *resolv_getserver(void);
-extern void resolv_init(void);
-extern uint16 *resolv_lookup(char *name);
-extern void resolv_query(char *name);
+EXTERN int resolv_init(void);
+
+#ifdef CONFIG_NET_IPv6
+EXTERN void resolv_conf(const struct sockaddr_in6 *dnsserver);
+EXTERN void resolv_getserver(const struct sockaddr_in6 *dnsserver);
+EXTERN int resolv_query(char *name, struct sockaddr_in6 *addr);
+#else
+EXTERN void resolv_conf(const struct sockaddr_in *dnsserver);
+EXTERN void resolv_getserver(const struct sockaddr_in *dnsserver);
+EXTERN int resolv_query(char *name, struct sockaddr_in *addr);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
#endif /* __UIP_RESOLV_H__ */
diff --git a/nuttx/include/net/uip/uip.h b/nuttx/include/net/uip/uip.h
index 65a772e60..b03233ed3 100644
--- a/nuttx/include/net/uip/uip.h
+++ b/nuttx/include/net/uip/uip.h
@@ -48,8 +48,9 @@
* Included Files
****************************************************************************/
-#include <sys/types.h>
#include <nuttx/config.h>
+#include <sys/types.h>
+#include <queue.h>
#include <arpa/inet.h>
#include <net/uip/uipopt.h>
@@ -158,12 +159,11 @@ typedef uip_ip4addr_t uip_ipaddr_t;
struct uip_conn
{
+ dq_entry_t node; /* Implements a doubly linked list */
uip_ipaddr_t ripaddr; /* The IP address of the remote host. */
-
uint16 lport; /* The local TCP port, in network byte order. */
uint16 rport; /* The local remote TCP port, in network byte
order. */
-
uint8 rcv_nxt[4]; /* The sequence number that we expect to
receive next. */
uint8 snd_nxt[4]; /* The sequence number that was last sent by
@@ -188,6 +188,7 @@ struct uip_conn
*/
void *private;
+ void (*callback)(void *private);
};
#ifdef CONFIG_NET_UDP
@@ -195,16 +196,16 @@ struct uip_conn
struct uip_udp_conn
{
+ dq_entry_t node; /* Implements a doubly linked list */
uip_ipaddr_t ripaddr; /* The IP address of the remote peer. */
uint16 lport; /* The local port number in network byte order. */
uint16 rport; /* The remote port number in network byte order. */
uint8 ttl; /* Default time-to-live. */
- /* Higher level logic can retain application specific information
- * in the following:
- */
+ /* Defines the UDP callback */
void *private;
+ void (*callback)(void *private);
};
#endif /* CONFIG_NET_UDP */
@@ -613,9 +614,6 @@ void uip_setipid(uint16 id);
*/
extern void uip_interrupt_event(void);
-#ifdef CONFIG_NET_UDP
-extern void uip_interrupt_udp_event(void);
-#endif
/* Find a free connection structure and allocate it for use. This is
* normally something done by the implementation of the socket() API
@@ -635,6 +633,34 @@ extern void uip_tcpfree(struct uip_conn *conn);
extern void uip_udpfree(struct uip_udp_conn *conn);
#endif
+/* Bind a TCP connection to a local address */
+
+#ifdef CONFIG_NET_IPv6
+extern int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in6 *addr);
+#else
+extern int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr);
+#endif
+
+/* This function implements the UIP specific parts of the standard
+ * TCP connect() operation: It connects to a remote host using TCP.
+ *
+ * This function is used to start a new connection to the specified
+ * port on the specied host. It uses the connection structure that was
+ * allocated by a preceding socket() call. It sets the connection to
+ * the SYN_SENT state and sets the retransmission timer to 0. This will
+ * cause a TCP SYN segment to be sent out the next time this connection
+ * is periodically processed, which usually is done within 0.5 seconds
+ * after the call to uip_tcpconnect().
+ *
+ * This function is called from normal user level code.
+ */
+
+#ifdef CONFIG_NET_IPv6
+extern int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in6 *addr);
+#else
+extern int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr);
+#endif
+
/* Start listening to the specified port.
*
* Note: Since this function expects the port number in network byte
@@ -848,51 +874,31 @@ void uip_send(const void *data, int len);
#define uip_mss() (uip_conn->mss)
-/* Set up a new UDP connection.
- *
- * This function sets up a new UDP connection. The function will
+/* Bind a UDP connection to a local address */
+
+#ifdef CONFIG_NET_IPv6
+extern int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr);
+#else
+extern int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in *addr);
+#endif
+
+/* This function sets up a new UDP connection. The function will
* automatically allocate an unused local port for the new
* connection. However, another port can be chosen by using the
- * uip_udp_bind() call, after the uip_udp_new() function has been
+ * uip_udpbind() call, after the uip_udpconnect() function has been
* called.
*
- * Example:
+ * This function is called as part of the implementation of sendto
+ * and recvfrom.
*
- * uip_ipaddr_t addr;
- * struct uip_udp_conn *c;
- *
- * uip_ipaddr(&addr, 192,168,2,1);
- * c = uip_udp_new(&addr, HTONS(12345));
- * if(c != NULL) {
- * uip_udp_bind(c, HTONS(12344));
- * }
- *
- * ripaddr The IP address of the remote host.
- *
- * rport The remote port number in network byte order.
- *
- * Return: The uip_udp_conn structure for the new connection or NULL
- * if no connection could be allocated.
+ * addr The address of the remote host.
*/
-struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, uint16 rport);
-
-/* Removed a UDP connection.
- *
- * conn A pointer to the uip_udp_conn structure for the connection.
- */
-
-#define uip_udp_remove(conn) (conn)->lport = 0
-
-/* Bind a UDP connection to a local port.
- *
- * conn A pointer to the uip_udp_conn structure for the
- * connection.
- *
- * port The local port number, in network byte order.
- */
-
-#define uip_udp_bind(conn, port) (conn)->lport = port
+#ifdef CONFIG_NET_IPv6
+extern int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr);
+#else
+extern int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr);
+#endif
/* Send a UDP datagram of length len on the current connection.
*
diff --git a/nuttx/include/nuttx/net.h b/nuttx/include/nuttx/net.h
index bb8ec8da3..ab6b4b93a 100644
--- a/nuttx/include/nuttx/net.h
+++ b/nuttx/include/nuttx/net.h
@@ -106,6 +106,10 @@ EXTERN FAR struct socketlist *net_alloclist(void);
EXTERN int net_addreflist(FAR struct socketlist *list);
EXTERN int net_releaselist(FAR struct socketlist *list);
+/* net-close.c ***************************************************************/
+
+EXTERN int net_close(int sockfd);
+
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/nuttx/include/sys/socket.h b/nuttx/include/sys/socket.h
index 589fafe13..e1204e68a 100644
--- a/nuttx/include/sys/socket.h
+++ b/nuttx/include/sys/socket.h
@@ -93,6 +93,28 @@
#define SOCK_RDM 4 /* Provides a reliable datagram layer that does not guarantee ordering. */
#define SOCK_PACKET 5 /* Obsolete and should not be used in new programs */
+
+/* Bits in the FLAGS argument to `send', `recv', et al. These are the bits
+ * recognized by Linus, not all are supported by NuttX.
+ */
+
+#define MSG_OOB 0x0001 /* Process out-of-band data. */
+#define MSG_PEEK 0x0002 /* Peek at incoming messages. */
+#define MSG_DONTROUTE 0x0004 /* Don't use local routing. */
+#define MSG_CTRUNC 0x0008 /* Control data lost before delivery. */
+#define MSG_PROXY 0x0010 /* Supply or ask second address. */
+#define MSG_TRUNC 0x0020
+#define MSG_DONTWAIT 0x0040 /* Enable nonblocking IO. */
+#define MSG_EOR 0x0080 /* End of record. */
+#define MSG_WAITALL 0x0100 /* Wait for a full request. */
+#define MSG_FIN 0x0200
+#define MSG_SYN 0x0400
+#define MSG_CONFIRM 0x0800 /* Confirm path validity. */
+#define MSG_RST 0x1000
+#define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue. */
+#define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE. */
+#define MSG_MORE 0x8000 /* Sender will send more. */
+
/****************************************************************************
* Type Definitions
****************************************************************************/
@@ -119,9 +141,15 @@ EXTERN int socket(int domain, int type, int protocol);
EXTERN int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
EXTERN int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
-EXTERN ssize_t send(int s, const void *buf, size_t len, int flags);
-EXTERN ssize_t sendto(int s, const void *buf, size_t len, int flags,
+EXTERN ssize_t send(int sockfd, const void *buf, size_t len, int flags);
+EXTERN ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *to, socklen_t tolen);
+
+EXTERN ssize_t recv(int sockfd, void *buf, size_t len, int flags);
+EXTERN ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
+ struct sockaddr *from, socklen_t *fromlen);
+
+
#undef EXTERN
#if defined(__cplusplus)
}