From: Erik Faye-Lund Subject: [PATCH v5 10/16] Improve the mingw getaddrinfo stub to handle more use cases Date: Fri, 22 Oct 2010 02:35:21 +0200 Message-ID: <1287707727-5780-11-git-send-email-kusmabite@gmail.com> References: <1287707727-5780-1-git-send-email-kusmabite@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: msysgit@googlegroups.com, j6t@kdbg.org, avarab@gmail.com, sunshine@sunshineco.com, jrnieder@gmail.com, schwab@linux-m68k.org, patthoyts@gmail.com, =?UTF-8?q?Martin=20Storsj=C3=B6?= To: git@vger.kernel.org X-From: msysgit+bncCOPdven-DxCXuYPmBBoELxm-jw@googlegroups.com Fri Oct 22 02:37:07 2010 Return-path: Envelope-to: gcvm-msysgit@m.gmane.org Received: from mail-ww0-f58.google.com ([74.125.82.58]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P95d1-0002Um-8K for gcvm-msysgit@m.gmane.org; Fri, 22 Oct 2010 02:37:03 +0200 Received: by mail-ww0-f58.google.com with SMTP id 28sf120656wwb.3 for ; Thu, 21 Oct 2010 17:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:received:received:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type :content-transfer-encoding; bh=AGa45tl2UrB+iH3YIC9cF+TxylosH2/BdjLAuH0g00A=; b=2rzCSuu1ydcr9XwgjEoqv9tp/wMsdMD6EQiktn4VUEkIGBVbgQLxg65KoDzVmlyBIO LdTjJTiZGhClPIN8Uun1pRkx/gdxOG2Fe1X/scEQY9DvIaVnitROmvR2m7eUD1r1Br8D rvcNJ/lgiS71sK0zd/oTm8D+g8gZ/DnjOdAQA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type:content-transfer-encoding; b=Ai14WxVIVGpslcnBjEK2NAgVkK3P5fSFe0PocQyoRCfe/JiEGaq+MQ1lKGSuF8EwX1 hR37cK8Whw1E94IxA0gtbUHd0eYqJP23fhcpQFEHoVhEI/btjqR8/qdOMT3j8WSa/Zov vpfR+nTcwHvhV+YHQVrnYPcYUBtUMP2fL2/8U= Received: by 10.216.240.140 with SMTP id e12mr288140wer.0.1287707799299; Thu, 21 Oct 2010 17:36:39 -0700 (PDT) X-BeenThere: msysgit@googlegroups.com Received: by 10.14.24.73 with SMTP id w49ls269152eew.4.p; Thu, 21 Oct 2010 17:36:38 -0700 (PDT) Received: by 10.14.119.72 with SMTP id m48mr153806eeh.22.1287707798453; Thu, 21 Oct 2010 17:36:38 -0700 (PDT) Received: by 10.14.119.72 with SMTP id m48mr153805eeh.22.1287707798420; Thu, 21 Oct 2010 17:36:38 -0700 (PDT) Received: from mail-ey0-f179.google.com (mail-ey0-f179.google.com [209.85.215.179]) by gmr-mx.google.com with ESMTP id r57si1452114eeh.5.2010.10.21.17.36.37; Thu, 21 Oct 2010 17:36:37 -0700 (PDT) Received-SPF: pass (google.com: domain of kusmabite@gmail.com designates 209.85.215.179 as permitted sender) client-ip=209.85.215.179; Received: by eyg24 with SMTP id 24so213335eyg.10 for ; Thu, 21 Oct 2010 17:36:37 -0700 (PDT) Received: by 10.14.48.73 with SMTP id u49mr1487176eeb.36.1287707797277; Thu, 21 Oct 2010 17:36:37 -0700 (PDT) Received: from localhost (cm-84.215.188.225.getinternet.no [84.215.188.225]) by mx.google.com with ESMTPS id w20sm2480100eeh.12.2010.10.21.17.36.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 21 Oct 2010 17:36:36 -0700 (PDT) X-Mailer: git-send-email 1.7.3.165.gdfe39.dirty In-Reply-To: <1287707727-5780-1-git-send-email-kusmabite@gmail.com> X-Original-Sender: kusmabite@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of kusmabite@gmail.com designates 209.85.215.179 as permitted sender) smtp.mail=kusmabite@gmail.com; dkim=pass (test mode) header.i=@gmail.com Precedence: list Mailing-list: list msysgit@googlegroups.com; contact msysgit+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: Sender: msysgit@googlegroups.com List-Subscribe: , List-Unsubscribe: , Archived-At: From: Martin Storsjö Allow the node parameter to be null, which is used for getting the default bind address. Also allow the hints parameter to be null, to improve standard conformance of the stub implementation a little. Signed-off-by: Martin Storsjo --- compat/mingw.c | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 21d1c2c..d88c0d0 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1035,19 +1035,22 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { - struct hostent *h = gethostbyname(node); + struct hostent *h = NULL; struct addrinfo *ai; struct sockaddr_in *sin; - if (!h) - return WSAGetLastError(); + if (node) { + h = gethostbyname(node); + if (!h) + return WSAGetLastError(); + } ai = xmalloc(sizeof(struct addrinfo)); *res = ai; ai->ai_flags = 0; ai->ai_family = AF_INET; - ai->ai_socktype = hints->ai_socktype; - switch (hints->ai_socktype) { + ai->ai_socktype = hints ? hints->ai_socktype : 0; + switch (ai->ai_socktype) { case SOCK_STREAM: ai->ai_protocol = IPPROTO_TCP; break; @@ -1059,14 +1062,25 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service, break; } ai->ai_addrlen = sizeof(struct sockaddr_in); - ai->ai_canonname = strdup(h->h_name); + if (hints && (hints->ai_flags & AI_CANONNAME)) + ai->ai_canonname = h ? strdup(h->h_name) : NULL; + else + ai->ai_canonname = NULL; sin = xmalloc(ai->ai_addrlen); memset(sin, 0, ai->ai_addrlen); sin->sin_family = AF_INET; + /* Note: getaddrinfo is supposed to allow service to be a string, + * which should be looked up using getservbyname. This is + * currently not implemented */ if (service) sin->sin_port = htons(atoi(service)); - sin->sin_addr = *(struct in_addr *)h->h_addr; + if (h) + sin->sin_addr = *(struct in_addr *)h->h_addr; + else if (hints && (hints->ai_flags & AI_PASSIVE)) + sin->sin_addr.s_addr = INADDR_ANY; + else + sin->sin_addr.s_addr = INADDR_LOOPBACK; ai->ai_addr = (struct sockaddr *)sin; ai->ai_next = 0; return 0; -- 1.7.3.1.199.g72340