Commit 1819c13c authored by Matthew Burket's avatar Matthew Burket

Fix hard coded port 80

parent cf2b48ef
Pipeline #339 passed with stage
in 15 seconds
This diff is collapsed.
......@@ -5,6 +5,9 @@
#include "connect.h"
#include "buffer.h"
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int calc_date(char *deltaString, char *returnTime);
......@@ -22,9 +25,14 @@ int calc_date(char *deltaString, char *returnTime);
hints.ai_flags = 0;
hints.ai_protocol = IPPROTO_TCP;
// Need to convert to string
// https://stackoverflow.com/a/32819876
int len = snprintf(NULL, 0, "%d", port);
char portString[6];
snprintf(portString,len+1, "%d",port);
errno = 0;
int erro = getaddrinfo(hostname, "80", &hints, info);
int erro = getaddrinfo(hostname, portString, &hints, info);
if (erro != 0) {
fprintf(stderr, "%s", gai_strerror(erro));
......
......@@ -54,9 +54,7 @@ int main (int argc, char **argv) {
}
}
for (index = optind; index < argc; index++) {
printf("Non-option argument %s\n", argv[index]);
}
for (index = optind; index < argc; index++);
if (argv[optind] == NULL) {
show_help_exit(argv[0]);
......@@ -66,7 +64,7 @@ int main (int argc, char **argv) {
int port = 80;
char *page = malloc(sizeof(char) * 256);
getUrlParts(argv[optind], &host, &port, &page);
init_connection(host, 80, &addressInfo);
init_connection(host, port, &addressInfo);
int sockfd = establish_connect(addressInfo);
execate_request(sockfd, host, page, header_only, timeDelta, cvalue);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment