From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH 05/16] kvm tools: Get domain name and nameserver from host Date: Sun, 17 Jul 2011 12:36:16 +0300 Message-ID: <1310895376.2393.29.camel@sasha> References: <1310893024-21615-1-git-send-email-asias.hejun@gmail.com> <1310893024-21615-6-git-send-email-asias.hejun@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Pekka Enberg , Cyrill Gorcunov , Ingo Molnar , Prasad Joshi , kvm@vger.kernel.org To: Asias He Return-path: Received: from mail-ww0-f44.google.com ([74.125.82.44]:41567 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753538Ab1GQJg0 (ORCPT ); Sun, 17 Jul 2011 05:36:26 -0400 Received: by wwe5 with SMTP id 5so2387047wwe.1 for ; Sun, 17 Jul 2011 02:36:25 -0700 (PDT) In-Reply-To: <1310893024-21615-6-git-send-email-asias.hejun@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Sun, 2011-07-17 at 16:56 +0800, Asias He wrote: > This patch get domain name and nameserver information from host config > file /etc/resolv.conf. > > Guest can obtain DNS information through DHCP. > > Signed-off-by: Asias He > --- Seeing this after this patch: cc1: warnings being treated as errors net/uip/dhcp.c: In function 'uip_dhcp_get_dns': net/uip/dhcp.c:49:9: error: ignoring return value of 'fscanf', declared with attribute warn_unused_result make: *** [net/uip/dhcp.o] Error 1 > tools/kvm/include/kvm/uip.h | 6 ++++++ > tools/kvm/net/uip/dhcp.c | 34 ++++++++++++++++++++++++++++++++++ > 2 files changed, 40 insertions(+), 0 deletions(-) > > diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h > index 6534c7f..e645d3f 100644 > --- a/tools/kvm/include/kvm/uip.h > +++ b/tools/kvm/include/kvm/uip.h > @@ -42,6 +42,8 @@ > #define UIP_DHCP_OFFER 2 > #define UIP_DHCP_REQUEST 3 > #define UIP_DHCP_ACK 5 > +#define UIP_DHCP_MAX_DNS_SERVER_NR 3 > +#define UIP_DHCP_MAX_DOMAIN_NAME_LEN 256 > #define UIP_DHCP_TAG_MSG_TYPE 53 > #define UIP_DHCP_TAG_MSG_TYPE_LEN 1 > /* > @@ -178,6 +180,8 @@ struct uip_info { > int buf_free_nr; > int buf_used_nr; > u32 host_ip; > + u32 dns_ip[UIP_DHCP_MAX_DNS_SERVER_NR]; > + char *domain_name; > u32 buf_nr; > }; > > @@ -327,4 +331,6 @@ struct uip_buf *uip_buf_clone(struct uip_tx_arg *arg); > > int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 *payload, int payload_len); > bool uip_udp_is_dhcp(struct uip_udp *udp); > + > +int uip_dhcp_get_dns(struct uip_info *info); > #endif /* KVM__UIP_H */ > diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c > index 0a6293a..9321cdc 100644 > --- a/tools/kvm/net/uip/dhcp.c > +++ b/tools/kvm/net/uip/dhcp.c > @@ -1,5 +1,7 @@ > #include "kvm/uip.h" > > +#include > + > static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp) > { > return (dhcp->option[2] == UIP_DHCP_DISCOVER && > @@ -29,3 +31,35 @@ bool uip_udp_is_dhcp(struct uip_udp *udp) > > return true; > } > + > +int uip_dhcp_get_dns(struct uip_info *info) > +{ > + char key[256], val[256]; > + struct in_addr addr; > + int ret = -1; > + int n = 0; > + FILE *fp; > + u32 ip; > + > + fp = fopen("/etc/resolv.conf", "r"); > + if (!fp) > + goto out; > + > + while (!feof(fp)) { > + fscanf(fp, "%s %s\n", key, val); > + if (strncmp("domain", key, 6) == 0) > + info->domain_name = strndup(val, UIP_DHCP_MAX_DOMAIN_NAME_LEN); > + else if (strncmp("nameserver", key, 10) == 0) { > + if (!inet_aton(val, &addr)) > + continue; > + ip = ntohl(addr.s_addr); > + if (n < UIP_DHCP_MAX_DNS_SERVER_NR) > + info->dns_ip[n++] = ip; > + ret = 0; > + } > + } > + > +out: > + fclose(fp); > + return ret; > +} -- Sasha.