remove h_has_internet()
This commit is contained in:
@@ -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);
|
||||
Reference in New Issue
Block a user