From 22927b0b9a75f2d8ccee0210645d690128b87e3e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 16 Jan 2019 08:58:04 -0600 Subject: Move xsendto() to lib/net.c. --- lib/lib.h | 1 + lib/net.c | 9 +++++++++ toys/net/ping.c | 9 --------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/lib.h b/lib/lib.h index 578a99c9..546b32b3 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -310,6 +310,7 @@ int xbind(struct addrinfo *ai); int xpoll(struct pollfd *fds, int nfds, int timeout); int pollinate(int in1, int in2, int out1, int out2, int timeout, int shutdown_timeout); char *ntop(struct sockaddr *sa); +void xsendto(int sockfd, void *buf, size_t len, struct sockaddr *dest); // password.c int get_salt(char *salt, char * algo); diff --git a/lib/net.c b/lib/net.c index 136536fe..4467f1fd 100644 --- a/lib/net.c +++ b/lib/net.c @@ -126,3 +126,12 @@ char *ntop(struct sockaddr *sa) return libbuf; } + +void xsendto(int sockfd, void *buf, size_t len, struct sockaddr *dest) +{ + int rc = sendto(sockfd, buf, len, 0, dest, + dest->sa_family == AF_INET ? sizeof(struct sockaddr_in) : + sizeof(struct sockaddr_in6)); + + if (rc != len) perror_exit("sendto"); +} diff --git a/toys/net/ping.c b/toys/net/ping.c index 1829af71..bc3381d8 100644 --- a/toys/net/ping.c +++ b/toys/net/ping.c @@ -55,15 +55,6 @@ GLOBALS( unsigned long sent, recv, fugit, min, max; ) -static void xsendto(int sockfd, void *buf, size_t len, struct sockaddr *dest) -{ - int rc = sendto(TT.sock, buf, len, 0, dest, - dest->sa_family == AF_INET ? sizeof(struct sockaddr_in) : - sizeof(struct sockaddr_in6)); - - if (rc != len) perror_exit("sendto"); -} - static void summary(int sig) { if (!(toys.optflags&FLAG_q) && TT.sent && TT.sa) { -- cgit v1.2.3