Deprecated fork of old network stack source from github. Please use official library instead: https://mbed.org/users/mbed_official/code/EthernetInterface/

Committer:
AdamGreen
Date:
Sat Oct 26 08:51:36 2013 +0000
Revision:
1:eadc868c2acf
Parent:
0:3b00827bb0b7
Fix TCP checksum bug and stranded large TCP segments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AdamGreen 0:3b00827bb0b7 1 /* Copyright (C) 2012 mbed.org, MIT License
AdamGreen 0:3b00827bb0b7 2 *
AdamGreen 0:3b00827bb0b7 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
AdamGreen 0:3b00827bb0b7 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
AdamGreen 0:3b00827bb0b7 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
AdamGreen 0:3b00827bb0b7 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
AdamGreen 0:3b00827bb0b7 7 * furnished to do so, subject to the following conditions:
AdamGreen 0:3b00827bb0b7 8 *
AdamGreen 0:3b00827bb0b7 9 * The above copyright notice and this permission notice shall be included in all copies or
AdamGreen 0:3b00827bb0b7 10 * substantial portions of the Software.
AdamGreen 0:3b00827bb0b7 11 *
AdamGreen 0:3b00827bb0b7 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
AdamGreen 0:3b00827bb0b7 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
AdamGreen 0:3b00827bb0b7 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
AdamGreen 0:3b00827bb0b7 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AdamGreen 0:3b00827bb0b7 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AdamGreen 0:3b00827bb0b7 17 */
AdamGreen 0:3b00827bb0b7 18 #ifndef SOCKET_H_
AdamGreen 0:3b00827bb0b7 19 #define SOCKET_H_
AdamGreen 0:3b00827bb0b7 20
AdamGreen 0:3b00827bb0b7 21 #include "lwip/sockets.h"
AdamGreen 0:3b00827bb0b7 22 #include "lwip/netdb.h"
AdamGreen 0:3b00827bb0b7 23
AdamGreen 0:3b00827bb0b7 24 //DNS
AdamGreen 0:3b00827bb0b7 25 inline struct hostent *gethostbyname(const char *name) {
AdamGreen 0:3b00827bb0b7 26 return lwip_gethostbyname(name);
AdamGreen 0:3b00827bb0b7 27 }
AdamGreen 0:3b00827bb0b7 28
AdamGreen 0:3b00827bb0b7 29 inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) {
AdamGreen 0:3b00827bb0b7 30 return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
AdamGreen 0:3b00827bb0b7 31 }
AdamGreen 0:3b00827bb0b7 32
AdamGreen 0:3b00827bb0b7 33 class TimeInterval;
AdamGreen 0:3b00827bb0b7 34
AdamGreen 0:3b00827bb0b7 35 /** Socket file descriptor and select wrapper
AdamGreen 0:3b00827bb0b7 36 */
AdamGreen 0:3b00827bb0b7 37 class Socket {
AdamGreen 0:3b00827bb0b7 38 public:
AdamGreen 0:3b00827bb0b7 39 /** Socket
AdamGreen 0:3b00827bb0b7 40 */
AdamGreen 0:3b00827bb0b7 41 Socket();
AdamGreen 0:3b00827bb0b7 42
AdamGreen 0:3b00827bb0b7 43 /** Set blocking or non-blocking mode of the socket and a timeout on
AdamGreen 0:3b00827bb0b7 44 blocking socket operations
AdamGreen 0:3b00827bb0b7 45 \param blocking true for blocking mode, false for non-blocking mode.
AdamGreen 0:3b00827bb0b7 46 \param timeout timeout in ms [Default: (1500)ms].
AdamGreen 0:3b00827bb0b7 47 */
AdamGreen 0:3b00827bb0b7 48 void set_blocking(bool blocking, unsigned int timeout=1500);
AdamGreen 0:3b00827bb0b7 49
AdamGreen 0:3b00827bb0b7 50 /** Set socket options
AdamGreen 0:3b00827bb0b7 51 \param level stack level (see: lwip/sockets.h)
AdamGreen 0:3b00827bb0b7 52 \param optname option ID
AdamGreen 0:3b00827bb0b7 53 \param optval option value
AdamGreen 0:3b00827bb0b7 54 \param socklen_t length of the option value
AdamGreen 0:3b00827bb0b7 55 \return 0 on success, -1 on failure
AdamGreen 0:3b00827bb0b7 56 */
AdamGreen 0:3b00827bb0b7 57 int set_option(int level, int optname, const void *optval, socklen_t optlen);
AdamGreen 0:3b00827bb0b7 58
AdamGreen 0:3b00827bb0b7 59 /** Get socket options
AdamGreen 0:3b00827bb0b7 60 \param level stack level (see: lwip/sockets.h)
AdamGreen 0:3b00827bb0b7 61 \param optname option ID
AdamGreen 0:3b00827bb0b7 62 \param optval buffer pointer where to write the option value
AdamGreen 0:3b00827bb0b7 63 \param socklen_t length of the option value
AdamGreen 0:3b00827bb0b7 64 \return 0 on success, -1 on failure
AdamGreen 0:3b00827bb0b7 65 */
AdamGreen 0:3b00827bb0b7 66 int get_option(int level, int optname, void *optval, socklen_t *optlen);
AdamGreen 0:3b00827bb0b7 67
AdamGreen 0:3b00827bb0b7 68 /** Close the socket
AdamGreen 0:3b00827bb0b7 69 \param shutdown free the left-over data in message queues
AdamGreen 0:3b00827bb0b7 70 */
AdamGreen 0:3b00827bb0b7 71 int close(bool shutdown=true);
AdamGreen 0:3b00827bb0b7 72
AdamGreen 0:3b00827bb0b7 73 ~Socket();
AdamGreen 0:3b00827bb0b7 74
AdamGreen 0:3b00827bb0b7 75 protected:
AdamGreen 0:3b00827bb0b7 76 int _sock_fd;
AdamGreen 0:3b00827bb0b7 77 int init_socket(int type);
AdamGreen 0:3b00827bb0b7 78
AdamGreen 0:3b00827bb0b7 79 int wait_readable(TimeInterval& timeout);
AdamGreen 0:3b00827bb0b7 80 int wait_writable(TimeInterval& timeout);
AdamGreen 0:3b00827bb0b7 81
AdamGreen 0:3b00827bb0b7 82 bool _blocking;
AdamGreen 0:3b00827bb0b7 83 unsigned int _timeout;
AdamGreen 0:3b00827bb0b7 84
AdamGreen 0:3b00827bb0b7 85 private:
AdamGreen 0:3b00827bb0b7 86 int select(struct timeval *timeout, bool read, bool write);
AdamGreen 0:3b00827bb0b7 87 };
AdamGreen 0:3b00827bb0b7 88
AdamGreen 0:3b00827bb0b7 89 /** Time interval class used to specify timeouts
AdamGreen 0:3b00827bb0b7 90 */
AdamGreen 0:3b00827bb0b7 91 class TimeInterval {
AdamGreen 0:3b00827bb0b7 92 friend class Socket;
AdamGreen 0:3b00827bb0b7 93
AdamGreen 0:3b00827bb0b7 94 public:
AdamGreen 0:3b00827bb0b7 95 /** Time Interval
AdamGreen 0:3b00827bb0b7 96 \param ms time interval expressed in milliseconds
AdamGreen 0:3b00827bb0b7 97 */
AdamGreen 0:3b00827bb0b7 98 TimeInterval(unsigned int ms);
AdamGreen 0:3b00827bb0b7 99
AdamGreen 0:3b00827bb0b7 100 private:
AdamGreen 0:3b00827bb0b7 101 struct timeval _time;
AdamGreen 0:3b00827bb0b7 102 };
AdamGreen 0:3b00827bb0b7 103
AdamGreen 0:3b00827bb0b7 104 #endif /* SOCKET_H_ */