in breve sono agli inizi della programmazione di rete e sto scrivendo un programma in ambiente C/Linux che prende inizialmente un link da riga di comando, lo divide in dominio e pagina rispettivamente con due funzioni web_address_domain e requested_page, inserisce queste due parti in una struttura da 200 elementi [dove entrerà anche altro] e poi usa questo link per scaricare il codice html dell'indirizzo web immesso passandolo ad una funzione htmlget [mutuata da http://coding.debuntu.org/c-linux-socke ... ttp-client] contenuta in una libreria personalizzata di nome setup.h. E' importante sottolineare che voglio che htmlget sia costruita in modo tale da leggere l'indirizzo dalla struttura e non da riga di comando come in quella "preconfezionata". Detto questo ecco gli errori di compilazione che non capisco:
setup.h: In function ‘htmlget’:
setup.h:446: warning: assignment makes pointer from integer without a cast
setup.h:466: warning: assignment makes pointer from integer without a cast
So bene che i suddetti errori escono fuori per colpa di queste due righe in setup.h
host = webdomain;
page = webpage;
ma non ho capito come correggerle
Vi sarei quindi particolarmente grato se mi faceste vedere gli errori del codice proposto più che fornire soluzioni molto diverse da questa
Il codice di interesse dentro il main:
- Codice: Seleziona tutto
char *domain_name;
char *page_name;
struct list result[200];
[...]
domain_name = web_address_domain(argv[2]); //esaminare correttezza da qui in poi, prima funziona
result[0].webdomain = domain_name;
page_name = requested_page(argv[2]);
result[0].webpage = requested_page(argv[2]);
printf("\n\n");
htmlget(domain_name, page_name);
Il codice di interesse dentro setup.h
- Codice: Seleziona tutto
struct list
{
[...]
char *webdomain;
char *webpage;
};
int htmlget(char *webdomain, char *webpage)
{
struct sockaddr_in *remote;
int sock;
int tmpres;
char *ip;
char *get;
char buf[BUFSIZ+1];
char *host;
char *page;
host = webdomain;
page = webpage;
sock = create_tcp_socket();
ip = get_ip(host); //line 446
fprintf(stderr, "IP is %s\n", ip);
remote = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in *));
remote->sin_family = AF_INET;
tmpres = inet_pton(AF_INET, ip, (void *)(&(remote->sin_addr.s_addr)));
if(tmpres < 0)
{
perror("Can't set remote->sin_addr.s_addr");
exit(1);
}else if(tmpres == 0)
{
fprintf(stderr, "%s is not a valid IP address\n", ip);
exit(1);
}
remote->sin_port = htons(PORT);
if(connect(sock, (struct sockaddr *)remote, sizeof(struct sockaddr)) < 0){
perror("Could not connect");
exit(1);
}
get = build_get_query(host, page); //line 466
fprintf(stderr, "Query is:\n<<START>>\n%s<<END>>\n", get);
[...]
il resto della funzione htmlget e la funzione get_ip sono identiche a quelle lette su coding.debuntu.org
Grazie anticipatamente a chi riuscirà ad aiutarmi e buona giornata!