I have a program that gets 5 random dice throws from random.org over and over. In order to avoid doing getaddrinfo() over and over with the exact same data, I moved some of the code to an initialization function (and an unused finalization function).My issues are:is this a bad idea?can bad things happen to the program in some situations?am I doing the socket thing correctly?Any other pointers, suggestions, criticisms are very welcome.#include <ctype.h>#include <netdb.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/socket.h>#include <sys/types.h>#include <unistd.h>struct Data {    char datetime[20];    int die[5];};struct ConnData {    char cmd[200];    size_t cmdlen;    struct addrinfo *p;    int csock;};int initdata(struct ConnData *cd, const char *url);int fetchpage(char *dst, size_t dstlen, struct ConnData *cd);int killdata(struct ConnData *cd);int process(struct Data *data, const char *html);int save(const struct Data *data);int gotenough(void);int initdata(struct ConnData *cd, const char *url) {    struct addrinfo hints[1];    struct addrinfo *servinfo;    char host[100];    char resource[100];    char *phost, *presource;    const char *ptr;    int rv;    strcpy(host, );    strcpy(resource, );    memset(hints, 0, sizeof hints);    servinfo = NULL;    cd->p = NULL;    phost = host;    presource = resource;    ptr = url + 7; // skip over http://    while (*ptr != '/') *phost++ = *ptr++;    *phost = 0;    while (*ptr) *presource++ = *ptr++;    *presource = 0;    cd->cmdlen = (size_t)sprintf(cd->cmd, GET %s HTTP/1.0\r\n\r\n, resource);    hints->ai_family = AF_UNSPEC;    hints->ai_socktype = SOCK_STREAM;    rv = getaddrinfo(host, 80, hints, &servinfo);    if (rv) {        fprintf(stderr, getaddrinfo: %s\n, gai_strerror(rv));        return 1;    }    for (cd->p = servinfo; cd->p; cd->p = cd->p->ai_next) {        cd->csock = socket(cd->p->ai_family, cd->p->ai_socktype,                           cd->p->ai_protocol);        if (cd->csock == -1) continue; // try next address        rv = connect(cd->csock, cd->p->ai_addr, cd->p->ai_addrlen);        close(cd->csock);        if (rv < 0) continue; // try next address        break; // successful connection    }    if (!cd->p) {        fprintf(stderr, Unable to connect to HTTP server\n);        return 2;    }    freeaddrinfo(servinfo);    return 0;}int killdata(struct ConnData *cd) {    /* nothing to do */    (void)cd;    return 0;}int fetchpage(char *dst, size_t dstlen, struct ConnData *cd) {    ssize_t nbuff = 1;    size_t used = 0;    cd->csock = socket(cd->p->ai_family, cd->p->ai_socktype,                       cd->p->ai_protocol);    connect(cd->csock, cd->p->ai_addr, cd->p->ai_addrlen);    send(cd->csock, cd->cmd, cd->cmdlen, 0);    do {        nbuff = recv(cd->csock, dst + used, dstlen - used - 1, 0);        if (nbuff < 0) {            fprintf(stderr, error obtaining data\n);            return 3;        }        used += (size_t)nbuff;        if (used + 1 == dstlen) break; /* ignore stuff that doesn't fit */    } while (nbuff > 0);    dst[used] = 0;    close(cd->csock);    return 0;}int process(struct Data *data, const char *html) {    char *ptr = NULL;    ptr = strstr(html, <p>You rolled 5 dice:</p>);    if (!ptr) return 1;    for (int k = 0; k < 5; k++) {        ptr = strstr(ptr, .png\ alt=\);        if (!ptr) return k + 2;        ptr += 11;        data->die[k] = atoi(ptr);    }    ptr = strstr(ptr, <p>Timestamp: );    if (!ptr) return 7;    strncpy(data->datetime, ptr + 14, 19);    data->datetime[19] = 0;    return 0;}int save(const struct Data *data) {    printf(%s:, data->datetime);    for (int k = 0; k < 5; k++) printf( %d, data->die[k]);    printf(\n);    return 0;}int gotenough(void) {    static int n = 0;    n += 1;    return (n == 10);}int main(void) {    unsigned afewseconds = 3;    char html[100000];    char url[] = http://www.random.org/dice/?num=5;    struct Data data[1] = {0};    struct ConnData cd[1] = {0};    if (initdata(cd, url)) goto LBL_INIT;    while (1) {        if (fetchpage(html, sizeof html, cd)) goto LBL_FETCH;        if (process(data, html)) goto LBL_PROCESS;        if (save(data)) goto LBL_SAVE;        if (gotenough()) break;        sleep(afewseconds);    }    if (killdata(cd)) goto LBL_KILL;    goto LBL_FINISH;LBL_KILL:    fprintf(stderr, Killing error (never happens)\n);    goto LBL_FINISH;LBL_SAVE:    fprintf(stderr, Saving error.\n);    goto LBL_FINISH;LBL_PROCESS:    fprintf(stderr, Processing error.\n);    goto LBL_FINISH;LBL_FETCH:    fprintf(stderr, Fetching page error.\n);    goto LBL_FINISH;LBL_INIT:    fprintf(stderr, Initializing data.\n);    goto LBL_FINISH;LBL_FINISH:    return 0;}
Checking web-page repeatedly
c;networking;socket;http