summaryrefslogtreecommitdiff
path: root/nuttx/netutils/smtp/smtp.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-09-02 21:58:35 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-09-02 21:58:35 +0000
commit9a272c38fb40781171f7b4d054430f2c0be730c0 (patch)
tree892d21bc1008301a5f07a8634cf5cb227f563dc6 /nuttx/netutils/smtp/smtp.c
parent8e6fadad87d3220628d412fee845ad0b0cfb697f (diff)
downloadpx4-nuttx-9a272c38fb40781171f7b4d054430f2c0be730c0.tar.gz
px4-nuttx-9a272c38fb40781171f7b4d054430f2c0be730c0.tar.bz2
px4-nuttx-9a272c38fb40781171f7b4d054430f2c0be730c0.zip
Implements basic TCP connection logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@326 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/netutils/smtp/smtp.c')
-rw-r--r--nuttx/netutils/smtp/smtp.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/nuttx/netutils/smtp/smtp.c b/nuttx/netutils/smtp/smtp.c
index 8ea6ca275..09d131057 100644
--- a/nuttx/netutils/smtp/smtp.c
+++ b/nuttx/netutils/smtp/smtp.c
@@ -50,6 +50,7 @@
#include <string.h>
#include <stdlib.h>
#include <semaphore.h>
+#include <sys/socket.h>
#include <net/uip/uip.h>
#include <net/uip/psock.h>
@@ -260,17 +261,10 @@ void smtp_configure(void *handle, char *lhostname, void *server)
int smtp_send(void *handle, char *to, char *cc, char *from, char *subject, char *msg, int msglen)
{
struct smtp_state *psmtp = (struct smtp_state *)handle;
- struct uip_conn *conn;
+ struct sockaddr_in server;
+ int sockfd;
- /* This is the moral equivalent of socket() + bind(). It returns the
- * initialized connection structure
- */
-
- conn = uip_connect(&psmtp->smtpserver, HTONS(25));
- if (conn == NULL)
- {
- return ERROR;
- }
+ /* Setup */
psmtp->connected = TRUE;
psmtp->to = to;
@@ -281,11 +275,35 @@ int smtp_send(void *handle, char *to, char *cc, char *from, char *subject, char
psmtp->msglen = msglen;
psmtp->result = OK;
- /* Make this instance globally visible */
+ /* Create a socket */
+
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ {
+ return ERROR;
+ }
- gpsmtp = psmtp;
+ /* Make this instance globally visible (we will get interrupts as
+ * soon as we connect
+ */
+
+ gpsmtp = psmtp;
+
+ /* Connect to server. First we have to set some fields in the
+ * 'server' structure. The system will assign me an arbitrary
+ * local port that is not in use.
+ */
+
+ server.sin_family = AF_INET;
+ memcpy(&server.sin_addr.s_addr, &psmtp->smtpserver, sizeof(in_addr_t));
+ server.sin_port = HTONS(25);
+
+ if (connect(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) < 0)
+ {
+ return ERROR;
+ }
- /* Initialized the psock structure inside the smtp state structure */
+ /* Initialize the psock structure inside the smtp state structure */
psock_init(&psmtp->psock, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE);