Hi,<br><br>I have written a C code which would let me connect to the Asterisk Manager Interface. The code compiles successfully but on running the code I get unauthorized login shown in the Asterisk command line console.<br>
<br>Here is my C code:<br><br>#include<stdio.h><br>#include<netdb.h><br>#include<unistd.h><br>#include<string.h><br>#include<arpa/inet.h><br>#include<sys/types.h><br>#include<sys/socket.h><br>
#include<netinet/in.h><br><br>#define MAX_MSG_SIZE 512<br>#define SERVER_ADDRESS "<a href="http://192.168.0.150">192.168.0.150</a>"<br>#define CLIENT_ADDRESS "<a href="http://192.168.0.150">192.168.0.150</a>"<br>
#define SERVER_PORT 5038<br>#define CLIENT_PORT 5100<br><br>int main()<br>{<br> int sd;<br> struct sockaddr_in serveraddr, clientaddr;<br> char msg[MAX_MSG_SIZE];<br><br> bzero((char *) &serveraddr, sizeof(serveraddr));<br>
serveraddr.sin_family = AF_INET;<br> serveraddr.sin_addr.s_addr = inet_addr(SERVER_ADDRESS);<br> serveraddr.sin_port = htons(SERVER_PORT);<br><br> bzero((char *) &clientaddr, sizeof(clientaddr));<br> clientaddr.sin_family = AF_INET;<br>
clientaddr.sin_addr.s_addr = INADDR_ANY;<br> clientaddr.sin_port = htons(CLIENT_PORT);<br><br> sd = socket(AF_INET, SOCK_STREAM, 0);<br> printf("\nCreated socket ...");<br><br> bind(sd,(struct sockaddr *) &clientaddr, sizeof(clientaddr));<br>
printf("\nBinding successful ...");<br><br> connect(sd,(struct sockaddr *) &serveraddr, sizeof(serveraddr));<br> printf("\nConnected ...");<br><br> *msg=(char)"Action: Login\r\nUsername: admin\r\nSecret: admin\r\nActionID: 1\r\n\r\n";<br>
send(sd,msg,strlen(msg)+1,0);<br> close(sd);<br><br> return(1);<br>}<br><br><br><br>Please correct me where I am going wrong. In manager.conf the username and secret has been defined.<br>Thank you.<br>