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