Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita717cdd

Browse files
committed
Remove dead ifaddr.c fallback code.
We carried a special implementation of pg_foreach_ifaddr() usingSolaris's ioctl(SIOCGLIFCONF), but Solaris 11 and illumos adoptedgetifaddrs() more than a decade ago, and we prefer to use that. Solaris10 is EOL'd. Remove the dead code.Adjust comment about which OSes have getifaddrs(), which alsoincorrectly listed AIX. AIX is in fact the only Unix in the build farmthat *doesn't* have it today, so the implementation based onioctl(SIOCGIFCONF) (note, no 'L') is still live. All the others havehad it for at least one but mostly two decades.The last-stop fallback at the bottom of the file is dead code inpractice, but it's hard to justify removing it because the betteroptions are all non-standard.Discussion:https://postgr.es/m/CA+hUKGKErNfhmvb_H0UprEmp4LPzGN06yR2_0tYikjzB-2ECMw@mail.gmail.com
1 parent3f5dbcb commita717cdd

File tree

1 file changed

+2
-110
lines changed

1 file changed

+2
-110
lines changed

‎src/backend/libpq/ifaddr.c

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
302302
* for each one. Returns 0 if successful, -1 if trouble.
303303
*
304304
* This version uses the getifaddrs() interface, which is available on
305-
* BSDs,AIX, and modern Linux.
305+
* BSDs,macOS, Solaris, illumos and Linux.
306306
*/
307307
int
308308
pg_foreach_ifaddr(PgIfAddrCallbackcallback,void*cb_data)
@@ -332,115 +332,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
332332
#include<sys/sockio.h>
333333
#endif
334334

335-
/*
336-
* SIOCGIFCONF does not return IPv6 addresses on Solaris.
337-
* So we prefer SIOCGLIFCONF if it's available.
338-
*/
339-
340-
#if defined(SIOCGLIFCONF)
341-
342-
/*
343-
* Enumerate the system's network interface addresses and call the callback
344-
* for each one. Returns 0 if successful, -1 if trouble.
345-
*
346-
* This version uses ioctl(SIOCGLIFCONF).
347-
*/
348-
int
349-
pg_foreach_ifaddr(PgIfAddrCallbackcallback,void*cb_data)
350-
{
351-
structlifconflifc;
352-
structlifreq*lifr,
353-
lmask;
354-
structsockaddr*addr,
355-
*mask;
356-
char*ptr,
357-
*buffer=NULL;
358-
size_tn_buffer=1024;
359-
pgsocketsock,
360-
fd;
361-
362-
#ifdefHAVE_IPV6
363-
pgsocketsock6;
364-
#endif
365-
inti,
366-
total;
367-
368-
sock=socket(AF_INET,SOCK_DGRAM,0);
369-
if (sock==PGINVALID_SOCKET)
370-
return-1;
371-
372-
while (n_buffer<1024*100)
373-
{
374-
n_buffer+=1024;
375-
ptr=realloc(buffer,n_buffer);
376-
if (!ptr)
377-
{
378-
free(buffer);
379-
close(sock);
380-
errno=ENOMEM;
381-
return-1;
382-
}
383-
384-
memset(&lifc,0,sizeof(lifc));
385-
lifc.lifc_family=AF_UNSPEC;
386-
lifc.lifc_buf=buffer=ptr;
387-
lifc.lifc_len=n_buffer;
388-
389-
if (ioctl(sock,SIOCGLIFCONF,&lifc)<0)
390-
{
391-
if (errno==EINVAL)
392-
continue;
393-
free(buffer);
394-
close(sock);
395-
return-1;
396-
}
397-
398-
/*
399-
* Some Unixes try to return as much data as possible, with no
400-
* indication of whether enough space allocated. Don't believe we have
401-
* it all unless there's lots of slop.
402-
*/
403-
if (lifc.lifc_len<n_buffer-1024)
404-
break;
405-
}
406-
407-
#ifdefHAVE_IPV6
408-
/* We'll need an IPv6 socket too for the SIOCGLIFNETMASK ioctls */
409-
sock6=socket(AF_INET6,SOCK_DGRAM,0);
410-
if (sock6==PGINVALID_SOCKET)
411-
{
412-
free(buffer);
413-
close(sock);
414-
return-1;
415-
}
416-
#endif
417-
418-
total=lifc.lifc_len /sizeof(structlifreq);
419-
lifr=lifc.lifc_req;
420-
for (i=0;i<total;++i)
421-
{
422-
addr= (structsockaddr*)&lifr[i].lifr_addr;
423-
memcpy(&lmask,&lifr[i],sizeof(structlifreq));
424-
#ifdefHAVE_IPV6
425-
fd= (addr->sa_family==AF_INET6) ?sock6 :sock;
426-
#else
427-
fd=sock;
428-
#endif
429-
if (ioctl(fd,SIOCGLIFNETMASK,&lmask)<0)
430-
mask=NULL;
431-
else
432-
mask= (structsockaddr*)&lmask.lifr_addr;
433-
run_ifaddr_callback(callback,cb_data,addr,mask);
434-
}
435-
436-
free(buffer);
437-
close(sock);
438-
#ifdefHAVE_IPV6
439-
close(sock6);
440-
#endif
441-
return0;
442-
}
443-
#elif defined(SIOCGIFCONF)
335+
#if defined(SIOCGIFCONF)
444336

445337
/*
446338
* Remaining Unixes use SIOCGIFCONF. Some only return IPv4 information

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp