Problem sending actions from a C code program to the API

Hi everyone,

I just made a little program in C code that allows me to login the the API manager. It works. Now I would like to send an simple action such as a ping but Asterisk doesn’t do anything. I looked thru forums and the syntaxe of my action seems to be correct. I am blocked.

Please help me if you know how to do ?

My C code program :

#include<string.h>
#include<arpa/inet.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>

#define MAX_MSG_SIZE 512
#define ASTERISK_ADDRESS “192.168.68.22 http://192.168.68.22
#define PROGRAM_ADDRESS “192.168.68.22 http://192.168.68.22
#define ASTERISK_PORT 5038
#define PROGRAM_PORT 0

int main()
{

int s;
struct sockaddr_in asteriskaddr, programaddr;
char msg[MAX_MSG_SIZE]; 

bzero((char *) &asteriskaddr, sizeof(asteriskaddr));
asteriskaddr.sin_family = AF_INET;
asteriskaddr.sin_addr.s_addr = inet_addr(ASTERISK_ADDRESS);
asteriskaddr.sin_port = htons(ASTERISK_PORT); 

bzero((char *) &programaddr, sizeof(programaddr));
programaddr.sin_family = AF_INET;
programaddr.sin_addr.s_addr = INADDR_ANY;
programaddr.sin_port = htons(PROGRAM_PORT); 

s = socket(AF_INET, SOCK_STREAM, 0); 
if (socket(AF_INET, SOCK_STREAM, 0) == -1)
	{
		printf("Error creating socket\n");
	}
	else
	{
		printf("Socket created\n");
	}

if (bind(s,(struct sockaddr *) &programaddr, sizeof(programaddr)) == -1)
	{
		printf("Error linking socket\n");
	}
	else
	{
		printf("Socket linked to the communication point\n");
	}

if (connect(s,(struct sockaddr *) &asteriskaddr, sizeof(asteriskaddr)) == -1)
	{
		printf("Error connecting\n");
	}
	else
	{
		printf("Connected Asterisk\n");
    }

char *message1 = "Action: Login\r\nUsername: admin\r\nSecret: asterisk\r\nActionID: 1\r\n\r\n";
if (send(s,message1,strlen(message1)+1,0) == -1)
	{
		printf("Error logging\n");
	}
	else
	{
		printf("Logged\n");
	}

char *message2 = "Action: Ping\r\nActionID: 2\r\n\r\n";
if (send(s,message2,strlen(message2)+1,0) == -1)
	{
		printf("Error ping\n");
	}
	else
	{
		printf("Waiting for a pong\n");
	}

close(s); 

return 0; 

}

My manager.conf :

[general]
enabled=yes
webenabled=yes
port=5038
bindaddr=0.0.0.0
[admin]
secret=asterisk
deny=0.0.0.0/0.0.0.0
permit=192.168.68.22/0.0.0.0
read=all,system,call,log,verbose,command,agent,user,config
write=all,system,call,log,verbose,command,agent,user,config

Thank you in advance, it’s my birthday today!

Edouard