]> The Tcpdump Group git mirrors - libpcap/blob - nametoaddr.c
Squelch some warnings.
[libpcap] / nametoaddr.c
1 /*
2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * Name to id translation routines used by the scanner.
22 * These functions are not time critical.
23 */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #ifdef DECNETLIB
30 #include <sys/types.h>
31 #include <netdnet/dnetdb.h>
32 #endif
33
34 #ifdef _WIN32
35 #include <winsock2.h>
36 #include <ws2tcpip.h>
37
38 #ifdef INET6
39 /*
40 * To quote the MSDN page for getaddrinfo() at
41 *
42 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx
43 *
44 * "Support for getaddrinfo on Windows 2000 and older versions
45 * The getaddrinfo function was added to the Ws2_32.dll on Windows XP and
46 * later. To execute an application that uses this function on earlier
47 * versions of Windows, then you need to include the Ws2tcpip.h and
48 * Wspiapi.h files. When the Wspiapi.h include file is added, the
49 * getaddrinfo function is defined to the WspiapiGetAddrInfo inline
50 * function in the Wspiapi.h file. At runtime, the WspiapiGetAddrInfo
51 * function is implemented in such a way that if the Ws2_32.dll or the
52 * Wship6.dll (the file containing getaddrinfo in the IPv6 Technology
53 * Preview for Windows 2000) does not include getaddrinfo, then a
54 * version of getaddrinfo is implemented inline based on code in the
55 * Wspiapi.h header file. This inline code will be used on older Windows
56 * platforms that do not natively support the getaddrinfo function."
57 *
58 * We use getaddrinfo(), so we include Wspiapi.h here.
59 */
60 #include <wspiapi.h>
61 #endif /* INET6 */
62 #else /* _WIN32 */
63 #include <sys/param.h>
64 #include <sys/types.h>
65 #include <sys/socket.h>
66 #include <sys/time.h>
67
68 #include <netinet/in.h>
69
70 #ifdef HAVE_ETHER_HOSTTON
71 #if defined(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
72 /*
73 * OK, just include <net/ethernet.h>.
74 */
75 #include <net/ethernet.h>
76 #elif defined(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
77 /*
78 * OK, just include <netinet/ether.h>
79 */
80 #include <netinet/ether.h>
81 #elif defined(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
82 /*
83 * OK, just include <sys/ethernet.h>
84 */
85 #include <sys/ethernet.h>
86 #elif defined(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
87 /*
88 * OK, just include <arpa/inet.h>
89 */
90 #include <arpa/inet.h>
91 #elif defined(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
92 /*
93 * OK, include <netinet/if_ether.h>, after all the other stuff we
94 * need to include or define for its benefit.
95 */
96 #define NEED_NETINET_IF_ETHER_H
97 #else
98 /*
99 * We'll have to declare it ourselves.
100 * If <netinet/if_ether.h> defines struct ether_addr, include
101 * it. Otherwise, define it ourselves.
102 */
103 #ifdef HAVE_STRUCT_ETHER_ADDR
104 #define NEED_NETINET_IF_ETHER_H
105 #else /* HAVE_STRUCT_ETHER_ADDR */
106 struct ether_addr {
107 unsigned char ether_addr_octet[6];
108 };
109 #endif /* HAVE_STRUCT_ETHER_ADDR */
110 #endif /* what declares ether_hostton() */
111
112 #ifdef NEED_NETINET_IF_ETHER_H
113 #include <net/if.h> /* Needed on some platforms */
114 #include <netinet/in.h> /* Needed on some platforms */
115 #include <netinet/if_ether.h>
116 #endif /* NEED_NETINET_IF_ETHER_H */
117
118 #ifndef HAVE_DECL_ETHER_HOSTTON
119 /*
120 * No header declares it, so declare it ourselves.
121 */
122 extern int ether_hostton(const char *, struct ether_addr *);
123 #endif /* !defined(HAVE_DECL_ETHER_HOSTTON) */
124 #endif /* HAVE_ETHER_HOSTTON */
125
126 #include <arpa/inet.h>
127 #include <netdb.h>
128 #endif /* _WIN32 */
129
130 #include <ctype.h>
131 #include <errno.h>
132 #include <stdlib.h>
133 #include <string.h>
134 #include <stdio.h>
135
136 #include "pcap-int.h"
137
138 #include "gencode.h"
139 #include <pcap/namedb.h>
140 #include "nametoaddr.h"
141
142 #ifdef HAVE_OS_PROTO_H
143 #include "os-proto.h"
144 #endif
145
146 #ifndef NTOHL
147 #define NTOHL(x) (x) = ntohl(x)
148 #define NTOHS(x) (x) = ntohs(x)
149 #endif
150
151 /*
152 * Convert host name to internet address.
153 * Return 0 upon failure.
154 * XXX - not thread-safe; don't use it inside libpcap.
155 */
156 bpf_u_int32 **
157 pcap_nametoaddr(const char *name)
158 {
159 #ifndef h_addr
160 static bpf_u_int32 *hlist[2];
161 #endif
162 bpf_u_int32 **p;
163 struct hostent *hp;
164
165 if ((hp = gethostbyname(name)) != NULL) {
166 #ifndef h_addr
167 hlist[0] = (bpf_u_int32 *)hp->h_addr;
168 NTOHL(hp->h_addr);
169 return hlist;
170 #else
171 for (p = (bpf_u_int32 **)hp->h_addr_list; *p; ++p)
172 NTOHL(**p);
173 return (bpf_u_int32 **)hp->h_addr_list;
174 #endif
175 }
176 else
177 return 0;
178 }
179
180 struct addrinfo *
181 pcap_nametoaddrinfo(const char *name)
182 {
183 struct addrinfo hints, *res;
184 int error;
185
186 memset(&hints, 0, sizeof(hints));
187 hints.ai_family = PF_UNSPEC;
188 hints.ai_socktype = SOCK_STREAM; /*not really*/
189 hints.ai_protocol = IPPROTO_TCP; /*not really*/
190 error = getaddrinfo(name, NULL, &hints, &res);
191 if (error)
192 return NULL;
193 else
194 return res;
195 }
196
197 /*
198 * Convert net name to internet address.
199 * Return 0 upon failure.
200 * XXX - not guaranteed to be thread-safe! See below for platforms
201 * on which it is thread-safe and on which it isn't.
202 */
203 bpf_u_int32
204 pcap_nametonetaddr(const char *name)
205 {
206 #ifdef _WIN32
207 /*
208 * There's no "getnetbyname()" on Windows.
209 *
210 * XXX - I guess we could use the BSD code to read
211 * C:\Windows\System32\drivers\etc/networks, assuming
212 * that's its home on all the versions of Windows
213 * we use, but that file probably just has the loopback
214 * network on 127/24 on 99 44/100% of Windows machines.
215 *
216 * (Heck, these days it probably just has that on 99 44/100%
217 * of *UN*X* machines.)
218 */
219 return 0;
220 #else
221 /*
222 * UN*X.
223 */
224 struct netent *np;
225 #if defined(HAVE_LINUX_GETNETBYNAME_R)
226 /*
227 * We have Linux's reentrant getnetbyname_r().
228 */
229 struct netent result_buf;
230 char buf[1024]; /* arbitrary size */
231 int h_errnoval;
232 int err;
233
234 err = getnetbyname_r(name, &result_buf, buf, sizeof buf, &np,
235 &h_errnoval);
236 if (err != 0) {
237 /*
238 * XXX - dynamically allocate the buffer, and make it
239 * bigger if we get ERANGE back?
240 */
241 return 0;
242 }
243 #elif defined(HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
244 /*
245 * We have Solaris's and IRIX's reentrant getnetbyname_r().
246 */
247 struct netent result_buf;
248 char buf[1024]; /* arbitrary size */
249
250 np = getnetbyname_r(name, &result_buf, buf, (int)sizeof buf);
251 #elif defined(HAVE_AIX_GETNETBYNAME_R)
252 /*
253 * We have AIX's reentrant getnetbyname_r().
254 */
255 struct netent result_buf;
256 struct netent_data net_data;
257
258 if (getnetbyname_r(name, &result_buf, &net_data) == -1)
259 np = NULL;
260 else
261 np = &result_buf;
262 #else
263 /*
264 * We don't have any getnetbyname_r(); either we have a
265 * getnetbyname() that uses thread-specific data, in which
266 * case we're thread-safe (sufficiently recent FreeBSD,
267 * sufficiently recent Darwin-based OS, sufficiently recent
268 * HP-UX, sufficiently recent Tru64 UNIX), or we have the
269 * traditional getnetbyname() (everything else, including
270 * current NetBSD and OpenBSD), in which case we're not
271 * thread-safe.
272 */
273 np = getnetbyname(name);
274 #endif
275 if (np != NULL)
276 return np->n_net;
277 else
278 return 0;
279 #endif /* _WIN32 */
280 }
281
282 /*
283 * Convert a port name to its port and protocol numbers.
284 * We assume only TCP or UDP.
285 * Return 0 upon failure.
286 */
287 int
288 pcap_nametoport(const char *name, int *port, int *proto)
289 {
290 struct addrinfo hints, *res, *ai;
291 int error;
292 struct sockaddr_in *in4;
293 #ifdef INET6
294 struct sockaddr_in6 *in6;
295 #endif
296 int tcp_port = -1;
297 int udp_port = -1;
298
299 /*
300 * We check for both TCP and UDP in case there are
301 * ambiguous entries.
302 */
303 memset(&hints, 0, sizeof(hints));
304 hints.ai_family = PF_UNSPEC;
305 hints.ai_socktype = SOCK_STREAM;
306 hints.ai_protocol = IPPROTO_TCP;
307 error = getaddrinfo(NULL, name, &hints, &res);
308 if (error != 0) {
309 if (error != EAI_NONAME) {
310 /*
311 * This is a real error, not just "there's
312 * no such service name".
313 * XXX - this doesn't return an error string.
314 */
315 return 0;
316 }
317 } else {
318 /*
319 * OK, we found it. Did it find anything?
320 */
321 for (ai = res; ai != NULL; ai = ai->ai_next) {
322 /*
323 * Does it have an address?
324 */
325 if (ai->ai_addr != NULL) {
326 /*
327 * Yes. Get a port number; we're done.
328 */
329 if (ai->ai_addr->sa_family == AF_INET) {
330 in4 = (struct sockaddr_in *)ai->ai_addr;
331 tcp_port = ntohs(in4->sin_port);
332 break;
333 }
334 #ifdef INET6
335 if (ai->ai_addr->sa_family == AF_INET6) {
336 in6 = (struct sockaddr_in6 *)ai->ai_addr;
337 tcp_port = ntohs(in6->sin6_port);
338 break;
339 }
340 #endif
341 }
342 }
343 freeaddrinfo(res);
344 }
345
346 memset(&hints, 0, sizeof(hints));
347 hints.ai_family = PF_UNSPEC;
348 hints.ai_socktype = SOCK_DGRAM;
349 hints.ai_protocol = IPPROTO_UDP;
350 error = getaddrinfo(NULL, name, &hints, &res);
351 if (error != 0) {
352 if (error != EAI_NONAME) {
353 /*
354 * This is a real error, not just "there's
355 * no such service name".
356 * XXX - this doesn't return an error string.
357 */
358 return 0;
359 }
360 } else {
361 /*
362 * OK, we found it. Did it find anything?
363 */
364 for (ai = res; ai != NULL; ai = ai->ai_next) {
365 /*
366 * Does it have an address?
367 */
368 if (ai->ai_addr != NULL) {
369 /*
370 * Yes. Get a port number; we're done.
371 */
372 if (ai->ai_addr->sa_family == AF_INET) {
373 in4 = (struct sockaddr_in *)ai->ai_addr;
374 udp_port = ntohs(in4->sin_port);
375 break;
376 }
377 #ifdef INET6
378 if (ai->ai_addr->sa_family == AF_INET6) {
379 in6 = (struct sockaddr_in6 *)ai->ai_addr;
380 udp_port = ntohs(in6->sin6_port);
381 break;
382 }
383 #endif
384 }
385 }
386 freeaddrinfo(res);
387 }
388
389 /*
390 * We need to check /etc/services for ambiguous entries.
391 * If we find an ambiguous entry, and it has the
392 * same port number, change the proto to PROTO_UNDEF
393 * so both TCP and UDP will be checked.
394 */
395 if (tcp_port >= 0) {
396 *port = tcp_port;
397 *proto = IPPROTO_TCP;
398 if (udp_port >= 0) {
399 if (udp_port == tcp_port)
400 *proto = PROTO_UNDEF;
401 #ifdef notdef
402 else
403 /* Can't handle ambiguous names that refer
404 to different port numbers. */
405 warning("ambiguous port %s in /etc/services",
406 name);
407 #endif
408 }
409 return 1;
410 }
411 if (udp_port >= 0) {
412 *port = udp_port;
413 *proto = IPPROTO_UDP;
414 return 1;
415 }
416 #if defined(ultrix) || defined(__osf__)
417 /* Special hack in case NFS isn't in /etc/services */
418 if (strcmp(name, "nfs") == 0) {
419 *port = 2049;
420 *proto = PROTO_UNDEF;
421 return 1;
422 }
423 #endif
424 return 0;
425 }
426
427 /*
428 * Convert a string in the form PPP-PPP, where correspond to ports, to
429 * a starting and ending port in a port range.
430 * Return 0 on failure.
431 */
432 int
433 pcap_nametoportrange(const char *name, int *port1, int *port2, int *proto)
434 {
435 u_int p1, p2;
436 char *off, *cpy;
437 int save_proto;
438
439 if (sscanf(name, "%d-%d", &p1, &p2) != 2) {
440 if ((cpy = strdup(name)) == NULL)
441 return 0;
442
443 if ((off = strchr(cpy, '-')) == NULL) {
444 free(cpy);
445 return 0;
446 }
447
448 *off = '\0';
449
450 if (pcap_nametoport(cpy, port1, proto) == 0) {
451 free(cpy);
452 return 0;
453 }
454 save_proto = *proto;
455
456 if (pcap_nametoport(off + 1, port2, proto) == 0) {
457 free(cpy);
458 return 0;
459 }
460 free(cpy);
461
462 if (*proto != save_proto)
463 *proto = PROTO_UNDEF;
464 } else {
465 *port1 = p1;
466 *port2 = p2;
467 *proto = PROTO_UNDEF;
468 }
469
470 return 1;
471 }
472
473 /*
474 * XXX - not guaranteed to be thread-safe! See below for platforms
475 * on which it is thread-safe and on which it isn't.
476 */
477 int
478 pcap_nametoproto(const char *str)
479 {
480 struct protoent *p;
481 #if defined(HAVE_LINUX_GETNETBYNAME_R)
482 /*
483 * We have Linux's reentrant getprotobyname_r().
484 */
485 struct protoent result_buf;
486 char buf[1024]; /* arbitrary size */
487 int err;
488
489 err = getprotobyname_r(str, &result_buf, buf, sizeof buf, &p);
490 if (err != 0) {
491 /*
492 * XXX - dynamically allocate the buffer, and make it
493 * bigger if we get ERANGE back?
494 */
495 return 0;
496 }
497 #elif defined(HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
498 /*
499 * We have Solaris's and IRIX's reentrant getprotobyname_r().
500 */
501 struct protoent result_buf;
502 char buf[1024]; /* arbitrary size */
503
504 p = getprotobyname_r(str, &result_buf, buf, (int)sizeof buf);
505 #elif defined(HAVE_AIX_GETNETBYNAME_R)
506 /*
507 * We have AIX's reentrant getprotobyname_r().
508 */
509 struct protoent result_buf;
510 struct protoent_data proto_data;
511
512 if (getprotobyname_r(str, &result_buf, &proto_data) == -1)
513 p = NULL;
514 else
515 p = &result_buf;
516 #else
517 /*
518 * We don't have any getprotobyname_r(); either we have a
519 * getprotobyname() that uses thread-specific data, in which
520 * case we're thread-safe (sufficiently recent FreeBSD,
521 * sufficiently recent Darwin-based OS, sufficiently recent
522 * HP-UX, sufficiently recent Tru64 UNIX, Windows), or we have
523 * the traditional getprotobyname() (everything else, including
524 * current NetBSD and OpenBSD), in which case we're not
525 * thread-safe.
526 */
527 p = getprotobyname(str);
528 #endif
529 if (p != 0)
530 return p->p_proto;
531 else
532 return PROTO_UNDEF;
533 }
534
535 #include "ethertype.h"
536
537 struct eproto {
538 const char *s;
539 u_short p;
540 };
541
542 /*
543 * Static data base of ether protocol types.
544 * tcpdump used to import this, and it's declared as an export on
545 * Debian, at least, so make it a public symbol, even though we
546 * don't officially export it by declaring it in a header file.
547 * (Programs *should* do this themselves, as tcpdump now does.)
548 */
549 PCAP_API_DEF struct eproto eproto_db[] = {
550 { "pup", ETHERTYPE_PUP },
551 { "xns", ETHERTYPE_NS },
552 { "ip", ETHERTYPE_IP },
553 #ifdef INET6
554 { "ip6", ETHERTYPE_IPV6 },
555 #endif
556 { "arp", ETHERTYPE_ARP },
557 { "rarp", ETHERTYPE_REVARP },
558 { "sprite", ETHERTYPE_SPRITE },
559 { "mopdl", ETHERTYPE_MOPDL },
560 { "moprc", ETHERTYPE_MOPRC },
561 { "decnet", ETHERTYPE_DN },
562 { "lat", ETHERTYPE_LAT },
563 { "sca", ETHERTYPE_SCA },
564 { "lanbridge", ETHERTYPE_LANBRIDGE },
565 { "vexp", ETHERTYPE_VEXP },
566 { "vprod", ETHERTYPE_VPROD },
567 { "atalk", ETHERTYPE_ATALK },
568 { "atalkarp", ETHERTYPE_AARP },
569 { "loopback", ETHERTYPE_LOOPBACK },
570 { "decdts", ETHERTYPE_DECDTS },
571 { "decdns", ETHERTYPE_DECDNS },
572 { (char *)0, 0 }
573 };
574
575 int
576 pcap_nametoeproto(const char *s)
577 {
578 struct eproto *p = eproto_db;
579
580 while (p->s != 0) {
581 if (strcmp(p->s, s) == 0)
582 return p->p;
583 p += 1;
584 }
585 return PROTO_UNDEF;
586 }
587
588 #include "llc.h"
589
590 /* Static data base of LLC values. */
591 static struct eproto llc_db[] = {
592 { "iso", LLCSAP_ISONS },
593 { "stp", LLCSAP_8021D },
594 { "ipx", LLCSAP_IPX },
595 { "netbeui", LLCSAP_NETBEUI },
596 { (char *)0, 0 }
597 };
598
599 int
600 pcap_nametollc(const char *s)
601 {
602 struct eproto *p = llc_db;
603
604 while (p->s != 0) {
605 if (strcmp(p->s, s) == 0)
606 return p->p;
607 p += 1;
608 }
609 return PROTO_UNDEF;
610 }
611
612 /* Hex digit to 8-bit unsigned integer. */
613 static inline u_char
614 xdtoi(u_char c)
615 {
616 if (isdigit(c))
617 return (u_char)(c - '0');
618 else if (islower(c))
619 return (u_char)(c - 'a' + 10);
620 else
621 return (u_char)(c - 'A' + 10);
622 }
623
624 int
625 __pcap_atoin(const char *s, bpf_u_int32 *addr)
626 {
627 u_int n;
628 int len;
629
630 *addr = 0;
631 len = 0;
632 for (;;) {
633 n = 0;
634 while (*s && *s != '.')
635 n = n * 10 + *s++ - '0';
636 *addr <<= 8;
637 *addr |= n & 0xff;
638 len += 8;
639 if (*s == '\0')
640 return len;
641 ++s;
642 }
643 /* NOTREACHED */
644 }
645
646 int
647 __pcap_atodn(const char *s, bpf_u_int32 *addr)
648 {
649 #define AREASHIFT 10
650 #define AREAMASK 0176000
651 #define NODEMASK 01777
652
653 u_int node, area;
654
655 if (sscanf(s, "%d.%d", &area, &node) != 2)
656 return(0);
657
658 *addr = (area << AREASHIFT) & AREAMASK;
659 *addr |= (node & NODEMASK);
660
661 return(32);
662 }
663
664 /*
665 * Convert 's', which can have the one of the forms:
666 *
667 * "xx:xx:xx:xx:xx:xx"
668 * "xx.xx.xx.xx.xx.xx"
669 * "xx-xx-xx-xx-xx-xx"
670 * "xxxx.xxxx.xxxx"
671 * "xxxxxxxxxxxx"
672 *
673 * (or various mixes of ':', '.', and '-') into a new
674 * ethernet address. Assumes 's' is well formed.
675 */
676 u_char *
677 pcap_ether_aton(const char *s)
678 {
679 register u_char *ep, *e;
680 register u_char d;
681
682 e = ep = (u_char *)malloc(6);
683 if (e == NULL)
684 return (NULL);
685
686 while (*s) {
687 if (*s == ':' || *s == '.' || *s == '-')
688 s += 1;
689 d = xdtoi(*s++);
690 if (isxdigit((unsigned char)*s)) {
691 d <<= 4;
692 d |= xdtoi(*s++);
693 }
694 *ep++ = d;
695 }
696
697 return (e);
698 }
699
700 #ifndef HAVE_ETHER_HOSTTON
701 /*
702 * Roll our own.
703 * XXX - not thread-safe, because pcap_next_etherent() isn't thread-
704 * safe! Needs a mutex or a thread-safe pcap_next_etherent().
705 */
706 u_char *
707 pcap_ether_hostton(const char *name)
708 {
709 register struct pcap_etherent *ep;
710 register u_char *ap;
711 static FILE *fp = NULL;
712 static int init = 0;
713
714 if (!init) {
715 fp = fopen(PCAP_ETHERS_FILE, "r");
716 ++init;
717 if (fp == NULL)
718 return (NULL);
719 } else if (fp == NULL)
720 return (NULL);
721 else
722 rewind(fp);
723
724 while ((ep = pcap_next_etherent(fp)) != NULL) {
725 if (strcmp(ep->name, name) == 0) {
726 ap = (u_char *)malloc(6);
727 if (ap != NULL) {
728 memcpy(ap, ep->addr, 6);
729 return (ap);
730 }
731 break;
732 }
733 }
734 return (NULL);
735 }
736 #else
737 /*
738 * Use the OS-supplied routine.
739 * This *should* be thread-safe; the API doesn't have a static buffer.
740 */
741 u_char *
742 pcap_ether_hostton(const char *name)
743 {
744 register u_char *ap;
745 u_char a[6];
746
747 ap = NULL;
748 if (ether_hostton(name, (struct ether_addr *)a) == 0) {
749 ap = (u_char *)malloc(6);
750 if (ap != NULL)
751 memcpy((char *)ap, (char *)a, 6);
752 }
753 return (ap);
754 }
755 #endif
756
757 /*
758 * XXX - not guaranteed to be thread-safe!
759 */
760 int
761 __pcap_nametodnaddr(const char *name, u_short *res)
762 {
763 #ifdef DECNETLIB
764 struct nodeent *getnodebyname();
765 struct nodeent *nep;
766
767 nep = getnodebyname(name);
768 if (nep == ((struct nodeent *)0))
769 return(0);
770
771 memcpy((char *)res, (char *)nep->n_addr, sizeof(unsigned short));
772 return(1);
773 #else
774 return(0);
775 #endif
776 }