1 /* $KAME: if_nametoindex.c,v 1.0 2005/11/14 16:23:54 sonic Exp $ */
4 * Copyright (c) 1997, 2000
5 * Berkeley Software Design, Inc. All rights reserved.
6 * Copyright (c) 2005 - 2006
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * BSDI Id: if_nametoindex.c,v 2.3 2000/04/17 22:38:05 dab Exp
30 //#include <emul/emulregs.h>
31 #include <exec/libraries.h>
34 #include <sys/cdefs.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <sys/sockio.h>
38 #include <net/route.h>
40 #include <net/if_dl.h>
41 #include <net/if_protos.h>
42 #include <api/amiga_api.h>
43 #include <api/ifaddrs.h>
47 #include "miami_api.h"
55 * The first function maps an interface name into its corresponding
60 * unsigned int if_nametoindex(const char *ifname);
62 * If the specified interface name does not exist, the return value is
63 * 0, and errno is set to ENXIO. If there was a system error (such as
64 * running out of memory), the return value is 0 and errno is set to the
65 * proper value (e.g., ENOMEM).
69 __if_nametoindex(char *ifname
, struct SocketBase
*SocketBase
)
73 struct ifaddrs
*ifaddrs
, *ifa
;
80 if (getifaddrs(&ifaddrs
, SocketBase
) < 0)
85 for (ifa
= ifaddrs
; ifa
!= NULL
; ifa
= ifa
->ifa_next
) {
87 ifa
->ifa_addr
->sa_family
== AF_LINK
&&
88 strcmp(ifa
->ifa_name
, ifname
) == 0) {
89 ni
= ((struct sockaddr_dl
*)ifa
->ifa_addr
)->sdl_index
;
96 writeErrnoValue(SocketBase
, ENXIO
);
100 AROS_LH1(LONG
, if_nametoindex
,
101 AROS_LHA(char *, ifname
, A0
),
102 struct MiamiBase
*, MiamiBase
, 46, Miami
107 return __if_nametoindex(ifname
, MiamiBase
->_SocketBase
);