Mateusz Jaskula
/
KL25Z_TangoIO
KL25 driver for Tango Control System
Socket/Endpoint.cpp@2:9fe6f1e273b4, 2014-08-28 (annotated)
- Committer:
- jskl
- Date:
- Thu Aug 28 07:50:06 2014 +0000
- Revision:
- 2:9fe6f1e273b4
- Parent:
- 0:5d27c333afa6
Fixed bugs in JSON format replies
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jskl | 0:5d27c333afa6 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
jskl | 0:5d27c333afa6 | 2 | * |
jskl | 0:5d27c333afa6 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
jskl | 0:5d27c333afa6 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
jskl | 0:5d27c333afa6 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
jskl | 0:5d27c333afa6 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
jskl | 0:5d27c333afa6 | 7 | * furnished to do so, subject to the following conditions: |
jskl | 0:5d27c333afa6 | 8 | * |
jskl | 0:5d27c333afa6 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
jskl | 0:5d27c333afa6 | 10 | * substantial portions of the Software. |
jskl | 0:5d27c333afa6 | 11 | * |
jskl | 0:5d27c333afa6 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
jskl | 0:5d27c333afa6 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
jskl | 0:5d27c333afa6 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
jskl | 0:5d27c333afa6 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jskl | 0:5d27c333afa6 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
jskl | 0:5d27c333afa6 | 17 | */ |
jskl | 0:5d27c333afa6 | 18 | #include "Socket.h" |
jskl | 0:5d27c333afa6 | 19 | #include "Endpoint.h" |
jskl | 0:5d27c333afa6 | 20 | |
jskl | 0:5d27c333afa6 | 21 | Endpoint::Endpoint() { |
jskl | 0:5d27c333afa6 | 22 | reset_address(); |
jskl | 0:5d27c333afa6 | 23 | } |
jskl | 0:5d27c333afa6 | 24 | Endpoint::~Endpoint() {} |
jskl | 0:5d27c333afa6 | 25 | |
jskl | 0:5d27c333afa6 | 26 | void Endpoint::reset_address(void) { |
jskl | 0:5d27c333afa6 | 27 | _ipAddress[0] = '\0'; |
jskl | 0:5d27c333afa6 | 28 | _port = 0; |
jskl | 0:5d27c333afa6 | 29 | } |
jskl | 0:5d27c333afa6 | 30 | |
jskl | 0:5d27c333afa6 | 31 | int Endpoint::set_address(const char* host, const int port) { |
jskl | 0:5d27c333afa6 | 32 | //Resolve DNS address or populate hard-coded IP address |
jskl | 0:5d27c333afa6 | 33 | WIZnet_Chip* eth = WIZnet_Chip::getInstance(); |
jskl | 0:5d27c333afa6 | 34 | if (eth == NULL) { |
jskl | 0:5d27c333afa6 | 35 | return -1; |
jskl | 0:5d27c333afa6 | 36 | } |
jskl | 0:5d27c333afa6 | 37 | uint32_t addr; |
jskl | 0:5d27c333afa6 | 38 | if (!eth->gethostbyname(host, &addr)) { |
jskl | 0:5d27c333afa6 | 39 | return -1; |
jskl | 0:5d27c333afa6 | 40 | } |
jskl | 0:5d27c333afa6 | 41 | snprintf(_ipAddress, sizeof(_ipAddress), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff); |
jskl | 0:5d27c333afa6 | 42 | _port = port; |
jskl | 0:5d27c333afa6 | 43 | return 0; |
jskl | 0:5d27c333afa6 | 44 | } |
jskl | 0:5d27c333afa6 | 45 | |
jskl | 0:5d27c333afa6 | 46 | char* Endpoint::get_address() { |
jskl | 0:5d27c333afa6 | 47 | return _ipAddress; |
jskl | 0:5d27c333afa6 | 48 | } |
jskl | 0:5d27c333afa6 | 49 | |
jskl | 0:5d27c333afa6 | 50 | int Endpoint::get_port() { |
jskl | 0:5d27c333afa6 | 51 | return _port; |
jskl | 0:5d27c333afa6 | 52 | } |
jskl | 0:5d27c333afa6 | 53 |