]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_btoa.c
Merge pull request #10558 from Jafaral/ospf-net-or-iface
[mirror_frr.git] / bgpd / bgp_btoa.c
index e729d78f518444ce51cac7e2aafce2f61727ff2f..13c42d95f4cb3cc04bf2123e99f86d75082dec58 100644 (file)
@@ -1,22 +1,22 @@
 /* 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>
 
@@ -68,12 +68,12 @@ enum MRT_MSG_TYPES {
        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;
 
@@ -94,7 +94,7 @@ static int attr_parse(struct stream *s, u_int16_t len)
 
                switch (type) {
                case BGP_ATTR_ORIGIN: {
-                       u_char origin;
+                       uint8_t origin;
                        origin = stream_getc(s);
                        printf("ORIGIN: %d\n", origin);
                } break;
@@ -108,21 +108,19 @@ static int attr_parse(struct stream *s, u_int16_t len)
                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;
@@ -134,7 +132,7 @@ int main(int argc, char **argv)
        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);
@@ -143,8 +141,8 @@ int main(int argc, char **argv)
                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));
@@ -154,13 +152,14 @@ int main(int argc, char **argv)
        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;
                }
 
@@ -217,23 +216,24 @@ int main(int argc, char **argv)
 
                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);
@@ -244,7 +244,7 @@ int main(int argc, char **argv)
                        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);
@@ -252,8 +252,7 @@ int main(int argc, char **argv)
                                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);
@@ -278,12 +277,12 @@ int main(int argc, char **argv)
                        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;
 }