aboutsummaryrefslogtreecommitdiffstats
path: root/epan/addr_resolv.c
diff options
context:
space:
mode:
authorMartin Kaiser <wireshark@kaiser.cx>2018-10-10 17:25:52 +0200
committerAnders Broman <a.broman58@gmail.com>2018-10-15 05:15:57 +0000
commit23b71ed266a327413406722da59d99cfee8de6b5 (patch)
treeb14bfcffb535212ee3a1f3882c14ede98090113c /epan/addr_resolv.c
parentc6dc4095b7aba75113e24868f174c3d4962075ca (diff)
addr_resolv: function to convert an eth address into raw bytes
Add a function to convert a string that contains an ethernet address (including the colons) into a sequence of 6 bytes. Use the existing internal functions to parse an ethernet address. Declare the new function as local to libwireshark. It'll be used by wslua to support ethernet addresses. While at it, fix an incorrect comment about parse_ether_address(). If accept_mask is false, only a complete 6-byte ethernet address is accepted. Change-Id: Ib03306c44866fe97d3cbff2634411b7f5ec31a79 Reviewed-on: https://code.wireshark.org/review/30162 Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/addr_resolv.c')
-rw-r--r--epan/addr_resolv.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c
index f0507eb328..1376634c61 100644
--- a/epan/addr_resolv.c
+++ b/epan/addr_resolv.c
@@ -1168,7 +1168,8 @@ host_lookup6(const ws_in6_addr *addr)
/*
- * If "accept_mask" is FALSE, either 3 or 6 bytes are valid, but no other number of bytes is.
+ * If "accept_mask" is FALSE, cp must point to an address that consists
+ * of exactly 6 bytes.
* If "accept_mask" is TRUE, parse an up-to-6-byte sequence with an optional
* mask.
*/
@@ -3503,6 +3504,23 @@ str_to_ip6(const char *str, void *dst)
}
/*
+ * convert a 0-terminated string that contains an ethernet address into
+ * the corresponding sequence of 6 bytes
+ * eth_bytes is a buffer >= 6 bytes that was allocated by the caller
+ */
+gboolean
+str_to_eth(const char *str, char *eth_bytes)
+{
+ ether_t eth;
+
+ if (!parse_ether_address(str, &eth, NULL, FALSE))
+ return FALSE;
+
+ memcpy(eth_bytes, eth.addr, sizeof(eth.addr));
+ return TRUE;
+}
+
+/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables: