Home > other >  Implement a UAC eXosip, can only send can't accept it
Implement a UAC eXosip, can only send can't accept it

Time:10-16

Hello, everyone, I'm going to use libosip2 and libeXosip2 implement A client (hereinafter referred to as uac demo), first going to do A demo program, to the specified Sip Server to Register, and Register to the same soft phone A call to the Server, but unable to sign up for success, I looked at it and send out after A Register message uac demo, received A 401 Challenge message, then the uac demo, there is no response, the program code is as follows:
# include & lt; EXosip2/eXosip. H>
# include & lt; EXosip2/eXosip2. H>
# include & lt; Pthread. H>
# include & lt; Netinet/in. H>
# include & lt; Unistd. H>
# include & lt; Stdlib. H>

Int32_t sip_init_reg int32_t (id);
Int32_t sip_init_call (int32_t dst_id);

EXosip_t * excontext;
Uint8_t proxy_ip_str [16]="10.1.1.2";

Int main (void)
{
Int32_t I, mtx_ret;
Uint32_t phone_number=30020209;
Uint16_t port;
Pthread_t dar.

TRACE_INITIALIZE (6, stdout);
Port=12345;

Excontext=(eXosip_t *) malloc (sizeof (eXosip_t));
If (NULL==excontext)
{
Fprintf (stderr, "excontext malloc failed! \n");
return -1;
}

I=eXosip_init (excontext);
If (I.=0)
{
Fprintf (stderr, "eXosip_init failed! \n");
return -1;
}

EXosip_set_user_agent (excontext, "uac - demo");

I=eXosip_listen_addr (excontext IPPROTO_UDP, NULL, port, AF_INET, 0).
If (I.=0)
{
EXosip_quit (excontext);
Fprintf (stderr, "could not initialize the transport layer \ n");
return -1;
}
If (sip_init_reg (phone_number) & lt; 0)
{
Fprintf (stderr, "sip init register failed! \n");
return -1;
}
getchar();//prevent programs too fast exit
Free (excontext);
return 0;
}

Int32_t sip_init_reg (int32_t id)
{
Reg osip_message_t *=NULL;
Int32_t I;
Int32_t regid;
Uint8_t userid [16].
Uint8_t passwd [16].
Char from [50];
Char contact [50].
Char proxy [50].
Char ip_buf [16].
Memset (userid, 0);
Memset (passwd, 0);
Memset (from 0, 50);
Memset (contact, 0, 50);
Memset (proxy, 0, 50);
Memset (ip_buf, 0);

Snprintf (userid, 9, "% d", id);
Snprintf (passwd, 4, "% s", "123");

EXosip_lock (excontext);
I=eXosip_add_authentication_info (excontext, userid, userid, passwd, "MD5", NULL);
If (I & lt; 0)
{
Fprintf (stderr, "add authentication info failed! \n");
return -1;
}

Sprintf (ip_buf, "% s", "10.1.1.100");
Sprintf (the from, "sip: % d @ % s", 30020209, ip_buf);
Sprintf (contact, "sip: % d @ % s: % d", 30020209, ip_buf, 12345);
Sprintf (proxy, "sip: % s: % d", "10.10.1.2", 5060);
Regid=eXosip_register_build_initial_register (excontext, the from, proxy, contact, 1800, & amp; Reg);
Printf (" regid=% d \ n ", regid);
If (regid & lt; 0)
{
Fprintf (stderr, "build initial register failed! \n");
return -1;
}
100 rel osip_message_set_supported (reg, "");
Osip_message_set_supported (reg, "path");
I=eXosip_register_send_register (excontext, regid, reg);
If (I & lt; 0)
{
Fprintf (stderr, "send the register failed! \n");
return -1;
}
EXosip_unlock (excontext);
return 0;
}

Server IP: 10.1.1.2
Server port: 5060

The local IP: 10.1.1.100
Local port: 12345


The question now is whether the server to the client after a 401 Challenge, the client is not then send the Register, it looks as if the client didn't receive 401 message,
Add: client runs on Linux, libeXosip2 support multithreading, and through the GDB tools found eXosip_listen_addr statement execution, program produced a new thread;
Here ask me what's the problem with the above code? Thank you very much!!!!!!
  • Related