Commit 995481ba authored by Matthew Burket's avatar Matthew Burket

Work on connect

parent 93b71f61
//
// Created by mburket on 4/7/18.
//
#include "buffer.h"
//
// 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
//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
//
// Created by mburket on 3/29/18.
//
#ifndef COMS352_PROJECT2_PART1_CONNECT_H
#define COMS352_PROJECT2_PART1_CONNECT_H
#include <netdb.h>
#include <unistd.h>
#include <memory.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
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
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