7 /* inet-domain name services
9 /* #include <find_inet.h>
11 /* unsigned find_inet_addr(host)
14 /* int find_inet_port(port, proto)
18 /* These functions translate network address information from
19 /* between printable form to the internal the form used by the
20 /* BSD TCP/IP network software.
22 /* find_inet_addr() translates a symbolic or numerical hostname.
23 /* This function is deprecated. Use hostname_to_hostaddr() instead.
25 /* find_inet_port() translates a symbolic or numerical port name.
27 /* find_inet_addr() ignores all but the first address listed for
28 /* a symbolic hostname.
30 /* Lookup and conversion errors are fatal.
34 /* The Secure Mailer license must be distributed with this software.
37 /* IBM T.J. Watson Research
39 /* Yorktown Heights, NY 10598, USA
42 /* System libraries. */
45 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <arpa/inet.h>
52 /* Application-specific. */
55 #include "stringops.h"
56 #include "find_inet.h"
59 #define INADDR_NONE 0xffffffff
62 /* find_inet_addr - translate numerical or symbolic host name */
64 unsigned find_inet_addr(const char *host
)
69 addr
.s_addr
= inet_addr(host
);
70 if ((addr
.s_addr
== INADDR_NONE
) || (addr
.s_addr
== 0)) {
71 if ((hp
= gethostbyname(host
)) == 0)
72 msg_fatal("host not found: %s", host
);
73 if (hp
->h_addrtype
!= AF_INET
)
74 msg_fatal("unexpected address family: %d", hp
->h_addrtype
);
75 if (hp
->h_length
!= sizeof(addr
))
76 msg_fatal("unexpected address length %d", hp
->h_length
);
77 memcpy((char *) &addr
, hp
->h_addr
, hp
->h_length
);
82 /* find_inet_port - translate numerical or symbolic service name */
84 int find_inet_port(const char *service
, const char *protocol
)
89 if (alldig(service
) && (port
= atoi(service
)) != 0) {
90 if (port
< 0 || port
> 65535)
91 msg_fatal("bad port number: %s", service
);
94 if ((sp
= getservbyname(service
, protocol
)) == 0)
95 msg_fatal("unknown service: %s/%s", service
, protocol
);