Add send, sendto, rec, recvfrom

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@328 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2007-09-03 20:34:44 +00:00
parent f72d286d19
commit cae9bad97b
26 changed files with 1699 additions and 614 deletions
+23 -17
View File
@@ -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__ */
+53 -47
View File
@@ -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.
*
+4
View File
@@ -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
}
+30 -2
View File
@@ -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)
}