[klibc] Undo breakage caused by kernel header changes.

The kernel headers have hidden a bunch of stuff that used to be
exported.  Compensate.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/usr/include/arch/mips/klibc/archconfig.h b/usr/include/arch/mips/klibc/archconfig.h
index 15b3208..ff0afb5 100644
--- a/usr/include/arch/mips/klibc/archconfig.h
+++ b/usr/include/arch/mips/klibc/archconfig.h
@@ -15,4 +15,7 @@
 /* MIPS defines it's own statfs */
 #define _KLIBC_STATFS_F_TYPE_32B 1
 
+/* MIPS has nonstandard socket definitions */
+#define _KLIBC_HAS_ARCHSOCKET_H 1
+
 #endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/mips/klibc/archsocket.h b/usr/include/arch/mips/klibc/archsocket.h
new file mode 100644
index 0000000..d6daf1b
--- /dev/null
+++ b/usr/include/arch/mips/klibc/archsocket.h
@@ -0,0 +1,17 @@
+/*
+ * arch/mips/klibc/archsocket.h
+ */
+
+#ifndef _KLIBC_ARCHSOCKET_H
+#define _KLIBC_ARCHSOCKET_H
+
+#ifndef SOCK_STREAM
+# define SOCK_DGRAM     1
+# define SOCK_STREAM    2
+# define SOCK_RAW       3
+# define SOCK_RDM       4
+# define SOCK_SEQPACKET 5
+# define SOCK_PACKET    10
+#endif
+
+#endif /* _KLIBC_ARCHSOCKET_H */
diff --git a/usr/include/arch/mips64/klibc/archconfig.h b/usr/include/arch/mips64/klibc/archconfig.h
index b440af1..9071cb4 100644
--- a/usr/include/arch/mips64/klibc/archconfig.h
+++ b/usr/include/arch/mips64/klibc/archconfig.h
@@ -9,6 +9,7 @@
 #ifndef _KLIBC_ARCHCONFIG_H
 #define _KLIBC_ARCHCONFIG_H
 
-/* All defaults */
+/* MIPS has nonstandard socket definitions */
+#define _KLIBC_HAS_ARCHSOCKET_H 1
 
 #endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/mips64/klibc/archsocket.h b/usr/include/arch/mips64/klibc/archsocket.h
new file mode 100644
index 0000000..6c3947d
--- /dev/null
+++ b/usr/include/arch/mips64/klibc/archsocket.h
@@ -0,0 +1,17 @@
+/*
+ * arch/mips64/klibc/archsocket.h
+ */
+
+#ifndef _KLIBC_ARCHSOCKET_H
+#define _KLIBC_ARCHSOCKET_H
+
+#ifndef SOCK_STREAM
+# define SOCK_DGRAM     1
+# define SOCK_STREAM    2
+# define SOCK_RAW       3
+# define SOCK_RDM       4
+# define SOCK_SEQPACKET 5
+# define SOCK_PACKET    10
+#endif
+
+#endif /* _KLIBC_ARCHSOCKET_H */
diff --git a/usr/include/klibc/sysconfig.h b/usr/include/klibc/sysconfig.h
index f4fb7a9..9c132d9 100644
--- a/usr/include/klibc/sysconfig.h
+++ b/usr/include/klibc/sysconfig.h
@@ -163,6 +163,7 @@
 # define _KLIBC_STATFS_F_TYPE_64 (_BITSIZE == 64)
 #endif
 
+
 /*
  * _KLIBC_STATFS_F_TYPE_32B:
  *
@@ -173,4 +174,14 @@
 # define _KLIBC_STATFS_F_TYPE_32B 0
 #endif
 
+
+/*
+ * _KLIBC_HAS_ARCHSOCKET_H
+ *
+ *       This architecture has <klibc/archsocket.h>
+ */
+#ifndef _KLIBC_HAS_ARCHSOCKET_H
+# define _KLIBC_HAS_ARCHSOCKET_H 0
+#endif
+
 #endif /* _KLIBC_SYSCONFIG_H */
diff --git a/usr/include/netinet/in.h b/usr/include/netinet/in.h
index 4ab7c24..2952bb2 100644
--- a/usr/include/netinet/in.h
+++ b/usr/include/netinet/in.h
@@ -5,12 +5,10 @@
 #ifndef _NETINET_IN_H
 #define _NETINET_IN_H
 
-/* added this include by Mats Petersson */
-#include <linux/socket.h>
-
 #include <klibc/extern.h>
 #include <stdint.h>
 #include <endian.h>		/* Must be included *before* <linux/in.h> */
+#include <sys/socket.h>		/* Must be included *before* <linux/in.h> */
 #include <linux/in.h>
 
 #ifndef htons
diff --git a/usr/include/sys/socket.h b/usr/include/sys/socket.h
index 2de1d6a..7d47087 100644
--- a/usr/include/sys/socket.h
+++ b/usr/include/sys/socket.h
@@ -7,9 +7,17 @@
 
 #include <klibc/extern.h>
 #include <klibc/compiler.h>
+#include <klibc/sysconfig.h>
 #include <linux/socket.h>
+#if _KLIBC_HAS_ARCHSOCKET_H
+#include <klibc/archsocket.h>
+#endif
 
-/* For some reason these may be protected by __KERNEL__ in asm/socket.h */
+/* Great job, guys!  These are *architecture-specific* ABI constants,
+   that are hidden under #ifdef __KERNEL__... what a brilliant idea!
+   These are the "common" definitions; if not appropriate, override
+   them in <klibc/archsocket.h>. */
+   
 #ifndef SOCK_STREAM
 # define SOCK_STREAM    1
 # define SOCK_DGRAM     2
diff --git a/usr/include/sys/stat.h b/usr/include/sys/stat.h
index 3226133..33182fc 100644
--- a/usr/include/sys/stat.h
+++ b/usr/include/sys/stat.h
@@ -9,7 +9,52 @@
 #include <sys/types.h>
 #include <sys/time.h>		/* For struct timespec */
 #include <klibc/archstat.h>
-#include <linux/stat.h>
+
+/* 2.6.21 kernels have once again hidden a bunch of stuff... */
+#ifndef S_IFMT
+
+#define S_IFMT  00170000
+#define S_IFSOCK 0140000
+#define S_IFLNK	 0120000
+#define S_IFREG  0100000
+#define S_IFBLK  0060000
+#define S_IFDIR  0040000
+#define S_IFCHR  0020000
+#define S_IFIFO  0010000
+#define S_ISUID  0004000
+#define S_ISGID  0002000
+#define S_ISVTX  0001000
+
+#define S_ISLNK(m)	(((m) & S_IFMT) == S_IFLNK)
+#define S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m)	(((m) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m)	(((m) & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m)	(((m) & S_IFMT) == S_IFIFO)
+#define S_ISSOCK(m)	(((m) & S_IFMT) == S_IFSOCK)
+
+#define S_IRWXU 00700
+#define S_IRUSR 00400
+#define S_IWUSR 00200
+#define S_IXUSR 00100
+
+#define S_IRWXG 00070
+#define S_IRGRP 00040
+#define S_IWGRP 00020
+#define S_IXGRP 00010
+
+#define S_IRWXO 00007
+#define S_IROTH 00004
+#define S_IWOTH 00002
+#define S_IXOTH 00001
+
+#define S_IRWXUGO	(S_IRWXU|S_IRWXG|S_IRWXO)
+#define S_IALLUGO	(S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
+#define S_IRUGO		(S_IRUSR|S_IRGRP|S_IROTH)
+#define S_IWUGO		(S_IWUSR|S_IWGRP|S_IWOTH)
+#define S_IXUGO		(S_IXUSR|S_IXGRP|S_IXOTH)
+
+#endif
 
 #ifdef _STATBUF_ST_NSEC
   /* struct stat has struct timespec instead of time_t */
diff --git a/usr/klibc/inet/inet_ntop.c b/usr/klibc/inet/inet_ntop.c
index ef31a18..106fb45 100644
--- a/usr/klibc/inet/inet_ntop.c
+++ b/usr/klibc/inet/inet_ntop.c
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/in6.h>