X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fpackets.c;h=b9f37bbb25aad436e68fbf827435d4b8ea18ee97;hb=6aa728e0efd1ed300c707af8fb54f9f3acacda10;hp=46a44bdb38a410f7457bba8cc95dad68176274ae;hpb=f4ebc25ea05ce635afeafdc089e6573c279c8cdf;p=sliver-openvswitch.git diff --git a/lib/packets.c b/lib/packets.c index 46a44bdb3..b9f37bbb2 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -121,6 +121,31 @@ eth_pop_vlan(struct ofpbuf *packet) } } +/* Converts hex digits in 'hex' to an Ethernet packet in '*packetp'. The + * caller must free '*packetp'. On success, returns NULL. On failure, returns + * an error message and stores NULL in '*packetp'. */ +const char * +eth_from_hex(const char *hex, struct ofpbuf **packetp) +{ + struct ofpbuf *packet; + + packet = *packetp = ofpbuf_new(strlen(hex) / 2); + + if (ofpbuf_put_hex(packet, hex, NULL)[0] != '\0') { + ofpbuf_delete(packet); + *packetp = NULL; + return "Trailing garbage in packet data"; + } + + if (packet->size < ETH_HEADER_LEN) { + ofpbuf_delete(packet); + *packetp = NULL; + return "Packet data too short for Ethernet"; + } + + return NULL; +} + /* Given the IP netmask 'netmask', returns the number of bits of the IP address * that it specifies, that is, the number of 1-bits in 'netmask'. 'netmask' * must be a CIDR netmask (see ip_is_cidr()). */