#include "asterisk.h"
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/srv.h"
#include "asterisk/dns.h"
#include "asterisk/options.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
struct | srv |
struct | srv_context |
Functions | |
int | ast_get_srv (struct ast_channel *chan, char *host, int hostlen, int *port, const char *service) |
static int | parse_srv (char *host, int hostlen, int *portno, unsigned char *answer, int len, unsigned char *msg) |
static int | srv_callback (void *context, unsigned char *answer, int len, unsigned char *fullanswer) |
Variables | |
struct srv | __packed__ |
Definition in file srv.c.
int ast_get_srv | ( | struct ast_channel * | chan, | |
char * | host, | |||
int | hostlen, | |||
int * | port, | |||
const char * | service | |||
) |
Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup Only do SRV record lookup if you get a domain without a port. If you get a port #, it's a DNS host name.
chan | Ast channel | |
host | host name (return value) | |
hostlen | Length of string "host" | |
port | Port number (return value) | |
service | Service tag for SRV lookup (like "_sip._udp" or "_stun._udp" |
Definition at line 117 of file srv.c.
Referenced by ast_get_ip_or_srv(), and create_addr().
00118 { 00119 struct srv_context context; 00120 int ret; 00121 00122 context.host = host; 00123 context.hostlen = hostlen; 00124 context.port = port; 00125 00126 if (chan && ast_autoservice_start(chan) < 0) 00127 return -1; 00128 00129 ret = ast_search_dns(&context, service, C_IN, T_SRV, srv_callback); 00130 00131 if (chan) 00132 ret |= ast_autoservice_stop(chan); 00133 00134 if (ret <= 0) { 00135 host[0] = '\0'; 00136 *port = -1; 00137 return ret; 00138 } 00139 return ret; 00140 }
static int parse_srv | ( | char * | host, | |
int | hostlen, | |||
int * | portno, | |||
unsigned char * | answer, | |||
int | len, | |||
unsigned char * | msg | |||
) | [static] |
Definition at line 65 of file srv.c.
References ast_log(), ast_verbose(), LOG_WARNING, option_verbose, and VERBOSE_PREFIX_3.
Referenced by srv_callback().
00066 { 00067 int res = 0; 00068 struct srv *srv = (struct srv *)answer; 00069 char repl[256] = ""; 00070 00071 if (len < sizeof(struct srv)) { 00072 printf("Length too short\n"); 00073 return -1; 00074 } 00075 answer += sizeof(struct srv); 00076 len -= sizeof(struct srv); 00077 00078 if ((res = dn_expand(msg, answer + len, answer, repl, sizeof(repl) - 1)) < 0) { 00079 ast_log(LOG_WARNING, "Failed to expand hostname\n"); 00080 return -1; 00081 } 00082 if (res && strcmp(repl, ".")) { 00083 if (option_verbose > 3) 00084 ast_verbose( VERBOSE_PREFIX_3 "parse_srv: SRV mapped to host %s, port %d\n", repl, ntohs(srv->portnum)); 00085 if (host) { 00086 ast_copy_string(host, repl, hostlen); 00087 host[hostlen-1] = '\0'; 00088 } 00089 if (portno) 00090 *portno = ntohs(srv->portnum); 00091 return 0; 00092 } 00093 return -1; 00094 }
static int srv_callback | ( | void * | context, | |
unsigned char * | answer, | |||
int | len, | |||
unsigned char * | fullanswer | |||
) | [static] |
Definition at line 102 of file srv.c.
References ast_log(), ast_strlen_zero(), srv_context::host, srv_context::hostlen, LOG_WARNING, parse_srv(), and srv_context::port.
Referenced by ast_get_srv().
00103 { 00104 struct srv_context *c = (struct srv_context *)context; 00105 00106 if (parse_srv(c->host, c->hostlen, c->port, answer, len, fullanswer)) { 00107 ast_log(LOG_WARNING, "Failed to parse srv\n"); 00108 return -1; 00109 } 00110 00111 if (!ast_strlen_zero(c->host)) 00112 return 1; 00113 00114 return 0; 00115 }
struct srv __packed__ |