commit - 314178bd504e028aa70baa30495fdb323dd6f82a
commit + 90fbce4058c3373fd0899a6160ce7e7b6f239830
blob - 13b0966257d91d948a4abb691e5acf181a043622 (mode 644)
blob + /dev/null
--- Makefile
+++ /dev/null
-PROG = lstun
-LDADD = -levent
-WARNINGS = yes
-
-.ifdef DEBUG
-CFLAGS = -O0 -g
-.endif
-
-.include <bsd.prog.mk>
blob - /dev/null
blob + db6a4af701de18d32b65511b652d01c51e03d70f (mode 644)
--- /dev/null
+++ Makefile.am
+bin_PROGRAMS = lstun
+lstun_SOURCES = lstun.c compat.h
+
+LDADD = $(LIBOBJS)
+
+dist_man1_MANS = lstun.1
blob - /dev/null
blob + 70027cbf3cf809c67ca8b5cff38df304aa29bcf6 (mode 755)
--- /dev/null
+++ autogen.sh
+#!/bin/sh
+
+exec autoreconf -vfi
blob - d79d1b25b0599f3657fa9a6ddfb465934adc6b2c
blob + 0b248da1c951313526b675a2d8e81d74d8c79c74
--- lstun.c
+++ lstun.c
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "compat.h"
+
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <ctype.h>
-#include <err.h>
#include <errno.h>
#include <event.h>
#include <limits.h>
blob - /dev/null
blob + 5b51015bf6346dc9fc122665c069773dda6027e4 (mode 644)
--- /dev/null
+++ compat/err.c
+/*
+ * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
+ *
+ * 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 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 "compat.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void vwarn(const char*, va_list);
+static void vwarnx(const char*, va_list);
+
+static void
+vwarn(const char *fmt, va_list ap)
+{
+ fprintf(stderr, "%s: ", getprogname());
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, ": %s\n", strerror(errno));
+}
+
+static void
+vwarnx(const char *fmt, va_list ap)
+{
+ fprintf(stderr, "%s: ", getprogname());
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+}
+
+void
+err(int ret, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vwarn(fmt, ap);
+ va_end(ap);
+ exit(ret);
+}
+
+void
+errx(int ret, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vwarnx(fmt, ap);
+ va_end(ap);
+ exit(ret);
+}
+
+void
+warn(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vwarn(fmt, ap);
+ va_end(ap);
+}
+
+void
+warnx(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vwarnx(fmt, ap);
+ va_end(ap);
+}
blob - /dev/null
blob + ef6e22826235080b0c3b5fb54048ca316355a6fe (mode 644)
--- /dev/null
+++ compat/getprogname.c
+/*
+ * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
+ *
+ * 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 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.
+ */
+
+/*
+ * XXX: eventualyl there are some ways, at least on linux, to get the
+ * program name, probably like glibc program_invocation_short_name or
+ * reading stuff from /proc/self.
+ */
+
+const char *
+getprogname(void)
+{
+ return "lstun";
+}
blob - /dev/null
blob + e1807693138c2fc6b662ac9d8859fa0f2431c360 (mode 644)
--- /dev/null
+++ compat/strtonum.c
+/*
+ * Copyright (c) 2004 Ted Unangst and Todd Miller
+ * All rights reserved.
+ *
+ * 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 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 <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#define INVALID 1
+#define TOOSMALL 2
+#define TOOLARGE 3
+
+long long
+strtonum(const char *numstr, long long minval, long long maxval,
+ const char **errstrp)
+{
+ long long ll = 0;
+ int error = 0;
+ char *ep;
+ struct errval {
+ const char *errstr;
+ int err;
+ } ev[4] = {
+ { NULL, 0 },
+ { "invalid", EINVAL },
+ { "too small", ERANGE },
+ { "too large", ERANGE },
+ };
+
+ ev[0].err = errno;
+ errno = 0;
+ if (minval > maxval) {
+ error = INVALID;
+ } else {
+ ll = strtoll(numstr, &ep, 10);
+ if (numstr == ep || *ep != '\0')
+ error = INVALID;
+ else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
+ error = TOOSMALL;
+ else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
+ error = TOOLARGE;
+ }
+ if (errstrp != NULL)
+ *errstrp = ev[error].errstr;
+ errno = ev[error].err;
+ if (error)
+ ll = 0;
+
+ return (ll);
+}
blob - /dev/null
blob + 4cafbf5b2796445777acdb8d609b7dc8153cd3f2 (mode 644)
--- /dev/null
+++ compat.h
+/*
+ * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
+ *
+ * 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 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.
+ */
+
+#ifndef COMPAT_H
+#define COMPAT_H
+
+#include "config.h"
+
+#ifdef HAVE_ERR
+# include <err.h>
+#else
+void err(int, const char*, ...);
+void errx(int, const char*, ...);
+void warn(const char*, ...);
+void warnx(const char*, ...);
+#endif
+
+#ifndef HAVE_GETPROGNAME
+const char *getprogname(void);
+#endif
+
+#ifndef HAVE_STRTONUM
+long long strtonum(const char*, long long, long long, const char**);
+#endif
+
+#endif /* COMPAT_H */
blob - /dev/null
blob + 65d714fbec3ece3b238ab4f8964f732377ab2e62 (mode 644)
--- /dev/null
+++ configure.ac
+AC_INIT([lstun], [0.1.0], [op@omarpolo.com])
+AC_CONFIG_LIBOBJ_DIR([compat])
+AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
+AC_PROG_CC_C99
+AC_USE_SYSTEM_EXTENSIONS
+
+AC_REPLACE_FUNCS([
+ err \
+ getprogname \
+ strtonum \
+])
+
+AC_CHECK_LIB([event2], [event_init], [], [
+ AC_CHECK_LIB([event], [event_init], [], [
+ AC_MSG_ERROR([requires libevent])
+ ])
+])
+
+AM_CFLAGS="${AM_CFLAGS} -Wall -Wextra -Wmissing-prototypes"
+AM_CFLAGS="${AM_CFLAGS} -Wstrict-prototypes -Wwrite-strings"
+AM_CFLAGS="${AM_CFLAGS} -Wno-unused-parameter"
+
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT