Subversion Repositories HelenOS

Rev

Rev 4743 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4743 Rev 4749
Line 24... Line 24...
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup echo
29
/** @addtogroup nettest
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
34
 *  Networking test 1 application - UDP sockets.
34
 *  Networking test 1 application - sockets.
35
 */
35
 */
36
 
36
 
37
#include <malloc.h>
37
#include <malloc.h>
38
#include <stdio.h>
38
#include <stdio.h>
39
#include <string.h>
39
#include <string.h>
Line 54... Line 54...
54
 */
54
 */
55
#define NAME    "Nettest1"
55
#define NAME    "Nettest1"
56
 
56
 
57
/** Packet data pattern.
57
/** Packet data pattern.
58
 */
58
 */
59
#define NETTEST1_TEXT   "Networking test 1 - UDP sockets"
59
#define NETTEST1_TEXT   "Networking test 1 - sockets"
60
 
60
 
61
/** Module entry point.
61
/** Module entry point.
62
 *  Starts testing.
62
 *  Starts testing.
63
 *  @param argc The number of command line parameters. Input parameter.
63
 *  @param argc The number of command line parameters. Input parameter.
64
 *  @param argv The command line parameters. Input parameter.
64
 *  @param argv The command line parameters. Input parameter.
Line 82... Line 82...
82
 *  @returns The corresponding socket type number.
82
 *  @returns The corresponding socket type number.
83
 *  @returns ESOCKNOSUPPORTED if the socket type is not supported.
83
 *  @returns ESOCKNOSUPPORTED if the socket type is not supported.
84
 */
84
 */
85
int     parse_socket_type( const char * name );
85
int     parse_socket_type( const char * name );
86
 
86
 
-
 
87
/** Refreshes the data.
-
 
88
 *  Fills the data block with the NETTEST1_TEXT pattern.
-
 
89
 *  @param data The data block. Output parameter.
-
 
90
 *  @param size The data block size in bytes. Input parameter
-
 
91
 */
87
void    refresh_data( char * data, size_t size );
92
void    refresh_data( char * data, size_t size );
-
 
93
 
-
 
94
/** Creates new sockets.
-
 
95
 *  @param verbose A value indicating whether to print out verbose information. Input parameter.
-
 
96
 *  @param socket_ids A field to store the socket identifiers. Output parameter.
-
 
97
 *  @param sockets The number of sockets to create. Should be at most the size of the field. Input parameter.
-
 
98
 *  @param family The socket address family. Input parameter.
-
 
99
 *  @param type The socket type. Input parameter.
-
 
100
 *  @returns EOK on success.
-
 
101
 *  @returns Other error codes as defined for the socket() function.
-
 
102
 */
88
int sockets_create( int verbose, int * socket_ids, int sockets, int family, sock_type_t type );
103
int sockets_create( int verbose, int * socket_ids, int sockets, int family, sock_type_t type );
-
 
104
 
-
 
105
/** Closes sockets.
-
 
106
 *  @param verbose A value indicating whether to print out verbose information. Input parameter.
-
 
107
 *  @param socket_ids A field of stored socket identifiers. Input parameter.
-
 
108
 *  @param sockets The number of sockets in the field. Should be at most the size of the field. Input parameter.
-
 
109
 *  @returns EOK on success.
-
 
110
 *  @returns Other error codes as defined for the closesocket() function.
-
 
111
 */
89
int sockets_close( int verbose, int * socket_ids, int sockets );
112
int sockets_close( int verbose, int * socket_ids, int sockets );
-
 
113
 
-
 
114
/** Connects sockets.
-
 
115
 *  @param verbose A value indicating whether to print out verbose information. Input parameter.
-
 
116
 *  @param socket_ids A field of stored socket identifiers. Input parameter.
-
 
117
 *  @param sockets The number of sockets in the field. Should be at most the size of the field. Input parameter.
-
 
118
 *  @param address The destination host address to connect to. Input parameter.
-
 
119
 *  @param addrlen The length of the destination address in bytes. Input parameter.
-
 
120
 *  @returns EOK on success.
-
 
121
 *  @returns Other error codes as defined for the connect() function.
-
 
122
 */
90
int sockets_connect( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen );
123
int sockets_connect( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen );
-
 
124
 
-
 
125
/** Sends data via sockets.
-
 
126
 *  @param verbose A value indicating whether to print out verbose information. Input parameter.
-
 
127
 *  @param socket_ids A field of stored socket identifiers. Input parameter.
-
 
128
 *  @param sockets The number of sockets in the field. Should be at most the size of the field. Input parameter.
-
 
129
 *  @param address The destination host address to send data to. Input parameter.
-
 
130
 *  @param addrlen The length of the destination address in bytes. Input parameter.
-
 
131
 *  @param data The data to be sent. Input parameter.
-
 
132
 *  @param size The data size in bytes. Input parameter
-
 
133
 *  @param messages The number of datagrams per socket to be sent. Input parameter.
-
 
134
 *  @returns EOK on success.
-
 
135
 *  @returns Other error codes as defined for the sendto() function.
-
 
136
 */
91
int sockets_sendto( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages );
137
int sockets_sendto( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages );
-
 
138
 
-
 
139
/** Receives data via sockets.
-
 
140
 *  @param verbose A value indicating whether to print out verbose information. Input parameter.
-
 
141
 *  @param socket_ids A field of stored socket identifiers. Input parameter.
-
 
142
 *  @param sockets The number of sockets in the field. Should be at most the size of the field. Input parameter.
-
 
143
 *  @param address The source host address of received datagrams. Input parameter.
-
 
144
 *  @param addrlen The maximum length of the source address in bytes. The actual size of the source address is set instead. Input/output parameter.
-
 
145
 *  @param data The received data. Output parameter.
-
 
146
 *  @param size The maximum data size in bytes. Input parameter
-
 
147
 *  @param messages The number of datagrams per socket to be received. Input parameter.
-
 
148
 *  @returns EOK on success.
-
 
149
 *  @returns Other error codes as defined for the recvfrom() function.
-
 
150
 */
92
int sockets_recvfrom( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages );
151
int sockets_recvfrom( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages );
-
 
152
 
-
 
153
/** Sends and receives data via sockets.
-
 
154
 *  Each datagram is sent and a reply read consequently.
-
 
155
 *  The next datagram is sent after the reply is received.
-
 
156
 *  @param verbose A value indicating whether to print out verbose information. Input parameter.
-
 
157
 *  @param socket_ids A field of stored socket identifiers. Input parameter.
-
 
158
 *  @param sockets The number of sockets in the field. Should be at most the size of the field. Input parameter.
-
 
159
 *  @param address The destination host address to send data to. The source host address of received datagrams is set instead. Input/output parameter.
-
 
160
 *  @param addrlen The length of the destination address in bytes. Input parameter.
-
 
161
 *  @param data The data to be sent. The received data are set instead. Input/output parameter.
-
 
162
 *  @param size The data size in bytes. Input parameter
-
 
163
 *  @param messages The number of datagrams per socket to be received. Input parameter.
-
 
164
 *  @returns EOK on success.
-
 
165
 *  @returns Other error codes as defined for the recvfrom() function.
-
 
166
 */
93
int sockets_sendto_recvfrom( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages );
167
int sockets_sendto_recvfrom( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages );
-
 
168
 
-
 
169
/** Prints a mark.
-
 
170
 *  If the index is a multiple of ten, a different mark is printed.
-
 
171
 *  @param index The index of the mark to be printed. Input parameter.
-
 
172
 */
94
void    print_mark( int index );
173
void    print_mark( int index );
95
 
174
 
96
void print_help( void ){
175
void print_help( void ){
97
    printf(
176
    printf(
98
        "Network Networking test 1 aplication - UDP sockets\n" \
177
        "Network Networking test 1 aplication - sockets\n" \
99
        "Usage: echo [options] numeric_address\n" \
178
        "Usage: echo [options] numeric_address\n" \
100
        "Where options are:\n" \
179
        "Where options are:\n" \
101
        "-f protocol_family | --family=protocol_family\n" \
180
        "-f protocol_family | --family=protocol_family\n" \
102
        "\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"
181
        "\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"
103
        "\n" \
182
        "\n" \
104
        "-h | --help\n" \
183
        "-h | --help\n" \
105
        "\tShow this application help.\n"
184
        "\tShow this application help.\n"
106
        "\n" \
185
        "\n" \
107
        "-m count | --messages=count\n" \
186
        "-m count | --messages=count\n" \
108
        "\tThe number of messages to send and receive per socket. The default is 100.\n" \
187
        "\tThe number of messages to send and receive per socket. The default is 10.\n" \
109
        "\n" \
188
        "\n" \
110
        "-n sockets | --sockets=count\n" \
189
        "-n sockets | --sockets=count\n" \
111
        "\tThe number of sockets to use. The default is 100.\n" \
190
        "\tThe number of sockets to use. The default is 10.\n" \
112
        "\n" \
191
        "\n" \
113
        "-p port_number | --port=port_number\n" \
192
        "-p port_number | --port=port_number\n" \
114
        "\tThe port number the application should send messages to. The default is 7.\n" \
193
        "\tThe port number the application should send messages to. The default is 7.\n" \
115
        "\n" \
194
        "\n" \
116
        "-s packet_size | --size=packet_size\n" \
195
        "-s packet_size | --size=packet_size\n" \
117
        "\tThe packet data size the application sends. The default is 38 bytes.\n" \
196
        "\tThe packet data size the application sends. The default is 28 bytes.\n" \
118
        "\n" \
197
        "\n" \
119
        "-v | --verbose\n" \
198
        "-v | --verbose\n" \
120
        "\tShow all output messages.\n"
199
        "\tShow all output messages.\n"
121
    );
200
    );
122
}
201
}
Line 142... Line 221...
142
void refresh_data( char * data, size_t size ){
221
void refresh_data( char * data, size_t size ){
143
    size_t  length;
222
    size_t  length;
144
 
223
 
145
    // fill the data
224
    // fill the data
146
    length = 0;
225
    length = 0;
147
    while( size > length + sizeof( NETTEST1_TEXT )){
226
    while( size > length + sizeof( NETTEST1_TEXT ) - 1 ){
148
        memcpy( data + length, NETTEST1_TEXT, sizeof( NETTEST1_TEXT ));
227
        memcpy( data + length, NETTEST1_TEXT, sizeof( NETTEST1_TEXT ) - 1 );
149
        length += sizeof( NETTEST1_TEXT );
228
        length += sizeof( NETTEST1_TEXT ) - 1;
150
    }
229
    }
151
    memcpy( data + length, NETTEST1_TEXT, size - length );
230
    memcpy( data + length, NETTEST1_TEXT, size - length );
-
 
231
    data[ size ] = '\0';
152
}
232
}
153
 
233
 
154
int sockets_create( int verbose, int * socket_ids, int sockets, int family, sock_type_t type ){
234
int sockets_create( int verbose, int * socket_ids, int sockets, int family, sock_type_t type ){
155
    int index;
235
    int index;
156
 
236
 
Line 283... Line 363...
283
}
363
}
284
 
364
 
285
int main( int argc, char * argv[] ){
365
int main( int argc, char * argv[] ){
286
    ERROR_DECLARE;
366
    ERROR_DECLARE;
287
 
367
 
288
    size_t              size            = 38;
368
    size_t              size            = 28;
289
    int                 verbose         = 0;
369
    int                 verbose         = 0;
290
    sock_type_t         type            = SOCK_DGRAM;
370
    sock_type_t         type            = SOCK_DGRAM;
291
    int                 sockets         = 10;
371
    int                 sockets         = 10;
292
    int                 messages        = 10;
372
    int                 messages        = 10;
293
    int                 family          = PF_INET;
373
    int                 family          = PF_INET;