Annotation of 43BSDTahoe/new/nntp/server/access_inet.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char    *sccsid = "@(#)access_inet.c    1.2     (Berkeley) 10/15/87";
                      3: #endif
                      4: 
                      5: #include <stdio.h>
                      6: #include <strings.h>
                      7: #include <netdb.h>
                      8: #include <syslog.h>
                      9: #include <sys/types.h>
                     10: #include <sys/socket.h>
                     11: #include <netinet/in.h>
                     12: #include <arpa/inet.h>
                     13: 
                     14: #include "../common/conf.h"
                     15: 
                     16: /*
                     17:  * inet_netnames -- return the network, subnet, and host names of
                     18:  * our peer process for the Internet domain.
                     19:  *
                     20:  *     Parameters:     "sock" is our socket, which we don't need.
                     21:  *                     "sin" is a pointer to the result of
                     22:  *                     a getpeername() call.
                     23:  *                     "net_name", "subnet_name", and "host_name"
                     24:  *                     are filled in by this routine with the
                     25:  *                     corresponding ASCII names of our peer.
                     26:  *     Returns:        Nothing.
                     27:  *     Side effects:   None.
                     28:  */
                     29: 
                     30: inet_netnames(sock, sin, net_name, subnet_name, host_name)
                     31:        int                     sock;
                     32:        struct sockaddr_in      *sin;
                     33:        char                    *net_name;
                     34:        char                    *subnet_name;
                     35:        char                    *host_name;
                     36: {
                     37:        static int              gotsubnetconf;
                     38:        u_long                  net_addr;
                     39:        u_long                  subnet_addr;
                     40:        struct hostent          *hp;
                     41:        struct netent           *np;
                     42: 
                     43: #ifdef SUBNET
                     44:        if (!gotsubnetconf) {
                     45:                if (getifconf() < 0) {
                     46: #ifdef SYSLOG
                     47:                        syslog(LOG_ERR, "host_access: getifconf: %m");
                     48: #endif
                     49:                        return;
                     50:                }
                     51:                gotsubnetconf = 1;
                     52:        }
                     53: #endif
                     54: 
                     55:        net_addr = inet_netof(sin->sin_addr);   /* net_addr in host order */
                     56:        np = getnetbyaddr(net_addr, AF_INET);
                     57:        if (np != NULL)
                     58:                (void) strcpy(net_name, np->n_name);
                     59:        else
                     60:                (void) strcpy(net_name,inet_ntoa(*(struct in_addr *)&net_addr));
                     61: 
                     62: #ifdef SUBNET
                     63:        subnet_addr = inet_snetof(sin->sin_addr.s_addr);
                     64:        if (subnet_addr == 0)
                     65:                subnet_name[0] = '\0';
                     66:        else {
                     67:                np = getnetbyaddr(subnet_addr, AF_INET);
                     68:                if (np != NULL)
                     69:                        (void) strcpy(subnet_name, np->n_name);
                     70:                else
                     71:                        (void) strcpy(subnet_name,
                     72:                            inet_ntoa(*(struct in_addr *)&subnet_addr));
                     73:        }
                     74: #else
                     75:        subnet_name[0] = '\0';
                     76: #endif SUBNET
                     77: 
                     78:        hp = gethostbyaddr((char *) &sin->sin_addr.s_addr,
                     79:                sizeof (sin->sin_addr.s_addr), AF_INET);
                     80:        if (hp != NULL)
                     81:                (void) strcpy(host_name, hp->h_name);
                     82:        else
                     83:                (void) strcpy(host_name, inet_ntoa(sin->sin_addr));
                     84: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.