[asterisk-dev] C Code to connect to Asterisk Manager
Soumya Kat
myth.war.mage at gmail.com
Sat Mar 1 23:58:57 CST 2008
Hi,
>Michael Henderson wrote:
> *msg=(char)"Action: Login\r\nUsername: admin\r\nSecret:
> admin\r\nActionID: 1\r\n\r\n";
>> Russell Bryant wrote:
>>change this to ...
>>
>>strncpy(msg, "Action: blahblahblah\r\n\r\n", sizeof(msg) - 1)
I have changed the code as you said with strcpy and now I can connect with
Asterisk Manager Interface. I can correctly see that admin is trying to
login in from 192.168.0.150. The problem that I am facing now is after
authentication if I try to ping the server the response I get is Response:
Error and states that there is no action.
Here is my code:
#define MAX_MSG_SIZE 3072
#define SERVER_ADDRESS "192.168.0.150"
#define CLIENT_ADDRESS "192.168.0.150"
#define SERVER_PORT 5038
#define CLIENT_PORT 5100
int main()
{
int sd;
struct sockaddr_in serveraddr, clientaddr;
char msg[MAX_MSG_SIZE];
char resp[MAX_MSG_SIZE];
bzero((char *) &serveraddr, sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = inet_addr(SERVER_ADDRESS);
serveraddr.sin_port = htons(SERVER_PORT);
bzero((char *) &clientaddr, sizeof(clientaddr));
clientaddr.sin_family = AF_INET;
clientaddr.sin_addr.s_addr = INADDR_ANY;
clientaddr.sin_port = htons(CLIENT_PORT);
sd = socket(AF_INET, SOCK_STREAM, 0);
bind(sd,(struct sockaddr *) &clientaddr, sizeof(clientaddr));
connect(sd,(struct sockaddr *) &serveraddr, sizeof(serveraddr));
strcpy(msg,"Action: Login\r\nUsername: admin\r\nSecret: admin\r\n\r\n");
send(sd,msg,strlen(msg)+1,0);
recv(sd,resp, sizeof resp,0);
printf("%s",resp);
strcpy(resp," ");
sleep(1);
strcpy(msg,"Action: Ping\r\n\r\n");
send(sd,msg,strlen(msg)+1,0);
recv(sd,resp,sizeof resp,0);
printf("%s",resp) // In here it prints Response: Error.
close(sd);
return(1);
}
Now why is it so ? It should return Response: Pong as I am still connected
with Asterisk Manager.
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20080302/4514d6ab/attachment.htm
More information about the asterisk-dev
mailing list