[ofw] [PATCH] etc: add generic linux compatibility code

Sean Hefty sean.hefty at intel.com
Tue Feb 24 12:16:59 PST 2009


To support the porting of OFED code, such as the infiniband-diags, provide a
set of linux compatible include files and functions.

This adds a set of header files under inc/user/linux so #include statements
in code will find them.  In some cases, the header files are blank, but in
others, they contain mappings between the linux calls and equivalent windows
calls.

Where more complex functionality is needed, source files are added under
etc/user to provide it, similar to what was done for getopt.

These headers and source files are used to support the OFED infiniband-diags
in the WinOF build environment.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Currently, only the ib-diags use these files, but other areas that might be able
to use thesm include libibmad, dapl, perftest, libibverbs samples, librdmacm
samples, and the mellanox hardware drivers.  Some time needs to be spent going
through those areas to see what, if anything, should be pulled out to a common
area.

diff -up -r -N -X trunk\docs\dontdiff.txt -I '\$Id:' trunk\inc\user/linux/arpa/inet.h branches\winverbs\inc\user/linux/arpa/inet.h
--- trunk\inc\user/linux/arpa/inet.h	1969-12-31 16:00:00.000000000 -0800
+++ branches\winverbs\inc\user/linux/arpa/inet.h	2009-02-20 14:12:03.055039700 -0800
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2009 Intel Corp, Inc.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef _INET_H_
+#define _INET_H_
+
+#include <ws2tcpip.h>
+
+#if WINVER < 0x600
+int inet_pton(int af, const char *src, void *dst);
+#endif
+
+#endif	/* _INET_H_ */
diff -up -r -N -X trunk\docs\dontdiff.txt -I '\$Id:' trunk\inc\user/linux/inttypes.h branches\winverbs\inc\user/linux/inttypes.h
--- trunk\inc\user/linux/inttypes.h	1969-12-31 16:00:00.000000000 -0800
+++ branches\winverbs\inc\user/linux/inttypes.h	2009-02-14 11:27:41.711216000 -0800
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2009 Intel Corp, Inc.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef _INTTYPES_H_
+#define _INTTYPES_H_
+
+#endif	/* _INTTYPES_H_ */
diff -up -r -N -X trunk\docs\dontdiff.txt -I '\$Id:' trunk\inc\user/linux/netinet/in.h branches\winverbs\inc\user/linux/netinet/in.h
--- trunk\inc\user/linux/netinet/in.h	1969-12-31 16:00:00.000000000 -0800
+++ branches\winverbs\inc\user/linux/netinet/in.h	2009-02-14 11:34:31.527048700 -0800
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2009 Intel Corp, Inc.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef _IN_H_
+#define _IN_H_
+
+#endif	/* _IN_H_ */
diff -up -r -N -X trunk\docs\dontdiff.txt -I '\$Id:' trunk\inc\user/linux/unistd.h branches\winverbs\inc\user/linux/unistd.h
--- trunk\inc\user/linux/unistd.h	1969-12-31 16:00:00.000000000 -0800
+++ branches\winverbs\inc\user/linux/unistd.h	2009-02-20 10:58:57.376687100 -0800
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2009 Intel Corp, Inc.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef _UNISTD_H_
+#define _UNISTD_H_
+
+#include <stdio.h>
+
+#define sleep(s) SleepEx(s * 1000, TRUE)
+
+static __inline int getdomainname(char *name, size_t len)
+{
+	return -1;
+}
+
+static __inline char* getpass(char *message)
+{
+	static char password[128];
+
+	printf("%s", message);
+	scanf_s("%127s", password, 128);
+	return password;
+}
+
+#endif	/* _UNISTD_H_ */
--- trunk\etc\user\inet.c	1969-12-31 16:00:00.000000000 -0800
+++ branches\winverbs\etc\user\inet.c	2009-02-20 15:59:18.391830500 -0800
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2009 Intel Corp., Inc.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <arpa/inet.h>
+
+static int inet_pton4(const char *src, struct in_addr *addr)
+{
+	unsigned long ip;
+
+	ip = inet_addr(src);
+	if (ip == INADDR_NONE)
+		return 0;
+
+	addr->S_un.S_addr = ip;
+	return 1;
+}
+
+enum in6_addr_format_state
+{
+	in6_fs_num,
+	in6_fs_colon,
+	in6_fs_0_colon,
+	in6_fs_0_num
+};
+
+static int inet_check_groups(const char *src)
+{
+	int i;
+	int digits = 0, groups = 0;
+	enum in6_addr_format_state state;
+
+	if (src[0] == ':') {
+		if (src[1] == ':') {
+			i = 2;
+			state = in6_fs_0_colon;
+		} else {
+			return -1;
+		}
+	} else {
+		i = 0;
+		state = in6_fs_num;
+	}
+
+	for (; src[i] != '\0'; i++) {
+		if (src[i] == ':') {
+
+			switch (state) {
+			case in6_fs_num:
+				state = in6_fs_colon;
+				break;
+			case in6_fs_colon:
+			case in6_fs_0_num:
+				state = in6_fs_0_colon;
+				break;
+			default:
+				return -1;
+			}
+			digits = 0;
+
+		} else if (isxdigit(src[i]) && digits++ < 4) {
+
+			switch (state) {
+			case in6_fs_colon:
+				state = in6_fs_num;
+				groups++;
+				break;
+			case in6_fs_0_colon:
+				state = in6_fs_0_num;
+				groups++;
+				break;
+			default:
+				break;
+			}
+		} else {
+			return -1;
+		}
+	}
+
+	if (groups > 8 || state == in6_fs_colon)
+		return -1;
+	
+	return groups;
+}
+
+/*
+ * We don't handle the format x:x:x:x:x:x:d.d.d.d
+ */
+static int inet_pton6(const char *src, struct in6_addr *addr)
+{
+	const char *pos;
+	int i, skip;
+
+	skip = 8 - inet_check_groups(src);
+	if (skip > 8)
+		return -1;
+
+	memset(addr, 0, sizeof(*addr));
+	if (src[0] == ':') {
+		pos = src + 2;
+		i = skip;
+	} else {
+		pos = src;
+		i = 0;
+	}
+
+	for (; i < 8; i++) {
+		addr->u.Word[i] = htons((u_short) strtoul(pos, (char **) &pos, 16));
+		pos++;
+		if (*pos == ':') {
+			pos++;
+			i += skip;
+		}
+	}
+
+	return 1;
+}
+
+int inet_pton(int af, const char *src, void *dst)
+{
+	switch (af) {
+	case AF_INET:
+		return inet_pton4(src, dst);
+	case AF_INET6:
+		return inet_pton6(src, dst);
+	default:
+		return -1;
+	}
+}





More information about the ofw mailing list