diff --git a/testing/test_bins/udp_send.c b/testing/test_bins/udp_send.c index e3a5f06c..b3ff59ce 100644 --- a/testing/test_bins/udp_send.c +++ b/testing/test_bins/udp_send.c @@ -1,43 +1,48 @@ -#include -#include -#include +#define _GNU_SOURCE /* program_invocation_name */ +#include +#include + #include -#include + +#include + +#include #include #include #include -#include -#include -#include -#include +#include +#include -#define BUFFER_SIZE 512 +int +main(int argc, char *argv[]) +{ + struct sockaddr_in sin; + int sock, ch, do_connect; + ssize_t n; + char* inaddr = "127.0.0.1"; + uint64_t buf[] = { + 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, + 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef + }; -char buffer[BUFFER_SIZE]; + bzero(&sin, sizeof(sin)); -int main(int argc, char **argv) -{ - int sockfd; - struct sockaddr_in server; - - memset(&buffer, 0xff, sizeof(buffer)); - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd < 0) { - fprintf(stderr, "Error opening socket"); - return -1; - } - - bzero((char *)&server, sizeof(server)); - server.sin_family = AF_INET; - server.sin_addr.s_addr = inet_addr("127.0.0.1"); - server.sin_port = htons(53); - printf("sending...\n"); - if (sendto(sockfd, &buffer, BUFFER_SIZE, 0, (const struct sockaddr *)&server, sizeof(server)) < - 0) { - fprintf(stderr, "Error in sendto()\n"); - return -1; - } - - return 0; + + if (inet_aton(inaddr, &sin.sin_addr) == 0) + errx(1, "inet_aton(%s)", inaddr); + sin.sin_port = htons(53); + sin.sin_family = AF_INET; + + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) + err(1, "socket"); + + + n = sendto(sock, buf, sizeof(buf), 0, + (struct sockaddr *)&sin, sizeof(sin)); + if (n == -1) + err(1, "sendto"); + else if (n != sizeof(buf)) + errx(1, "sendto: shortcount"); + + return (0); } \ No newline at end of file