66 lines
1.7 KiB
C
66 lines
1.7 KiB
C
#ifndef _POSIX_C_SOURCE
|
|
#define _POSIX_C_SOURCE 200112L /* Required for networking struct addrinfo */
|
|
#endif /* Unless using std=gnu89 or higher */
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netdb.h>
|
|
|
|
#define RESPONSESIZE 1024*1024*50
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int status, sock;
|
|
char *request = "spartan.mozz.us / 0\r\n";
|
|
char *response;
|
|
struct addrinfo hints;
|
|
struct addrinfo *servinfo;
|
|
|
|
memset(&hints, 0, sizeof hints);
|
|
hints.ai_family = AF_UNSPEC;
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
hints.ai_flags = AI_PASSIVE;
|
|
|
|
status = getaddrinfo("spartan.mozz.us", "300", &hints, &servinfo);
|
|
if(status != 0) {
|
|
fprintf(stderr, "gai error: %s\n", gai_strerror(status));
|
|
exit(1);
|
|
}
|
|
|
|
sock = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
|
|
if(sock == -1){
|
|
fprintf(stderr, "Error obtaining socket\n");
|
|
exit(1);
|
|
}
|
|
|
|
status = connect(sock, servinfo->ai_addr, servinfo->ai_addrlen);
|
|
if(status == -1){
|
|
fprintf(stderr, "Error connecting to host\n");
|
|
exit(1);
|
|
}
|
|
|
|
status = send(sock, request, strlen(request), 0);
|
|
if(status != strlen(request)){
|
|
fprintf(stderr, "Error sending request\n");
|
|
exit(1);
|
|
}
|
|
|
|
response = malloc(RESPONSESIZE);
|
|
memset(response, 0, RESPONSESIZE);
|
|
do {
|
|
status = recv(sock, response, RESPONSESIZE, 0);
|
|
if(status == -1){
|
|
fprintf(stderr, "Error receiving response from server\n");
|
|
exit(1);
|
|
} else {
|
|
response[status] = '\0';
|
|
printf("%s", response);
|
|
}
|
|
} while (status > 0);
|
|
|
|
printf("Success!");
|
|
|
|
return 0;
|
|
}
|