/* * This file is part of the Sofia-SIP package * * Copyright (C) 2006 Nokia Corporation. * * Contact: Pekka Pessi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ /** * @file lookup_stun_server.c * @brief Test app for STUN DNS-SRV lookups. * * @author Kai Vehmanen * * @todo TODO * - picks one UDP and TLS target:port * - does not pick up A/AAAA records that might be delivered * in 'Additional Data' section as defined in RFC2782 */ #include #include #include #include #define STUN_MAGIC_T su_root_t #include static void lookup_cb(stun_dns_lookup_t *self, su_root_t *root) { const char *tls_target = NULL, *udp_target = NULL; uint16_t tls_port = 0, udp_port = 0; int res; res = stun_dns_lookup_get_results(self, &tls_target, &tls_port, &udp_target, &udp_port); if (res == 0) { printf("STUN DNS-SRV: stun (tcp) at %s:%u.\n", tls_target, tls_port); printf("STUN DNS-SRV: stun (udp) at %s:%u.\n", udp_target, udp_port); } su_root_break(root); } int main(int argc, char *argv[]) { su_root_t *root; stun_dns_lookup_t *lookup; if (argc < 2) { printf("usage: ./lookup_stun_server \n"); return -1; } /* step: initialize sofia su OS abstraction layer */ su_init(); /* step: create a su event loop and connect it to glib */ root = su_root_create(NULL); /* step: initiate the DNS-SRV lookup */ lookup = stun_dns_lookup(root, root, lookup_cb, argv[1]); /* step: enter the main loop (break fro lookup_cb()) */ su_root_run(root); /* step: free any allocated resources */ stun_dns_lookup_destroy(lookup); su_root_destroy(root); su_deinit(); return 0; }