Error in AGI script in c language

hi to all
can anyone solve this problem
c language program ,extension in extensions.confg and error r given below

///////////////////////error displayed in cli////////////////
*CLI> – Registered SIP ‘Exam_controller’ at port 40126 expires 3600
– Executing Answer(“SIP/Exam_controller-0a0f2750”, “”) in new stack
– Executing AGI(“SIP/Exam_controller-0a0f2750”, “zagi.c”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/zagi.c
AGI Tx >> agi_request: zagi.c
AGI Tx >> agi_channel: SIP/Exam_controller-0a0f2750
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1162503099.0
AGI Tx >> agi_callerid: Exam_controller
AGI Tx >> agi_calleridname: Exam_controller
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 555
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: employee
AGI Tx >> agi_extension: 555
AGI Tx >> agi_priority: 2
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
Failed to execute ‘/var/lib/asterisk/agi-bin/zagi.c’: Exec format error
– AGI Script zagi.c completed, returning 0
– Executing Hangup(“SIP/Exam_controller-0a0f2750”, “”) in new stack
== Spawn extension (employee, 555, 3) exited non-zero on ‘SIP/Exam_controller-0a0f2750’
– Incoming call: Got SIP response 500 “Server Internal Error” back from
– Registered SIP ‘PTD’ at port 53910 expires 3600
– Unregistered SIP ‘PTD’


exten => 555,1,answer()
exten => 555,2,agi,zagi.c
exten => 555,3,hangup()

/////////////////// agi script in clanguage saved in
agi-bin folder///////////////////////

#include <stdio.h>
char line[80];
int a=11,i;



if anyone know about AGI scripting in c language so please tell me the requirments that i didn’t fulfill to run it.

positive response will be highly appreciated
ok bye

Ok, I have to admit that I have never bothered to try AGI via Std:IO on my * server but I am instead using fastAGI (actually deadAGI) to connect to a dedicated “business logic” server (running W2003).
But I believe your problem lies in the fact that you are using a .c file as target for the AGI.
As you can see from the agi-test.agi example in /usr/src/asterisk/agi you will see that it’s a perl script accessing the StdIN stream so I would consider it as very unlikely that you can just hand over a c source file and hope for * to first compile and then run it for you.

You might want to try fastAGI to connect to either a remote server or to your loopback interface ( so that you can have your own application listening for incoming tcp connections on port 4573.
You would then run that app (as a tcp server) and once you call the extension Asterisk would start a TCP session with your app and would tell you which script is being run so that you could differentiate your logic accordingly.

Hope that helped.



You first compile the C code and create and specify the executable as the
arg to AGI.

check your brackets… main() is missing one…

I see 3 opening brackets and only 2 closing brackets.

Might cause a compile error…been to long since I did this stuff.

for compiling a c code, in which directory of gcc in fedora core 4 i should place the c source code

you can place the c souce code anywhere u like.
I think you need some help in using “gcc” as well. Try google.
After compiling, put the executable in /var/lib/asterisk/agi-bin/
Use the executable name in the extensions.conf.

hope this helps.