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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/*****************************************************************************/
/*** client-socket-Asterisk.c ***/
/*** ***/
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <resolv.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#define PORT_TIME 13 /* "time" (not available on RedHat) */
#define PORT_FTP 5038 /* FTP connection port */
#define SERVER_ADDR "192.168.112.238" /* localhost */
#define MAXBUF "1024" /* DEF Buffer*/
#define LOGINASTERISK "username: testA" /*login connexion asterisk*/
#define PASSASTERISK "secret: MDPtestA" /*MDP connexion asterisk*/
#define ACTION "Action: login" /*Action Serv Asterisk*/
#define EVENT "Events: on" /*Action Serv Asterisk*/
int main()
{ int sockfd;
int errno;
struct sockaddr_in dest;
char buffer[1024];
int taille;
char login;
int retour;
/*---Open socket for streaming---*/
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
{
printf("Socket open fail");
return 0;
}
/*---Initialize server address/port struct---*/
bzero(&dest, sizeof(dest));
dest.sin_family = AF_INET;
dest.sin_port = htons(PORT_FTP);
if ( inet_aton(SERVER_ADDR, &dest.sin_addr.s_addr) == 0 )
{
printf(SERVER_ADDR);
return 0;
}
/*---Connect to server---*/
if ( connect(sockfd, (struct sockaddr*)&dest, sizeof(dest)) != 0 )
{
printf("Connect fail ");
return 0;
}
/*--login-to-asterisk--*/
login = send(sockfd,ACTION,sizeof(buffer),0 );
if (retour == SOCK_STREAM){
return 0;
}
login = send(sockfd,LOGINASTERISK,sizeof(buffer),0 );
if (retour == SOCK_STREAM){
return 0;
}
login = send(sockfd,PASSASTERISK,sizeof(buffer),0 );
if (retour == SOCK_STREAM){
return 0;
}
login = send(sockfd,EVENT,sizeof(buffer),0 );
if (retour == SOCK_STREAM){
return 0;
}
/* login = send(sockfd,LOGINASTERISK,sizeof(buffer),0 );
if (retour == SOCK_STREAM){
return 0;
}*/
/*---Get "Hello?"---*/
while(1)
{
taille=recv(sockfd,& buffer,sizeof(buffer),0);
buffer[taille]='\0';
printf("%s",buffer);
}
printf("\n");
/*---Clean up---*/
printf("close connexion\n");
close(sockfd);
return 0;
} |
Partager