Own fork of C027_Support
Dependents: MbedSmartRestMain MbedSmartRestMain
Fork of C027_Support by
Socket/Endpoint.h@134:d84232916eac, 2017-09-15 (annotated)
- Committer:
- xinlei
- Date:
- Fri Sep 15 10:12:03 2017 +0000
- Revision:
- 134:d84232916eac
- Parent:
- 63:42cb563a25bc
new apns
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mazgch | 63:42cb563a25bc | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
mazgch | 63:42cb563a25bc | 2 | * |
mazgch | 63:42cb563a25bc | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
mazgch | 63:42cb563a25bc | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
mazgch | 63:42cb563a25bc | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
mazgch | 63:42cb563a25bc | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
mazgch | 63:42cb563a25bc | 7 | * furnished to do so, subject to the following conditions: |
mazgch | 63:42cb563a25bc | 8 | * |
mazgch | 63:42cb563a25bc | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
mazgch | 63:42cb563a25bc | 10 | * substantial portions of the Software. |
mazgch | 63:42cb563a25bc | 11 | * |
mazgch | 63:42cb563a25bc | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
mazgch | 63:42cb563a25bc | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
mazgch | 63:42cb563a25bc | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
mazgch | 63:42cb563a25bc | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mazgch | 63:42cb563a25bc | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
mazgch | 63:42cb563a25bc | 17 | */ |
mazgch | 63:42cb563a25bc | 18 | #ifndef ENDPOINT_H |
mazgch | 63:42cb563a25bc | 19 | #define ENDPOINT_H |
mazgch | 63:42cb563a25bc | 20 | |
mazgch | 63:42cb563a25bc | 21 | #include "MDM.h" |
mazgch | 63:42cb563a25bc | 22 | |
mazgch | 63:42cb563a25bc | 23 | class UDPSocket; |
mazgch | 63:42cb563a25bc | 24 | |
mazgch | 63:42cb563a25bc | 25 | class Endpoint { |
mazgch | 63:42cb563a25bc | 26 | friend class UDPSocket; |
mazgch | 63:42cb563a25bc | 27 | public: |
mazgch | 63:42cb563a25bc | 28 | Endpoint(void) { |
mazgch | 63:42cb563a25bc | 29 | _ip[0] = '\0'; |
mazgch | 63:42cb563a25bc | 30 | _port = 0; |
mazgch | 63:42cb563a25bc | 31 | _mdm = NULL; |
mazgch | 63:42cb563a25bc | 32 | } |
mazgch | 63:42cb563a25bc | 33 | |
mazgch | 63:42cb563a25bc | 34 | void reset_address(void) { |
mazgch | 63:42cb563a25bc | 35 | _ip[0] = '\0'; |
mazgch | 63:42cb563a25bc | 36 | _port = 0; |
mazgch | 63:42cb563a25bc | 37 | } |
mazgch | 63:42cb563a25bc | 38 | |
mazgch | 63:42cb563a25bc | 39 | int set_address(const char* host, const int port) { |
mazgch | 63:42cb563a25bc | 40 | _ip[0] = '\0'; |
mazgch | 63:42cb563a25bc | 41 | _port = 0; |
mazgch | 63:42cb563a25bc | 42 | if (_mdm == NULL) |
mazgch | 63:42cb563a25bc | 43 | _mdm = MDMParser::getInstance(); |
mazgch | 63:42cb563a25bc | 44 | if (_mdm == NULL) |
mazgch | 63:42cb563a25bc | 45 | return -1; |
mazgch | 63:42cb563a25bc | 46 | // resove the host name (eventually does a dns lookup) |
mazgch | 63:42cb563a25bc | 47 | MDMParser::IP ip = _mdm->gethostbyname(host); |
mazgch | 63:42cb563a25bc | 48 | if (ip == NOIP) |
mazgch | 63:42cb563a25bc | 49 | return -1; |
mazgch | 63:42cb563a25bc | 50 | sprintf(_ip, IPSTR, IPNUM(ip)); |
mazgch | 63:42cb563a25bc | 51 | _port = port; |
mazgch | 63:42cb563a25bc | 52 | return 0; |
mazgch | 63:42cb563a25bc | 53 | } |
mazgch | 63:42cb563a25bc | 54 | |
mazgch | 63:42cb563a25bc | 55 | char* get_address(void) { return _ip; } |
mazgch | 63:42cb563a25bc | 56 | |
mazgch | 63:42cb563a25bc | 57 | int get_port(void) { return _port; } |
mazgch | 63:42cb563a25bc | 58 | |
mazgch | 63:42cb563a25bc | 59 | protected: |
mazgch | 63:42cb563a25bc | 60 | MDMParser* _mdm; |
mazgch | 63:42cb563a25bc | 61 | char _ip[17]; |
mazgch | 63:42cb563a25bc | 62 | int _port; |
mazgch | 63:42cb563a25bc | 63 | }; |
mazgch | 63:42cb563a25bc | 64 | |
mazgch | 63:42cb563a25bc | 65 | #endif |