blob: 3b713f5ab9d30468a14ebaee5c99bcf5743bc29a [file] [log] [blame]
Benny Prijonob681a2f2007-03-25 18:44:51 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include <pj/ip_helper.h>
20#include <pj/addr_resolv.h>
21#include <pj/assert.h>
22#include <pj/errno.h>
23#include <pj/string.h>
24
25/*
26 * Enumerate the local IP interface currently active in the host.
27 */
28PJ_DEF(pj_status_t) pj_enum_ip_interface(unsigned *p_cnt,
29 pj_in_addr ifs[])
30{
31 pj_status_t status;
32
33 PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && ifs, PJ_EINVAL);
34
35 pj_bzero(ifs, sizeof(ifs[0]) * (*p_cnt));
36
37 /* Just get one default route */
38 status = pj_gethostip(&ifs[0]);
39 if (status != PJ_SUCCESS)
40 return status;
41
42 *p_cnt = 1;
43 return PJ_SUCCESS;
44}
45
46/*
47 * Enumerate the IP routing table for this host.
48 */
49PJ_DEF(pj_status_t) pj_enum_ip_route(unsigned *p_cnt,
50 pj_ip_route_entry routes[])
51{
52 pj_status_t status;
53
54 PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && routes, PJ_EINVAL);
55
56 pj_bzero(routes, sizeof(routes[0]) * (*p_cnt));
57
58 /* Just get one default route */
59 status = pj_gethostip(&routes[0].ipv4.if_addr);
60 if (status != PJ_SUCCESS)
61 return status;
62
63 routes[0].ipv4.dst_addr.s_addr = 0;
64 routes[0].ipv4.mask.s_addr = 0;
65 *p_cnt = 1;
66
67 return PJ_SUCCESS;
68}
69