Added initial TcpTransport
diff --git a/Makefile.am b/Makefile.am
index b51bb9e..98f5be3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -30,6 +30,7 @@
ndn-cpp/c/encoding/BinaryXMLName.c ndn-cpp/c/encoding/BinaryXMLName.h \
ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.c ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.h \
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.c ndn-cpp/c/encoding/BinaryXMLStructureDecoder.h \
+ ndn-cpp/c/network/TcpTransport.c ndn-cpp/c/network/TcpTransport.c \
ndn-cpp/c/util/DynamicUCharArray.c ndn-cpp/c/util/DynamicUCharArray.h \
ndn-cpp/c/util/ndn_memory.c ndn-cpp/c/util/ndn_memory.h
diff --git a/Makefile.in b/Makefile.in
index 2a84ac9..0c245ab 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -144,6 +144,8 @@
ndn-cpp/c/encoding/BinaryXMLName.$(OBJEXT) \
ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.$(OBJEXT) \
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.$(OBJEXT) \
+ ndn-cpp/c/network/TcpTransport.$(OBJEXT) \
+ ndn-cpp/c/network/TcpTransport.$(OBJEXT) \
ndn-cpp/c/util/DynamicUCharArray.$(OBJEXT) \
ndn-cpp/c/util/ndn_memory.$(OBJEXT)
libndn_c_a_OBJECTS = $(am_libndn_c_a_OBJECTS)
@@ -419,6 +421,7 @@
ndn-cpp/c/encoding/BinaryXMLName.c ndn-cpp/c/encoding/BinaryXMLName.h \
ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.c ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.h \
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.c ndn-cpp/c/encoding/BinaryXMLStructureDecoder.h \
+ ndn-cpp/c/network/TcpTransport.c ndn-cpp/c/network/TcpTransport.c \
ndn-cpp/c/util/DynamicUCharArray.c ndn-cpp/c/util/DynamicUCharArray.h \
ndn-cpp/c/util/ndn_memory.c ndn-cpp/c/util/ndn_memory.h
@@ -564,6 +567,15 @@
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.$(OBJEXT): \
ndn-cpp/c/encoding/$(am__dirstamp) \
ndn-cpp/c/encoding/$(DEPDIR)/$(am__dirstamp)
+ndn-cpp/c/network/$(am__dirstamp):
+ @$(MKDIR_P) ndn-cpp/c/network
+ @: > ndn-cpp/c/network/$(am__dirstamp)
+ndn-cpp/c/network/$(DEPDIR)/$(am__dirstamp):
+ @$(MKDIR_P) ndn-cpp/c/network/$(DEPDIR)
+ @: > ndn-cpp/c/network/$(DEPDIR)/$(am__dirstamp)
+ndn-cpp/c/network/TcpTransport.$(OBJEXT): \
+ ndn-cpp/c/network/$(am__dirstamp) \
+ ndn-cpp/c/network/$(DEPDIR)/$(am__dirstamp)
ndn-cpp/c/util/$(am__dirstamp):
@$(MKDIR_P) ndn-cpp/c/util
@: > ndn-cpp/c/util/$(am__dirstamp)
@@ -680,6 +692,7 @@
-rm -f ndn-cpp/*.$(OBJEXT)
-rm -f ndn-cpp/c/*.$(OBJEXT)
-rm -f ndn-cpp/c/encoding/*.$(OBJEXT)
+ -rm -f ndn-cpp/c/network/*.$(OBJEXT)
-rm -f ndn-cpp/c/util/*.$(OBJEXT)
-rm -f ndn-cpp/encoding/*.$(OBJEXT)
-rm -f tests/*.$(OBJEXT)
@@ -700,6 +713,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLName.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLPublisherPublicKeyDigest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLStructureDecoder.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/network/$(DEPDIR)/TcpTransport.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/util/$(DEPDIR)/DynamicUCharArray.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/util/$(DEPDIR)/ndn_memory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/$(DEPDIR)/BinaryXMLWireFormat.Po@am__quote@
@@ -994,6 +1008,8 @@
-rm -f ndn-cpp/c/$(am__dirstamp)
-rm -f ndn-cpp/c/encoding/$(DEPDIR)/$(am__dirstamp)
-rm -f ndn-cpp/c/encoding/$(am__dirstamp)
+ -rm -f ndn-cpp/c/network/$(DEPDIR)/$(am__dirstamp)
+ -rm -f ndn-cpp/c/network/$(am__dirstamp)
-rm -f ndn-cpp/c/util/$(DEPDIR)/$(am__dirstamp)
-rm -f ndn-cpp/c/util/$(am__dirstamp)
-rm -f ndn-cpp/encoding/$(DEPDIR)/$(am__dirstamp)
@@ -1011,7 +1027,7 @@
distclean: distclean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
- -rm -rf ndn-cpp/$(DEPDIR) ndn-cpp/c/$(DEPDIR) ndn-cpp/c/encoding/$(DEPDIR) ndn-cpp/c/util/$(DEPDIR) ndn-cpp/encoding/$(DEPDIR) tests/$(DEPDIR)
+ -rm -rf ndn-cpp/$(DEPDIR) ndn-cpp/c/$(DEPDIR) ndn-cpp/c/encoding/$(DEPDIR) ndn-cpp/c/network/$(DEPDIR) ndn-cpp/c/util/$(DEPDIR) ndn-cpp/encoding/$(DEPDIR) tests/$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-hdr distclean-tags
@@ -1059,7 +1075,7 @@
maintainer-clean: maintainer-clean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf $(top_srcdir)/autom4te.cache
- -rm -rf ndn-cpp/$(DEPDIR) ndn-cpp/c/$(DEPDIR) ndn-cpp/c/encoding/$(DEPDIR) ndn-cpp/c/util/$(DEPDIR) ndn-cpp/encoding/$(DEPDIR) tests/$(DEPDIR)
+ -rm -rf ndn-cpp/$(DEPDIR) ndn-cpp/c/$(DEPDIR) ndn-cpp/c/encoding/$(DEPDIR) ndn-cpp/c/network/$(DEPDIR) ndn-cpp/c/util/$(DEPDIR) ndn-cpp/encoding/$(DEPDIR) tests/$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
diff --git a/ndn-cpp/c/network/TcpTransport.c b/ndn-cpp/c/network/TcpTransport.c
new file mode 100644
index 0000000..30e6828
--- /dev/null
+++ b/ndn-cpp/c/network/TcpTransport.c
@@ -0,0 +1,89 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "TcpTransport.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+#include <arpa/inet.h>
+
+// get sockaddr, IPv4 or IPv6:
+static inline void *get_in_addr(struct sockaddr *sa)
+{
+ if (sa->sa_family == AF_INET)
+ return &(((struct sockaddr_in*)sa)->sin_addr);
+
+ return &(((struct sockaddr_in6*)sa)->sin6_addr);
+}
+
+ndn_Error ndn_TcpTransport_connect(ndn_TcpTransport *self, char *host, int port)
+{
+
+}
+
+int testTcpTransport(unsigned char *data, unsigned int dataLength)
+{
+ struct addrinfo hints, *serverInfo;
+
+ printf("starting\n");
+
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+
+ if (getaddrinfo("E.hub.ndn.ucla.edu", "9695", &hints, &serverInfo) != 0)
+ return 1;
+
+ // loop through all the results and connect to the first we can
+ struct addrinfo *p;
+ for(p = serverInfo; p != NULL; p = p->ai_next) {
+ if ((socketDescriptor = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1)
+ continue;
+
+ if (connect(socketDescriptor, p->ai_addr, p->ai_addrlen) == -1) {
+ close(socketDescriptor);
+ continue;
+ }
+
+ break;
+ }
+
+ if (p == NULL)
+ return 2;
+
+ freeaddrinfo(serverInfo); // all done with this structure
+
+ int nBytes;
+ while (1) {
+ if ((nBytes = send(socketDescriptor, data, dataLength, 0)) < 0)
+ return 1;
+ if (nBytes >= dataLength)
+ break;
+
+ dataLength -= nBytes;
+ }
+
+ unsigned char buffer[1000];
+ if ((nBytes = recv(socketDescriptor, buffer, sizeof(buffer) - 1, 0)) == -1)
+ return 1;
+
+ printf("received %d bytes\n", nBytes);
+ int i;
+ for (i = 0; i < nBytes; ++i)
+ printf("%02X ", (unsigned int)buffer[i]);
+ printf("\n");
+
+ close(socketDescriptor);
+
+ return 0;
+}
diff --git a/ndn-cpp/c/network/TcpTransport.h b/ndn-cpp/c/network/TcpTransport.h
new file mode 100644
index 0000000..82ef03b
--- /dev/null
+++ b/ndn-cpp/c/network/TcpTransport.h
@@ -0,0 +1,30 @@
+/*
+ * File: TcpTransport.h
+ * Author: jefft0
+ *
+ * Created on July 14, 2013, 4:15 PM
+ */
+
+#ifndef NDN_TCPTRANSPORT_H
+#define NDN_TCPTRANSPORT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ndn_TcpTransport {
+ int socketDescriptor; /**< -1 if not connected */
+};
+
+static inline void ndn_TcpTransport_init(ndn_TcpTransport *self)
+{
+ self->socketDescriptor = -1;
+}
+
+int testTcpTransport(unsigned char *data, unsigned int dataLength);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif