Forked from the DieterGraef Library
Fork of F7_Ethernet by
Socket/Endpoint.h@2:fdef48f830c0, 2016-11-18 (annotated)
- Committer:
- EmbeddedSam
- Date:
- Fri Nov 18 12:48:10 2016 +0000
- Revision:
- 2:fdef48f830c0
- Parent:
- 0:d26c1b55cfca
Linking MQTT together, starting with mbed-cli
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 0:d26c1b55cfca | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
DieterGraef | 0:d26c1b55cfca | 2 | * |
DieterGraef | 0:d26c1b55cfca | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
DieterGraef | 0:d26c1b55cfca | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
DieterGraef | 0:d26c1b55cfca | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
DieterGraef | 0:d26c1b55cfca | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
DieterGraef | 0:d26c1b55cfca | 7 | * furnished to do so, subject to the following conditions: |
DieterGraef | 0:d26c1b55cfca | 8 | * |
DieterGraef | 0:d26c1b55cfca | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
DieterGraef | 0:d26c1b55cfca | 10 | * substantial portions of the Software. |
DieterGraef | 0:d26c1b55cfca | 11 | * |
DieterGraef | 0:d26c1b55cfca | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
DieterGraef | 0:d26c1b55cfca | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
DieterGraef | 0:d26c1b55cfca | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
DieterGraef | 0:d26c1b55cfca | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
DieterGraef | 0:d26c1b55cfca | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
DieterGraef | 0:d26c1b55cfca | 17 | */ |
DieterGraef | 0:d26c1b55cfca | 18 | #ifndef ENDPOINT_H |
DieterGraef | 0:d26c1b55cfca | 19 | #define ENDPOINT_H |
DieterGraef | 0:d26c1b55cfca | 20 | |
DieterGraef | 0:d26c1b55cfca | 21 | class UDPSocket; |
DieterGraef | 0:d26c1b55cfca | 22 | |
DieterGraef | 0:d26c1b55cfca | 23 | /** |
DieterGraef | 0:d26c1b55cfca | 24 | IP Endpoint (address, port) |
DieterGraef | 0:d26c1b55cfca | 25 | */ |
DieterGraef | 0:d26c1b55cfca | 26 | class Endpoint { |
DieterGraef | 0:d26c1b55cfca | 27 | friend class UDPSocket; |
DieterGraef | 0:d26c1b55cfca | 28 | |
DieterGraef | 0:d26c1b55cfca | 29 | public: |
DieterGraef | 0:d26c1b55cfca | 30 | /** IP Endpoint (address, port) |
DieterGraef | 0:d26c1b55cfca | 31 | */ |
DieterGraef | 0:d26c1b55cfca | 32 | Endpoint(void); |
DieterGraef | 0:d26c1b55cfca | 33 | |
DieterGraef | 0:d26c1b55cfca | 34 | ~Endpoint(void); |
DieterGraef | 0:d26c1b55cfca | 35 | |
DieterGraef | 0:d26c1b55cfca | 36 | /** Reset the address of this endpoint |
DieterGraef | 0:d26c1b55cfca | 37 | */ |
DieterGraef | 0:d26c1b55cfca | 38 | void reset_address(void); |
DieterGraef | 0:d26c1b55cfca | 39 | |
DieterGraef | 0:d26c1b55cfca | 40 | /** Set the address of this endpoint |
DieterGraef | 0:d26c1b55cfca | 41 | \param host The endpoint address (it can either be an IP Address or a hostname that will be resolved with DNS). |
DieterGraef | 0:d26c1b55cfca | 42 | \param port The endpoint port |
DieterGraef | 0:d26c1b55cfca | 43 | \return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). |
DieterGraef | 0:d26c1b55cfca | 44 | */ |
DieterGraef | 0:d26c1b55cfca | 45 | int set_address(const char* host, const int port); |
DieterGraef | 0:d26c1b55cfca | 46 | int set_address(in_addr host); |
DieterGraef | 0:d26c1b55cfca | 47 | /** Get the IP address of this endpoint |
DieterGraef | 0:d26c1b55cfca | 48 | \return The IP address of this endpoint. |
DieterGraef | 0:d26c1b55cfca | 49 | */ |
DieterGraef | 0:d26c1b55cfca | 50 | char* get_address(void); |
DieterGraef | 0:d26c1b55cfca | 51 | |
DieterGraef | 0:d26c1b55cfca | 52 | /** Get the port of this endpoint |
DieterGraef | 0:d26c1b55cfca | 53 | \return The port of this endpoint |
DieterGraef | 0:d26c1b55cfca | 54 | */ |
DieterGraef | 0:d26c1b55cfca | 55 | int get_port(void); |
DieterGraef | 0:d26c1b55cfca | 56 | |
DieterGraef | 0:d26c1b55cfca | 57 | protected: |
DieterGraef | 0:d26c1b55cfca | 58 | char _ipAddress[17]; |
DieterGraef | 0:d26c1b55cfca | 59 | struct sockaddr_in _remoteHost; |
DieterGraef | 0:d26c1b55cfca | 60 | |
DieterGraef | 0:d26c1b55cfca | 61 | |
DieterGraef | 0:d26c1b55cfca | 62 | }; |
DieterGraef | 0:d26c1b55cfca | 63 | |
DieterGraef | 0:d26c1b55cfca | 64 | #endif |