a

Fork of EthernetNetIf by Donatien Garnier

Committer:
donatien
Date:
Thu Aug 05 15:09:22 2010 +0000
Revision:
5:bc7df6da7589

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 5:bc7df6da7589 1
donatien 5:bc7df6da7589 2 /*
donatien 5:bc7df6da7589 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
donatien 5:bc7df6da7589 4
donatien 5:bc7df6da7589 5 Permission is hereby granted, free of charge, to any person obtaining a copy
donatien 5:bc7df6da7589 6 of this software and associated documentation files (the "Software"), to deal
donatien 5:bc7df6da7589 7 in the Software without restriction, including without limitation the rights
donatien 5:bc7df6da7589 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
donatien 5:bc7df6da7589 9 copies of the Software, and to permit persons to whom the Software is
donatien 5:bc7df6da7589 10 furnished to do so, subject to the following conditions:
donatien 5:bc7df6da7589 11
donatien 5:bc7df6da7589 12 The above copyright notice and this permission notice shall be included in
donatien 5:bc7df6da7589 13 all copies or substantial portions of the Software.
donatien 5:bc7df6da7589 14
donatien 5:bc7df6da7589 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donatien 5:bc7df6da7589 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donatien 5:bc7df6da7589 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donatien 5:bc7df6da7589 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donatien 5:bc7df6da7589 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 5:bc7df6da7589 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
donatien 5:bc7df6da7589 21 THE SOFTWARE.
donatien 5:bc7df6da7589 22 */
donatien 5:bc7df6da7589 23
donatien 5:bc7df6da7589 24 #ifndef HOST_H
donatien 5:bc7df6da7589 25 #define HOST_H
donatien 5:bc7df6da7589 26
donatien 5:bc7df6da7589 27 #include "ipaddr.h"
donatien 5:bc7df6da7589 28 #include <string.h>
donatien 5:bc7df6da7589 29
donatien 5:bc7df6da7589 30 ///Host information container
donatien 5:bc7df6da7589 31 /**
donatien 5:bc7df6da7589 32 This class is a container for data relative to a connection:
donatien 5:bc7df6da7589 33 - IP Address
donatien 5:bc7df6da7589 34 - Port number
donatien 5:bc7df6da7589 35 - Host Name
donatien 5:bc7df6da7589 36 */
donatien 5:bc7df6da7589 37 class Host
donatien 5:bc7df6da7589 38 {
donatien 5:bc7df6da7589 39 public:
donatien 5:bc7df6da7589 40 ///Initiliazes host with null values
donatien 5:bc7df6da7589 41 Host() : m_ip(0,0,0,0), m_port(0), m_name(NULL)
donatien 5:bc7df6da7589 42 {
donatien 5:bc7df6da7589 43
donatien 5:bc7df6da7589 44 }
donatien 5:bc7df6da7589 45
donatien 5:bc7df6da7589 46 ///Initializes host
donatien 5:bc7df6da7589 47 Host(const IpAddr& ip, const int& port, const char* name="" ) : m_ip(ip), m_port(port), m_name(NULL)
donatien 5:bc7df6da7589 48 {
donatien 5:bc7df6da7589 49 setName(name);
donatien 5:bc7df6da7589 50 }
donatien 5:bc7df6da7589 51
donatien 5:bc7df6da7589 52 ~Host()
donatien 5:bc7df6da7589 53 {
donatien 5:bc7df6da7589 54 if(m_name)
donatien 5:bc7df6da7589 55 {
donatien 5:bc7df6da7589 56 delete[] m_name;
donatien 5:bc7df6da7589 57 }
donatien 5:bc7df6da7589 58 }
donatien 5:bc7df6da7589 59
donatien 5:bc7df6da7589 60 ///Returns IP address
donatien 5:bc7df6da7589 61 const IpAddr& getIp() const
donatien 5:bc7df6da7589 62 {
donatien 5:bc7df6da7589 63 return m_ip;
donatien 5:bc7df6da7589 64 }
donatien 5:bc7df6da7589 65
donatien 5:bc7df6da7589 66 ///Returns port number
donatien 5:bc7df6da7589 67 const int& getPort() const
donatien 5:bc7df6da7589 68 {
donatien 5:bc7df6da7589 69 return m_port;
donatien 5:bc7df6da7589 70 }
donatien 5:bc7df6da7589 71
donatien 5:bc7df6da7589 72 ///Returns host name
donatien 5:bc7df6da7589 73 const char* getName() const
donatien 5:bc7df6da7589 74 {
donatien 5:bc7df6da7589 75 return m_name;
donatien 5:bc7df6da7589 76 }
donatien 5:bc7df6da7589 77
donatien 5:bc7df6da7589 78 ///Sets IP address
donatien 5:bc7df6da7589 79 void setIp(const IpAddr& ip)
donatien 5:bc7df6da7589 80 {
donatien 5:bc7df6da7589 81 m_ip = ip;
donatien 5:bc7df6da7589 82 }
donatien 5:bc7df6da7589 83
donatien 5:bc7df6da7589 84 ///Sets port number
donatien 5:bc7df6da7589 85 void setPort(int port)
donatien 5:bc7df6da7589 86 {
donatien 5:bc7df6da7589 87 m_port = port;
donatien 5:bc7df6da7589 88 }
donatien 5:bc7df6da7589 89
donatien 5:bc7df6da7589 90 ///Sets host name
donatien 5:bc7df6da7589 91 void setName(const char* name)
donatien 5:bc7df6da7589 92 {
donatien 5:bc7df6da7589 93 if(m_name)
donatien 5:bc7df6da7589 94 delete[] m_name;
donatien 5:bc7df6da7589 95 int len = strlen(name);
donatien 5:bc7df6da7589 96 if(len)
donatien 5:bc7df6da7589 97 {
donatien 5:bc7df6da7589 98 m_name = new char[len+1];
donatien 5:bc7df6da7589 99 strcpy(m_name, name);
donatien 5:bc7df6da7589 100 }
donatien 5:bc7df6da7589 101 }
donatien 5:bc7df6da7589 102
donatien 5:bc7df6da7589 103 private:
donatien 5:bc7df6da7589 104 IpAddr m_ip;
donatien 5:bc7df6da7589 105 int m_port;
donatien 5:bc7df6da7589 106 char* m_name;
donatien 5:bc7df6da7589 107 };
donatien 5:bc7df6da7589 108
donatien 5:bc7df6da7589 109 #endif