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: #if defined(DOSCCS) && !defined(lint)
   8: static char sccsid[] = "@(#)af.c	5.4.1 (2.11BSD GTE) 1/1/94";
   9: #endif
  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:     u_long n;
  44: 
  45:     n = inet_netof(sin->sin_addr);
  46:     if (n)
  47:         while ((n & 0xff) == 0) {
  48:         n >>= 8;
  49:         }
  50:     hp->afh_nethash = n;
  51:     hp->afh_hosthash = ntohl(sin->sin_addr.s_addr);
  52: #ifdef pdp11
  53:     hp->afh_hosthash &= 0x7fff;
  54: #else
  55:     hp->afh_hosthash &= 0x7fffffff;
  56: #endif
  57: }
  58: 
  59: inet_netmatch(sin1, sin2)
  60:     struct sockaddr_in *sin1, *sin2;
  61: {
  62: 
  63:     return (inet_netof(sin1->sin_addr) == inet_netof(sin2->sin_addr));
  64: }
  65: 
  66: /*
  67:  * Verify the message is from the right port.
  68:  */
  69: inet_portmatch(sin)
  70:     register struct sockaddr_in *sin;
  71: {
  72: 
  73:     return (sin->sin_port == sp->s_port);
  74: }
  75: 
  76: /*
  77:  * Verify the message is from a "trusted" port.
  78:  */
  79: inet_portcheck(sin)
  80:     struct sockaddr_in *sin;
  81: {
  82: 
  83:     return (ntohs(sin->sin_port) <= IPPORT_RESERVED);
  84: }
  85: 
  86: /*
  87:  * Internet output routine.
  88:  */
  89: inet_output(s, flags, sin, size)
  90:     int s, flags;
  91:     struct sockaddr_in *sin;
  92:     int size;
  93: {
  94:     struct sockaddr_in dst;
  95: 
  96:     dst = *sin;
  97:     sin = &dst;
  98:     if (sin->sin_port == 0)
  99:         sin->sin_port = sp->s_port;
 100:     if (sendto(s, packet, size, flags, sin, sizeof (*sin)) < 0)
 101:         perror("sendto");
 102: }
 103: 
 104: /*
 105:  * Return 1 if the address is believed
 106:  * for an Internet host -- THIS IS A KLUDGE.
 107:  */
 108: inet_checkhost(sin)
 109:     struct sockaddr_in *sin;
 110: {
 111:     u_long n = ntohl(sin->sin_addr.s_addr);
 112:     int i;
 113: 
 114: #ifdef IN_BADCLASS
 115: #undef IN_BADCLASS
 116: #endif IN_BADCLASS
 117: 
 118: #define IN_BADCLASS(n)  (((long) (n) & 0xe0000000) == 0xe0000000)
 119: 
 120:     if (IN_BADCLASS(n) || sin->sin_port != 0)
 121:         return (0);
 122:     if (n != 0 && (n & 0xff000000) == 0)
 123:         return (0);
 124:     for (i = 0; i < sizeof(sin->sin_zero)/sizeof(sin->sin_zero[0]); i++)
 125:         if (sin->sin_zero[i])
 126:             return (0);
 127:     return (1);
 128: }
 129: 
 130: inet_canon(sin)
 131:     struct sockaddr_in *sin;
 132: {
 133: 
 134:     sin->sin_port = 0;
 135: }
 136: 
 137: char *
 138: inet_format(sin)
 139:     struct sockaddr_in *sin;
 140: {
 141:     char *inet_ntoa();
 142: 
 143:     return (inet_ntoa(sin->sin_addr));
 144: }

Defined functions

inet_canon defined in line 130; used 2 times
inet_checkhost defined in line 108; used 2 times
inet_format defined in line 137; used 2 times
inet_hash defined in line 39; used 2 times
inet_netmatch defined in line 59; used 2 times
inet_output defined in line 89; used 2 times
inet_portcheck defined in line 79; used 2 times
inet_portmatch defined in line 69; 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 118; used 3 times
NIL defined in line 21; used 2 times
Last modified: 1994-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1303
Valid CSS Valid XHTML 1.0 Strict