[asterisk-users] C Code to connect to Asterisk Manager Interface

jonas boering jboergol at yahoo.com.ar
Thu Feb 28 09:40:12 CST 2008


Hi, I believe your problem of authorization is relative to astersik's manager.conf configuration and you need to add and user and password in the manager.conf to have remote access. I have used some examples of voip-info.org, look at this link in the second half part, it explain how to configure the manager.conf file.

http://www.voip-info.org/wiki/view/Asterisk%20Zaptel%20Nagios%20plugin

 # You need a manager entry in /etc/asterisk/manager.conf

# [nagios]

# secret=somesecret

# deny=0.0.0.0/0.0.0.0

# permit=127.0.0.0/255.0.0.0

# permit=111.222.333.444/255.255.255.111 <-- the network nagios connects from

# read = system,call,log,verbose,command,agent,user

# write = system,call,log,verbose,command,agent,user


and in this other link, you can find the Manager API and another examples:

http://www.voip-info.org/wiki/view/Asterisk+manager+API

regards,
               Claro Taroco

----- Mensaje original ----
De: Michael Henderson <mdfromusa at gmail.com>
Para: asterisk-dev at lists.digium.com; asterisk-users at lists.digium.com
Enviado: jueves 28 de febrero de 2008, 5:14:36
Asunto: [asterisk-users] C Code to connect to Asterisk Manager Interface

Hi,

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.

Here is my C code:

#include<stdio.h>
#include<netdb.h>
#include<unistd.h>
#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 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];

    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);
    printf("\nCreated socket ...");

    bind(sd,(struct sockaddr *) &clientaddr, sizeof(clientaddr));
    printf("\nBinding successful ...");

    connect(sd,(struct sockaddr *) &serveraddr, sizeof(serveraddr));
    printf("\nConnected ...");

    *msg=(char)"Action: Login\r\nUsername: admin\r\nSecret: admin\r\nActionID: 1\r\n\r\n";
    send(sd,msg,strlen(msg)+1,0);
    close(sd);

    return(1);
}



Please correct me where I am going wrong. In manager.conf the username and secret has been defined.
Thank you.


-----Sigue archivo adjunto en el mensaje-----

_______________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users






      Los referentes más importantes en compra/ venta de autos se juntaron:
Demotores y Yahoo!
Ahora comprar o vender tu auto es más fácil. Vistá ar.autos.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20080228/fa6185d4/attachment.htm 


More information about the asterisk-users mailing list