Ejemplo n.º 1
0
char *
ofl_msg_to_string(struct ofl_msg_header *msg, struct ofl_exp *exp) {
    char *str;
    size_t str_size;
    FILE *stream = open_memstream(&str, &str_size);
    ofl_msg_print(stream, msg, exp);
    fclose(stream);
    return str;
}
Ejemplo n.º 2
0
char *
ofl_msg_to_string(struct ofl_msg_header *msg, struct ofl_exp *exp, char *errbuf) {
    char *str;
    size_t str_size;
    FILE *stream = open_memstream(&str, &str_size);

    int ret = ofl_msg_print(stream, msg, exp, errbuf);
    fclose(stream);
    if (ret == 0) {
        return str;
    } else {
        free(str);
        return NULL;
    }
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	uint8_t *buf ,*buf0;
	size_t buf_len = 0;
	ofl_err err;
	struct ofl_msg_header *msg = NULL;
	uint32_t xid;
	FILE *msg_file;
	struct ofp_header *oh;

	if (argc < 2) {
		fprintf(stderr, "Expecting msg file.\n");
		return 1;
	}

	time_init();
	vlog_init();
	vlog_set_verbosity(NULL);

	msg_file = fopen(argv[1], "r");
	if (msg_file == NULL) {
		fprintf(stderr, "Cannot open msg file.\n");
		return 1;
	}
	buf_len = read_all(msg_file, &buf);
	buf0 = buf;

	while (buf_len > 0) {
		oh = (struct ofp_header *)buf;
		err = ofl_msg_unpack(buf, ntohs(oh->length), &msg, &xid, NULL);
		if (err == 0) {
			//printf("Success!\n");
			ofl_msg_print(stdout, msg, NULL);
			printf("\n\n");
			ofl_msg_free(msg, NULL);
		} else {
			free(buf);
			printf("Failed :-( error type: %d code %d\n", ofl_error_type(err), ofl_error_code(err));
			return 1;
		}
		buf_len -= ntohs(oh->length);
		buf += ntohs(oh->length);
	}
	free(buf0);
	return 0;
}