From cccdd689e39b51af02b156229e5236a2a69dcdcb Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Wed, 19 Nov 2014 07:43:07 -0600 Subject: [PATCH] add minimal winsock->BSD networking header shims also add license header to existing shims --- include/Makefile.am | 15 +++++++++++++++ include/arpa/inet.h | 10 ++++++++++ include/err.h | 5 +++++ include/machine/endian.h | 5 +++++ include/netdb.h | 10 ++++++++++ include/netinet/in.h | 10 ++++++++++ include/netinet/tcp.h | 10 ++++++++++ include/poll.h | 11 +++++++++-- include/stdio.h | 5 +++++ include/stdlib.h | 5 +++++ include/string.h | 5 +++++ include/sys/ioctl.h | 11 +++++++++++ include/sys/mman.h | 5 +++++ include/sys/select.h | 10 ++++++++++ include/sys/socket.h | 10 ++++++++++ include/sys/times.h | 10 ++++++++++ include/sys/types.h | 5 +++++ include/syslog.h | 38 ++++++++++++++++++++++++++++++++++++++ include/unistd.h | 5 +++++ include/win32netcompat.h | 22 ++++++++++++++++++++++ 20 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 include/arpa/inet.h create mode 100644 include/netdb.h create mode 100644 include/netinet/in.h create mode 100644 include/netinet/tcp.h create mode 100644 include/sys/ioctl.h create mode 100644 include/sys/select.h create mode 100644 include/sys/socket.h create mode 100644 include/sys/times.h create mode 100644 include/syslog.h create mode 100644 include/win32netcompat.h diff --git a/include/Makefile.am b/include/Makefile.am index 4811145..543713e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,11 +1,26 @@ SUBDIRS = openssl noinst_HEADERS = err.h +noinst_HEADERS += netdb.h +noinst_HEADERS += poll.h noinst_HEADERS += pqueue.h noinst_HEADERS += stdio.h noinst_HEADERS += stdlib.h noinst_HEADERS += string.h +noinst_HEADERS += syslog.h noinst_HEADERS += unistd.h +noinst_HEADERS += win32netcompat.h + +noinst_HEADERS += arpa/inet.h + noinst_HEADERS += machine/endian.h + +noinst_HEADERS += netinet/in.h +noinst_HEADERS += netinet/tcp.h + +noinst_HEADERS += sys/ioctl.h noinst_HEADERS += sys/mman.h +noinst_HEADERS += sys/select.h +noinst_HEADERS += sys/socket.h +noinst_HEADERS += sys/times.h noinst_HEADERS += sys/types.h diff --git a/include/arpa/inet.h b/include/arpa/inet.h new file mode 100644 index 0000000..5d43e4f --- /dev/null +++ b/include/arpa/inet.h @@ -0,0 +1,10 @@ +/* + * Public domain + * arpa/inet.h compatibility shim + */ + +#ifndef _WIN32 +#include_next +#else +#include +#endif diff --git a/include/err.h b/include/err.h index 8f555e8..ec90327 100644 --- a/include/err.h +++ b/include/err.h @@ -1,3 +1,8 @@ +/* + * Public domain + * err.h compatibility shim + */ + #ifdef HAVE_ERR_H #include_next diff --git a/include/machine/endian.h b/include/machine/endian.h index e3120db..5ec39af 100644 --- a/include/machine/endian.h +++ b/include/machine/endian.h @@ -1,3 +1,8 @@ +/* + * Public domain + * machine/endian.h compatibility shim + */ + #ifndef LIBCRYPTOCOMPAT_BYTE_ORDER_H_ #define LIBCRYPTOCOMPAT_BYTE_ORDER_H_ diff --git a/include/netdb.h b/include/netdb.h new file mode 100644 index 0000000..d36b91d --- /dev/null +++ b/include/netdb.h @@ -0,0 +1,10 @@ +/* + * Public domain + * netdb.h compatibility shim + */ + +#ifndef _WIN32 +#include_next +#else +#include +#endif diff --git a/include/netinet/in.h b/include/netinet/in.h new file mode 100644 index 0000000..20e57b8 --- /dev/null +++ b/include/netinet/in.h @@ -0,0 +1,10 @@ +/* + * Public domain + * netinet/in.h compatibility shim + */ + +#ifndef _WIN32 +#include_next +#else +#include +#endif diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h new file mode 100644 index 0000000..c98cf74 --- /dev/null +++ b/include/netinet/tcp.h @@ -0,0 +1,10 @@ +/* + * Public domain + * netinet/tcp.h compatibility shim + */ + +#ifndef _WIN32 +#include_next +#else +#include +#endif diff --git a/include/poll.h b/include/poll.h index 37f32cd..c02a560 100644 --- a/include/poll.h +++ b/include/poll.h @@ -1,7 +1,14 @@ /* - * poll(2) emulation for Windows * Public domain - * from Dongsheng Song + * + * poll(2) emulation for Windows + * + * This emulates just-enough poll functionality on Windows to work in the + * context of the openssl(1) program. This is not a replacement for + * POSIX.1-2001 poll(2). + * + * Dongsheng Song + * Brent Cook */ #ifndef LIBCRYPTOCOMPAT_POLL_H diff --git a/include/stdio.h b/include/stdio.h index 4a40f6a..989b7fc 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,3 +1,8 @@ +/* + * Public domain + * stdio.h compatibility shim + */ + #include_next #ifndef LIBCRYPTOCOMPAT_STDIO_H diff --git a/include/stdlib.h b/include/stdlib.h index 1a1cb6c..e77f0b4 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -1,3 +1,8 @@ +/* + * stdlib.h compatibility shim + * Public domain + */ + #include_next #ifndef LIBCRYPTOCOMPAT_STDLIB_H diff --git a/include/string.h b/include/string.h index 47ada28..a3263e7 100644 --- a/include/string.h +++ b/include/string.h @@ -1,3 +1,8 @@ +/* + * Public domain + * string.h compatibility shim + */ + #include_next #ifndef LIBCRYPTOCOMPAT_STRING_H diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h new file mode 100644 index 0000000..a255506 --- /dev/null +++ b/include/sys/ioctl.h @@ -0,0 +1,11 @@ +/* + * Public domain + * sys/ioctl.h compatibility shim + */ + +#ifndef _WIN32 +#include_next +#else +#include +#define ioctl(fd, type, arg) ioctlsocket(fd, type, arg) +#endif diff --git a/include/sys/mman.h b/include/sys/mman.h index cb1fa21..d9eb6a9 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -1,3 +1,8 @@ +/* + * Public domain + * sys/mman.h compatibility shim + */ + #include_next #ifndef LIBCRYPTOCOMPAT_MMAN_H diff --git a/include/sys/select.h b/include/sys/select.h new file mode 100644 index 0000000..5ca0ea1 --- /dev/null +++ b/include/sys/select.h @@ -0,0 +1,10 @@ +/* + * Public domain + * sys/select.h compatibility shim + */ + +#ifndef _WIN32 +#include_next +#else +#include +#endif diff --git a/include/sys/socket.h b/include/sys/socket.h new file mode 100644 index 0000000..17e84f1 --- /dev/null +++ b/include/sys/socket.h @@ -0,0 +1,10 @@ +/* + * Public domain + * sys/socket.h compatibility shim + */ + +#ifndef _WIN32 +#include_next +#else +#include +#endif diff --git a/include/sys/times.h b/include/sys/times.h new file mode 100644 index 0000000..5b9841b --- /dev/null +++ b/include/sys/times.h @@ -0,0 +1,10 @@ +/* + * Public domain + * sys/times.h compatibility shim + */ + +#ifndef _WIN32 +#include_next +#else +#include +#endif diff --git a/include/sys/types.h b/include/sys/types.h index 34c3e03..bceedc2 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -1,3 +1,8 @@ +/* + * Public domain + * sys/types.h compatibility shim + */ + #include_next #ifndef LIBCRYPTOCOMPAT_SYS_TYPES_H diff --git a/include/syslog.h b/include/syslog.h new file mode 100644 index 0000000..f61e33b --- /dev/null +++ b/include/syslog.h @@ -0,0 +1,38 @@ +/* + * Public domain + * syslog.h compatibility shim + */ + +#ifndef LIBCRYPTOCOMPAT_SYSLOG_H +#define LIBCRYPTOCOMPAT_SYSLOG_H + +#ifndef _WIN32 +#include_next +#else + +/* priorities */ +#define LOG_EMERG 0 +#define LOG_ALERT 1 +#define LOG_CRIT 2 +#define LOG_ERR 3 +#define LOG_WARNING 4 +#define LOG_NOTICE 5 +#define LOG_INFO 6 +#define LOG_DEBUG 7 + +/* facility codes */ +#define LOG_KERN (0<<3) +#define LOG_USER (1<<3) +#define LOG_DAEMON (3<<3) + +/* flags for openlog */ +#define LOG_PID 0x01 +#define LOG_CONS 0x02 + +extern void openlog(const char *ident, int option, int facility); +extern void syslog(int priority, const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); +extern void closelog (void); +#endif + +#endif /* LIBCRYPTOCOMPAT_SYSLOG_H */ diff --git a/include/unistd.h b/include/unistd.h index 38caeb1..3aecd68 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -1,3 +1,8 @@ +/* + * Public domain + * unistd.h compatibility shim + */ + #include_next #ifndef LIBCRYPTOCOMPAT_UNISTD_H diff --git a/include/win32netcompat.h b/include/win32netcompat.h new file mode 100644 index 0000000..3c716b0 --- /dev/null +++ b/include/win32netcompat.h @@ -0,0 +1,22 @@ +#ifndef LIBCRYPTOCOMPAT_WIN32NETCOMPAT_H +#define LIBCRYPTOCOMPAT_WIN32NETCOMPAT_H + +#ifdef _WIN32 + +#include + +#ifndef SHUT_RDWR +#define SHUT_RDWR SD_BOTH +#endif + +#ifndef SHUT_RD +#define SHUT_RD SD_RECEIVE +#endif + +#ifndef SHUT_WR +#define SHUT_WR SD_SEND +#endif + +#endif + +#endif