1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
const int port = 8008;
const char * message = "Bonjour";
/*void message (char);
void message (char)
{
do
{
}while(1)
}*/
int main(int argc, char ** argv)
{
struct sockaddr_in sock_host;
int sock;
/* ouverture d'une socket */
sock = socket(AF_INET, SOCK_STREAM, 0);
/* on cree l'adresse de la machine distante */
memset(& sock_host, '\0', sizeof(sock_host));
sock_host.sin_family = AF_INET;
sock_host.sin_port = htons(port);
inet_aton("193.1.84.7", & sock_host.sin_addr);
/* on demande une connection sur l'adresse distante */
connect(sock, (struct sockaddr *) & sock_host, sizeof(sock_host));
/* on envoi le message sur le serveur */
write(sock, message, strlen(message));
/* on ferme la socket */
close(sock);
return 0;
} |
Partager