1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)af.c	5.4 (Berkeley) 4/20/86";
   9: #endif not lint
  10: 
  11: #include "defs.h"
  12: 
  13: /*
  14:  * Address family support routines
  15:  */
  16: int inet_hash(), inet_netmatch(), inet_output(),
  17:     inet_portmatch(), inet_portcheck(),
  18:     inet_checkhost(), inet_rtflags(), inet_sendsubnet(), inet_canon();
  19: char    *inet_format();
  20: 
  21: #define NIL { 0 }
  22: #define INET \
  23:     { inet_hash,        inet_netmatch,      inet_output, \
  24:       inet_portmatch,   inet_portcheck,     inet_checkhost, \
  25:       inet_rtflags,     inet_sendsubnet,    inet_canon, \
  26:       inet_format \
  27:     }
  28: 
  29: struct afswitch afswitch[AF_MAX] = {
  30:     NIL,        /* 0- unused */
  31:     NIL,        /* 1- Unix domain, unused */
  32:     INET,       /* Internet */
  33: };
  34: 
  35: int af_max = sizeof(afswitch) / sizeof(afswitch[0]);
  36: 
  37: struct sockaddr_in inet_default = { AF_INET, INADDR_ANY };
  38: 
  39: inet_hash(sin, hp)
  40:     register struct sockaddr_in *sin;
  41:     struct afhash *hp;
  42: {
  43:     register u_long n;
  44: 
  45:     n = inet_netof(sin->sin_addr);
  46:     if (n)
  47:         while ((n & 0xff) == 0)
  48:         n >>= 8;
  49:     hp->afh_nethash = n;
  50:     hp->afh_hosthash = ntohl(sin->sin_addr.s_addr);
  51:     hp->afh_hosthash &= 0x7fffffff;
  52: }
  53: 
  54: inet_netmatch(sin1, sin2)
  55:     struct sockaddr_in *sin1, *sin2;
  56: {
  57: 
  58:     return (inet_netof(sin1->sin_addr) == inet_netof(sin2->sin_addr));
  59: }
  60: 
  61: /*
  62:  * Verify the message is from the right port.
  63:  */
  64: inet_portmatch(sin)
  65:     register struct sockaddr_in *sin;
  66: {
  67: 
  68:     return (sin->sin_port == sp->s_port);
  69: }
  70: 
  71: /*
  72:  * Verify the message is from a "trusted" port.
  73:  */
  74: inet_portcheck(sin)
  75:     struct sockaddr_in *sin;
  76: {
  77: 
  78:     return (ntohs(sin->sin_port) <= IPPORT_RESERVED);
  79: }
  80: 
  81: /*
  82:  * Internet output routine.
  83:  */
  84: inet_output(s, flags, sin, size)
  85:     int s, flags;
  86:     struct sockaddr_in *sin;
  87:     int size;
  88: {
  89:     struct sockaddr_in dst;
  90: 
  91:     dst = *sin;
  92:     sin = &dst;
  93:     if (sin->sin_port == 0)
  94:         sin->sin_port = sp->s_port;
  95:     if (sendto(s, packet, size, flags, sin, sizeof (*sin)) < 0)
  96:         perror("sendto");
  97: }
  98: 
  99: /*
 100:  * Return 1 if the address is believed
 101:  * for an Internet host -- THIS IS A KLUDGE.
 102:  */
 103: inet_checkhost(sin)
 104:     struct sockaddr_in *sin;
 105: {
 106:     u_long i = ntohl(sin->sin_addr.s_addr);
 107: 
 108: #define IN_BADCLASS(i)  (((long) (i) & 0xe0000000) == 0xe0000000)
 109: 
 110:     if (IN_BADCLASS(i) || sin->sin_port != 0)
 111:         return (0);
 112:     if (i != 0 && (i & 0xff000000) == 0)
 113:         return (0);
 114:     for (i = 0; i < sizeof(sin->sin_zero)/sizeof(sin->sin_zero[0]); i++)
 115:         if (sin->sin_zero[i])
 116:             return (0);
 117:     return (1);
 118: }
 119: 
 120: inet_canon(sin)
 121:     struct sockaddr_in *sin;
 122: {
 123: 
 124:     sin->sin_port = 0;
 125: }
 126: 
 127: char *
 128: inet_format(sin)
 129:     struct sockaddr_in *sin;
 130: {
 131:     char *inet_ntoa();
 132: 
 133:     return (inet_ntoa(sin->sin_addr));
 134: }

Defined functions

inet_canon defined in line 120; used 2 times
inet_checkhost defined in line 103; used 2 times
inet_format defined in line 127; used 2 times
inet_hash defined in line 39; used 2 times
inet_netmatch defined in line 54; used 2 times
inet_output defined in line 84; used 2 times
inet_portcheck defined in line 74; used 2 times
inet_portmatch defined in line 64; used 2 times

Defined variables

af_max defined in line 35; never used
afswitch defined in line 29; used 2 times
  • in line 35(2)
inet_default defined in line 37; never used
sccsid defined in line 8; never used

Defined macros

INET defined in line 22; used 1 times
  • in line 32
IN_BADCLASS defined in line 108; used 1 times
NIL defined in line 21; used 2 times
Last modified: 1986-04-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1078
Valid CSS Valid XHTML 1.0 Strict