* Copyright (c) 1988-1990 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Name to id translation routines used by the scanner.
* These functions are not time critical.
"@(#) $Header: nametoaddr.c,v 1.9 91/02/04 16:56:46 mccanne Exp $ (LBL)";
#include <netinet/if_ether.h>
* Convert host name to internet address.
if (hp
= gethostbyname(name
)) {
hlist
[0] = (u_long
*)hp
->h_addr
;
for (p
= (u_long
**)hp
->h_addr_list
; *p
; ++p
)
return (u_long
**)hp
->h_addr_list
;
* Convert net name to internet address.
if (np
= getnetbyname(name
))
* Convert a port name to its port and protocol numbers.
* We assume only TCP or UDP.
s_nametoport(name
, port
, proto
)
sp
= getservbyname(name
, (char *)0);
*proto
= s_nametoproto(sp
->s_proto
);
* We need to check /etc/services for ambiguous entries.
* If we find the ambiguous entry, and it has the
* same port number, change the proto to PROTO_UNDEF
* so both TCP and UDP will be checked.
if (*proto
== IPPROTO_TCP
)
sp
= getservbyname(name
, other
);
/* Can't handle ambigous names that refer
to different port numbers. */
warning("ambiguous port %s in /etc/services",
/* Special hack in case NFS isn't in /etc/services */
if (strcmp(name
, "nfs") == 0) {
struct eproto
*p
= eproto_db
;
if (strcmp(p
->s
, s
) == 0)
/* Hex digit to integer. */
* Convert 's' which has the form "xx:xx:xx:xx:xx:xx" into a new
* ethernet address. Assumes 's' is well formed.
e
= ep
= (u_char
*)malloc(6);
fp
= fopen(ETHERS_FILE
, "r");
while (ep
= next_etherent(fp
)) {
if (strcmp(ep
->name
, name
) == 0) {
ap
= (u_char
*)malloc(6);