Beispiel #1
0
static int
getsockopt_ipv6_ifindex (struct msghdr *msgh)
{
  struct in6_pktinfo *pktinfo;
  
  pktinfo = getsockopt_cmsg_data (msgh, IPPROTO_IPV6, IPV6_PKTINFO);
  
  return pktinfo->ipi6_ifindex;
}
Beispiel #2
0
/*
 * Requires: msgh is not NULL and points to a valid struct msghdr, which
 * may or may not have control data about the incoming interface.
 *
 * Returns the interface index (small integer >= 1) if it can be
 * determined, or else 0.
 */
static int
getsockopt_ipv4_ifindex (struct msghdr *msgh)
{
	/* XXX: initialize to zero?  (Always overwritten, so just cosmetic.) */
	int ifindex = -1;

	/* Linux pktinfo based ifindex retrieval */
	struct in_pktinfo *pktinfo;

	pktinfo = 
		(struct in_pktinfo *)getsockopt_cmsg_data (msgh, IPPROTO_IP, IP_PKTINFO);
	/* XXX Can pktinfo be NULL?  Clean up post 0.98. */
	ifindex = pktinfo->ipi_ifindex;

	return ifindex;
}
Beispiel #3
0
/*
 * Requires: msgh is not NULL and points to a valid struct msghdr, which
 * may or may not have control data about the incoming interface.
 *
 * Returns the interface index (small integer >= 1) if it can be
 * determined, or else 0.
 */
static int
getsockopt_ipv4_ifindex (struct msghdr *msgh)
{
    /* XXX: initialize to zero?  (Always overwritten, so just cosmetic.) */
    int ifindex = -1;

#if defined(IP_PKTINFO)
    /* Linux pktinfo based ifindex retrieval */
    struct in_pktinfo *pktinfo;

    pktinfo =
        (struct in_pktinfo *)getsockopt_cmsg_data (msgh, IPPROTO_IP, IP_PKTINFO);
    /* XXX Can pktinfo be NULL?  Clean up post 0.98. */
    ifindex = pktinfo->ipi_ifindex;

#elif defined(IP_RECVIF)

    /* retrieval based on IP_RECVIF */

#ifndef SUNOS_5
    /* BSD systems use a sockaddr_dl as the control message payload. */
    struct sockaddr_dl *sdl;
#else
    /* SUNOS_5 uses an integer with the index. */
    int *ifindex_p;
#endif /* SUNOS_5 */

#ifndef SUNOS_5
    /* BSD */
    sdl =
        (struct sockaddr_dl *)getsockopt_cmsg_data (msgh, IPPROTO_IP, IP_RECVIF);
    if (sdl != NULL)
        ifindex = sdl->sdl_index;
    else
        ifindex = 0;
#else
    /*
     * Solaris.  On Solaris 8, IP_RECVIF is defined, but the call to
     * enable it fails with errno=99, and the struct msghdr has
     * controllen 0.
     */
    ifindex_p = (uint_t *)getsockopt_cmsg_data (msgh, IPPROTO_IP, IP_RECVIF);
    if (ifindex_p != NULL)
        ifindex = *ifindex_p;
    else
        ifindex = 0;
#endif /* SUNOS_5 */

#else
    /*
     * Neither IP_PKTINFO nor IP_RECVIF defined - warn at compile time.
     * XXX Decide if this is a core service, or if daemons have to cope.
     * Since Solaris 8 and OpenBSD seem not to provide it, it seems that
     * daemons have to cope.
     */
#warning "getsockopt_ipv4_ifindex: Neither IP_PKTINFO nor IP_RECVIF defined."
#warning "Some daemons may fail to operate correctly!"
    ifindex = 0;

#endif /* IP_PKTINFO */

    return ifindex;
}