@@ -1827,6 +1827,65 @@ int dns_resolve_name_internal(struct dns_resolve_context *ctx,
1827
1827
ARG_UNUSED (use_cache );
1828
1828
#endif /* CONFIG_DNS_RESOLVER_CACHE */
1829
1829
1830
+ if (IS_ENABLED (CONFIG_NET_HOSTNAME_ENABLE )) {
1831
+ const char * hostname = net_hostname_get ();
1832
+ struct dns_addrinfo info = { 0 };
1833
+
1834
+ /* If the hostname is the same as the query, then
1835
+ * return a local address.
1836
+ */
1837
+ if (strcmp (hostname , query ) == 0 ) {
1838
+
1839
+ if (type == DNS_QUERY_TYPE_A ) {
1840
+ if (!IS_ENABLED (CONFIG_NET_IPV4 )) {
1841
+ return - EAFNOSUPPORT ;
1842
+ }
1843
+
1844
+ struct in_addr addr4 = INADDR_LOOPBACK_INIT ;
1845
+ const struct in_addr * paddr ;
1846
+
1847
+ paddr = net_if_ipv4_select_src_addr (NULL , & addr4 );
1848
+ if (paddr == NULL ) {
1849
+ return - ENOENT ;
1850
+ }
1851
+
1852
+ memcpy (& net_sin (& info .ai_addr )-> sin_addr , paddr ,
1853
+ sizeof (struct in_addr ));
1854
+
1855
+ info .ai_family = AF_INET ;
1856
+ info .ai_addr .sa_family = AF_INET ;
1857
+ info .ai_addrlen = sizeof (struct sockaddr_in );
1858
+
1859
+ } else if (type == DNS_QUERY_TYPE_AAAA ) {
1860
+ if (!IS_ENABLED (CONFIG_NET_IPV6 )) {
1861
+ return - EAFNOSUPPORT ;
1862
+ }
1863
+
1864
+ struct in6_addr addr6 = IN6ADDR_LOOPBACK_INIT ;
1865
+ const struct in6_addr * paddr ;
1866
+
1867
+ paddr = net_if_ipv6_select_src_addr (NULL , & addr6 );
1868
+ if (paddr == NULL ) {
1869
+ return - ENOENT ;
1870
+ }
1871
+
1872
+ memcpy (& net_sin6 (& info .ai_addr )-> sin6_addr , paddr ,
1873
+ sizeof (struct in6_addr ));
1874
+
1875
+ info .ai_family = AF_INET6 ;
1876
+ info .ai_addr .sa_family = AF_INET6 ;
1877
+ info .ai_addrlen = sizeof (struct sockaddr_in6 );
1878
+ } else {
1879
+ return - EINVAL ;
1880
+ }
1881
+
1882
+ cb (DNS_EAI_INPROGRESS , & info , user_data );
1883
+ cb (DNS_EAI_ALLDONE , NULL , user_data );
1884
+
1885
+ return 0 ;
1886
+ }
1887
+ }
1888
+
1830
1889
k_mutex_lock (& ctx -> lock , K_FOREVER );
1831
1890
1832
1891
if (ctx -> state != DNS_RESOLVE_CONTEXT_ACTIVE ) {
0 commit comments