}
return ds_cstr(&string);
}
+
+/* Returns the name for the specified OpenFlow message type as a string,
+ * e.g. "OFPT_FEATURES_REPLY". If no name is known, the string returned is a
+ * hex number, e.g. "0x55".
+ *
+ * The caller must free the returned string when it is no longer needed. */
+char *
+ofp_message_type_to_string(uint8_t type)
+{
+ struct ds s = DS_EMPTY_INITIALIZER;
+ const struct openflow_packet *pkt;
+ for (pkt = packets; ; pkt++) {
+ if (pkt >= &packets[ARRAY_SIZE(packets)]) {
+ ds_put_format(&s, "0x%02"PRIx8, type);
+ break;
+ } else if (type == pkt->type) {
+ const char *p;
+
+ ds_put_cstr(&s, "OFPT_");
+ for (p = pkt->name; *p; p++) {
+ ds_put_char(&s, toupper((unsigned char) *p));
+ }
+ break;
+ }
+ }
+ return ds_cstr(&s);
+}
\f
static void
print_and_free(FILE *stream, char *string)
#ifndef OFP_PRINT_H
#define OFP_PRINT_H 1
+#include <stdint.h>
#include <stdio.h>
struct ofp_flow_mod;
char *ofp_to_string(const void *, size_t, int verbosity);
char *ofp_packet_to_string(const void *data, size_t len, size_t total_len);
+char *ofp_message_type_to_string(uint8_t type);
#ifdef __cplusplus
}