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.Stenberg@haxx.nu>
38 * ------------------------------------------------------------
39 ****************************************************************************/
51 #if ! defined(WIN32) && ! defined(__BEOS__)
53 #include <sys/socket.h>
54 #include <netinet/in.h>
55 #ifdef HAVE_ARPA_INET_H
56 #include <arpa/inet.h>
58 #include <netinet/in.h>
62 #include <sys/ioctl.h>
69 #ifdef HAVE_SYS_SOCKIO_H
70 #include <sys/sockio.h>
75 char *if2ip(char *interface)
83 dummy = socket(AF_INET, SOCK_STREAM, 0);
84 if (SYS_ERROR == dummy) {
89 memset(&req, 0, sizeof(req));
90 strcpy(req.ifr_name, interface);
91 req.ifr_addr.sa_family = AF_INET;
92 if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req, sizeof(req))) {
98 struct sockaddr_in *s = (struct sockaddr_in *)&req.ifr_dstaddr;
99 memcpy(&in, &(s->sin_addr.s_addr), sizeof(in));
100 ip = (char *)strdup(inet_ntoa(in));
107 /* -- end of if2ip() -- */
109 #define if2ip(x) NULL