ID the MBED processor on the network if you have more than one. View MBED name on DHCP of your Router - Example \"MBED PE\" Change your ID in Core / host.h

Committer:
JeffM
Date:
Sat Nov 06 14:11:02 2010 +0000
Revision:
0:fd3b85615428
MBED ID 1A

Who changed what in which revision?

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