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
|
#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 "AppDWH" /*login connexion asterisk*/
#define PASSASTERISK "AppDWHSecret123" /*MDP connexion asterisk*/
int main()
{ int sockfd;
int errno;
struct sockaddr_in dest;
char buffer[1024];
int taille;
/*---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;
}
/*---Get "Hello?"---*/
while(1)
{
taille=recv(sockfd,& buffer,sizeof(buffer),0);
buffer[taille]='\0';
printf("%s",buffer);
if ((taille=='\0')||(recv==-1)) break;
}
printf("\n");
/*---Clean up---*/
printf("close connexion\n");
close(sockfd);
return 0;
} |
Partager