From e52388311e5c076e7dc2ca59e1e5a66b02970eb5 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Thu, 18 Sep 2025 23:07:21 +0200 Subject: [PATCH] remove h_has_internet() --- src/{main.c => hdb.c} | 53 ------------------------------------------- 1 file changed, 53 deletions(-) rename src/{main.c => hdb.c} (81%) diff --git a/src/main.c b/src/hdb.c similarity index 81% rename from src/main.c rename to src/hdb.c index f556ab0..7543fde 100644 --- a/src/main.c +++ b/src/hdb.c @@ -78,53 +78,6 @@ int h_config_parser(Config *config) { return 0; } -int h_has_internet() { - int ret; - - /* https://www.man7.org/linux/man-pages/man3/getaddrinfo.3.html */ - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = 0; - hints.ai_protocol = 0; - struct addrinfo *res, *rp; - ret = getaddrinfo("hopeless-cloud.xyz", "80", 0, &res); - if (ret != 0) { - return 1; - } - int sockfd; - for (rp = res; rp != NULL; rp = rp->ai_next) { - /* https://www.man7.org/linux/man-pages/man2/socket.2.html */ - sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (sockfd == -1) { continue; } - - /* https://www.man7.org/linux/man-pages/man2/connect.2.html */ - if (connect(sockfd, rp->ai_addr, rp->ai_addrlen) == 0) { break; } - - close(sockfd); - } - freeaddrinfo(res); - if (rp == NULL) { - return 1; - } - - /* https://www.man7.org/linux/man-pages/man2/write.2.html */ - char *req_msg = "GET / HTTP/1.1\r\n\r\n"; - if (write(sockfd, req_msg, strlen(req_msg)) != strlen(req_msg)) { - return 1; - } - - /* https://www.man7.org/linux/man-pages/man2/recv.2.html */ - size_t count = 1000000; - char buf[count]; - if (recv(sockfd, buf, count-1, MSG_WAITALL) == -1 ) { - return 1; - } - close(sockfd); - return 0; -} - int h_download(char *line, Config config) { int ret; char *url = malloc(strlen(line)); @@ -179,12 +132,6 @@ int h_download(char *line, Config config) { fprintf(stderr, "Command exited with non-zero code. code = %d\n", ret); - /* TODO: move contents of h_has_internet here */ - ret = h_has_internet(); - if (ret != 0) { - fprintf(stderr, "No internet\n"); - return 1; - } } free(url); free(artist_name);