-/* $OpenBSD: netcat.c,v 1.184 2017/06/10 18:14:10 tb Exp $ */
+/* $OpenBSD: netcat.c,v 1.185 2017/06/11 10:53:07 tb Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
* Copyright (c) 2015 Bob Beck. All rights reserved.
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <unistd.h>
#include <tls.h>
+#include <unistd.h>
+
#include "atomicio.h"
#define PORT_MAX 65535
#define UNIX_DG_TMP_SOCKET_SIZE 19
-#define POLL_STDIN 0
-#define POLL_NETOUT 1
-#define POLL_NETIN 2
-#define POLL_STDOUT 3
-#define BUFSIZE 16384
-#define DEFAULT_CA_FILE "/etc/ssl/cert.pem"
+#define POLL_STDIN 0
+#define POLL_NETOUT 1
+#define POLL_NETIN 2
+#define POLL_STDOUT 3
+#define BUFSIZE 16384
+#define DEFAULT_CA_FILE "/etc/ssl/cert.pem"
#define TLS_ALL (1 << 1)
#define TLS_NOVERIFY (1 << 2)
void atelnet(int, unsigned char *, unsigned int);
int strtoport(char *portstr, int udp);
void build_ports(char *);
-void help(void);
+void help(void) __attribute__((noreturn));
int local_listen(char *, char *, struct addrinfo);
void readwrite(int, struct tls *);
void fdpass(int nfd) __attribute__((noreturn));
host = argv[0];
uport = NULL;
} else if (argv[0] && !argv[1]) {
- if (!lflag)
+ if (!lflag)
usage(1);
uport = argv[0];
host = NULL;
if (uflag)
unlink(unix_dg_tmp_socket);
- exit(ret);
+ return ret;
} else {
int i = 0;
tls_config_free(tls_cfg);
- exit(ret);
+ return ret;
}
/*
/* Create unix domain socket. */
if ((s = socket(AF_UNIX, flags | (uflag ? SOCK_DGRAM : SOCK_STREAM),
0)) < 0)
- return (-1);
+ return -1;
memset(&s_un, 0, sizeof(struct sockaddr_un));
s_un.sun_family = AF_UNIX;
sizeof(s_un.sun_path)) {
close(s);
errno = ENAMETOOLONG;
- return (-1);
+ return -1;
}
if (bind(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) {
save_errno = errno;
close(s);
errno = save_errno;
- return (-1);
+ return -1;
}
- return (s);
+
+ return s;
}
int
err(1, "poll failed");
}
- return (ret);
+ return ret;
}
void
if (uflag) {
if ((s = unix_bind(unix_dg_tmp_socket, SOCK_CLOEXEC)) < 0)
- return (-1);
+ return -1;
} else {
if ((s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) < 0)
- return (-1);
+ return -1;
}
memset(&s_un, 0, sizeof(struct sockaddr_un));
sizeof(s_un.sun_path)) {
close(s);
errno = ENAMETOOLONG;
- return (-1);
+ return -1;
}
if (connect(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) {
save_errno = errno;
close(s);
errno = save_errno;
- return (-1);
+ return -1;
}
- return (s);
+ return s;
}
{
int s;
if ((s = unix_bind(path, 0)) < 0)
- return (-1);
+ return -1;
if (listen(s, 5) < 0) {
close(s);
- return (-1);
+ return -1;
}
- return (s);
+ return s;
}
/*
freeaddrinfo(res0);
- return (s);
+ return s;
}
int
err(1, "poll failed");
}
- return (ret);
+ return ret;
}
/*
freeaddrinfo(res0);
- return (s);
+ return s;
}
/*
else
ret = -1;
}
- return (ret);
+ return ret;
}
void
for (t = toskeywords; t->keyword != NULL; t++) {
if (strcmp(s, t->keyword) == 0) {
*val = t->val;
- return (1);
+ return 1;
}
}
- return (0);
+ return 0;
}
int
for (t = tlskeywords; t->keyword != NULL; t++) {
if (strcmp(s, t->keyword) == 0) {
*val |= t->val;
- return (1);
+ return 1;
}
}
- return (0);
+ return 0;
}
void