diff --git a/buffer.c b/buffer.c new file mode 100644 index 0000000000000000000000000000000000000000..90bbd2218baa3f5166a6884c534ad5104532140f --- /dev/null +++ b/buffer.c @@ -0,0 +1,5 @@ +// +// Created by mburket on 4/7/18. +// + +#include "buffer.h" diff --git a/buffer.h b/buffer.h new file mode 100644 index 0000000000000000000000000000000000000000..902d831df8823aecd32ab98ef2463be049b26b41 --- /dev/null +++ b/buffer.h @@ -0,0 +1,8 @@ +// +// Created by mburket on 4/7/18. +// + +#ifndef COMS352_PROJECT2_PART1_BUFFER_H +#define COMS352_PROJECT2_PART1_BUFFER_H + +#endif //COMS352_PROJECT2_PART1_BUFFER_H diff --git a/connect.c b/connect.c new file mode 100644 index 0000000000000000000000000000000000000000..5612826391b630f5eb53632e2939585c916866da --- /dev/null +++ b/connect.c @@ -0,0 +1,71 @@ +//w +// Created by mburket on 3/29/18. +// + +#include "connect.h" + +/// Initalize the connection +/// +/// \param hostname hostname to connect to +/// \param port port to connect to +/// \param info addrinfo struct to be returned + void init_connection(char *hostname, int port, struct addrinfo **info) { + struct addrinfo hints; + + memset(&hints,0, sizeof(struct addrinfo)); + hints.ai_family= AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = 0; + hints.ai_protocol = IPPROTO_TCP; + + errno = 0; + + int erro = getaddrinfo(hostname, NULL, &hints, info); + + if (erro != 0) { + fprintf(stderr, "%s", gai_strerror(erro)); + exit(EXIT_FAILURE); + } + +} + + +int establish_connect(struct addrinfo *info) { + int socketfd, connection; + + errno = 0; + socketfd = socket(info->ai_family, info->ai_socktype, info->ai_protocol); + + if (socketfd > 0) { + fprintf(stderr, "\nFailure to create socket.\n"); + fprintf(stderr, "%s", strerror(errno)); + exit(EXIT_FAILURE); + } + + errno = 0; + connection = connect(socketfd, info->ai_addr, info->ai_protocol); + + if (connection != 0) { + fprintf(stderr, "\nUnable to connect.\n"); + fprintf(stderr, "%s", strerror(errno)); + } + + return socketfd; + +} + +int execate_request(int socketfd, char *hostname, char *path) { + char *request = "GET /index.shtml HTTP/1.1\\r\\nHost: www.cs.iastate.edu\\r\\n\\r\\n"; + ssize_t sentByte = send(socketfd, request, strlen(request), 0); + + return sentByte; +} + +int get_result(int socketfd, char *recvBuff, int recvBuffSize) { + int bytesRecv; + + char recvData[recvBuffSize]; + while (1) { + bytesRecv = recv(socketfd, ) + } +} \ No newline at end of file diff --git a/connect.h b/connect.h new file mode 100644 index 0000000000000000000000000000000000000000..7ac67601843ceab15c26b61265d22ddf90d72346 --- /dev/null +++ b/connect.h @@ -0,0 +1,20 @@ +// +// Created by mburket on 3/29/18. +// + +#ifndef COMS352_PROJECT2_PART1_CONNECT_H +#define COMS352_PROJECT2_PART1_CONNECT_H + +#include +#include +#include +#include +#include +#include + +void init_connection(char *hostname, int port, struct addrinfo **info); +int establish_connect(struct addrinfo *info); +int execate_request(int socketfd, char *hostname, char *path); +int get_result(int socketfd, char *recvBuff, int recvBuffSize); + +#endif //COMS352_PROJECT2_PART1_CONNECT_H