cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: NI_WITHSCOPEID (was Re: Debugging test cases) (fwd)

From: Joe Halpin <j.p.h_at_comcast.net>
Date: Wed, 31 Mar 2004 17:31:48 -0600

Daniel Stenberg wrote:

> I'm currently trying variations on the configure teste to see if
> there's _any_ platform among the autobuild ones that detect a working
> NI_WITHSCOPEID. So far I've failed... I've wanted to see how other platforms
> perform on this test before I change the code as you suggest, which indeed is
> the correct fix.

This works for FreeBSD 4.9-STABLE, which does support the option. Sorry
it's more different than it needs to be from the original, but I was
fiddling with things for a while.

Joe

Index: acinclude.m4
===================================================================
RCS file: /repository/curl/acinclude.m4,v
retrieving revision 1.31
diff -u -r1.31 acinclude.m4
--- acinclude.m4 31 Mar 2004 20:13:53 -0000 1.31
+++ acinclude.m4 31 Mar 2004 23:28:28 -0000
@@ -282,40 +282,45 @@
   AC_CACHE_CHECK(for working NI_WITHSCOPEID, ac_cv_working_ni_withscopeid,[
 
  AC_RUN_IFELSE([[
+#include <stdio.h>
+#include <netdb.h>
+#include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
+
 int main()
 {
 #ifdef NI_WITHSCOPEID
- struct sockaddr_storage ss;
- int sslen;
- int rc;
- char hbuf[NI_MAXHOST];
- int fd = socket(AF_INET6, SOCK_STREAM, 0);
- if(fd < 0) {
- printf("couldn't create AF_INET6 socket\n");
- return 4; /* couldn't create socket of either kind */
- }
-
- rc = getsockname(fd, (struct sockaddr *)&ss, &sslen);
- if(rc) {
- printf("getsockname() failed\n");
- return 1; /* getsockname() failed unexpectedly */
- }
-
- rc = getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf),
- NULL, 0,
- NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID);
-
- if(rc) {
- printf("rc = %s\n", gai_strerror(rc));
- return 2; /* getnameinfo() failed, we take this as an indication to
- avoid NI_WITHSCOPEID */
- }
+ struct sockaddr_storage ss;
+ int sslen = sizeof ss;
+ char hbuf[NI_MAXHOST];
+ int fd = socket(AF_INET6, SOCK_STREAM, 0);
+ int rc;
+
+ if(fd < 0)
+ {
+ perror("socket()");
+ return 1;
+ }
+
+ if(getsockname(fd, (struct sockaddr *)&ss, &sslen) != 0)
+ {
+ perror("getsockname()");
+ return 2;
+ }
+
+ if((rc = getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf),
+ NULL, 0,
+ NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID) != 0))
+ {
+ printf("rc = %s\n", gai_strerror(rc));
+ return 3;
+ }
+
+ return 0;
 
- return 0; /* everything works fine, use NI_WITHSCOPEID! */
 #else
- return 3; /* we don't seem to have the definition, don't use it */
+ return 4;
 #endif
 }
 ]],
Received on 2004-04-01