1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * In order to be useful for every potential user, curl and libcurl are
11 * dual-licensed under the MPL and the MIT/X-derivate licenses.
13 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
14 * copies of the Software, and permit persons to whom the Software is
15 * furnished to do so, under the terms of the MPL or the MIT/X-derivate
16 * licenses. You may pick one of these licenses.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
22 *****************************************************************************/
35 #if ! defined(WIN32) && ! defined(__BEOS__) && !defined(__CYGWIN32__)
37 #ifdef HAVE_SYS_SOCKET_H
38 #include <sys/socket.h>
40 #ifdef HAVE_NETINET_IN_H
41 #include <netinet/in.h>
43 #ifdef HAVE_ARPA_INET_H
44 #include <arpa/inet.h>
47 #ifdef HAVE_SYS_TIME_H
48 /* This must be before net/if.h for AIX 3.2 to enjoy life */
54 #include <sys/ioctl.h>
61 #ifdef HAVE_SYS_SOCKIO_H
62 #include <sys/sockio.h>
65 #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
66 #include "inet_ntoa_r.h"
69 /* The last #include file should be: */
76 char *Curl_if2ip(char *interface, char *buf, int buf_size)
84 dummy = socket(AF_INET, SOCK_STREAM, 0);
85 if (SYS_ERROR == dummy) {
90 memset(&req, 0, sizeof(req));
91 strcpy(req.ifr_name, interface);
92 req.ifr_addr.sa_family = AF_INET;
93 if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req, sizeof(req))) {
100 struct sockaddr_in *s = (struct sockaddr_in *)&req.ifr_dstaddr;
101 memcpy(&in, &(s->sin_addr.s_addr), sizeof(in));
102 #if defined(HAVE_INET_NTOA_R)
103 ip = inet_ntoa_r(in,buf,buf_size);
105 ip = strncpy(buf,inet_ntoa(in),buf_size);
106 ip[buf_size - 1] = 0;
114 /* -- end of if2ip() -- */
116 #define if2ip(x) NULL