1: #ifndef lint
   2: static char *sccsid = "@(#)access_inet.c	1.4	(Berkeley) 1/9/88";
   3: #endif
   4: 
   5: #include "common.h"
   6: 
   7: #include <stdio.h>
   8: #include <sys/socket.h>
   9: #include <netinet/in.h>
  10: #ifndef EXCELAN
  11: #include <netdb.h>
  12: #include <arpa/inet.h>
  13: #endif
  14: 
  15: /*
  16:  * inet_netnames -- return the network, subnet, and host names of
  17:  * our peer process for the Internet domain.
  18:  *
  19:  *	Parameters:	"sock" is our socket, which we don't need.
  20:  *			"sin" is a pointer to the result of
  21:  *			a getpeername() call.
  22:  *			"net_name", "subnet_name", and "host_name"
  23:  *			are filled in by this routine with the
  24:  *			corresponding ASCII names of our peer.
  25:  *	Returns:	Nothing.
  26:  *	Side effects:	None.
  27:  */
  28: 
  29: inet_netnames(sock, sin, net_name, subnet_name, host_name)
  30:     int         sock;
  31:     struct sockaddr_in  *sin;
  32:     char            *net_name;
  33:     char            *subnet_name;
  34:     char            *host_name;
  35: {
  36: #ifdef EXCELAN
  37:     excelan_netnames(sock, sin, net_name, subnet_name, host_name);
  38: #else
  39:     static int      gotsubnetconf;
  40:     u_long          net_addr;
  41:     u_long          subnet_addr;
  42:     struct hostent      *hp;
  43:     struct netent       *np;
  44: 
  45: #ifdef SUBNET
  46:     if (!gotsubnetconf) {
  47:         if (getifconf() < 0) {
  48: #ifdef SYSLOG
  49:             syslog(LOG_ERR, "host_access: getifconf: %m");
  50: #endif
  51:             return;
  52:         }
  53:         gotsubnetconf = 1;
  54:     }
  55: #endif
  56: 
  57:     net_addr = inet_netof(sin->sin_addr);   /* net_addr in host order */
  58:     np = getnetbyaddr(net_addr, AF_INET);
  59:     if (np != NULL)
  60:         (void) strcpy(net_name, np->n_name);
  61:     else
  62:         (void) strcpy(net_name,inet_ntoa(*(struct in_addr *)&net_addr));
  63: 
  64: #ifdef SUBNET
  65:     subnet_addr = inet_snetof(sin->sin_addr.s_addr);
  66:     if (subnet_addr == 0)
  67:         subnet_name[0] = '\0';
  68:     else {
  69:         np = getnetbyaddr(subnet_addr, AF_INET);
  70:         if (np != NULL)
  71:             (void) strcpy(subnet_name, np->n_name);
  72:         else
  73:             (void) strcpy(subnet_name,
  74:                 inet_ntoa(*(struct in_addr *)&subnet_addr));
  75:     }
  76: #else
  77:     subnet_name[0] = '\0';
  78: #endif SUBNET
  79: 
  80:     hp = gethostbyaddr((char *) &sin->sin_addr.s_addr,
  81:         sizeof (sin->sin_addr.s_addr), AF_INET);
  82:     if (hp != NULL)
  83:         (void) strcpy(host_name, hp->h_name);
  84:     else
  85:         (void) strcpy(host_name, inet_ntoa(sin->sin_addr));
  86: #endif
  87: }
  88: 
  89: 
  90: #ifdef EXCELAN
  91: excelan_netnames(sock, sin, net_name, subnet_name, host_name)
  92:     int         sock;
  93:     struct sockaddr_in  *sin;
  94:     char            *net_name;
  95:     char            *subnet_name;
  96:     char            *host_name;
  97: {
  98:     char *hp, *raddr();
  99:     int octet[4];
 100: 
 101:     /* assumes sizeof addr is long */
 102:     octet[0] = (sin->sin_addr.s_addr>>24)&0xff;
 103:     octet[1] = (sin->sin_addr.s_addr>>16)&0xff;
 104:     octet[2] = (sin->sin_addr.s_addr>>8 )&0xff;
 105:     octet[3] = (sin->sin_addr.s_addr    )&0xff;
 106: 
 107:     hp = raddr(sin->sin_addr.s_addr);
 108:     if (hp != NULL)
 109:         (void) strcpy(host_name,hp);
 110:     else
 111: 
 112:         (void) sprintf(host_name,"%d.%d.%d.%d",
 113:             octet[0],octet[1],octet[2],octet[3]);
 114:     /* No inet* routines here, so we fake it. */
 115:     if (octet[0] < 128)     /* CLASS A address */
 116:         (void) sprintf(net_name,"%d",octet[0]);
 117:     else if(octet[0] < 192)     /* CLASS B address */
 118:             (void) sprintf(net_name,"%d.%d",
 119:                         octet[0],octet[1]);
 120:         else            /* CLASS C address */
 121:             (void) sprintf(net_name,"%d.%d.%d",
 122:                     octet[0],octet[1],octet[2]);
 123: 
 124: /* hack to cover the subnet stuff */
 125:     (void) sprintf(subnet_name,"%d.%d.%d",octet[0],octet[1],octet[2]);
 126: }
 127: #endif

Defined functions

excelan_netnames defined in line 91; used 1 times
  • in line 37
inet_netnames defined in line 29; used 1 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1988-01-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3159
Valid CSS Valid XHTML 1.0 Strict