Commit 714ab988 authored by Simon Morlat's avatar Simon Morlat

belle-sip builds on windows.

Only parsing tests are sucessful.
parent f42c9d12
......@@ -134,6 +134,7 @@ case "$target_os" in
;;
*mingw*)
CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x0501"
LIBS="$LIBS -lws2_32"
;;
esac
......
......@@ -68,6 +68,8 @@ libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS) $(TLS_CFLAGS)
libbellesip_la_LIBADD=libbellesip_generated.la $(ANTLR_LIBS) $(TLS_LIBS)
libbellesip_la_LDFLAGS=-no-undefined
INCLUDES=-I$(top_srcdir)/include
......@@ -78,3 +80,4 @@ CLEANFILES=$(generated_src) *.tokens generated_src_stamp
discovery:
touch specs.cpp
$(CC) $(CFLAGS) -include $(top_builddir)/config.h $(ANTLR_CFLAGS) $(CUNIT_CFLAGS) $(TLS_CFLAGS) -E -P -v -dD specs.cpp
......@@ -193,6 +193,8 @@ struct belle_sip_source{
void belle_sip_socket_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_socket_t fd, unsigned int events, unsigned int timeout_value_ms);
void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_fd_t fd, unsigned int events, unsigned int timeout_value_ms);
void belle_sip_source_uninit(belle_sip_source_t *s);
#define belle_list_next(elem) ((elem)->next)
/* include private headers */
......@@ -434,16 +436,7 @@ void belle_sip_parameters_init(belle_sip_parameters_t *obj);
* Listening points
*/
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_listening_point_t,belle_sip_object_t)
const char *transport;
belle_sip_channel_t * (*create_channel)(belle_sip_listening_point_t *,const char *dest_ip, int port);
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
#define BELLE_SIP_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_listening_point_t)
void belle_sip_listening_point_remove_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan);
#include "listeningpoint_internal.h"
/*
belle_sip_stack_t
......
......@@ -126,12 +126,7 @@ static void belle_sip_source_destroy(belle_sip_source_t *obj){
if (obj->node.next || obj->node.prev){
belle_sip_fatal("Destroying source currently used in main loop !");
}
#ifdef WIN32
if (obj->sock!=(belle_sip_socket_t)-1){
WSACloseEvent(obj->fd);
obj->fd=(WSAEVENT)-1;
}
#endif
belle_sip_source_uninit(obj);
}
static void belle_sip_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_fd_t fd, unsigned int events, unsigned int timeout_value_ms){
......@@ -145,6 +140,17 @@ static void belle_sip_source_init(belle_sip_source_t *s, belle_sip_source_func_t
s->notify=func;
}
void belle_sip_source_uninit(belle_sip_source_t *obj){
#ifdef WIN32
if (obj->sock!=(belle_sip_socket_t)-1){
WSACloseEvent(obj->fd);
obj->fd=(WSAEVENT)-1;
}
#endif
obj->fd=(belle_sip_fd_t)-1;
obj->sock=(belle_sip_socket_t)-1;
}
void belle_sip_socket_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_socket_t sock, unsigned int events, unsigned int timeout_value_ms){
s->sock=sock;
#ifdef WIN32
......
......@@ -240,8 +240,8 @@ void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack,c
belle_sip_channel_input_stream_reset(&obj->input_stream,0);
}
void belle_sip_channel_set_fd(belle_sip_channel_t *obj, int fd, belle_sip_source_func_t datafunc){
belle_sip_fd_source_init((belle_sip_source_t*)obj, datafunc, obj, fd, BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_WRITE, belle_sip_stack_get_transport_timeout(obj->stack));
void belle_sip_channel_set_socket(belle_sip_channel_t *obj, belle_sip_socket_t sock, belle_sip_source_func_t datafunc){
belle_sip_socket_source_init((belle_sip_source_t*)obj, datafunc, obj, sock, BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_WRITE, belle_sip_stack_get_transport_timeout(obj->stack));
}
void belle_sip_channel_add_listener(belle_sip_channel_t *obj, belle_sip_channel_listener_t *l){
......
......@@ -116,7 +116,7 @@ int belle_sip_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen);
/*only used by channels implementation*/
void belle_sip_channel_set_ready(belle_sip_channel_t *obj, const struct sockaddr *addr, socklen_t slen);
void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack, const char *bindip,int localport,const char *peername, int peer_port);
void belle_sip_channel_set_fd(belle_sip_channel_t *obj, int fd, belle_sip_source_func_t datafunc);
void belle_sip_channel_set_socket(belle_sip_channel_t *obj, belle_sip_socket_t sock, belle_sip_source_func_t datafunc);
/*end of channel implementations*/
/**
* pickup last received message. This method take the ownership of the message.
......
......@@ -16,11 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "listeningpoint_internal.h"
#include "belle_sip_internal.h"
void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_stack_t *s, const char *address, int port){
belle_sip_init_sockets();
lp->stack=s;
lp->listening_uri=belle_sip_uri_create(NULL,address);
belle_sip_object_ref(lp->listening_uri);
......@@ -29,6 +29,7 @@ void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_s
}
static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){
belle_sip_listening_point_clean_channels(lp);
belle_sip_message("Listening [%p] on [%s://%s:%i] destroyed" ,lp
,belle_sip_uri_get_transport_param(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
......@@ -36,7 +37,7 @@ static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){
,belle_sip_uri_get_port(BELLE_SIP_LISTENING_POINT(lp)->listening_uri));
belle_sip_object_unref(lp->listening_uri);
lp->channel_listener=NULL; /*does not unref provider*/
belle_sip_uninit_sockets();
}
......
......@@ -19,10 +19,19 @@
#ifndef LISTENINGPOINT_INTERNAL_H_
#define LISTENINGPOINT_INTERNAL_H_
#include "belle_sip_internal.h"
#ifdef HAVE_TLS
#include "gnutls/openssl.h"
#endif
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_listening_point_t,belle_sip_object_t)
const char *transport;
belle_sip_channel_t * (*create_channel)(belle_sip_listening_point_t *,const char *dest_ip, int port);
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
#define BELLE_SIP_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_listening_point_t)
/*
Listening points: base, udp
*/
......@@ -38,6 +47,7 @@ struct belle_sip_listening_point{
void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_stack_t *s, const char *address, int port);
belle_sip_channel_t *_belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp,const char *peer_name, int peer_port, const struct addrinfo *addr);
belle_sip_channel_t *belle_sip_listening_point_create_channel(belle_sip_listening_point_t *ip,const char *dest, int port);
void belle_sip_listening_point_remove_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan);
int belle_sip_listening_point_get_well_known_port(const char *transport);
belle_sip_channel_t *belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp,const char *peer_name, int peer_port);
void belle_sip_listening_point_add_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan);
......@@ -80,3 +90,4 @@ belle_sip_channel_t * belle_sip_channel_new_tls(belle_sip_tls_listening_point_t*
#endif /* LISTENINGPOINT_INTERNAL_H_ */
......@@ -20,6 +20,26 @@
#ifdef WIN32
static int sockets_initd=0;
int belle_sip_init_sockets(void){
if (sockets_initd==0){
WSADATA data;
int err = WSAStartup(MAKEWORD(2,2), &data);
if (err != 0) {
belle_sip_error("WSAStartup failed with error: %d\n", err);
return -1;
}
}
sockets_initd++;
return 0;
}
void belle_sip_uninit_sockets(void){
sockets_initd--;
if (sockets_initd==0) WSACleanup();
}
typedef struct thread_param{
void * (*func)(void *);
void * arg;
......@@ -51,5 +71,40 @@ int belle_sip_thread_join(belle_sip_thread_t thread_h, void **unused)
return 0;
}
int belle_sip_socket_set_nonblocking (belle_sip_socket_t sock)
{
unsigned long nonBlock = 1;
return ioctlsocket(sock, FIONBIO , &nonBlock);
}
const char *belle_sip_get_socket_error_string(){
return belle_sip_get_socket_error_string_from_code(WSAGetLastError());
}
const char *belle_sip_get_socket_error_string_from_code(int code){
static TCHAR msgBuf[256];
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
code,
0, // Default language
(LPTSTR) &msgBuf,
sizeof(msgBuf),
NULL);
/*FIXME: should convert from TCHAR to UTF8 */
return (const char *)msgBuf;
}
#else
int belle_sip_socket_set_nonblocking(belle_sip_socket_t sock){
return fcntl (sock, F_SETFL, fcntl(sock,F_GETFL) | O_NONBLOCK);
}
#endif
......@@ -27,7 +27,7 @@
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <pthread.h>
#else
......@@ -46,8 +46,13 @@
* Socket abstraction layer
*/
int belle_sip_socket_set_nonblocking (belle_sip_socket_t sock);
#if defined(WIN32)
int belle_sip_init_sockets(void);
void belle_sip_uninit_sockets(void);
static inline void close_socket(belle_sip_socket_t s){
closesocket(s);
}
......@@ -56,9 +61,9 @@ static inline int get_socket_error(void){
return WSAGetLastError();
}
const char *getSocketErrorString();
#define belle_sip_get_socket_error_string() getSocketErrorString()
#define belle_sip_get_socket_error_string_from_code(code) getSocketErrorString()
const char *belle_sip_get_socket_error_string();
const char *belle_sip_get_socket_error_string_from_code();
#define usleep(us) Sleep((us)/1000)
static inline int inet_aton(const char *ip, struct in_addr *p){
*(long*)p=inet_addr(ip);
......@@ -70,6 +75,8 @@ static inline int inet_aton(const char *ip, struct in_addr *p){
#else
#define belle_sip_init_sockets() 0
#define belle_sip_uninit_sockets()
static inline void close_socket(belle_sip_socket_t s){
close(s);
}
......
......@@ -16,14 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/socket.h>
#include <netinet/tcp.h>
#include "belle_sip_internal.h"
#include "belle-sip/mainloop.h"
#include "stream_channel.h"
......@@ -34,15 +26,15 @@ static int stream_channel_process_data(belle_sip_channel_t *obj,unsigned int rev
static void stream_channel_uninit(belle_sip_stream_channel_t *obj){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (sock!=-1) stream_channel_close((belle_sip_channel_t*)obj);
belle_sip_socket_t sock = belle_sip_source_get_socket((belle_sip_source_t*)obj);
if (sock!=(belle_sip_socket_t)-1) stream_channel_close((belle_sip_channel_t*)obj);
}
int stream_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
belle_sip_socket_t sock = belle_sip_source_get_socket((belle_sip_source_t*)obj);
int err;
err=send(sock,buf,buflen,0);
if (err==-1){
if (err==(belle_sip_socket_t)-1){
belle_sip_error("Could not send stream packet on channel [%p]: %s",obj,strerror(errno));
return -errno;
}
......@@ -50,10 +42,10 @@ int stream_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen
}
int stream_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
belle_sip_socket_t sock = belle_sip_source_get_socket((belle_sip_source_t*)obj);
int err;
err=recv(sock,buf,buflen,0);
if (err==-1){
if (err==(belle_sip_socket_t)-1){
belle_sip_error("Could not receive stream packet: %s",strerror(errno));
return -errno;
}
......@@ -61,22 +53,22 @@ int stream_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
}
void stream_channel_close(belle_sip_channel_t *obj){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (sock!=-1){
belle_sip_socket_t sock = belle_sip_source_get_socket((belle_sip_source_t*)obj);
if (sock!=(belle_sip_socket_t)-1){
close_socket(sock);
obj->base.fd=-1;
belle_sip_source_uninit((belle_sip_source_t*)obj);
}
}
int stream_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai){
int err;
int tmp;
belle_sip_fd_t sock;
belle_sip_socket_t sock;
tmp=1;
sock=socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
if (sock==-1){
if (sock==(belle_sip_socket_t)-1){
belle_sip_error("Could not create socket: %s",belle_sip_get_socket_error_string());
return -1;
}
......@@ -85,8 +77,8 @@ int stream_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai){
if (err!=0){
belle_sip_error("setsockopt TCP_NODELAY failed: [%s]",belle_sip_get_socket_error_string());
}
fcntl(sock,F_SETFL,fcntl(sock,F_GETFL) | O_NONBLOCK);
belle_sip_channel_set_fd(obj,sock,(belle_sip_source_func_t)stream_channel_process_data);
belle_sip_socket_set_nonblocking(sock);
belle_sip_channel_set_socket(obj,sock,(belle_sip_source_func_t)stream_channel_process_data);
belle_sip_source_set_events((belle_sip_source_t*)obj,BELLE_SIP_EVENT_WRITE|BELLE_SIP_EVENT_ERROR);
belle_sip_main_loop_add_source(obj->stack->ml,(belle_sip_source_t*)obj);
err = connect(sock,ai->ai_addr,ai->ai_addrlen);
......@@ -119,24 +111,24 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_stream_channel_t)=
}
};
int finalize_stream_connection (belle_sip_fd_t fd, struct sockaddr *addr, socklen_t* slen) {
int finalize_stream_connection (belle_sip_socket_t sock, struct sockaddr *addr, socklen_t* slen) {
int err, errnum;
socklen_t optlen=sizeof(errnum);
err=getsockopt(fd,SOL_SOCKET,SO_ERROR,&errnum,&optlen);
err=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void*)&errnum,&optlen);
if (err!=0){
belle_sip_error("Failed to retrieve connection status for fd [%i]: cause [%s]",fd,belle_sip_get_socket_error_string());
belle_sip_error("Failed to retrieve connection status for fd [%i]: cause [%s]",sock,belle_sip_get_socket_error_string());
return -1;
}else{
if (errnum==0){
/*obtain bind address for client*/
err=getsockname(fd,addr,slen);
err=getsockname(sock,addr,slen);
if (err<0){
belle_sip_error("Failed to retrieve sockname for fd [%i]: cause [%s]",fd,belle_sip_get_socket_error_string());
belle_sip_error("Failed to retrieve sockname for fd [%i]: cause [%s]",sock,belle_sip_get_socket_error_string());
return -1;
}
return 0;
}else{
belle_sip_error("Connection failed for fd [%i]: cause [%s]",fd,belle_sip_get_socket_error_string_from_code(errnum));
belle_sip_error("Connection failed for fd [%i]: cause [%s]",sock,belle_sip_get_socket_error_string_from_code(errnum));
return -1;
}
}
......@@ -144,7 +136,7 @@ int finalize_stream_connection (belle_sip_fd_t fd, struct sockaddr *addr, sockle
static int stream_channel_process_data(belle_sip_channel_t *obj,unsigned int revents){
struct sockaddr_storage ss;
socklen_t addrlen=sizeof(ss);
belle_sip_fd_t fd=belle_sip_source_get_fd((belle_sip_source_t*)obj);
belle_sip_socket_t fd=belle_sip_source_get_socket((belle_sip_source_t*)obj);
belle_sip_message("TCP channel process_data");
......
......@@ -30,7 +30,7 @@ BELLE_SIP_DECLARE_CUSTOM_VPTR_END
void stream_channel_close(belle_sip_channel_t *obj);
int stream_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai);
/*return 0 if succeed*/
int finalize_stream_connection (belle_sip_fd_t fd, struct sockaddr *addr, socklen_t* slen);
int finalize_stream_connection(belle_sip_socket_t sock, struct sockaddr *addr, socklen_t* slen);
int stream_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen);
int stream_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen);
#endif /* STREAM_CHANNEL_H_ */
......@@ -16,14 +16,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle_sip_internal.h"
#include "listeningpoint_internal.h"
struct belle_sip_stream_listening_point{
belle_sip_listening_point_t base;
};
static void belle_sip_stream_listening_point_uninit(belle_sip_stream_listening_point_t *lp){
}
......@@ -55,3 +53,4 @@ belle_sip_listening_point_t * belle_sip_stream_listening_point_new(belle_sip_sta
belle_sip_listening_point_init((belle_sip_listening_point_t*)lp,s,ipaddress,port);
return BELLE_SIP_LISTENING_POINT(lp);
}
......@@ -16,12 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/socket.h>
#include <netinet/tcp.h>
#include "listeningpoint_internal.h"
#include "belle_sip_internal.h"
#include "belle-sip/mainloop.h"
#include "stream_channel.h"
#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
......@@ -55,7 +50,7 @@ static void tls_channel_close(belle_sip_tls_channel_t *obj){
}
static void tls_channel_uninit(belle_sip_tls_channel_t *obj){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
belle_sip_socket_t sock = belle_sip_source_get_socket((belle_sip_source_t*)obj);
if (sock!=-1)
tls_channel_close(obj);
}
......@@ -74,12 +69,13 @@ static int tls_channel_send(belle_sip_channel_t *obj, const void *buf, size_t bu
static ssize_t tls_channel_pull_func(gnutls_transport_ptr_t obj, void* buff, size_t bufflen) {
int err=recv(
belle_sip_source_get_fd((belle_sip_source_t *)obj),buff,bufflen,0);
belle_sip_source_get_socket((belle_sip_source_t *)obj),buff,bufflen,0);
if (err==-1 && get_socket_error()!=EWOULDBLOCK){
belle_sip_error("tls_channel_pull_func: %s",belle_sip_get_socket_error_string());
}
return err;
}
static int tls_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
belle_sip_tls_channel_t* channel = (belle_sip_tls_channel_t*)obj;
int err;
......@@ -94,8 +90,8 @@ static int tls_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
int tls_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai){
int err= stream_channel_connect(obj,ai);
if (err==0){
belle_sip_fd_t sock=belle_sip_source_get_fd((belle_sip_source_t*)obj);
belle_sip_channel_set_fd(obj,sock,(belle_sip_source_func_t)tls_process_data);
belle_sip_socket_t sock=belle_sip_source_get_socket((belle_sip_source_t*)obj);
belle_sip_channel_set_socket(obj,sock,(belle_sip_source_func_t)tls_process_data);
return 0;
}
return -1;
......@@ -133,7 +129,7 @@ static int tls_process_data(belle_sip_channel_t *obj,unsigned int revents){
#ifdef HAVE_OPENSSL
char ssl_error_string[128];
#endif /*HAVE_OPENSSL*/
belle_sip_fd_t fd=belle_sip_source_get_fd((belle_sip_source_t*)channel);
belle_sip_socket_t fd=belle_sip_source_get_socket((belle_sip_source_t*)channel);
if (obj->state == BELLE_SIP_CHANNEL_CONNECTING) {
if (!channel->socket_connected) {
if (finalize_stream_connection(fd,(struct sockaddr*)&channel->ss,&addrlen)) {
......
......@@ -16,7 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle_sip_internal.h"
#include "listeningpoint_internal.h"
#ifdef HAVE_OPENSSL
#include "gnutls/openssl.h"
......
......@@ -51,7 +51,7 @@ static int udp_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
int err;
struct sockaddr_storage addr;
socklen_t addrlen=sizeof(addr);
err=recvfrom(chan->sock,buf,buflen,MSG_DONTWAIT,(struct sockaddr*)&addr,&addrlen);
err=recvfrom(chan->sock,buf,buflen,0,(struct sockaddr*)&addr,&addrlen);
if (err==-1 && errno!=EWOULDBLOCK){
belle_sip_error("Could not receive UDP packet: %s",strerror(errno));
......
......@@ -16,11 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle_sip_internal.h"
#include "listeningpoint_internal.h"
struct belle_sip_udp_listening_point{
belle_sip_listening_point_t base;
int sock;
belle_sip_socket_t sock;
belle_sip_source_t *source;
};
......@@ -58,11 +57,11 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_udp_listening_point_t)={
};
static int create_udp_socket(const char *addr, int port){
static belle_sip_socket_t create_udp_socket(const char *addr, int port){
struct addrinfo hints={0};
struct addrinfo *res=NULL;
int err;
int sock;
belle_sip_socket_t sock;
char portnum[10];
snprintf(portnum,sizeof(portnum),"%i",port);
......@@ -102,7 +101,7 @@ static int on_udp_data(belle_sip_udp_listening_point_t *lp, unsigned int events)
if (events & BELLE_SIP_EVENT_READ){
belle_sip_message("udp_listening_point: data to read.");
err=recvfrom(lp->sock,buf,sizeof(buf),MSG_PEEK,(struct sockaddr*)&addr,&addrlen);
err=recvfrom(lp->sock,(void*)buf,sizeof(buf),MSG_PEEK,(struct sockaddr*)&addr,&addrlen);
if (err==-1){
belle_sip_error("udp_listening_point: recvfrom() failed: %s",strerror(errno));
}else{
......@@ -140,11 +139,12 @@ belle_sip_listening_point_t * belle_sip_udp_listening_point_new(belle_sip_stack_
belle_sip_udp_listening_point_t *lp=belle_sip_object_new(belle_sip_udp_listening_point_t);
belle_sip_listening_point_init((belle_sip_listening_point_t*)lp,s,ipaddress,port);
lp->sock=create_udp_socket(ipaddress,port);
if (lp->sock==-1){
if (lp->sock==(belle_sip_socket_t)-1){
belle_sip_object_unref(lp);
return NULL;
}
lp->source=belle_sip_fd_source_new((belle_sip_source_func_t)on_udp_data,lp,lp->sock,BELLE_SIP_EVENT_READ,-1);
lp->source=belle_sip_socket_source_new((belle_sip_source_func_t)on_udp_data,lp,lp->sock,BELLE_SIP_EVENT_READ,-1);
belle_sip_main_loop_add_source(s->ml,lp->source);
return BELLE_SIP_LISTENING_POINT(lp);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment