summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Rice <tim@multitalents.net>2015-02-24 07:56:47 -0800
committerTim Rice <tim@multitalents.net>2015-02-24 07:56:47 -0800
commit13af342458f5064144abbb07e5ac9bbd4eb42567 (patch)
tree1fc2d1eedd7eb944918a4036d15b7f58c4feff7c
parent910209203d0cd60c5083901cbcc0b7b44d9f48d2 (diff)
downloadopenssh-git-13af342458f5064144abbb07e5ac9bbd4eb42567.tar.gz
Original portability patch from djm@ for platforms missing err.h.
Fix name space clash on Solaris 10. Still more to do for Solaris 10 to deal with msghdr structure differences. ok djm@
-rw-r--r--regress/netcat.c67
1 files changed, 53 insertions, 14 deletions
diff --git a/regress/netcat.c b/regress/netcat.c
index 84efe118..3f100bdd 100644
--- a/regress/netcat.c
+++ b/regress/netcat.c
@@ -44,7 +44,6 @@
#include <netinet/ip.h>
#include <arpa/telnet.h>
-#include <err.h>
#include <errno.h>
#include <netdb.h>
#include <poll.h>
@@ -122,6 +121,47 @@ void usage(int);
ssize_t drainbuf(int, unsigned char *, size_t *);
ssize_t fillbuf(int, unsigned char *, size_t *);
+static void err(int, const char *, ...) __attribute__((format(printf, 2, 3)));
+static void errx(int, const char *, ...) __attribute__((format(printf, 2, 3)));
+static void warn(const char *, ...) __attribute__((format(printf, 1, 2)));
+
+static void
+err(int r, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ fprintf(stderr, "%s: ", strerror(errno));
+ vfprintf(stderr, fmt, args);
+ fputc('\n', stderr);
+ va_end(args);
+ exit(r);
+}
+
+static void
+errx(int r, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ fputc('\n', stderr);
+ va_end(args);
+ exit(r);
+}
+
+static void
+warn(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ fprintf(stderr, "%s: ", strerror(errno));
+ vfprintf(stderr, fmt, args);
+ fputc('\n', stderr);
+ va_end(args);
+}
+
int
main(int argc, char *argv[])
{
@@ -500,7 +540,7 @@ main(int argc, char *argv[])
int
unix_bind(char *path)
{
- struct sockaddr_un sun;
+ struct sockaddr_un sun_sa;
int s;
/* Create unix domain socket. */
@@ -508,17 +548,17 @@ unix_bind(char *path)
0)) < 0)
return (-1);
- memset(&sun, 0, sizeof(struct sockaddr_un));
- sun.sun_family = AF_UNIX;
+ memset(&sun_sa, 0, sizeof(struct sockaddr_un));
+ sun_sa.sun_family = AF_UNIX;
- if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
- sizeof(sun.sun_path)) {
+ if (strlcpy(sun_sa.sun_path, path, sizeof(sun_sa.sun_path)) >=
+ sizeof(sun_sa.sun_path)) {
close(s);
errno = ENAMETOOLONG;
return (-1);
}
- if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
+ if (bind(s, (struct sockaddr *)&sun_sa, SUN_LEN(&sun_sa)) < 0) {
close(s);
return (-1);
}
@@ -532,7 +572,7 @@ unix_bind(char *path)
int
unix_connect(char *path)
{
- struct sockaddr_un sun;
+ struct sockaddr_un sun_sa;
int s;
if (uflag) {
@@ -544,16 +584,16 @@ unix_connect(char *path)
}
(void)fcntl(s, F_SETFD, FD_CLOEXEC);
- memset(&sun, 0, sizeof(struct sockaddr_un));
- sun.sun_family = AF_UNIX;
+ memset(&sun_sa, 0, sizeof(struct sockaddr_un));
+ sun_sa.sun_family = AF_UNIX;
- if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
- sizeof(sun.sun_path)) {
+ if (strlcpy(sun_sa.sun_path, path, sizeof(sun_sa.sun_path)) >=
+ sizeof(sun_sa.sun_path)) {
close(s);
errno = ENAMETOOLONG;
return (-1);
}
- if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
+ if (connect(s, (struct sockaddr *)&sun_sa, SUN_LEN(&sun_sa)) < 0) {
close(s);
return (-1);
}
@@ -1331,7 +1371,6 @@ usage(int ret)
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <err.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>