MSG_TABLE_DUMP /* routing table dump */
};
-static int attr_parse(struct stream *s, u_int16_t len)
+static int 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;
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);
printf("\n");
}
}
- fclose(fp);
+ close(fd);
return 0;
}