From 25efa12431c9b1e4e7ada71cd041d548f647d03b Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Thu, 19 Nov 2020 21:26:28 +0100
Subject: [PATCH] WIP u_types

---
 include/arpa/inet.h         | 12 +++++++++---
 include/netdb.h             |  6 +++++-
 include/stdint.h            | 20 ++++++++++++++++----
 sys/netinet/in.h            | 21 ++++++++++++++++++++-
 sys/netinet6/in6.h          | 23 +++++++++++++++++++++++
 sys/netproto/smb/netbios.h  |  1 +
 sys/netproto/smb/smb_conn.h |  1 +
 7 files changed, 75 insertions(+), 9 deletions(-)

diff --git a/include/arpa/inet.h b/include/arpa/inet.h
index b0277f030c..bc0eed974f 100644
--- a/include/arpa/inet.h
+++ b/include/arpa/inet.h
@@ -61,9 +61,6 @@
 #include <sys/cdefs.h>
 #include <machine/endian.h>	/* Required for byteorder(3) functions. */
 #include <machine/stdint.h>	/* for __size_t, __socklen_t */
-#ifndef _KERNEL
-#include <stdint.h>		/* for uint16_t, uint32_t as per POSIX */
-#endif
 
 #define	INET_ADDRSTRLEN		16
 #define	INET6_ADDRSTRLEN	46
@@ -78,6 +75,15 @@ typedef	__uint16_t	in_port_t;
 #define	_IN_PORT_T_DECLARED
 #endif
 
+#ifndef _UINT16_T_DECLARED
+typedef	__uint16_t	uint16_t;
+#define	_UINT16_T_DECLARED
+#endif
+#ifndef _UINT32_T_DECLARED
+typedef	__uint32_t	uint32_t;
+#define	_UINT32_T_DECLARED
+#endif
+
 #if __BSD_VISIBLE
 #ifndef _SIZE_T_DECLARED
 #define	_SIZE_T_DECLARED
diff --git a/include/netdb.h b/include/netdb.h
index 19aa7b6548..e2044861b9 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -59,7 +59,6 @@
 
 #include <sys/cdefs.h>
 #include <machine/stdint.h>	/* for __size_t, __socklen_t */
-#include <stdint.h>
 
 #ifndef _IN_ADDR_T_DECLARED
 typedef	__uint32_t	in_addr_t;	/* base type for internet address */
@@ -81,6 +80,11 @@ typedef	__socklen_t	socklen_t;
 #define	_SOCKLEN_T_DECLARED
 #endif
 
+#ifndef _UINT32_T_DECLARED
+typedef	__uint32_t	uint32_t;
+#define	_UINT32_T_DECLARED
+#endif
+
 #ifndef _PATH_HEQUIV
 # define	_PATH_HEQUIV	"/etc/hosts.equiv"
 #endif
diff --git a/include/stdint.h b/include/stdint.h
index 4a3d37376f..6780be85e9 100644
--- a/include/stdint.h
+++ b/include/stdint.h
@@ -34,10 +34,22 @@ typedef __int16_t	int16_t;
 typedef __int32_t	int32_t;
 typedef __int64_t	int64_t;
 
-typedef __uint8_t	uint8_t;
-typedef __uint16_t	uint16_t;
-typedef __uint32_t	uint32_t;
-typedef __uint64_t	uint64_t;
+#ifndef _UINT8_T_DECLARED
+typedef	__uint8_t	uint8_t;
+#define	_UINT8_T_DECLARED
+#endif
+#ifndef _UINT16_T_DECLARED
+typedef	__uint16_t	uint16_t;
+#define	_UINT16_T_DECLARED
+#endif
+#ifndef _UINT32_T_DECLARED
+typedef	__uint32_t	uint32_t;
+#define	_UINT32_T_DECLARED
+#endif
+#ifndef _UINT64_T_DECLARED
+typedef	__uint64_t	uint64_t;
+#define	_UINT64_T_DECLARED
+#endif
 
 #ifndef _INTPTR_T_DECLARED
 #define _INTPTR_T_DECLARED
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 2873a8ac99..085651e018 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -33,7 +33,7 @@
 #ifndef _NETINET_IN_H_
 #define	_NETINET_IN_H_
 
-#include <sys/types.h>
+#include <machine/stdint.h>
 
 #ifndef _KERNEL
 #include <machine/endian.h>
@@ -246,11 +246,30 @@
 
 #define	IPPORT_MAX		65535
 
+#ifndef _IN_ADDR_T_DECLARED
+typedef	__uint32_t	in_addr_t;	/* base type for internet address */
+#define	_IN_ADDR_T_DECLARED
+#endif
+
+#ifndef _IN_PORT_T_DECLARED
+typedef	__uint16_t	in_port_t;
+#define	_IN_PORT_T_DECLARED
+#endif
+
 #ifndef _SA_FAMILY_T_DECLARED
 typedef	__uint8_t	sa_family_t;
 #define	_SA_FAMILY_T_DECLARED
 #endif
 
+#ifndef _UINT8_T_DECLARED
+typedef	__uint8_t	uint8_t;
+#define	_UINT8_T_DECLARED
+#endif
+#ifndef _UINT32_T_DECLARED
+typedef	__uint32_t	uint32_t;
+#define	_UINT32_T_DECLARED
+#endif
+
 #ifndef _STRUCT_IN_ADDR_DECLARED
 #define	_STRUCT_IN_ADDR_DECLARED
 /*
diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h
index a6bcce4745..ec93576151 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -76,11 +76,34 @@
 #define __KAME__
 #define __KAME_VERSION		"20010528/FreeBSD"
 
+#ifndef _SA_FAMILY_T_DECLARED
+typedef	__uint8_t	sa_family_t;
+#define	_SA_FAMILY_T_DECLARED
+#endif
+
+#ifndef _SIZE_T_DECLARED
+typedef	__size_t	size_t;
+#define	_SIZE_T_DECLARED
+#endif
+
 #ifndef _SOCKLEN_T_DECLARED
 #define _SOCKLEN_T_DECLARED
 typedef __socklen_t	socklen_t;
 #endif
 
+#ifndef _UINT8_T_DECLARED
+typedef	__uint8_t	uint8_t;
+#define	_UINT8_T_DECLARED
+#endif
+#ifndef _UINT16_T_DECLARED
+typedef	__uint16_t	uint16_t;
+#define	_UINT16_T_DECLARED
+#endif
+#ifndef _UINT32_T_DECLARED
+typedef	__uint32_t	uint32_t;
+#define	_UINT32_T_DECLARED
+#endif
+
 /*
  * Local port number conventions:
  *
diff --git a/sys/netproto/smb/netbios.h b/sys/netproto/smb/netbios.h
index 3ffcf996fc..bfe30764d7 100644
--- a/sys/netproto/smb/netbios.h
+++ b/sys/netproto/smb/netbios.h
@@ -38,6 +38,7 @@
 /*
  * make this file dirty...
  */
+#include <sys/types.h>
 #ifndef _NETINET_IN_H_
 #include <netinet/in.h>
 #endif
diff --git a/sys/netproto/smb/smb_conn.h b/sys/netproto/smb/smb_conn.h
index e0f72c871c..4a3fbccb68 100644
--- a/sys/netproto/smb/smb_conn.h
+++ b/sys/netproto/smb/smb_conn.h
@@ -35,6 +35,7 @@
 #ifndef _NETPROTO_SMB_SMB_CONN_H_
 #define	_NETPROTO_SMB_SMB_CONN_H_
 
+#include <sys/types.h>
 #ifndef _NETINET_IN_H_
 #include <netinet/in.h>
 #endif
-- 
2.28.0

