Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision ddfcfeb22fe529fef60132084a109a424354cd72)
+++ uspace/lib/c/Makefile	(revision 2721a75a80b078ca942208aff692e091cec7496b)
@@ -61,4 +61,5 @@
 	generic/mem.c \
 	generic/str.c \
+	generic/str_error.c \
 	generic/fibril.c \
 	generic/fibril_synch.c \
@@ -94,5 +95,5 @@
 	generic/vfs/canonify.c \
 	generic/stacktrace.c \
-	generic/strerror.c
+	generic/arg_parse.c
 
 SOURCES = \
Index: uspace/lib/c/generic/arg_parse.c
===================================================================
--- uspace/lib/c/generic/arg_parse.c	(revision 2721a75a80b078ca942208aff692e091cec7496b)
+++ uspace/lib/c/generic/arg_parse.c	(revision 2721a75a80b078ca942208aff692e091cec7496b)
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ * Command-line arguments parsing functions
+ */
+
+#include <arg_parse.h>
+#include <errno.h>
+#include <str.h>
+
+/** Parse the next argument as an integer.
+ *
+ * The actual argument is pointed by the index.
+ * Parse the offseted argument value if the offset is set
+ * or the next one if not.
+ *
+ * @param[in]     argc   The total number of arguments.
+ * @param[in]     argv   The arguments.
+ * @param[in,out] index  The actual argument index. The index is incremented
+ *                       by the number of processed arguments.
+ * @param[out]    value  The parsed argument value.
+ * @param[in]     offset The value offset in the actual argument. If not set,
+ *                       the next argument is parsed instead.
+ *
+ * @return EOK on success.
+ * @return ENOENT if the argument is missing.
+ * @return EINVAL if the argument is in wrong format.
+ *
+ */
+int arg_parse_int(int argc, char *argv[], int *index, int *value,
+    int offset)
+{
+	char *rest;
+	
+	if (offset)
+		*value = strtol(argv[*index] + offset, &rest, 10);
+	else if ((*index) + 1 < argc) {
+		(*index)++;
+		*value = strtol(argv[*index], &rest, 10);
+	} else
+		return ENOENT;
+	
+	if ((rest) && (*rest))
+		return EINVAL;
+	
+	return EOK;
+}
+
+/** Parse the next named argument as an integral number.
+ *
+ * The actual argument is pointed by the index.
+ * Parse the offseted actual argument if the offset is set or the next
+ * one if not. Translate the argument using the parse_value function.
+ * Increment the actual index by the number of processed arguments.
+ *
+ * @param[in]     argc        The total number of arguments.
+ * @param[in]     argv        The arguments.
+ * @param[in,out] index       The actual argument index. The index is
+ *                            incremented by the number of processed arguments.
+ * @param[out]    value       The parsed argument value.
+ * @param[in]     offset      The value offset in the actual argument. If not
+ *                            set, the next argument is parsed instead.
+ * @param[in]     parse_value The translation function to parse the named value.
+ *
+ * @return EOK on success.
+ * @return ENOENT if the argument is missing.
+ * @return EINVAL if the argument name has not been found.
+ *
+ */
+int arg_parse_name_int(int argc, char *argv[], int *index, int *value,
+    int offset, arg_parser parser)
+{
+	char *arg;
+	
+	int ret = arg_parse_string(argc, argv, index, &arg, offset);
+	if (ret != EOK)
+		return ret;
+	
+	return parser(arg, value);
+}
+
+/** Parse the next argument as a character string.
+ *
+ * The actual argument is pointed by the index.
+ * Parse the offseted actual argument value if the offset is set or the next
+ * one if not. Increment the actual index by the number of processed arguments.
+ *
+ * @param[in]     argc   The total number of arguments.
+ * @param[in]     argv   The arguments.
+ * @param[in,out] index  The actual argument index. The index is
+ *                       incremented by the number of processed arguments.
+ * @param[out]    value  The parsed argument value.
+ * @param[in]     offset The value offset in the actual argument. If not set,
+ *                       the next argument is parsed instead.
+ *
+ * @return EOK on success.
+ * @return ENOENT if the parameter is missing.
+ *
+ */
+int arg_parse_string(int argc, char **argv, int *index, char **value,
+    int offset)
+{
+	if (offset)
+		*value = argv[*index] + offset;
+	else if ((*index) + 1 < argc) {
+		(*index)++;
+		*value = argv[*index];
+	} else
+		return ENOENT;
+	
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/str_error.c
===================================================================
--- uspace/lib/c/generic/str_error.c	(revision 2721a75a80b078ca942208aff692e091cec7496b)
+++ uspace/lib/c/generic/str_error.c	(revision 2721a75a80b078ca942208aff692e091cec7496b)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <str_error.h>
+#include <stdio.h>
+#include <fibril.h>
+
+#define MIN_ERRNO  -17
+#define NOERR_LEN  64
+
+static const char* err_desc[] = {
+	"No error",
+	"No such entry",
+	"Not enought memory",
+	"Limit exceeded", 
+	"Connection refused",
+	"Forward error",
+	"Permission denied",
+	"Answerbox closed connection",
+	"Other party error",
+	"Entry already exists",
+	"Bad memory pointer",
+	"Not supported",
+	"Address not available",
+	"Timeout expired",
+	"Invalid value",
+	"Resource is busy",
+	"Result does not fits its size",
+	"Operation was interrupted"
+};
+
+static fibril_local char noerr[NOERR_LEN];
+
+const char *str_error(const int errno)
+{
+	if ((errno <= 0) && (errno >= MIN_ERRNO))
+		return err_desc[-errno];
+	
+	snprintf(noerr, NOERR_LEN, "Unkown error code %d", errno);
+	return noerr;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/strerror.c
===================================================================
--- uspace/lib/c/generic/strerror.c	(revision ddfcfeb22fe529fef60132084a109a424354cd72)
+++ 	(revision )
@@ -1,75 +1,0 @@
-/*
- * Copyright (c) 2010 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <strerror.h>
-#include <stdio.h>
-#include <fibril.h>
-
-#define MIN_ERRNO  -17
-#define NOERR_LEN  64
-
-static const char* err_desc[] = {
-	"No error",
-	"No such entry",
-	"Not enought memory",
-	"Limit exceeded", 
-	"Connection refused",
-	"Forward error",
-	"Permission denied",
-	"Answerbox closed connection",
-	"Other party error",
-	"Entry already exists",
-	"Bad memory pointer",
-	"Not supported",
-	"Address not available",
-	"Timeout expired",
-	"Invalid value",
-	"Resource is busy",
-	"Result does not fits its size",
-	"Operation was interrupted"
-};
-
-static fibril_local char noerr[NOERR_LEN];
-
-const char *str_error(const int errno)
-{
-	if ((errno <= 0) && (errno >= MIN_ERRNO))
-		return err_desc[-errno];
-	
-	snprintf(noerr, NOERR_LEN, "Unkown error code %d", errno);
-	return noerr;
-}
-
-/** @}
- */
Index: uspace/lib/c/include/arg_parse.h
===================================================================
--- uspace/lib/c/include/arg_parse.h	(revision 2721a75a80b078ca942208aff692e091cec7496b)
+++ uspace/lib/c/include/arg_parse.h	(revision 2721a75a80b078ca942208aff692e091cec7496b)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ARG_PARSE_H_
+#define LIBC_ARG_PARSE_H_
+
+typedef int (*arg_parser)(const char *, int *);
+
+extern int arg_parse_int(int, char **, int *, int *, int);
+extern int arg_parse_name_int(int, char **, int *, int *, int, arg_parser);
+extern int arg_parse_string(int, char **, int *, char **, int);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/str_error.h
===================================================================
--- uspace/lib/c/include/str_error.h	(revision 2721a75a80b078ca942208aff692e091cec7496b)
+++ uspace/lib/c/include/str_error.h	(revision 2721a75a80b078ca942208aff692e091cec7496b)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_STRERROR_H_
+#define LIBC_STRERROR_H_
+
+const char *str_error(const int);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/strerror.h
===================================================================
--- uspace/lib/c/include/strerror.h	(revision ddfcfeb22fe529fef60132084a109a424354cd72)
+++ 	(revision )
@@ -1,43 +1,0 @@
-/*
- * Copyright (c) 2010 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#ifndef LIBC_STRERROR_H_
-#define LIBC_STRERROR_H_
-
-const char *str_error(const int);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/socket/Makefile
===================================================================
--- uspace/lib/socket/Makefile	(revision ddfcfeb22fe529fef60132084a109a424354cd72)
+++ uspace/lib/socket/Makefile	(revision 2721a75a80b078ca942208aff692e091cec7496b)
@@ -35,4 +35,5 @@
 	generic/socket_client.c \
 	generic/socket_core.c \
+	generic/socket_parse.c \
 	generic/inet.c \
 	generic/net_modules.c \
Index: uspace/lib/socket/include/net_err.h
===================================================================
--- uspace/lib/socket/include/net_err.h	(revision ddfcfeb22fe529fef60132084a109a424354cd72)
+++ uspace/lib/socket/include/net_err.h	(revision 2721a75a80b078ca942208aff692e091cec7496b)
@@ -42,5 +42,5 @@
 #ifdef CONFIG_DEBUG
 	#include <stdio.h>
-	#include <strerror.h>
+	#include <str_error.h>
 #endif
 
