1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
22 ***************************************************************************/
36 #if !defined(WIN32) && !defined(__BEOS__) && !defined(__CYGWIN32__) && \
37 !defined(__riscos__) && !defined(__INTERIX) && !defined(NETWARE)
39 #ifdef HAVE_SYS_SOCKET_H
40 #include <sys/socket.h>
42 #ifdef HAVE_NETINET_IN_H
43 #include <netinet/in.h>
45 #ifdef HAVE_ARPA_INET_H
46 #include <arpa/inet.h>
49 #ifdef HAVE_SYS_TIME_H
50 /* This must be before net/if.h for AIX 3.2 to enjoy life */
56 #ifdef HAVE_SYS_IOCTL_H
57 #include <sys/ioctl.h>
64 #ifdef HAVE_SYS_SOCKIO_H
65 #include <sys/sockio.h>
72 #include "inet_ntop.h"
75 /* The last #include file should be: */
80 char *Curl_if2ip(const char *interface, char *buf, int buf_size)
88 dummy = socket(AF_INET, SOCK_STREAM, 0);
89 if (SYS_ERROR == dummy) {
94 size_t len = strlen(interface);
95 memset(&req, 0, sizeof(req));
96 if(len >= sizeof(req.ifr_name))
97 return NULL; /* this can't be a fine interface name */
98 memcpy(req.ifr_name, interface, len+1);
99 req.ifr_addr.sa_family = AF_INET;
101 if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req)) {
103 if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req, sizeof(req))) {
111 struct sockaddr_in *s = (struct sockaddr_in *)&req.ifr_dstaddr;
112 memcpy(&in, &(s->sin_addr.s_addr), sizeof(in));
113 ip = Curl_inet_ntop(s->sin_family, &in, buf, buf_size);
120 /* -- end of if2ip() -- */
122 char *Curl_if2ip(const char *interf, char *buf, int buf_size)