Commit 6e121e37 authored by Simon Morlat's avatar Simon Morlat
Browse files

add resolver test program

parent 597fc1a9
......@@ -61,7 +61,7 @@ BELLESIP_EXPORT struct addrinfo * belle_sip_ip_address_to_addrinfo(int family, c
* @param transport the queried transport ("udp", "tcp", "tls")
* @param name the SIP domain name
* @param port a port that will be filled in the addrinfo list returned by the callback, for the case where no SRV records are found.
* @param family address family expected in the addrinfo result list. AF_INET or AF_INET6. If AF_INET6 is used but no IPv4 records are found, the IPv4 addresses
* @param family address family expected in the addrinfo result list. AF_INET or AF_INET6. If AF_INET6 is used but no IPv6 records are found, the IPv4 addresses
* will be returned as IPv6 with v4 mapping (AI_V4MAPPED).
* @param cb a callback function that will be called to notify the results.
* @param data a user pointer passed through the callback as first argument.
......
if ENABLE_TESTS
noinst_PROGRAMS=belle_sip_tester belle_sip_object_describe belle_sip_parse belle_http_get
noinst_PROGRAMS=belle_sip_tester belle_sip_object_describe belle_sip_parse belle_http_get belle_sip_resolve
belle_sip_tester_SOURCES= belle_sip_tester.c belle_sip_tester.h\
belle_sdp_tester.c \
......@@ -30,6 +30,8 @@ belle_sip_parse_SOURCES=parse.c
belle_http_get_SOURCES=get.c
belle_sip_resolve_SOURCES=resolve.c
AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src
LDADD=$(top_builddir)/src/libbellesip.la
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
Copyright (C) 2013 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2013 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "belle-sip/belle-sip.h"
static belle_sip_stack_t *stack;
static void resolver_callback(void *data, const char *queried_name, struct addrinfo *ai_list){
int err;
struct addrinfo *ai_it;
char name[NI_MAXHOST];
char port[NI_MAXSERV];
for(ai_it=ai_list;ai_it!=NULL;ai_it=ai_it->ai_next){
err=getnameinfo(ai_it->ai_addr,ai_list->ai_addrlen,name,sizeof(name),port,sizeof(port),NI_NUMERICSERV|NI_NUMERICHOST);
if (err!=0){
fprintf(stderr,"getnameinfo error: %s",gai_strerror(err));
}else{
printf("\t%s %s\n",name,port);
}
}
belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
}
int main(int argc, char *argv[]){
int i;
const char *domain=NULL;
const char *transport="udp";
if (argc<2){
fprintf(stderr,"Usage:\n%s <domain name> [transport] [--debug]\n",argv[0]);
return -1;
}
domain=argv[1];
for (i=2;i<argc;i++){
if (strcmp(argv[2],"--debug")==0){
belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG);
}else if (strstr(argv[i],"--")!=argv[i]) transport=argv[i];
}
stack=belle_sip_stack_new(NULL);
printf("Tying to resolve domain '%s', with transport hint '%s'\n",domain,transport);
belle_sip_stack_resolve(stack,transport,domain,5060,AF_INET6,resolver_callback,NULL);
belle_sip_stack_main(stack);
belle_sip_object_unref(stack);
return 0;
}
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