summaryrefslogtreecommitdiffstats
path: root/sys/netinet
diff options
context:
space:
mode:
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/in.c24
-rw-r--r--sys/netinet/in.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index bfcb33a..f47492d 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -128,6 +128,30 @@ in_localip(struct in_addr in)
}
/*
+ * Return 1 if an internet address is configured on an interface.
+ */
+int
+in_ifhasaddr(struct ifnet *ifp, struct in_addr in)
+{
+ struct ifaddr *ifa;
+ struct in_ifaddr *ia;
+
+ IF_ADDR_RLOCK(ifp);
+ TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
+ if (ifa->ifa_addr->sa_family != AF_INET)
+ continue;
+ ia = (struct in_ifaddr *)ifa;
+ if (ia->ia_addr.sin_addr.s_addr == in.s_addr) {
+ IF_ADDR_RUNLOCK(ifp);
+ return (1);
+ }
+ }
+ IF_ADDR_RUNLOCK(ifp);
+
+ return (0);
+}
+
+/*
* Return a reference to the interface address which is different to
* the supplied one but with same IP address value.
*/
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 1f79761..325b523 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -642,6 +642,7 @@ int in_broadcast(struct in_addr, struct ifnet *);
int in_canforward(struct in_addr);
int in_localaddr(struct in_addr);
int in_localip(struct in_addr);
+int in_ifhasaddr(struct ifnet *, struct in_addr);
int inet_aton(const char *, struct in_addr *); /* in libkern */
char *inet_ntoa(struct in_addr); /* in libkern */
char *inet_ntoa_r(struct in_addr ina, char *buf); /* in libkern */
OpenPOWER on IntegriCloud