diff options
author | Joe Hershberger <joe.hershberger@ni.com> | 2018-07-02 14:47:51 -0500 |
---|---|---|
committer | Joe Hershberger <joe.hershberger@ni.com> | 2018-07-26 14:08:18 -0500 |
commit | ac13270b49d55677aeea5a64dfbf1764118820e3 (patch) | |
tree | 2a8fe6eb4e638bb018f4f4661623fa47b553ccd0 /arch | |
parent | 8c7988b6dbfb0aa05a935e602b8cdb67f7dd60b2 (diff) |
sandbox: eth-raw: Add a function to ask the host about localhost
Instead of doing a simple string compare against "lo", look for the flag
that indicates a localhost interface.
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/sandbox/cpu/eth-raw-os.c | 27 | ||||
-rw-r--r-- | arch/sandbox/include/asm/eth-raw-os.h | 8 |
2 files changed, 31 insertions, 4 deletions
diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c index 82bf666886..12ddb345d9 100644 --- a/arch/sandbox/cpu/eth-raw-os.c +++ b/arch/sandbox/cpu/eth-raw-os.c @@ -1,9 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (c) 2015 National Instruments - * - * (C) Copyright 2015 - * Joe Hershberger <joe.hershberger@ni.com> + * Copyright (c) 2015-2018 National Instruments + * Copyright (c) 2015-2018 Joe Hershberger <joe.hershberger@ni.com> */ #include <asm/eth-raw-os.h> @@ -25,6 +23,27 @@ #include <linux/if_ether.h> #include <linux/if_packet.h> +int sandbox_eth_raw_os_is_local(const char *ifname) +{ + int fd = socket(AF_INET, SOCK_DGRAM, 0); + struct ifreq ifr; + int ret = 0; + + if (fd < 0) + return -errno; + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + ret = ioctl(fd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + ret = -errno; + goto out; + } + ret = !!(ifr.ifr_flags & IFF_LOOPBACK); +out: + close(fd); + return ret; +} + static int _raw_packet_start(struct eth_sandbox_raw_priv *priv, unsigned char *ethmac) { diff --git a/arch/sandbox/include/asm/eth-raw-os.h b/arch/sandbox/include/asm/eth-raw-os.h index 760f5fbedd..edd09d2e08 100644 --- a/arch/sandbox/include/asm/eth-raw-os.h +++ b/arch/sandbox/include/asm/eth-raw-os.h @@ -34,6 +34,14 @@ struct eth_sandbox_raw_priv { unsigned short local_bind_udp_port; }; +/* + * Check if the interface named "ifname" is a localhost interface or not. + * ifname - the interface name on the host to check + * + * returns - 0 if real interface, 1 if local, negative if error + */ +int sandbox_eth_raw_os_is_local(const char *ifname); + int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv, unsigned char *ethmac); int sandbox_eth_raw_os_send(void *packet, int length, |