X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpackets.c;h=2dc82fe12e0d138cf821218fd7633cbfa24f58a4;hb=eb9b830766044475277a590dbf8d213b77b62188;hp=0547791ab653d86a8812306a8c27ab948f521dc8;hpb=b9e8b45a3936441bd0fd1fd156cae498bf72cac8;p=openvswitch diff --git a/lib/packets.c b/lib/packets.c index 0547791a..2dc82fe1 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Nicira Networks. + * Copyright (c) 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,35 @@ #include #include "packets.h" #include +#include #include "ofpbuf.h" +/* Parses 's' as a 16-digit hexadecimal number representing a datapath ID. On + * success stores the dpid into '*dpidp' and returns true, on failure stores 0 + * into '*dpidp' and returns false. + * + * Rejects an all-zeros dpid as invalid. */ +bool +dpid_from_string(const char *s, uint64_t *dpidp) +{ + *dpidp = (strlen(s) == 16 && strspn(s, "0123456789abcdefABCDEF") == 16 + ? strtoull(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.