2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 01:22:00 +00:00

Cleanup per coverity

Fix a number of concerns that coverity reports
This commit is contained in:
Jarrod Johnson 2022-02-17 17:05:00 -05:00
parent 58b55b6ef6
commit b463a53146
5 changed files with 247 additions and 68 deletions

View File

@ -62,6 +62,10 @@ int main(int argc, char* argv[]) {
exit(0);
}
ttyf = open(buff, O_RDWR | O_NOCTTY);
if (ttyf < 0) {
fprintf(stderr, "Unable to open tty\n");
exit(1);
}
if (currspeed == SPEED9600) {
cspeed = B9600;
strcpy(offset, ",9600");
@ -87,7 +91,9 @@ int main(int argc, char* argv[]) {
cfmakeraw(&tty2);
tcsetattr(ttyf, TCSANOW, &tty2);
flags = fcntl(ttyf, F_GETFL, 0);
fcntl(ttyf, F_SETFL, flags | O_NONBLOCK);
if (fcntl(ttyf, F_SETFL, flags | O_NONBLOCK) < 0) {
fprintf(stderr, "Failed setting flags on tty\n");
}
while (read(ttyf, buff, 64) > 0) {
// Drain any pending reads
}

View File

@ -23,11 +23,16 @@ unsigned char* genpasswd(int len) {
int urandom, ret;
passwd = calloc(len + 1, sizeof(char));
urandom = open("/dev/urandom", O_RDONLY);
if (urandom < 0) {
fprintf(stderr, "Failed reading /dev/urandom\n");
exit(1);
}
ret = read(urandom, passwd, len);
close(urandom);
for (urandom = 0; urandom < len; urandom++) {
passwd[urandom] = cryptalpha[passwd[urandom] >> 2];
}
passwd[len] = 0; // Should be redundant with calloc, but be explicit
return passwd;
}
@ -80,7 +85,9 @@ int main(int argc, char* argv[]) {
for (curr = addrs; curr != NULL; curr = curr->ai_next) {
sock = socket(curr->ai_family, curr->ai_socktype, curr->ai_protocol);
if (sock < 0) continue;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int));
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0) {
fprintf(stderr, "Failed setting reusaddr\n");
}
if (curr->ai_family == AF_INET) {
if (bind(sock, (struct sockaddr*)&net4bind, sizeof(struct sockaddr_in)) < 0) {
fprintf(stderr, "Unable to bind port 302\n");
@ -100,7 +107,9 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "Unable to reach %s\n", argv[2]);
exit(1);
}
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) {
fprintf(stderr, "Unable to set timeout\n");
}
freeaddrinfo(addrs);
ret = read(sock, buffer, 8);
if (memcmp(buffer, "\xc2\xd1-\xa8\x80\xd8j\xba", 8) != 0) {
@ -124,7 +133,7 @@ int main(int argc, char* argv[]) {
memset(buffer, 0, MAXPACKET);
if (currlen > 1000) {
fprintf(stderr, "Received oversized message\n");
exit(1);
exit(1);
}
if (currlen) {
ret = read(sock, buffer, currlen); // Max is 1000, well under MAX_PACKET
@ -137,9 +146,9 @@ int main(int argc, char* argv[]) {
dprintf(sock, "\x04%c%s", slen, cryptedpass);
ret = write(sock, "\x00\x00", 2);
} else if (currtype == 128) {
printf("SEALED:%s", buffer);
printf("\n");
exit(0);
printf("SEALED:%s", buffer);
printf("\n");
exit(0);
} else if (currtype == 5) {
printf("%s", passwd);
printf("\n");

View File

@ -4,42 +4,90 @@
#include <string.h>
int read_part(FILE* img, long int imgsize) {
char mountpath[65537];
char devpath[65537];
char fstype[65537];
char * mountpath;
char * devpath;
char * fstype;
uint16_t shortlength;
uint32_t length;
uint64_t longlength;
fread(&shortlength, 2, 1, img);
if (fread(&shortlength, 2, 1, img) < 2) {
fprintf(stderr, "Error reading section\n");
exit(1);
}
shortlength = be16toh(shortlength);
fread(mountpath, 1, shortlength, img);
mountpath = (char*)malloc(shortlength + 1);
if (fread(mountpath, 1, shortlength, img) < shortlength) {
fprintf(stderr, "Failure reading segment\n");
exit(1);
}
mountpath[shortlength] = 0;
fread(&length, 4, 1, img);
if (fread(&length, 4, 1, img) < 4) {
fprintf(stderr, "Failure reading segment\n");
exit(1);
}
length = be32toh(length);
fseek(img, length, SEEK_CUR); // skip json section that we don't support
fread(&longlength, 8, 1, img); // minimum size in bytes
if (fseek(img, length, SEEK_CUR) != 0) { // skip json section that we don't support
fprintf(stderr, "Error skipping json segment");
exit(1);
}
if (fread(&longlength, 8, 1, img) < 8) { // minimum size in bytes
fprintf(stderr, "Failure reading segment\n");
exit(1);
}
longlength = be64toh(longlength);
printf("%ld\t", longlength);
fread(&longlength, 8, 1, img); // default size in bytes
if (fread(&longlength, 8, 1, img) < 8) { // default size in bytes
fprintf(stderr, "Error reading segment\n");
exit(1);
}
longlength = be64toh(longlength);
printf("%ld\t", longlength);
fread(&shortlength, 2, 1, img); // length of filesystem type
if (fread(&shortlength, 2, 1, img) < 2) { // length of filesystem type
fprintf(stderr, "Error reading segment\n");
exit(1);
}
shortlength = be16toh(shortlength);
fread(fstype, 1, shortlength, img);
fstype = (char*)malloc(shortlength + 1);
if (fread(fstype, 1, shortlength, img) < shortlength) {
fprintf(stderr, "Error reading segment\n");
exit(1);
}
fstype[shortlength] = 0;
fread(&shortlength, 2, 1, img); // length of DEVICE
if (fread(&shortlength, 2, 1, img) < 2) { // length of DEVICE
fprintf(stderr, "Error reading segment\n");
exit(1);
}
shortlength = be16toh(shortlength);
fread(devpath, 1, shortlength, img);
devpath = (char*)malloc(shortlength + 1);
if (fread(devpath, 1, shortlength, img) < shortlength) {
fprintf(stderr, "Error reading segment\n");
exit(1);
}
devpath[shortlength] = 0;
fread(&shortlength, 2, 1, img);
if (fread(&shortlength, 2, 1, img) < 2) {
fprintf(stderr, "Error reading segment\n");
exit(1);
}
shortlength = be16toh(shortlength);
fseek(img, shortlength, SEEK_CUR); // Skip the padding
fread(&longlength, 8, 1, img);
if (fseek(img, shortlength, SEEK_CUR) != 0) { // Skip the padding
fprintf(stderr, "Failure skipping padding\n");
exit(1);
}
if (fread(&longlength, 8, 1, img) < 8) {
fprintf(stderr, "Error reading section\n");
exit(1);
}
longlength = be64toh(longlength);
printf("%ld\t", ftell(img) / 512);
printf("%ld\t", longlength / 512);
printf("%s\t%s\t%s\n", fstype, devpath, mountpath);
fseek(img, longlength, SEEK_CUR);
free(mountpath);
free(devpath);
free(fstype);
if (fseek(img, longlength, SEEK_CUR) != 0) {
fprintf(stderr, "Error restoring seek\n");
exit(1);
}
return (ftell(img) < imgsize);
}
@ -62,15 +110,30 @@ int main(int argc, char* argv[]) {
}
if (memcmp(buffer, "\x63\x7b\x9d\x26\xb7\xfd\x48\x30\x89\xf9\x11\xcf\x18\xfd\xff\xa1", 16) == 0) {
printf("Format: confluent_multisquash\nminsize\tdefsize\toffset\tsize\tfstype\torigdev\tmount\n");
fread(buffer, 1, 1, img);
fseek(img, buffer[0], SEEK_CUR);
if (fread(buffer, 1, 1, img) < 1) {
fprintf(stderr, "Error reading image\n");
exit(1);
}
if (fseek(img, buffer[0], SEEK_CUR) != 0) {
fprintf(stderr, "Error seeking in image\n");
exit(1);
}
while (read_part(img, imgsize));
exit(0);
}
if (memcmp(buffer, "\xaa\xd5\x0f\x7e\x5d\xfb\x4b\x7c\xa1\x2a\xf4\x0b\x6d\x94\xf7\xfc", 16) == 0) {
fread(buffer, 1, 1, img);
fseek(img, buffer[0], SEEK_CUR);
fread(buffer, 1, 1, img);
if (fread(buffer, 1, 1, img) < 1) {
fprintf(stderr, "Error reading image\n");
exit(1);
}
if (fseek(img, buffer[0], SEEK_CUR) != 0) {
fprintf(stderr, "Error reading image\n");
exit(1);
}
if (fread(buffer, 1, 1, img) < 1) {
fprintf(stderr, "Error reading image\n");
exit(1);
}
if (buffer[0] == 0) {
printf("Format: confluent_crypted\n");
exit(0);

View File

@ -13,11 +13,21 @@
#include <sys/time.h>
#include <net/if.h>
typedef struct sockaddr_llib {
unsigned short int sll_family;
unsigned short int sll_protocol;
int sll_ifindex;
unsigned short int sll_hatype;
unsigned char sll_pkttype;
unsigned char sll_halen;
unsigned char sll_addr[20];
} sockaddr_llib;
int add_uuid(char* destination, int maxsize) {
int uuidf;
int uuidsize;
uuidf = open("/sys/devices/virtual/dmi/id/product_uuid", O_RDONLY);
if (uuidf < 1) { return 0; }
if (uuidf < 0) { return 0; }
strncpy(destination, "/uuid=", maxsize);
uuidsize = read(uuidf, destination + 6, maxsize - 6);
close(uuidf);
@ -31,7 +41,7 @@ int add_confluent_uuid(char* destination, int maxsize) {
int uuidf;
int uuidsize;
uuidf = open("/confluent_uuid", O_RDONLY);
if (uuidf < 1) { return 0; }
if (uuidf < 0) { return 0; }
strncpy(destination, "/confluentuuid=", maxsize);
uuidsize = read(uuidf, destination + 15, maxsize - 15);
close(uuidf);
@ -43,7 +53,7 @@ int add_confluent_uuid(char* destination, int maxsize) {
void add_macs(char* destination, int maxsize) {
struct ifaddrs *ifc, *ifa;
struct sockaddr_ll *lla;
struct sockaddr_llib *lla;
int offset;
char macaddr[32];
@ -52,7 +62,7 @@ void add_macs(char* destination, int maxsize) {
for (ifc = ifa; ifc != NULL; ifc = ifc->ifa_next) {
if (ifc->ifa_addr->sa_family != AF_PACKET)
continue;
lla = (struct sockaddr_ll *)ifc->ifa_addr;
lla = (struct sockaddr_llib *)ifc->ifa_addr;
if (lla->sll_hatype == ARPHRD_INFINIBAND) {
snprintf(macaddr, 32, "/mac=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
lla->sll_addr[12], lla->sll_addr[13], lla->sll_addr[14],
@ -127,12 +137,30 @@ int main(int argc, char* argv[]) {
offset = strnlen(msg, 1024);
ns = socket(AF_INET6, SOCK_DGRAM, 0);
n4 = socket(AF_INET, SOCK_DGRAM, 0);
if (ns < 0) {
fprintf(stderr, "Error opening IPv6 socket\n");
exit(1);
}
if (n4 < 0) {
fprintf(stderr, "Error opening IPv4 socket\n");
exit(1);
}
ifidx = 1; /* reuse ifidx because it's an unused int here */
setsockopt(n4, SOL_SOCKET, SO_BROADCAST, &ifidx, sizeof(ifidx));
setsockopt(ns, IPPROTO_IPV6, IPV6_V6ONLY, &ifidx, sizeof(ifidx));
if (setsockopt(n4, SOL_SOCKET, SO_BROADCAST, &ifidx, sizeof(ifidx)) != 0) {
fprintf(stderr, "Unable to set broadcast on socket\n");
}
if (setsockopt(ns, IPPROTO_IPV6, IPV6_V6ONLY, &ifidx, sizeof(ifidx)) != 0) {
fprintf(stderr, "Unable to limit socket to IPv6 only\n");
}
/* For now, bind to 190 to prove we are a privileged process */
bind(n4, (const struct sockaddr *)&addr4, sizeof(addr4));
bind(ns, (const struct sockaddr *)&addr, sizeof(addr));
if (bind(n4, (const struct sockaddr *)&addr4, sizeof(addr4)) < 0) {
fprintf(stderr, "Eror binding privilged port!\n");
exit(1);
}
if (bind(ns, (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
fprintf(stderr, "Error binding ipv6 privileged port!\n");
exit(1);
}
getifaddrs(&ifa);
for (ifc = ifa; ifc != NULL; ifc = ifc->ifa_next) {
if (!ifc->ifa_addr) continue;
@ -143,15 +171,23 @@ int main(int argc, char* argv[]) {
if (in6->sin6_scope_id == 0)
continue;
ifidx = in6->sin6_scope_id;
setsockopt(ns, IPPROTO_IPV6, IPV6_MULTICAST_IF, &ifidx, sizeof(ifidx));
sendto(ns, msg, strnlen(msg, 1024), 0, (const struct sockaddr *)&dst, sizeof(dst));
if (setsockopt(ns, IPPROTO_IPV6, IPV6_MULTICAST_IF, &ifidx, sizeof(ifidx)) != 0)
continue;
if (sendto(ns, msg, strnlen(msg, 1024), 0, (const struct sockaddr *)&dst, sizeof(dst)) < 0) {
continue;
}
} else if (ifc->ifa_addr->sa_family == AF_INET) {
in = (struct sockaddr_in *)ifc->ifa_addr;
bin = (struct sockaddr_in *)ifc->ifa_ifu.ifu_broadaddr;
bin->sin_port = htons(1900);
setsockopt(n4, IPPROTO_IP, IP_MULTICAST_IF, &in->sin_addr, sizeof(in->sin_addr));
sendto(n4, msg, strnlen(msg, 1024), 0, (const struct sockaddr *)&dst4, sizeof(dst4));
sendto(n4, msg, strnlen(msg, 1024), 0, (const struct sockaddr *)bin, sizeof(*bin));
if (setsockopt(n4, IPPROTO_IP, IP_MULTICAST_IF, &in->sin_addr, sizeof(in->sin_addr)) != 0)
continue;
if (sendto(n4, msg, strnlen(msg, 1024), 0, (const struct sockaddr *)&dst4, sizeof(dst4)) < 0) {
// ignore failure to send, we are trying to be opportunistic
}
if (sendto(n4, msg, strnlen(msg, 1024), 0, (const struct sockaddr *)bin, sizeof(*bin)) < 0) {
continue;
}
}
}
FD_ZERO(&rfds);

View File

@ -39,9 +39,9 @@ typedef struct downloadbuffer {
#define MAX_FILE_LEN 1024
#define MAX_URL_PATHS 512
static char filename[MAX_FILE_LEN];
static char filename[MAX_FILE_LEN + 1];
static int urlidx, newidx;
static char* urls[MAX_URL_PATHS];
static char* urls[MAX_URL_PATHS + 1];
void *http_rechecker(void *argp) {
@ -50,21 +50,36 @@ void *http_rechecker(void *argp) {
tmpidx = open("/dev/urandom", O_RDONLY);
if (tmpidx <= 0 || read(tmpidx, (char*)&tmpval, 4) < 0)
tmpval = time(NULL);
if (tmpidx > 0)
if (tmpidx >= 0)
close(tmpidx);
srand(tmpval);
checkurl = curl_easy_init();
curl_easy_setopt(checkurl, CURLOPT_ERRORBUFFER, curlerror);
if (curl_easy_setopt(checkurl, CURLOPT_ERRORBUFFER, curlerror) != CURLE_OK) {
fprintf(stderr, "Error buffer\n");
exit(1);
}
//We want to consider error conditions fatal, rather than
//passing error text as data
curl_easy_setopt(checkurl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(checkurl, CURLOPT_TIMEOUT, 10L);
curl_easy_setopt(checkurl, CURLOPT_NOBODY, 1);
if (curl_easy_setopt(checkurl, CURLOPT_FAILONERROR, 1L) != CURLE_OK) {
fprintf(stderr, "Fail on error\n");
exit(1);
}
if (curl_easy_setopt(checkurl, CURLOPT_TIMEOUT, 10L) != CURLE_OK) {
fprintf(stderr, "Error setting timeout\n");
exit(1);
}
if (curl_easy_setopt(checkurl, CURLOPT_NOBODY, 1) != CURLE_OK) {
fprintf(stderr, "Error setting nobody\n");
exit(1);
}
while (1) {
sleep(25 + rand() % 10); // Spread out retries across systems
sleep(25 + tmpval % 10); // Spread out retries across systems
tmpidx = 0;
while (tmpidx < urlidx && tmpidx < newidx && urls[tmpidx] != NULL) {
curl_easy_setopt(checkurl, CURLOPT_URL, urls[tmpidx]);
if (curl_easy_setopt(checkurl, CURLOPT_URL, urls[tmpidx]) != CURLE_OK) {
tmpidx++;
continue;
}
if (curl_easy_perform(checkurl) == CURLE_OK)
newidx = tmpidx;
else
@ -120,8 +135,14 @@ static int http_read(const char *path, char *buf, size_t size, off_t offset,
if (offset >= filesize) return 0;
if (offset + size - 1 >= filesize) size = filesize - offset - 1;
snprintf(headbuffer, 512, "%ld-%ld", offset, offset + size - 1);
curl_easy_setopt(curl, CURLOPT_RANGE, headbuffer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &dlbuf);
if (curl_easy_setopt(curl, CURLOPT_RANGE, headbuffer) != CURLE_OK) {
fprintf(stderr, "Error setting range\n");
exit(1);
}
if (curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&dlbuf) != CURLE_OK) {
fprintf(stderr, "Error setting writedata\n");
exit(1);
}
if (newidx < MAX_URL_PATHS) {
reconnecting = 1;
urlidx = newidx;
@ -129,7 +150,8 @@ static int http_read(const char *path, char *buf, size_t size, off_t offset,
fd = fopen("/dev/kmsg", "w+");
fprintf(fd, "<5>urlmount: Connecting to %s\n", urls[urlidx]);
fclose(fd);
curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]);
// if fail, carry on and take the error in curl_easy_perform instead
if (curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]) != CURLE_OK) {}
}
while (curl_easy_perform(curl) != CURLE_OK) {
reconnecting = 1;
@ -138,6 +160,8 @@ static int http_read(const char *path, char *buf, size_t size, off_t offset,
fprintf(fd, "<4>urlmount: error while communicating with %s: %s\n", urls[urlidx], curlerror);
fclose(fd);
urlidx++;
if (urlidx > MAX_URL_PATHS)
urlidx = 0;
if (urls[urlidx] == NULL)
urlidx = 0;
if (urlidx == startidx) {
@ -149,7 +173,12 @@ static int http_read(const char *path, char *buf, size_t size, off_t offset,
fd = fopen("/dev/kmsg", "w+");
fprintf(fd, "<5>urlmount: Connecting to %s\n", urls[urlidx]);
fclose(fd);
curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]);
if (urlidx > MAX_URL_PATHS) {
fprintf(stderr, "Maximum url path exceeded\n");
exit(1);
}
// ignore, let the curl_easy_perform get the error
if (curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]) != CURLE_OK) {}
}
if (reconnecting) {
fd = fopen("/dev/kmsg", "w+");
@ -180,13 +209,28 @@ static void* http_init(struct fuse_conn_info *conn) {
curl_global_init(CURL_GLOBAL_DEFAULT);
pthread_create(&tid, NULL, http_rechecker, NULL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlerror);
if (curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlerror) != CURLE_OK) {
fprintf(stderr, "Failure initializing libcurl error buffor\n");
exit(1);
}
//We want to consider error conditions fatal, rather than
//passing error text as data
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fill_buffer);
if (curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L) != CURLE_OK) {
fprintf(stderr, "Failure initializing libcurl failonerror\n");
exit(1);
}
if (curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L) != CURLE_OK) {
fprintf(stderr, "Failure initializing libcurl timeout\n");
exit(1);
}
if (curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]) != CURLE_OK) {
fprintf(stderr, "Failure initializing url\n");
exit(1);
}
if (curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fill_buffer) != CURLE_OK) {
fprintf(stderr, "Failure initializing libcurl fill buffer\n");
exit(1);
}
return NULL;
}
@ -225,11 +269,20 @@ int main(int argc, char* argv[]) {
newidx = MAX_URL_PATHS;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlerror);
if (curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlerror) != CURLE_OK) {
fprintf(stderr, "Unable to set error buffer\n");
exit(1);
}
//We want to consider error conditions fatal, rather than
//passing error text as data
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15L);
if (curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L) != CURLE_OK) {
fprintf(stderr, "Unable to set fail on error\n");
exit(1);
}
if (curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15L) != CURLE_OK) {
fprintf(stderr, "Unable to setup curl timeout\n");
exit(1);
}
memset(filename, 0, MAX_FILE_LEN);
for (i=0; i < argc; i++) {
if (strstr(argv[i], ":") > 0) {
@ -252,8 +305,12 @@ int main(int argc, char* argv[]) {
}
j = urlidx;
printf("Connecting to %s\n", urls[urlidx]);
curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
if (curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]) != CURLE_OK) {
fprintf(stderr, "Unable to set url\n");
}
if (curl_easy_setopt(curl, CURLOPT_NOBODY, 1) != CURLE_OK) {
fprintf(stderr, "Failure setting no body\n");
}
while (curl_easy_perform(curl) != CURLE_OK) {
fprintf(stderr, "urlmount: error while communicating with %s: %s\n", urls[urlidx++], curlerror);
if (urls[urlidx] == NULL)
@ -263,12 +320,20 @@ int main(int argc, char* argv[]) {
exit(1);
}
printf("Connecting to %s\n", urls[urlidx]);
curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]);
if (curl_easy_setopt(curl, CURLOPT_URL, urls[urlidx]) != CURLE_OK) {
fprintf(stderr, "Unable to set url\n");
}
}
printf("Successfully connected to %s\n", urls[urlidx]);
curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fsize);
if (curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fsize) != CURLE_OK) {
fprintf(stderr, "Failed getting content length\n");
exit(1);
}
filesize = round(fsize);
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
if (curl_easy_setopt(curl, CURLOPT_NOBODY, 0) != CURLE_OK) {
fprintf(stderr, "Failed setting nobody\n");
exit(1);
}
if (filesize < 1) {
fprintf(stderr, "Unable to reach designated URL\n");
exit(1);