/* BGP dump to ascii converter
- Copyright (C) 1999 Kunihiro Ishiguro
-
-This file is part of GNU Zebra.
-
-GNU Zebra 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, or (at your option) any
-later version.
-
-GNU Zebra 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 GNU Zebra; see the file COPYING. If not, write to the Free
-Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+ * Copyright (C) 1999 Kunihiro Ishiguro
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra 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, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra 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; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
#include <zebra.h>
MSG_TABLE_DUMP /* routing table dump */
};
-static int attr_parse(struct stream *s, u_int16_t len)
+static void attr_parse(struct stream *s, uint16_t len)
{
- u_int flag;
- u_int type;
- u_int16_t length;
- u_int16_t lim;
+ unsigned int flag;
+ unsigned int type;
+ uint16_t length;
+ uint16_t lim;
lim = s->getp + len;
switch (type) {
case BGP_ATTR_ORIGIN: {
- u_char origin;
+ uint8_t origin;
origin = stream_getc(s);
printf("ORIGIN: %d\n", origin);
} break;
case BGP_ATTR_NEXT_HOP: {
struct in_addr nexthop;
nexthop.s_addr = stream_get_ipv4(s);
- printf("NEXTHOP: %s\n", inet_ntoa(nexthop));
+ printf("NEXTHOP: %pI4\n", &nexthop);
} break;
default:
stream_getw_from(s, length);
break;
}
}
-
- return 0;
}
int main(int argc, char **argv)
{
int ret;
- FILE *fp;
+ int fd;
struct stream *s;
time_t now;
int type;
int family;
struct in_addr sip;
struct in_addr dip;
- u_int16_t viewno, seq_num;
+ uint16_t viewno, seq_num;
struct prefix_ipv4 p;
s = stream_new(10000);
fprintf(stderr, "Usage: %s FILENAME\n", argv[0]);
exit(1);
}
- fp = fopen(argv[1], "r");
- if (!fp) {
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
fprintf(stdout,
"%% Can't open configuration file %s due to '%s'.\n",
argv[1], safe_strerror(errno));
while (1) {
stream_reset(s);
- ret = fread(s->data, 12, 1, fp);
- if (!ret || feof(fp)) {
- printf("END OF FILE\n");
- break;
- }
- if (ferror(fp)) {
- printf("ERROR OF FREAD\n");
+ ret = stream_read(s, fd, 12);
+ if (ret != 12) {
+ if (!ret)
+ printf("END OF FILE\n");
+ else if (ret < 0)
+ printf("ERROR OF READ\n");
+ else
+ printf("UNDERFLOW\n");
break;
}
printf("len: %zd\n", len);
- fread(s->data + 12, len, 1, fp);
- if (feof(fp)) {
- printf("ENDOF FILE 2\n");
- break;
- }
- if (ferror(fp)) {
- printf("ERROR OF FREAD 2\n");
+ ret = stream_read(s, fd, len);
+ if (ret != (int)len) {
+ if (!ret)
+ printf("END OF FILE 2\n");
+ else if (ret < 0)
+ printf("ERROR OF READ 2\n");
+ else
+ printf("UNDERFLOW 2\n");
break;
}
/* printf ("now read %d\n", len); */
if (type == MSG_TABLE_DUMP) {
- u_char status;
+ uint8_t status;
time_t originated;
struct in_addr peer;
- u_int16_t attrlen;
+ uint16_t attrlen;
viewno = stream_getw(s);
seq_num = stream_getw(s);
while (s->getp < len - 16) {
p.prefix.s_addr = stream_get_ipv4(s);
p.prefixlen = stream_getc(s);
- printf("PREFIX: %s/%d\n", inet_ntoa(p.prefix),
+ printf("PREFIX: %pI4/%d\n", &p.prefix,
p.prefixlen);
status = stream_getc(s);
peer.s_addr = stream_get_ipv4(s);
source_as = stream_getw(s);
- printf("FROM: %s AS%d\n", inet_ntoa(peer),
- source_as);
+ printf("FROM: %pI4 AS%d\n", &peer, source_as);
printf("ORIGINATED: %s", ctime(&originated));
attrlen = stream_getw(s);
sip.s_addr = stream_get_ipv4(s);
dip.s_addr = stream_get_ipv4(s);
- printf("saddr: %s\n", inet_ntoa(sip));
- printf("daddr: %s\n", inet_ntoa(dip));
+ printf("saddr: %pI4\n", &sip);
+ printf("daddr: %pI4\n", &dip);
printf("\n");
}
}
- fclose(fp);
+ close(fd);
return 0;
}