Changeset 344856b8 in rtems
- Timestamp:
- 02/23/15 17:06:21 (9 years ago)
- Branches:
- 4.9
- Parents:
- 237595d8
- git-author:
- Jeffrey Hill <johill@…> (02/23/15 17:06:21)
- git-committer:
- Gedare Bloom <gedare@…> (02/23/15 17:06:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/librpc/src/rpc/get_myaddress.c
r237595d8 r344856b8 46 46 #include <sys/socket.h> 47 47 #include <stdio.h> 48 #include <stdlib.h> 48 49 #include <unistd.h> 49 #include <sys/mbuf.h>50 50 #include <net/if.h> 51 51 #include <sys/ioctl.h> 52 52 #include <netinet/in.h> 53 53 #include <arpa/inet.h> 54 55 56 /* 57 * Determine the size of an ifreq structure when addresses larger 58 * than the pifreq structure size may be returned from the kernel. 59 */ 60 static size_t ifreqSize ( struct ifreq *pifreq ) 61 { 62 size_t size = pifreq->ifr_addr.sa_len + sizeof(pifreq->ifr_name); 63 if ( size < sizeof ( *pifreq ) ) { 64 size = sizeof ( *pifreq ); 65 } 66 return size; 67 } 54 68 55 69 /* … … 64 78 { 65 79 int s; 66 char buf[BUFSIZ];67 80 struct ifconf ifc; 68 struct ifreq ifreq, *ifr , *end;81 struct ifreq ifreq, *ifr; 69 82 int loopback = 0, gotit = 0; 70 83 … … 72 85 return(-1); 73 86 } 74 ifc.ifc_len = sizeof (buf); 75 ifc.ifc_buf = buf; 87 again: 88 ifc.ifc_len = sizeof ( struct ifreq ) * 8u; 89 ifc.ifc_buf = malloc ( ifc.ifc_len ); 90 if ( ! ifc.ifc_buf ) { 91 _RPC_close(s); 92 return -1; 93 } 76 94 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) { 77 95 _RPC_close(s); 96 free ( ifc.ifc_buf ); 78 97 return(-1); 79 98 } 80 again:81 99 ifr = ifc.ifc_req; 82 end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);83 100 84 while ( ifr < end) {85 86 if (ioctl(s, SIOCGIFFLAGS, (char *) &ifreq) < 0) {101 while ( ifc.ifc_len >= ifreqSize ( ifr ) ) { 102 ifreq = *ifr; 103 if (ioctl(s, SIOCGIFFLAGS, (char *) &ifreq ) < 0) { 87 104 _RPC_close(s); 105 free ( ifc.ifc_buf ); 88 106 return(-1); 89 107 } … … 99 117 break; 100 118 } 101 if (ifr->ifr_addr.sa_len) 102 ifr = (struct ifreq *) ((caddr_t) ifr + 103 ifr->ifr_addr.sa_len - 104 sizeof(struct sockaddr)); 105 ifr++; 119 120 const size_t len = ifreqSize ( ifr ); 121 ifc.ifc_len -= len; 122 /* 123 * RTEMS seems to require copy up to properly aligned 124 * boundary at the beginning of the buffer? 125 */ 126 memmove ( ifr, len + (char *) ifr, ifc.ifc_len ); 106 127 } 107 128 if (gotit == 0 && loopback == 0) { 129 free ( ifc.ifc_buf ); 108 130 loopback = 1; 109 131 goto again; 110 132 } 111 133 (void)_RPC_close(s); 134 free ( ifc.ifc_buf ); 112 135 return (gotit ? 0 : -1); 113 136 }
Note: See TracChangeset
for help on using the changeset viewer.