diff options
| author | cmetz <> | 1999-06-23 22:26:03 +0000 |
|---|---|---|
| committer | cmetz <> | 1999-06-23 22:26:03 +0000 |
| commit | bb8e4a1e2b3fa93fc2def309cb510f1734df4d77 (patch) | |
| tree | fb30f8c734151c7d33f82c5347fcd2a0d5b67671 /src/lib/libc/net/if_nameindex.c | |
| parent | 8deb91d95656ce00b75b7bbf5b424aa7b9d7faff (diff) | |
| download | openbsd-bb8e4a1e2b3fa93fc2def309cb510f1734df4d77.tar.gz openbsd-bb8e4a1e2b3fa93fc2def309cb510f1734df4d77.tar.bz2 openbsd-bb8e4a1e2b3fa93fc2def309cb510f1734df4d77.zip | |
Removed portability ifdefs and calls to nonstandard back-end.
Diffstat (limited to 'src/lib/libc/net/if_nameindex.c')
| -rw-r--r-- | src/lib/libc/net/if_nameindex.c | 70 |
1 files changed, 13 insertions, 57 deletions
diff --git a/src/lib/libc/net/if_nameindex.c b/src/lib/libc/net/if_nameindex.c index 65bdbde9af..ba7f5e5525 100644 --- a/src/lib/libc/net/if_nameindex.c +++ b/src/lib/libc/net/if_nameindex.c | |||
| @@ -58,33 +58,6 @@ | |||
| 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 59 | * SUCH DAMAGE. | 59 | * SUCH DAMAGE. |
| 60 | * | 60 | * |
| 61 | * Redistribution and use in source and binary forms, with or without | ||
| 62 | * modification, are permitted provided that the following conditions | ||
| 63 | * are met: | ||
| 64 | * 1. Redistributions of source code must retain the above copyright | ||
| 65 | * notice, this list of conditions and the following disclaimer. | ||
| 66 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 67 | * notice, this list of conditions and the following disclaimer in the | ||
| 68 | * documentation and/or other materials provided with the distribution. | ||
| 69 | * 3. All advertising materials mentioning features or use of this software | ||
| 70 | * must display the following acknowledgement: | ||
| 71 | * This product includes software developed by Craig Metz and | ||
| 72 | * by other contributors. | ||
| 73 | * 4. Neither the name of the author nor the names of contributors | ||
| 74 | * may be used to endorse or promote products derived from this software | ||
| 75 | * without specific prior written permission. | ||
| 76 | * | ||
| 77 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 78 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 79 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 80 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 81 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 82 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 83 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 84 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 85 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 86 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 87 | * SUCH DAMAGE. | ||
| 88 | */ | 61 | */ |
| 89 | 62 | ||
| 90 | #include <stdlib.h> | 63 | #include <stdlib.h> |
| @@ -92,9 +65,7 @@ | |||
| 92 | #include <sys/socket.h> | 65 | #include <sys/socket.h> |
| 93 | #include <sys/ioctl.h> | 66 | #include <sys/ioctl.h> |
| 94 | #include <net/if.h> | 67 | #include <net/if.h> |
| 95 | #ifdef AF_LINK | ||
| 96 | #include <net/if_dl.h> | 68 | #include <net/if_dl.h> |
| 97 | #endif /* AF_LINK */ | ||
| 98 | #include <errno.h> | 69 | #include <errno.h> |
| 99 | 70 | ||
| 100 | struct if_nameindex *if_nameindex(void) | 71 | struct if_nameindex *if_nameindex(void) |
| @@ -109,10 +80,16 @@ struct if_nameindex *if_nameindex(void) | |||
| 109 | if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) | 80 | if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) |
| 110 | return NULL; | 81 | return NULL; |
| 111 | 82 | ||
| 112 | if (__siocgifconf(fd, &ifconf)) { | 83 | ifconf.ifc_len = 0; |
| 113 | close(fd); | 84 | ifconf.ifc_buf = 0; |
| 114 | return NULL; | 85 | if (ioctl(fd, SIOCGIFCONF, (void *)&ifconf)) |
| 115 | }; | 86 | goto ret; |
| 87 | if (ifconf->ifc_len < IFNAMSIZ) | ||
| 88 | goto ret; | ||
| 89 | if (!(ifconf->ifc_buf = malloc(ifconf->ifc_len))) | ||
| 90 | goto ret; | ||
| 91 | if (ioctl(fd, SIOCGIFCONF, (void *)&ifconf)) | ||
| 92 | goto ret; | ||
| 116 | 93 | ||
| 117 | i = sizeof(struct if_nameindex); | 94 | i = sizeof(struct if_nameindex); |
| 118 | j = 0; | 95 | j = 0; |
| @@ -145,9 +122,6 @@ struct if_nameindex *if_nameindex(void) | |||
| 145 | memset(nameindex, 0, i + j); | 122 | memset(nameindex, 0, i + j); |
| 146 | 123 | ||
| 147 | { | 124 | { |
| 148 | #ifdef SIOCGIFINDEX | ||
| 149 | struct ifreq ifreq; | ||
| 150 | #endif /* SIOCGIFINDEX */ | ||
| 151 | struct if_nameindex *n; | 125 | struct if_nameindex *n; |
| 152 | char *c; | 126 | char *c; |
| 153 | 127 | ||
| @@ -163,16 +137,8 @@ struct if_nameindex *if_nameindex(void) | |||
| 163 | goto ret; | 137 | goto ret; |
| 164 | if (strncmp(lastname, p, IFNAMSIZ)) { | 138 | if (strncmp(lastname, p, IFNAMSIZ)) { |
| 165 | if (i) { | 139 | if (i) { |
| 166 | if (!n->if_index) { | 140 | if (!n->if_index) |
| 167 | #ifdef SIOCGIFINDEX | 141 | n->if_index = i; |
| 168 | strcpy(ifreq.ifr_name, lastname); | ||
| 169 | if (ioctl(fd, SIOCGIFINDEX, &ifreq)) | ||
| 170 | goto ret; | ||
| 171 | n->if_index = ifreq.ifr_ifindex; | ||
| 172 | #else /* SIOCGIFINDEX */ | ||
| 173 | n->if_index = i; | ||
| 174 | #endif /* SIOCGIFINDEX */ | ||
| 175 | }; | ||
| 176 | n++; | 142 | n++; |
| 177 | }; | 143 | }; |
| 178 | i++; | 144 | i++; |
| @@ -185,24 +151,14 @@ struct if_nameindex *if_nameindex(void) | |||
| 185 | 151 | ||
| 186 | if (len < SA_LEN((struct sockaddr *)p)) | 152 | if (len < SA_LEN((struct sockaddr *)p)) |
| 187 | goto ret; | 153 | goto ret; |
| 188 | #ifdef AF_LINK | ||
| 189 | if (((struct sockaddr *)p)->sa_family == AF_LINK) | 154 | if (((struct sockaddr *)p)->sa_family == AF_LINK) |
| 190 | n->if_index = ((struct sockaddr_dl *)p)->sdl_index; | 155 | n->if_index = ((struct sockaddr_dl *)p)->sdl_index; |
| 191 | #endif /* AF_LINK */ | ||
| 192 | len -= SA_LEN((struct sockaddr *)p); | 156 | len -= SA_LEN((struct sockaddr *)p); |
| 193 | p += SA_LEN((struct sockaddr *)p); | 157 | p += SA_LEN((struct sockaddr *)p); |
| 194 | }; | 158 | }; |
| 195 | 159 | ||
| 196 | if (!n->if_index) { | 160 | if (!n->if_index) |
| 197 | #ifdef SIOCGIFINDEX | ||
| 198 | strcpy(ifreq.ifr_name, lastname); | ||
| 199 | if (ioctl(fd, SIOCGIFINDEX, &ifreq)) | ||
| 200 | goto ret; | ||
| 201 | n->if_index = ifreq.ifr_ifindex; | ||
| 202 | #else /* SIOCGIFINDEX */ | ||
| 203 | n->if_index = i; | 161 | n->if_index = i; |
| 204 | #endif /* SIOCGIFINDEX */ | ||
| 205 | }; | ||
| 206 | }; | 162 | }; |
| 207 | 163 | ||
| 208 | ret: | 164 | ret: |
