diff --git a/Makefile.am b/Makefile.am
index 69d321a1..717628a5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.8 2011-01-07 15:09:04 tcunha Exp $
+# $Id: Makefile.am,v 1.9 2011-01-21 20:35:20 nicm Exp $
 
 # Obvious program stuff.
 bin_PROGRAMS = tmux
@@ -12,6 +12,9 @@ dist-hook:
 	grep "^#found_debug=" configure
 	find $(distdir) -name CVS -type d|xargs rm -Rf
 
+# Preprocessor flags.
+CPPFLAGS += @XOPEN_DEFINES@
+
 # glibc as usual does things ass-backwards and hides useful things by default,
 # so everyone has to add this.
 if IS_GLIBC
diff --git a/compat/forkpty-hpux.c b/compat/forkpty-hpux.c
new file mode 100644
index 00000000..a2afc361
--- /dev/null
+++ b/compat/forkpty-hpux.c
@@ -0,0 +1,89 @@
+/* $Id: forkpty-hpux.c,v 1.1 2011-01-21 20:35:20 nicm Exp $ */
+
+/*
+ * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stropts.h>
+#include <unistd.h>
+
+#include "tmux.h"
+
+pid_t
+forkpty(int *master, char *name, struct termios *tio, struct winsize *ws)
+{
+	int	slave;
+	char   *path;
+	pid_t	pid;
+
+	if ((*master = open("/dev/ptmx", O_RDWR|O_NOCTTY)) == -1)
+		return (-1);
+	if (grantpt(*master) != 0)
+		goto out;
+	if (unlockpt(*master) != 0)
+		goto out;
+
+	if ((path = ptsname(*master)) == NULL)
+		goto out;
+	if (name != NULL)
+		strlcpy(name, path, TTY_NAME_MAX);
+	if ((slave = open(path, O_RDWR|O_NOCTTY)) == -1)
+		goto out;
+
+	switch (pid = fork()) {
+	case -1:
+		goto out;
+	case 0:
+		close(*master);
+
+		setsid();
+#ifdef TIOCSCTTY
+		if (ioctl(slave, TIOCSCTTY, NULL) == -1)
+			fatal("ioctl failed");
+#endif
+
+		if (ioctl(slave, I_PUSH, "ptem") == -1)
+			fatal("ioctl failed");
+		if (ioctl(slave, I_PUSH, "ldterm") == -1)
+			fatal("ioctl failed");
+
+		if (tio != NULL && tcsetattr(slave, TCSAFLUSH, tio) == -1)
+			fatal("tcsetattr failed");
+		if (ioctl(slave, TIOCSWINSZ, ws) == -1)
+			fatal("ioctl failed");
+
+		dup2(slave, 0);
+		dup2(slave, 1);
+		dup2(slave, 2);
+		if (slave > 2)
+			close(slave);
+		return (0);
+	}
+
+	close(slave);
+	return (pid);
+
+out:
+	if (*master != -1)
+		close(*master);
+	if (slave != -1)
+		close(slave);
+	return (-1);
+}
diff --git a/configure.ac b/configure.ac
index d50dde90..01a739b8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-# $Id: configure.ac,v 1.12 2011-01-10 22:12:31 nicm Exp $
+# $Id: configure.ac,v 1.13 2011-01-21 20:35:20 nicm Exp $
 
 # Miscellaneous autofoo bullshit.
 AC_INIT(tmux, 1.5)
@@ -120,6 +120,47 @@ fi
 # Look for networking libraries.
 AC_SEARCH_LIBS(inet_ntoa, nsl)
 AC_SEARCH_LIBS(socket, socket)
+AC_CHECK_LIB(xnet, socket)
+
+# Check for CMSG_DATA. Some platforms require _XOPEN_SOURCE_EXTENDED (for
+# example see xopen_networking(7) on HP-UX).
+XOPEN_DEFINES=
+AC_MSG_CHECKING(for CMSG_DATA)
+AC_EGREP_CPP(
+	yes,
+	[
+		#include <sys/socket.h>
+		#ifdef CMSG_DATA
+		yes
+		#endif
+	],
+	found_cmsg_data=yes,
+	found_cmsg_data=no
+)
+AC_MSG_RESULT($found_cmsg_data)
+if test "x$found_cmsg_data" = xno; then
+	AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED)
+	AC_EGREP_CPP(
+		yes,
+		[
+			#define _XOPEN_SOURCE 1
+			#define _XOPEN_SOURCE_EXTENDED 1
+			#include <sys/socket.h>
+			#ifdef CMSG_DATA
+			yes
+			#endif
+		],
+		found_cmsg_data=yes,
+		found_cmsg_data=no
+	)
+	AC_MSG_RESULT($found_cmsg_data)
+	if test "x$found_cmsg_data" = xyes; then
+		XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
+	else
+    		AC_MSG_ERROR("CMSG_DATA not found")
+	fi
+fi
+AC_SUBST(XOPEN_DEFINES)
 
 # Look for imsg in libutil. compat/imsg.c is linked by Makefile.am if missing.
 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
@@ -355,6 +396,10 @@ case "$host_os" in
 		AC_MSG_RESULT(sunos)
 		PLATFORM=sunos
 		;;
+	*hpux*)
+		AC_MSG_RESULT(hpux)
+		PLATFORM=hpux
+		;;
 	*)
 		AC_MSG_RESULT(unknown)
 		PLATFORM=unknown
@@ -368,6 +413,7 @@ AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd)
 AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
 AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
 AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
+AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
 AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
 
 # autoconf should create a Makefile. A shock!
diff --git a/osdep-hpux.c b/osdep-hpux.c
new file mode 100644
index 00000000..ecbbd380
--- /dev/null
+++ b/osdep-hpux.c
@@ -0,0 +1,35 @@
+/* $Id: osdep-hpux.c,v 1.1 2011-01-21 20:35:20 nicm Exp $ */
+
+/*
+ * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <event.h>
+
+#include "tmux.h"
+
+char *
+osdep_get_name(unused int fd, unused char *tty)
+{
+	return (NULL);
+}
+
+struct event_base *
+osdep_event_init(void)
+{
+	return (event_init());
+}