Code:
/* cc -o client client.c -lsocket -lnsl on solaris
* or gcc -o client client.c on linux
* usage: client <server> <port>
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
#include <arpa/inet.h>
#define MSGLEN 100000000
#define MSGLENOUT 100000000
void
E (char *msg){perror (msg);exit (-1);}
void main (int narg, char **args)
{
struct hostent *_hostent;
int _socket;
int _domain = PF_INET;
int _type = SOCK_STREAM;
int _protocol = 0;
int _flags = 0;
int _n;
char _msg[MSGLEN] =
"GET /default.htm HTTP/1.1 \n Referer: http://www.pippo.com \n Connection: Keep-Alive \n User-Agent: Mozilla/4.61 (Machintosh; I; PPC) \n";
char _buf[MSGLEN];
struct sockaddr_in _addr;
int _port = atoi (args[2]);
_hostent = gethostbyname (args[1]);
if (_hostent == NULL) E ("ERROR, no host");
printf ("connectiong...\n");
bcopy (_hostent->h_addr_list[0], &_addr.sin_addr,_hostent->h_length);
_addr.sin_family = AF_INET;
_addr.sin_port = htons (_port);
_socket = socket (_domain, _type, _protocol);
printf ("socket created\n");
if (connect(_socket, (struct sockaddr *) &_addr, sizeof (_addr)) < 0) E ("ERRORE nella connessione");
printf (" connected!\n");
_n = send (_socket, _msg, MSGLEN, _flags);
if (_n < 0) E ("ERROR, send message \n");
printf ("send: %s\n", _msg);
_n = recv (_socket, _buf, MSGLEN, _flags);
if (_n < 0) E ("ERROR, receive message \n");
printf ("recv: %s\n", _buf);
close (_socket);
printf ("close\n");
}
Now that I can look at it