1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * The contents of this file are subject to the Mozilla Public License
9 * Version 1.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS"
14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15 * License for the specific language governing rights and limitations
18 * The Original Code is Curl.
20 * The Initial Developer of the Original Code is Daniel Stenberg.
22 * Portions created by the Initial Developer are Copyright (C) 1998.
23 * All Rights Reserved.
25 * ------------------------------------------------------------
27 * - Daniel Stenberg <daniel@haxx.se>
38 * ------------------------------------------------------------
39 ****************************************************************************/
51 #if ! defined(WIN32) && ! defined(__BEOS__)
57 #ifdef HAVE_SYS_SOCKET_H
58 #include <sys/socket.h>
60 #ifdef HAVE_NETINET_IN_H
61 #include <netinet/in.h>
63 #ifdef HAVE_ARPA_INET_H
64 #include <arpa/inet.h>
67 #ifdef HAVE_SYS_TIME_H
68 /* This must be before net/if.h for AIX 3.2 to enjoy life */
74 #include <sys/ioctl.h>
81 #ifdef HAVE_SYS_SOCKIO_H
82 #include <sys/sockio.h>
85 #ifndef HAVE_INET_NTOA_R_DECL
86 #include "inet_ntoa_r.h"
91 char *if2ip(char *interface, char *buf, int buf_size)
99 dummy = socket(AF_INET, SOCK_STREAM, 0);
100 if (SYS_ERROR == dummy) {
105 memset(&req, 0, sizeof(req));
106 strcpy(req.ifr_name, interface);
107 req.ifr_addr.sa_family = AF_INET;
108 if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req, sizeof(req))) {
114 struct sockaddr_in *s = (struct sockaddr_in *)&req.ifr_dstaddr;
115 memcpy(&in, &(s->sin_addr.s_addr), sizeof(in));
116 #if defined(HAVE_INET_NTOA_R)
117 ip = inet_ntoa_r(in,buf,buf_size);
119 ip = strncpy(buf,inet_ntoa(in),buf_size);
120 ip[buf_size - 1] = 0;
128 /* -- end of if2ip() -- */
130 #define if2ip(x) NULL