A new object oriented network api that can be used to replace the one provided by the EthernetInterface library.

Dependents:   NetRelais TCP_Client_Example TCP_Server_Example UDP_Server_Example ... more

Object oriented network interface for the mbed platform

Currently implemented:

  • Address
  • Endpoint
  • UDP Socket
  • TCP Socket
  • Databuffer
  • Select API

It depends on the EthernetInterface for the lwip network stack.

Please do not hesitate to contact me with any remarks, improvements or questions.

The API is also available for unix at GitHub: LibNosa

Examples

Files at this revision

API Documentation at this revision

Comitter:
NegativeBlack
Date:
Tue Jul 17 15:01:25 2012 +0000
Child:
1:6956f6f96fef
Commit message:
Initial implementation of the network API. Address and Endpoint structures work.

Changed in this revision

ip/address.cpp Show annotated file Show diff for this revision Revisions of this file
ip/address.hpp Show annotated file Show diff for this revision Revisions of this file
ip/endpoint.cpp Show annotated file Show diff for this revision Revisions of this file
ip/endpoint.hpp Show annotated file Show diff for this revision Revisions of this file
socket.cpp Show annotated file Show diff for this revision Revisions of this file
socket.hpp Show annotated file Show diff for this revision Revisions of this file
tcp/socket.cpp Show annotated file Show diff for this revision Revisions of this file
tcp/socket.hpp Show annotated file Show diff for this revision Revisions of this file
udp/socket.cpp Show annotated file Show diff for this revision Revisions of this file
udp/socket.hpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ip/address.cpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,147 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+ 
+#include "network/ip/address.hpp"
+using namespace network::ip;
+ 
+Address::Address()
+{
+    std::memset(&this->_address, 0, sizeof(this->_address));
+}
+
+Address::Address(const int address)
+{
+    this->fromNative(address);
+}
+
+Address::Address(const Address &other)
+{
+    std::memcpy(&this->_address, &other._address, sizeof(this->_address));
+}
+
+Address::Address(const char *address)
+{
+    std::string _address(address);
+    if (this->fromString(_address) < 0) {
+       std::memset(&this->_address, 0, sizeof(this->_address));
+   }
+}
+
+Address::Address(const std::string &address)
+{
+   if (this->fromString(address) < 0) {
+       std::memset(&this->_address, 0, sizeof(this->_address));
+   }
+}
+ 
+int
+Address::fromString(const std::string &address)
+{
+    // Decode the ASCI string into integer values.
+    int result = std::sscanf(address.c_str(), "%3u.%3u.%3u.%3u",
+        (int *)&this->_address[3],
+        (int *)&this->_address[2],
+        (int *)&this->_address[1],
+        (int *)&this->_address[0]);
+
+    // Check if all four fields got set.
+    if (result != 4) {
+        return -1;
+    }
+    
+    return 0;
+}
+
+std::string
+Address::toString()
+{
+    char address[16];
+    
+    // Encode integer fields into the ASCI string.
+    int result = sprintf(address, "%u.%u.%u.%u",
+        (unsigned int)this->_address[3],
+        (unsigned int)this->_address[2],
+        (unsigned int)this->_address[1],
+        (unsigned int)this->_address[0]);
+
+    // Check if atleast 8 and at maximum 15 bytes got written.
+    if (result < 8 || result > 16) {
+        return std::string("0.0.0.0");
+    }
+    
+    return std::string(address);
+}
+
+int
+Address::fromHostname(const char *hostname)
+{
+    if (hostname == NULL) {
+        return -1;
+    }
+    
+    struct hostent *address = ::gethostbyname(hostname);
+    if (address == NULL) {
+        return -1;
+    }
+    
+    std::memcpy(this->_address, address->h_addr_list[0], sizeof(this->_address));
+    // Todo: Free hostent structure? I have no idea...
+    
+    return 0;
+}
+
+void
+Address::fromNative(const int address)
+{
+    // Todo: Check byteorder
+    std::memcpy(&this->_address, &address, sizeof(address));
+}
+
+int
+Address::toNative()
+{
+    int address;
+    
+    // Todo: Check byteorder
+    std::memcpy(&address, &this->_address, sizeof(address));
+    
+    return address;
+}
+
+Address &
+Address::operator=(const Address &other) {
+    std::memcpy(&this->_address, &other._address, sizeof(this->_address));
+    return (*this);
+}
+
+bool
+Address::operator==(const Address &other) {
+    return (std::memcmp(&this->_address, &other._address, sizeof(this->_address)) == 0);
+}
+
+bool
+Address::operator!=(const Address &other) {
+    return !((*this) == other);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ip/address.hpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NETWORK_IP_ADDRESS_HPP_
+#define _NETWORK_IP_ADDRESS_HPP_
+
+#include <cstdio>
+#include <cstring>
+#include <string>
+
+#include "bsd_socket.h"
+
+namespace network {
+namespace ip {
+
+    class Address
+    {
+        public:
+            static const int Any       = (int)0x00000000;
+            static const int Loopback  = (int)0x7f000001;
+            static const int Broadcast = (int)0xffffffff;
+    
+        protected:
+            unsigned char _address[4];
+            
+        public:
+            Address();
+            explicit Address(const Address &other);
+            explicit Address(const int address);
+            explicit Address(const char *address);
+            explicit Address(const std::string &address);
+            
+            int fromString(const std::string &address);
+            std::string toString();
+            
+            int fromHostname(const char *hostname);
+            
+            void fromNative(const int address);
+            int toNative();
+            
+            Address &operator=(const Address &other);
+            
+            bool operator==(const Address &other);
+            bool operator!=(const Address &other);
+    };
+
+} // namespace ip
+} // namespace network
+
+#endif // _NETWORK_IP_ADDRESS_HPP_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ip/endpoint.cpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,105 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+ 
+#include "network/ip/endpoint.hpp"
+using namespace network::ip;
+
+Endpoint::Endpoint():
+    _port(0)
+{}
+
+Endpoint::Endpoint(const Endpoint &other):
+    _address(other._address),
+    _port(other._port)
+{}
+
+Endpoint::Endpoint(const Address &address):
+    _address(address),
+    _port(0)
+{}
+
+Endpoint::Endpoint(const Address &address, int port):
+    _address(address),
+    _port(port)
+{}
+
+int
+Endpoint::setPort(int port)
+{
+    if (port > 65536) {
+        return -1;
+    }
+    
+    this->_port = port;
+    return 0;
+}
+
+int
+Endpoint::getPort()
+{
+    return this->_port;
+}
+
+void
+Endpoint::setAddress(const Address &address)
+{
+    this->_address = address;
+}
+
+Address &
+Endpoint::getAddress()
+{
+    return this->_address;
+}
+
+int
+Endpoint::toNative(struct sockaddr_in *endpoint)
+{
+    if (endpoint == NULL) {
+        return 1;
+    }
+    
+    // Clear structure
+    std::memset(endpoint, 0, sizeof(struct sockaddr_in));
+    
+    // Export endpoint
+    endpoint->sin_family = AF_INET;
+    endpoint->sin_port = htons(this->_port);
+    endpoint->sin_addr.s_addr = this->_address.toNative();
+    return 0;
+}
+
+int
+Endpoint::fromNative(struct sockaddr_in *endpoint)
+{
+    if (endpoint == NULL) {
+        return 1;
+    }
+    
+    // Import endpoint
+    this->_port = ntohs(endpoint->sin_port);
+    this->_address.fromNative(endpoint->sin_addr.s_addr);
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ip/endpoint.hpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NETWORK_IP_ENDPOINT_HPP_
+#define _NETWORK_IP_ENDPOINT_HPP_
+
+#include <cstring>
+
+#include "bsd_socket.h"
+#include "network/ip/address.hpp"
+
+namespace network {
+namespace ip {
+
+    class Endpoint
+    {
+        protected:
+            Address _address;
+            int _port;
+            
+        public:
+            Endpoint();
+            explicit Endpoint(const Endpoint &other);
+            explicit Endpoint(const Address &address);
+            explicit Endpoint(const Address &address, int port);
+            
+            int setPort(int port);
+            int getPort();
+            
+            void setAddress(const Address &address);
+            Address &getAddress();
+            
+            int toNative(struct sockaddr_in *endpoint);
+            int fromNative(struct sockaddr_in *endpoint);
+    };
+
+} // namespace ip
+} // namespace network
+
+#endif // _NETWORK_IP_ENDPOINT_HPP_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/socket.cpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+ 
+#include "network/socket.hpp"
+using namespace network;
+
+Socket::Socket():
+    _status(Socket::Closed),
+    _socket(-1)
+{}
+
+Socket::~Socket()
+{
+    if (this->_status != Socket::Closed) {
+        this->close();
+    }
+}
+
+int
+Socket::close()
+{
+    if (this->_status == Socket::Closed) {
+        return -1;
+    }
+    
+    int result = ::close(this->_socket);
+    this->_socket = -1;
+    
+    return result;
+}
+
+const ip::Endpoint &
+Socket::getRemoteEndpoint()
+{
+    return this->_remote_endpoint;
+}
+
+const ip::Endpoint &
+Socket::getLocalEndpoint()
+{
+    return this->_local_endpoint;
+}
+
+int
+Socket::getHandle()
+{
+    return this->_socket;
+}
+
+enum Socket::Status
+Socket::getStatus()
+{
+    return this->_status;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/socket.hpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NETWORK_SOCKET_HPP_
+#define _NETWORK_SOCKET_HPP_
+
+#include "bsd_socket.h"
+#include "network/ip/endpoint.hpp"
+
+namespace network {
+
+    class Socket
+    {
+        public:
+            enum Status {
+                Closed       = 0,
+                Open         = 1,
+                Listening    = 2,
+                Accepting    = 3,
+                Connected    = 4,
+                Disconnected = 5,
+                Receiving    = 6,
+                Sending      = 7
+            };
+    
+        protected:
+            ip::Endpoint _remote_endpoint;
+            ip::Endpoint _local_endpoint;
+            
+            Status _status;
+            int _socket;
+            
+        public:
+            Socket();
+            virtual ~Socket();
+            
+            virtual int open() =0;
+            virtual int close();
+            virtual int bind(int port) =0;
+            
+            const ip::Endpoint &getRemoteEndpoint();
+            const ip::Endpoint &getLocalEndpoint();
+            
+            int getHandle();
+            enum Status getStatus();
+    };
+
+} // namespace network
+
+#endif // _NETWORK_SOCKET_HPP_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tcp/socket.hpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NETWORK_TCP_SOCKET_HPP_
+#define _NETWORK_TCP_SOCKET_HPP_
+
+#include "network/socket.hpp"
+#include "network/ip/address.hpp"
+
+namespace network {
+namespace tcp {
+
+    class Socket :
+        public network::Socket
+    {
+        protected:
+            int _max_pending;
+        
+        public:    
+            ~Socket();
+            
+            int open();
+            int close();
+            int bind(int port);
+            int listen(int max_pending);
+        
+            int send(void *data, size_t size);
+            int reveive(void *data, size_t max_size);
+    };
+
+} // namespace tcp
+} // namespace network
+
+#endif // _NETWORK_UDP_SOCKET_HPP_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/udp/socket.cpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,69 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "network/udp/socket.hpp"
+using namespace network::udp;
+
+int
+Socket::open()
+{
+    return 0;
+}
+
+int
+Socket::close()
+{
+    return 0;
+}
+
+int
+Socket::bind(int port)
+{
+    return 0;
+}
+
+int
+Socket::send(void *data, size_t size, ip::Endpoint &endpoint)
+{
+    return 0;
+}
+
+int
+Socket::send(void *data, size_t size, ip::Address &address, int port)
+{
+    return 0;
+}
+
+int
+Socket::reveive(void *data, size_t max_size, ip::Endpoint &endpoint)
+{
+    return 0;
+}
+
+int
+Socket::reveive(void *data, size_t max_size, ip::Address &address, int port)
+{
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/udp/socket.hpp	Tue Jul 17 15:01:25 2012 +0000
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NETWORK_UDP_SOCKET_HPP_
+#define _NETWORK_UDP_SOCKET_HPP_
+
+#include "network/socket.hpp"
+#include "network/ip/address.hpp"
+
+namespace network {
+namespace udp {
+
+    class Socket :
+        public network::Socket
+    {
+        public:        
+            int open();
+            int close();
+            int bind(int port);
+        
+            int send(void *data, size_t size, ip::Endpoint &endpoint);
+            int send(void *data, size_t size, ip::Address &address, int port);
+            
+            int reveive(void *data, size_t max_size, ip::Endpoint &endpoint);
+            int reveive(void *data, size_t max_size, ip::Address &address, int port);
+    };
+
+} // namespace udp
+} // namespace network
+
+#endif // _NETWORK_UDP_SOCKET_HPP_
\ No newline at end of file