89 lines
1.8 KiB
C
89 lines
1.8 KiB
C
#ifndef lint
|
|
static char sccsid[] = "@(#)in.c 1.1 92/07/30 Copyr 1983 Sun Micro";
|
|
#endif
|
|
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/mbuf.h>
|
|
#include "boot/protosw.h"
|
|
#include <sys/socket.h>
|
|
#include <sys/socketvar.h>
|
|
#include <netinet/in.h>
|
|
#include <netinet/in_systm.h>
|
|
#include <net/if.h>
|
|
#include <net/route.h>
|
|
#include <net/af.h>
|
|
|
|
#ifdef INET
|
|
inet_hash(sin, hp)
|
|
register struct sockaddr_in *sin;
|
|
struct afhash *hp;
|
|
{
|
|
|
|
hp->afh_nethash = in_netof(sin->sin_addr);
|
|
hp->afh_hosthash = ntohl(sin->sin_addr.s_addr);
|
|
}
|
|
|
|
inet_netmatch(sin1, sin2)
|
|
struct sockaddr_in *sin1, *sin2;
|
|
{
|
|
|
|
return (in_netof(sin1->sin_addr) == in_netof(sin2->sin_addr));
|
|
}
|
|
|
|
/*
|
|
* Formulate an Internet address from network + host. Used in
|
|
* building addresses stored in the ifnet structure.
|
|
*/
|
|
struct in_addr
|
|
if_makeaddr(net, host)
|
|
int net, host;
|
|
{
|
|
u_long addr;
|
|
|
|
if (net < 128)
|
|
addr = (net << IN_CLASSA_NSHIFT) | host;
|
|
else if (net < 65536)
|
|
addr = (net << IN_CLASSB_NSHIFT) | host;
|
|
else
|
|
addr = (net << IN_CLASSC_NSHIFT) | host;
|
|
addr = htonl(addr);
|
|
return (*(struct in_addr *)&addr);
|
|
}
|
|
|
|
/*
|
|
* Return the network number from an internet address.
|
|
*/
|
|
u_long
|
|
in_netof(in)
|
|
struct in_addr in;
|
|
{
|
|
register u_long i = ntohl(in.s_addr);
|
|
|
|
if (IN_CLASSA(i))
|
|
return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
|
|
else if (IN_CLASSB(i))
|
|
return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
|
|
else
|
|
return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
|
|
}
|
|
|
|
/*
|
|
* Initialize an interface's routing
|
|
* table entry according to the network.
|
|
* INTERNET SPECIFIC.
|
|
*/
|
|
if_rtinit(ifp, flags)
|
|
register struct ifnet *ifp;
|
|
int flags;
|
|
{
|
|
struct sockaddr_in sin;
|
|
register struct ifaddr *ifa = ifp->if_addrlist;
|
|
|
|
bzero((caddr_t)&sin, sizeof (sin));
|
|
sin.sin_family = AF_INET;
|
|
sin.sin_addr = if_makeaddr(0, (int)INADDR_ANY);
|
|
rtinit((struct sockaddr *)&sin, &ifa->ifa_addr, flags);
|
|
}
|
|
#endif
|