Saturday, September 6, 2014

Unix Prog: Other system data files

1. hosts

hosts file is used to map the networking address to the host machine.

/etc/hosts:
 ubuntu@ip-172-31-23-227:~$ less /etc/hosts  
 127.0.0.1 localhost  
   
 # The following lines are desirable for IPv6 capable hosts  
 ::1 ip6-localhost ip6-loopback  
 fe00::0 ip6-localnet  
 ff00::0 ip6-mcastprefix  
 ff02::1 ip6-allnodes  
 ff02::2 ip6-allrouters  
 ff02::3 ip6-allhosts  

system calls:
 ubuntu@ip-172-31-23-227:~$ less /usr/include/netdb.h  
 ......  
 /* Description of data base entry for a single host. */  
 struct hostent  
 {  
  char *h_name;         /* Official name of host. */  
  char **h_aliases;       /* Alias list. */  
  int h_addrtype;        /* Host address type. */  
  int h_length;         /* Length of address. */  
  char **h_addr_list;      /* List of addresses from name server. */  
 #if defined __USE_MISC || defined __USE_GNU  
 # define    h_addr h_addr_list[0] /* Address, for backward compatibility.*/  
 #endif  
 };  
   
 /* Open host data base files and mark them as staying open even after  
   a later search if STAY_OPEN is non-zero.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern void sethostent (int __stay_open);  
   
 /* Close host data base files and clear `stay open' flag.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern void endhostent (void);  
   
 /* Get next entry from host data base file. Open data base if  
   necessary.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct hostent *gethostent (void);  
   
 /* Return entry from host data base which address match ADDR with  
   length LEN and type TYPE.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct hostent *gethostbyaddr (const void *__addr, __socklen_t __len,  
                    int __type);  
   
 /* Return entry from host data base for host with NAME.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct hostent *gethostbyname (const char *__name);  
 ......  

2. networks

networks is used to describe the known DARPA networks and symbolic names for these networks.

/etc/networks:
 ubuntu@ip-172-31-23-227:~$ less /etc/networks  
 # symbolic names for networks, see networks(5) for more information  
 link-local 169.254.0.0  

system calls:
 ubuntu@ip-172-31-23-227:~$ less /usr/include/netdb.h  
 ......  
 /* Open network data base files and mark them as staying open even  
   after a later search if STAY_OPEN is non-zero.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern void setnetent (int __stay_open);  
   
 /* Close network data base files and clear `stay open' flag.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern void endnetent (void);  
   
 /* Get next entry from network data base file. Open data base if  
   necessary.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct netent *getnetent (void);  
   
 /* Return entry from network data base which address match NET and  
   type TYPE.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct netent *getnetbyaddr (uint32_t __net, int __type);  
   
 /* Return entry from network data base for network with NAME.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct netent *getnetbyname (const char *__name);  
 ......  

3. protocols

protocols is used to describe various DARPA internet protocols that are available from the TCP/IP subsystems.

/etc/protocols:
 ubuntu@ip-172-31-23-227:~$ less /etc/protocols  
 # Internet (IP) protocols  
 #  
 # Updated from http://www.iana.org/assignments/protocol-numbers and other  
 # sources.  
 # New protocols will be added on request if they have been officially  
 # assigned by IANA and are not historical.  
 # If you need a huge list of used numbers please install the nmap package.  
   
 ip   0    IP       # internet protocol, pseudo protocol number  
 hopopt 0    HOPOPT     # IPv6 Hop-by-Hop Option [RFC1883]  
 icmp  1    ICMP      # internet control message protocol  
 igmp  2    IGMP      # Internet Group Management  
 ggp   3    GGP       # gateway-gateway protocol  
 ipencap 4    IP-ENCAP    # IP encapsulated in IP (officially ``IP'')  
 st   5    ST       # ST datagram mode  
 tcp   6    TCP       # transmission control protocol  
 ......  

System Calls:
 ubuntu@ip-172-31-23-227:~$ less /usr/include/netdb.h  
 ......  
 /* Description of data base entry for a single service. */  
 struct protoent  
 {  
  char *p_name;         /* Official protocol name. */  
  char **p_aliases;       /* Alias list. */  
  int p_proto;         /* Protocol number. */  
 };  
   
 /* Open protocol data base files and mark them as staying open even  
   after a later search if STAY_OPEN is non-zero.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern void setprotoent (int __stay_open);  
   
 /* Close protocol data base files and clear `stay open' flag.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern void endprotoent (void);  
   
 /* Get next entry from protocol data base file. Open data base if  
   necessary.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct protoent *getprotoent (void);  
   
 /* Return entry from protocol data base for network with NAME.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct protoent *getprotobyname (const char *__name);  
   
 /* Return entry from protocol data base which number is PROTO.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct protoent *getprotobynumber (int __proto);  
 ......  

4. services
services is used to describe the mapping between textual names and underlying assigned port numbers and protocol types.

/etc/services:
 ubuntu@ip-172-31-23-227:~$ less /etc/services  
 ......  
 # Network services, Internet style  
 #  
 # Note that it is presently the policy of IANA to assign a single well-known  
 # port number for both TCP and UDP; hence, officially ports have two entries  
 # even if the protocol doesn't support UDP operations.  
 #  
 # Updated from http://www.iana.org/assignments/port-numbers and other  
 # sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services .  
 # New ports will be added on request if they have been officially assigned  
 # by IANA and used in the real-world or are needed by a debian package.  
 # If you need a huge list of used numbers please install the nmap package.  
   
 tcpmux     1/tcp              # TCP port service multiplexer  
 echo      7/tcp  
 echo      7/udp  
 discard     9/tcp      sink null  
 discard     9/udp      sink null  
 systat     11/tcp     users  
 ......  

System Calls:
 ubuntu@ip-172-31-23-227:~$ less /usr/include/netdb.h  
 ......  
 /* Description of data base entry for a single service. */  
 struct servent  
 {  
  char *s_name;         /* Official service name. */  
  char **s_aliases;       /* Alias list. */  
  int s_port;          /* Port number. */  
  char *s_proto;        /* Protocol to use. */  
 };  
   
 /* Open service data base files and mark them as staying open even  
   after a later search if STAY_OPEN is non-zero.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern void setservent (int __stay_open);  
   
 /* Close service data base files and clear `stay open' flag.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern void endservent (void);  
   
 /* Get next entry from service data base file. Open data base if  
   necessary.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct servent *getservent (void);  
   
 /* Return entry from network data base for network with NAME and  
   protocol PROTO.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct servent *getservbyname (const char *__name, const char *__proto);  
   
 /* Return entry from service data base which matches port PORT and  
   protocol PROTO.  
   
   This function is a possible cancellation point and therefore not  
   marked with __THROW. */  
 extern struct servent *getservbyport (int __port, const char *__proto);  
 ......  

No comments:

Post a Comment