aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorAndreas Schwab2011-08-18 17:33:22 +0200
committerAndreas Schwab2011-08-18 17:33:22 +0200
commit156bffbe26748a0e60ec7125da4b960a0b6b455f (patch)
treed4b679934c179b6a0ea84f02e96faf5efbcabdc4 /src/process.c
parentbc987f8b80cbab4d8319d05a9499c615213a0685 (diff)
downloademacs-156bffbe26748a0e60ec7125da4b960a0b6b455f.tar.gz
emacs-156bffbe26748a0e60ec7125da4b960a0b6b455f.zip
* src/process.c (Fnetwork_interface_list): Correctly determine buffer
size.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c63
1 files changed, 41 insertions, 22 deletions
diff --git a/src/process.c b/src/process.c
index 71a6f91a7bb..2125478907f 100644
--- a/src/process.c
+++ b/src/process.c
@@ -3580,38 +3580,57 @@ format; see the description of ADDRESS in `make-network-process'. */)
3580 if (s < 0) 3580 if (s < 0)
3581 return Qnil; 3581 return Qnil;
3582 3582
3583 again: 3583 ifconf.ifc_buf = 0;
3584 buf_size *= 2; 3584 ifconf.ifc_len = 0;
3585 buf = xrealloc(buf, buf_size); 3585 if (ioctl (s, SIOCGIFCONF, &ifconf) == 0 && ifconf.ifc_len > 0)
3586 if (!buf)
3587 { 3586 {
3588 close (s); 3587 ifconf.ifc_buf = xmalloc (ifconf.ifc_len);
3589 return Qnil; 3588 if (ifconf.ifc_buf == NULL)
3589 {
3590 close (s);
3591 return Qnil;
3592 }
3593 if (ioctl (s, SIOCGIFCONF, &ifconf))
3594 {
3595 close (s);
3596 xfree (ifconf.ifc_buf);
3597 return Qnil;
3598 }
3590 } 3599 }
3600 else
3601 do
3602 {
3603 buf_size *= 2;
3604 buf = xrealloc (buf, buf_size);
3605 if (!buf)
3606 {
3607 close (s);
3608 return Qnil;
3609 }
3591 3610
3592 ifconf.ifc_buf = buf; 3611 ifconf.ifc_buf = buf;
3593 if (ioctl (s, SIOCGIFCONF, &ifconf)) 3612 ifconf.ifc_len = buf_size;
3594 { 3613 if (ioctl (s, SIOCGIFCONF, &ifconf))
3595 close (s); 3614 {
3596 xfree (buf); 3615 close (s);
3597 return Qnil; 3616 xfree (buf);
3598 } 3617 return Qnil;
3618 }
3599 3619
3600 if (ifconf.ifc_len == buf_size) 3620 }
3601 goto again; 3621 while (ifconf.ifc_len == buf_size);
3602 3622
3603 close (s); 3623 close (s);
3604 3624
3605 res = Qnil; 3625 res = Qnil;
3606 for (ifreq = ifconf.ifc_req; 3626 ifreq = ifconf.ifc_req;
3607 (char *) ifreq < (char *) (ifconf.ifc_req) + ifconf.ifc_len; 3627 while ((char *) ifreq < (char *) ifconf.ifc_req + ifconf.ifc_len)
3608 )
3609 { 3628 {
3610 struct ifreq *ifq = ifreq; 3629 struct ifreq *ifq = ifreq;
3611#ifdef HAVE_STRUCT_IFREQ_IFR_ADDR_SA_LEN 3630#ifdef HAVE_STRUCT_IFREQ_IFR_ADDR_SA_LEN
3612#define SIZEOF_IFREQ(sif) \ 3631#define SIZEOF_IFREQ(sif) \
3613 ((sif)->ifr_addr.sa_len < sizeof(struct sockaddr) ? \ 3632 ((sif)->ifr_addr.sa_len < sizeof (struct sockaddr) \
3614 sizeof((*sif)) : sizeof ((sif)->ifr_name) + sif->ifr_addr.sa_len) 3633 ? sizeof (*(sif)) : sizeof ((sif)->ifr_name) + (sif)->ifr_addr.sa_len)
3615 3634
3616 int len = SIZEOF_IFREQ (ifq); 3635 int len = SIZEOF_IFREQ (ifq);
3617#else 3636#else
@@ -3619,7 +3638,7 @@ format; see the description of ADDRESS in `make-network-process'. */)
3619#endif 3638#endif
3620 char namebuf[sizeof (ifq->ifr_name) + 1]; 3639 char namebuf[sizeof (ifq->ifr_name) + 1];
3621 i += len; 3640 i += len;
3622 ifreq = (struct ifreq*) ((char*) ifreq + len); 3641 ifreq = (struct ifreq *) ((char *) ifreq + len);
3623 3642
3624 if (ifq->ifr_addr.sa_family != AF_INET) 3643 if (ifq->ifr_addr.sa_family != AF_INET)
3625 continue; 3644 continue;