MiniDLNA update: 1.0.19.1 to 1.0.20
[tomato.git] / release / src / router / zebra / zebra / rtread_sysctl.c
blob970c0aa1db87cb73d3b948aae83e3ea0b93f751c
1 /*
2 * Kernel routing table read by sysctl function.
3 * Copyright (C) 1997, 98 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
23 #include <zebra.h>
25 #include "memory.h"
26 #include "log.h"
28 /* Kernel routing table read up by sysctl function. */
29 int
30 route_read ()
32 caddr_t buf, end, ref;
33 size_t bufsiz;
34 struct rt_msghdr *rtm;
35 void rtm_read (struct rt_msghdr *);
37 #define MIBSIZ 6
38 int mib[MIBSIZ] =
40 CTL_NET,
41 PF_ROUTE,
44 NET_RT_DUMP,
48 /* Get buffer size. */
49 if (sysctl (mib, MIBSIZ, NULL, &bufsiz, NULL, 0) < 0)
51 zlog_warn ("sysctl fail: %s", strerror (errno));
52 return -1;
55 /* Allocate buffer. */
56 ref = buf = XMALLOC (MTYPE_TMP, bufsiz);
58 /* Read routing table information by calling sysctl(). */
59 if (sysctl (mib, MIBSIZ, buf, &bufsiz, NULL, 0) < 0)
61 zlog_warn ("sysctl() fail by %s", strerror (errno));
62 return -1;
65 for (end = buf + bufsiz; buf < end; buf += rtm->rtm_msglen)
67 rtm = (struct rt_msghdr *) buf;
68 rtm_read (rtm);
71 /* Free buffer. */
72 XFREE (MTYPE_TMP, ref);
74 return 0;