软件版本: libosip2-3.3.0.tar.gz libeXosip2-3.3.0.tar.gz ./configure --prefix=/opt/sip/target --disable-static make make install 测试代码: 代码来源:http://blog.csdn.net/bat603/archive/2006/11/15/1386277.aspx 1、UAS //*******************U
软件版本:
libosip2-3.3.0.tar.gz
libeXosip2-3.3.0.tar.gz
./configure --prefix=/opt/sip/target --disable-static
make
make install
测试代码:
代码来源:http://blog.csdn.net/bat603/archive/2006/11/15/1386277.aspx
1、UAS
//*******************UAS**************************************************//
#include #include #include #include #include #include #include int
main (int argc, char *argv[])
{
eXosip_event_t *je = NULL;
osip_message_t *ack = NULL;
osip_message_t *invite = NULL;
osip_message_t *answer = NULL;
sdp_message_t *remote_sdp = NULL;
int call_id, dialog_id;
int i,j;
int id;
char *sour_call = "sip:133@192.168.0.133";
char *dest_call = "sip:140@192.168.0.140:5060";
char command;
char tmp[4096];
char localip[128];
int pos = 0;
//初始化sip
i = eXosip_init ();
if (i != 0)
{
printf ("Can't initialize eXosip!/n");
return -1;
}
else
{
printf ("eXosip_init successfully!/n");
}
i = eXosip_listen_addr (IPPROTO_UDP, NULL, 5060, AF_INET, 0);
if (i != 0)
{
eXosip_quit ();
fprintf (stderr, "eXosip_listen_addr error!/nCouldn't initialize transport layer!/n");
}
for(;;)
{
//侦听是否有消息到来
je = eXosip_event_wait (0,50);
//协议栈带有此语句,具体作用未知
eXosip_lock ();
eXosip_default_action (je);
eXosip_automatic_refresh ();
eXosip_unlock ();
if (je == NULL)//没有接收到消息
continue;
// printf ("the cid is %s, did is %s/n", je->did, je->cid);
switch (je->type)
{
case EXOSIP_MESSAGE_NEW://新的消息到来
printf (" EXOSIP_MESSAGE_NEW!/n");
if (MSG_IS_MESSAGE (je->request))//如果接受到的消息类型是MESSAGE
{
{
osip_body_t *body;
osip_message_get_body (je->request, 0, &body);
printf ("I get the msg is: %s/n", body->body);
//printf ("the cid is %s, did is %s/n", je->did, je->cid);
}
//按照规则,需要回复200 OK信息
eXosip_message_build_answer (je->tid, 200,&answer);
eXosip_message_send_answer (je->tid, 200,answer);
}
break;
case EXOSIP_CALL_INVITE:
//得到接收到消息的具体信息
printf ("Received a INVITE msg from %s:%s, UserName is %s, password is %s/n",je->request->req_uri->