5
/* inet-domain name services
7
/* #include <find_inet.h>
9
/* unsigned find_inet_addr(host)
12
/* int find_inet_port(port, proto)
16
/* These functions translate network address information from
17
/* between printable form to the internal the form used by the
18
/* BSD TCP/IP network software.
20
/* find_inet_addr() translates a symbolic or numerical hostname.
22
/* find_inet_port() translates a symbolic or numerical port name.
24
/* find_inet_addr() ignores all but the first address listed for
25
/* a symbolic hostname.
27
/* Lookup and conversion errors are fatal.
31
/* The Secure Mailer license must be distributed with this software.
34
/* IBM T.J. Watson Research
36
/* Yorktown Heights, NY 10598, USA
39
/* System libraries. */
42
#include <sys/socket.h>
43
#include <netinet/in.h>
44
#include <arpa/inet.h>
49
/* Application-specific. */
52
#include "stringops.h"
53
#include "find_inet.h"
56
#define INADDR_NONE 0xffffffff
59
/* find_inet_addr - translate numerical or symbolic host name */
61
unsigned find_inet_addr(const char *host)
66
addr.s_addr = inet_addr(host);
67
if ((addr.s_addr == INADDR_NONE) || (addr.s_addr == 0)) {
68
if ((hp = gethostbyname(host)) == 0)
69
msg_fatal("host not found: %s", host);
70
if (hp->h_addrtype != AF_INET)
71
msg_fatal("unexpected address family: %d", hp->h_addrtype);
72
if (hp->h_length != sizeof(addr))
73
msg_fatal("unexpected address length %d", hp->h_length);
74
memcpy((char *) &addr, hp->h_addr, hp->h_length);
79
/* find_inet_port - translate numerical or symbolic service name */
81
int find_inet_port(const char *service, const char *protocol)
86
if (alldig(service) && (port = atoi(service)) != 0) {
89
if ((sp = getservbyname(service, protocol)) == 0)
90
msg_fatal("unknown service: %s/%s", service, protocol);