20
20
#define ICMPSOCKET_H
21
21
22
22
#include " netsocket/InternetSocket.h"
23
+ #include " netsocket/InternetDatagram.h"
23
24
#include " netsocket/NetworkStack.h"
24
25
#include " netsocket/NetworkInterface.h"
25
26
#include " rtos/EventFlags.h"
26
27
27
28
28
- /* * RAW socket implementation.
29
+ /* * ICMP socket implementation.
29
30
*/
30
- class ICMPSocket : public InternetSocket {
31
+ class ICMPSocket : public InternetDatagram {
31
32
public:
32
33
/* * Create an uninitialized socket.
33
34
*
@@ -41,113 +42,6 @@ class ICMPSocket : public InternetSocket {
41
42
*/
42
43
virtual ~ICMPSocket ();
43
44
44
- /* * Send data to the specified host and port.
45
- *
46
- * By default, sendto blocks until data is sent. If socket is set to
47
- * nonblocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
48
- * immediately.
49
- *
50
- * @param host Domain name of the remote host or a dotted notation IP address.
51
- * @param port Port of the remote host.
52
- * @param data Buffer of data to send to the host.
53
- * @param size Size of the buffer in bytes.
54
- * @return Number of sent bytes on success, negative error
55
- * code on failure.
56
- */
57
- virtual nsapi_size_or_error_t sendto (const char *host, uint16_t port,
58
- const void *data, nsapi_size_t size);
59
-
60
- /* * Send data to the specified address.
61
- *
62
- * By default, sendto blocks until data is sent. If socket is set to
63
- * nonblocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
64
- * immediately.
65
- *
66
- * @param address The SocketAddress of the remote host.
67
- * @param data Buffer of data to send to the host.
68
- * @param size Size of the buffer in bytes.
69
- * @return Number of sent bytes on success, negative error
70
- * code on failure.
71
- */
72
- virtual nsapi_size_or_error_t sendto (const SocketAddress &address,
73
- const void *data, nsapi_size_t size);
74
-
75
- /* * Receive a datagram and store the source address in address if it's not NULL.
76
- *
77
- * By default, recvfrom blocks until a datagram is received. If socket is set to
78
- * nonblocking or times out with no datagram, NSAPI_ERROR_WOULD_BLOCK
79
- * is returned.
80
- *
81
- * @note If the datagram is larger than the buffer, the excess data is silently discarded.
82
- *
83
- * @note If socket is connected, only packets coming from connected peer address
84
- * are accepted.
85
- *
86
- * @note recvfrom() is allowed write to address and data buffers even if error occurs.
87
- *
88
- * @param address Destination for the source address or NULL.
89
- * @param data Destination buffer for RAW data to be received from the host.
90
- * @param size Size of the buffer in bytes.
91
- * @return Number of received bytes on success, negative error
92
- * code on failure.
93
- */
94
- virtual nsapi_size_or_error_t recvfrom (SocketAddress *address,
95
- void *data, nsapi_size_t size);
96
-
97
- /* * Set the remote address for next send() call and filtering
98
- * of incoming packets. To reset the address, zero initialized
99
- * SocketAddress must be in the address parameter.
100
- *
101
- * @param address The SocketAddress of the remote host.
102
- * @return 0 on success, negative error code on failure.
103
- */
104
- virtual nsapi_error_t connect (const SocketAddress &address);
105
-
106
- /* * Send a raw data to connected remote address.
107
- *
108
- * By default, send blocks until all data is sent. If socket is set to
109
- * nonblocking or times out, a partial amount can be written.
110
- * NSAPI_ERROR_WOULD_BLOCK is returned if no data was written.
111
- *
112
- * @note The socket must be connected to a remote host before send() call.
113
- *
114
- * @param data Buffer of data to send to the host.
115
- * @param size Size of the buffer in bytes.
116
- * @return Number of sent bytes on success, negative error
117
- * code on failure.
118
- */
119
- virtual nsapi_size_or_error_t send (const void *data, nsapi_size_t size);
120
-
121
- /* * Receive data from a socket.
122
- *
123
- * This is equivalent to calling recvfrom(NULL, data, size).
124
- *
125
- * By default, recv blocks until some data is received. If socket is set to
126
- * nonblocking or times out, NSAPI_ERROR_WOULD_BLOCK can be returned to
127
- * indicate no data.
128
- *
129
- * @note recv() is allowed write to data buffer even if error occurs.
130
- *
131
- * @param data Pointer to buffer for data received from the host.
132
- * @param size Size of the buffer in bytes.
133
- * @return Number of received bytes on success, negative error
134
- * code on failure.
135
- */
136
- virtual nsapi_size_or_error_t recv (void *data, nsapi_size_t size);
137
-
138
- /* * Not implemented for ICMPSocket.
139
- *
140
- * @param error Not used.
141
- * @return NSAPI_ERROR_UNSUPPORTED
142
- */
143
- virtual Socket *accept (nsapi_error_t *error = NULL );
144
-
145
- /* * Not implemented for ICMPSocket.
146
- *
147
- * @param backlog Not used.
148
- * @return NSAPI_ERROR_UNSUPPORTED
149
- */
150
- virtual nsapi_error_t listen (int backlog = 1 );
151
45
#if !defined(DOXYGEN_ONLY)
152
46
153
47
protected:
0 commit comments