ENUt

udpv6socket.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of ENUt, a library containing network
00004   programming utilities.
00005   
00006   Copyright (C) 2006-2008  Hasselt University - Expertise Centre for
00007                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00022   USA
00023 
00024 */
00025 
00030 #ifndef NUT_UDPV6SOCKET_H
00031 
00032 #define NUT_UDPV6SOCKET_H
00033 
00034 #include "nutconfig.h"
00035 
00036 #ifdef NUTCONFIG_SUPPORT_IPV6
00037 
00038 #include "udpsocket.h"
00039 #include "ipv6address.h"
00040 #include <netinet/in.h>
00041 
00042 namespace nut
00043 {
00044 
00046 class ENUT_IMPORTEXPORT UDPv6Socket : public UDPSocket
00047 {
00048 public:
00050         UDPv6Socket();
00051 
00053         UDPv6Socket(const std::string &objName);
00054 
00055         ~UDPv6Socket();
00056 
00057         bool create(uint16_t portNumber = 0, bool obtainDestination = false);
00058         bool create(NetworkLayerAddress &bindAddress, uint16_t portNumber = 0, bool obtainDestination = false);
00059         bool destroy();
00060         
00061         bool setNonBlocking(bool f = true);
00062         
00063         uint16_t getLocalPortNumber() const                                                             { return m_localPort; }
00064         
00065         bool joinMulticastGroup(const NetworkLayerAddress &groupAddress);
00066         bool leaveMulticastGroup(const NetworkLayerAddress &groupAddress);
00067         bool setMulticastTTL(uint8_t ttl);
00068         
00069         bool write(const void *data, size_t &length, const NetworkLayerAddress &destinationAddress, 
00070                    uint16_t destinationPort);
00071         bool getAvailableDataLength(size_t &length, bool &available);
00072         bool read(void *buffer, size_t &bufferSize);
00073         const NetworkLayerAddress *getLastSourceAddress() const                                         { return &m_srcIP; }
00074         uint16_t getLastSourcePort() const                                                              { return m_srcPort; }
00075         const NetworkLayerAddress *getLastDestinationAddress() const                                    { return &m_dstIP; }
00076 protected:
00077         int getSocketDescriptor()                                                                       { return m_sock; }
00078 private:
00079         // make sure we can't copy the socket
00080         UDPv6Socket(const UDPv6Socket &s) : UDPSocket(s)                                                { }
00081         UDPv6Socket &operator=(const UDPv6Socket &s)                                                    { }
00082         
00083         void zeroAll();
00084         bool internalCreate(in6_addr ip, uint16_t port, bool obtainDestination);
00085 
00086         int m_sock;
00087         uint16_t m_localPort;
00088         IPv6Address m_srcIP;
00089         uint16_t m_srcPort;
00090         IPv6Address m_dstIP;
00091         bool m_obtainDest;
00092 };
00093 
00094 } // end namespace
00095 
00096 #endif // NUTCONFIG_SUPPORT_IPV6
00097 
00098 #endif // NUT_UDPV6SOCKET_H
00099