X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpackets.c;h=5c51feb1f3d289490de750063c8e9d79214df822;hb=67b30fcde789088b2e43407167f9ad656c2cc1e5;hp=0547791ab653d86a8812306a8c27ab948f521dc8;hpb=576e26d7b47f4e53116ef0b5f035d260f426d37b;p=openvswitch diff --git a/lib/packets.c b/lib/packets.c index 0547791a..5c51feb1 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -17,8 +17,30 @@ #include #include "packets.h" #include +#include #include "ofpbuf.h" +bool +dpid_from_string(const char *s, uint64_t *dpidp) +{ + *dpidp = (strlen(s) == 16 && strspn(s, "0123456789abcdefABCDEF") == 16 + ? strtoll(s, NULL, 16) + : 0); + return *dpidp != 0; +} + +bool +eth_addr_from_string(const char *s, uint8_t ea[ETH_ADDR_LEN]) +{ + if (sscanf(s, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(ea)) + == ETH_ADDR_SCAN_COUNT) { + return true; + } else { + memset(ea, 0, ETH_ADDR_LEN); + return false; + } +} + /* Fills 'b' with an 802.2 SNAP packet with Ethernet source address 'eth_src', * the Nicira OUI as SNAP organization and 'snap_type' as SNAP type. The text * string in 'tag' is enclosed as the packet payload.