source: mainline/uspace/lib/c/generic/net/socket_parse.c@ 32fef47

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 32fef47 was d9e2e0e, checked in by Jakub Jermar <jakub@…>, 15 years ago

Move the client socket code to the standard library.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2009 Lukas Mejdrech
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup socket
30 * @{
31 */
32
33/** @file
34 * Command-line argument parsing functions related to networking.
35 */
36
37#include <net/socket_parse.h>
38#include <net/socket.h>
39#include <arg_parse.h>
40#include <errno.h>
41#include <str.h>
42
43/** Translate the character string to the address family number.
44 *
45 * @param[in] name The address family name.
46 * @param[out] af The corresponding address family number
47 * or EAFNOSUPPORTED.
48 *
49 * @return EOK on success.
50 * @return ENOTSUP on unsupported address family.
51 *
52 */
53int socket_parse_address_family(const char *name, int *af)
54{
55 if (str_lcmp(name, "AF_INET", 7) == 0) {
56 *af = AF_INET;
57 return EOK;
58 }
59
60 if (str_lcmp(name, "AF_INET6", 8) == 0) {
61 *af = AF_INET6;
62 return EOK;
63 }
64
65 *af = EAFNOSUPPORT;
66 return ENOTSUP;
67}
68
69/** Translate the character string to the protocol family number.
70 *
71 * @param[in] name The protocol family name.
72 * @param[out] pf The corresponding protocol family number
73 * or EPFNOSUPPORTED.
74 *
75 * @return EOK on success.
76 * @return ENOTSUP on unsupported protocol family.
77 *
78 */
79int socket_parse_protocol_family(const char *name, int *pf)
80{
81 if (str_lcmp(name, "PF_INET", 7) == 0) {
82 *pf = PF_INET;
83 return EOK;
84 }
85
86 if (str_lcmp(name, "PF_INET6", 8) == 0) {
87 *pf = PF_INET6;
88 return EOK;
89 }
90
91 *pf = EPFNOSUPPORT;
92 return ENOTSUP;
93}
94
95/** Translate the character string to the socket type number.
96 *
97 * @param[in] name The socket type name.
98 * @param[out] sockt The corresponding socket type number
99 * or ESOCKTNOSUPPORT.
100 *
101 * @return EOK on success.
102 * @return ENOTSUP on unsupported socket type.
103 *
104 */
105int socket_parse_socket_type(const char *name, int *sockt)
106{
107 if (str_lcmp(name, "SOCK_DGRAM", 11) == 0) {
108 *sockt = SOCK_DGRAM;
109 return EOK;
110 }
111
112 if (str_lcmp(name, "SOCK_STREAM", 12) == 0) {
113 *sockt = SOCK_STREAM;
114 return EOK;
115 }
116
117 *sockt = ESOCKTNOSUPPORT;
118 return ENOTSUP;
119}
120
121/** @}
122 */
Note: See TracBrowser for help on using the repository browser.