summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress/netcat.c67
1 files changed, 53 insertions, 14 deletions
diff --git a/regress/netcat.c b/regress/netcat.c
index 84efe1182..3f100bdd6 100644
--- a/regress/netcat.c
+++ b/regress/netcat.c
@@ -44,7 +44,6 @@
44#include <netinet/ip.h> 44#include <netinet/ip.h>
45#include <arpa/telnet.h> 45#include <arpa/telnet.h>
46 46
47#include <err.h>
48#include <errno.h> 47#include <errno.h>
49#include <netdb.h> 48#include <netdb.h>
50#include <poll.h> 49#include <poll.h>
@@ -122,6 +121,47 @@ void usage(int);
122ssize_t drainbuf(int, unsigned char *, size_t *); 121ssize_t drainbuf(int, unsigned char *, size_t *);
123ssize_t fillbuf(int, unsigned char *, size_t *); 122ssize_t fillbuf(int, unsigned char *, size_t *);
124 123
124static void err(int, const char *, ...) __attribute__((format(printf, 2, 3)));
125static void errx(int, const char *, ...) __attribute__((format(printf, 2, 3)));
126static void warn(const char *, ...) __attribute__((format(printf, 1, 2)));
127
128static void
129err(int r, const char *fmt, ...)
130{
131 va_list args;
132
133 va_start(args, fmt);
134 fprintf(stderr, "%s: ", strerror(errno));
135 vfprintf(stderr, fmt, args);
136 fputc('\n', stderr);
137 va_end(args);
138 exit(r);
139}
140
141static void
142errx(int r, const char *fmt, ...)
143{
144 va_list args;
145
146 va_start(args, fmt);
147 vfprintf(stderr, fmt, args);
148 fputc('\n', stderr);
149 va_end(args);
150 exit(r);
151}
152
153static void
154warn(const char *fmt, ...)
155{
156 va_list args;
157
158 va_start(args, fmt);
159 fprintf(stderr, "%s: ", strerror(errno));
160 vfprintf(stderr, fmt, args);
161 fputc('\n', stderr);
162 va_end(args);
163}
164
125int 165int
126main(int argc, char *argv[]) 166main(int argc, char *argv[])
127{ 167{
@@ -500,7 +540,7 @@ main(int argc, char *argv[])
500int 540int
501unix_bind(char *path) 541unix_bind(char *path)
502{ 542{
503 struct sockaddr_un sun; 543 struct sockaddr_un sun_sa;
504 int s; 544 int s;
505 545
506 /* Create unix domain socket. */ 546 /* Create unix domain socket. */
@@ -508,17 +548,17 @@ unix_bind(char *path)
508 0)) < 0) 548 0)) < 0)
509 return (-1); 549 return (-1);
510 550
511 memset(&sun, 0, sizeof(struct sockaddr_un)); 551 memset(&sun_sa, 0, sizeof(struct sockaddr_un));
512 sun.sun_family = AF_UNIX; 552 sun_sa.sun_family = AF_UNIX;
513 553
514 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= 554 if (strlcpy(sun_sa.sun_path, path, sizeof(sun_sa.sun_path)) >=
515 sizeof(sun.sun_path)) { 555 sizeof(sun_sa.sun_path)) {
516 close(s); 556 close(s);
517 errno = ENAMETOOLONG; 557 errno = ENAMETOOLONG;
518 return (-1); 558 return (-1);
519 } 559 }
520 560
521 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { 561 if (bind(s, (struct sockaddr *)&sun_sa, SUN_LEN(&sun_sa)) < 0) {
522 close(s); 562 close(s);
523 return (-1); 563 return (-1);
524 } 564 }
@@ -532,7 +572,7 @@ unix_bind(char *path)
532int 572int
533unix_connect(char *path) 573unix_connect(char *path)
534{ 574{
535 struct sockaddr_un sun; 575 struct sockaddr_un sun_sa;
536 int s; 576 int s;
537 577
538 if (uflag) { 578 if (uflag) {
@@ -544,16 +584,16 @@ unix_connect(char *path)
544 } 584 }
545 (void)fcntl(s, F_SETFD, FD_CLOEXEC); 585 (void)fcntl(s, F_SETFD, FD_CLOEXEC);
546 586
547 memset(&sun, 0, sizeof(struct sockaddr_un)); 587 memset(&sun_sa, 0, sizeof(struct sockaddr_un));
548 sun.sun_family = AF_UNIX; 588 sun_sa.sun_family = AF_UNIX;
549 589
550 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= 590 if (strlcpy(sun_sa.sun_path, path, sizeof(sun_sa.sun_path)) >=
551 sizeof(sun.sun_path)) { 591 sizeof(sun_sa.sun_path)) {
552 close(s); 592 close(s);
553 errno = ENAMETOOLONG; 593 errno = ENAMETOOLONG;
554 return (-1); 594 return (-1);
555 } 595 }
556 if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { 596 if (connect(s, (struct sockaddr *)&sun_sa, SUN_LEN(&sun_sa)) < 0) {
557 close(s); 597 close(s);
558 return (-1); 598 return (-1);
559 } 599 }
@@ -1331,7 +1371,6 @@ usage(int ret)
1331#include <netinet/in.h> 1371#include <netinet/in.h>
1332#include <arpa/inet.h> 1372#include <arpa/inet.h>
1333 1373
1334#include <err.h>
1335#include <errno.h> 1374#include <errno.h>
1336#include <netdb.h> 1375#include <netdb.h>
1337#include <stdio.h> 1376#include <stdio.h>