Kernel functions net_getlifaddr(9F) NAME net_getlifaddr - determine a network address for a given interface SYNOPSIS #include int net_getlifaddr(const net_data_t net, const phy_if_t ifp, const net_if_t lif, int const type, struct sockaddr *storage); INTERFACE LEVEL Solaris DDI specific (Solaris DDI) PARAMETERS net value returned from a successful call to net_protocol_lookup. ifp value returned from a successful call to net_phylookup or net_phygetnext, indicating which network interface the information should be returned from. lif value returned from a succesful call t ne_liflookup, indicating which logical interface to fetch the address from. type this indicates what type of address should be returned. See below more details on this field. storage pointer to an area of memory to store the address data. DESCRIPTION + This function can be used to determine the IP address for an + IP layer interface, or MAC address for a MAC layer interface. + The usage differs slightly in the two cases. + + Determine IP address + In following with the Solaris design of IP addresses and relevant details are associated with a logical interface and not a physical interface, retrieving the address information SunOS 5.10 Last change: 3 November 2008 1 Kernel functions net_getlifaddr(9F) for each logical interface is achieved through using net_getlifaddr. Each call to net_getlifaddr requires that the caller pass in a pointer to an array of address information types to retrieve and an accompanying pointer to an array of pointers to struct sockaddr structures in which to copy the address information into. See net_lifgetnext(9f) for an example of how to use this function. Each member of the address type array should be one of the values listed here. NA_ADDRESS Return the network address associated with the logical interface (lif) that belongs to the network interface (ifp). NA_PEER For point to point network interfaces, return the address assigned to the remote host for the given network/logical interface. NA_BROADCAST For network interfaces that support broadcast packets, return the broadcast address assigned to the given network/logical interface. NA_NETMASK For network interfaces that support broadcast packets, return the netmask associated with the given network/logical interface. + + Determine MAC address + + Unlike IP, MAC doesn't have the concept of logical interface, + so the caller should pass in the physical interface as ifp, and + pass in a 0 as the lif because there is no valid lif for MAC. + The address information for the physical interface is retrieved + through net_getlifaddr. + + Each call to net_getlifaddr requires that the caller pass in + a pointer to an array of address information types to + retrieve and an accompanying pointer to an array of pointers + to struct sockaddr_dl structures in which to copy the address + information into. See below for an example of how to use this + function. + + Each member of the address type array should be one of NA_ADDRESS, + NA_PEER, NA_BROADCAST or NA_NETMASK, and it is up to each layer 2 + protocol to implement the address type. For Ethernet, NA_ADDRESS + and NA_BROADCAST are supported, and NA_BROADCAST always return + ff:ff:ff:ff:ff:ff. + + net_data_t net; + phy_if_t ifp; + net_ifaddr_t atype[1]; + struct sockaddr_dl sdl[1]; + netid_t id = net_zoneidtonetid(GLOBAL_ZONEID); + + net = net_protocol_lookup(id, NHF_ETHER); + + if (net != NULL) { + atype[0] = NA_ADDRESS; + if (net_getlifaddr(net, ifp, 0, 1, atype, sdl) == 0) { + printf("hme0: %2x:%2x:%2x:%2x:%2x:%2x", + sdl[0].sdl_data[sdl_nlen], + sdl[0].sdl_data[sdl_nlen+1], + sdl[0].sdl_data[sdl_nlen+2], + sdl[0].sdl_data[sdl_nlen+3], + sdl[0].sdl_data[sdl_nlen+4], + sdl[0].sdl_data[sdl_nlen+5]); + } + } RETURN VALUES This function returns -1 if it is not implemented by the network protocol, 0 if it succeeds or 1 if it cannot supply the requested address information. ATTRIBUTES See attributes(5) for descriptions of the following attri- butes: ____________________________________________________________ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |_____________________________|_____________________________| | Interface Stability | Committed | |_____________________________|_____________________________| SEE ALSO net_lifgetnext(9f) SunOS 5.10 Last change: 3 November 2008 2