getnameinfo.c (92986) | getnameinfo.c (99252) |
---|---|
1/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ 2 3/* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 23 unchanged lines hidden (view full) --- 32/* 33 * Issues to be discussed: 34 * - Thread safe-ness must be checked 35 * - RFC2553 says that we should raise error on short buffer. X/Open says 36 * we need to truncate the result. We obey RFC2553 (and X/Open should be 37 * modified). ipngwg rough consensus seems to follow RFC2553. 38 * - What is "local" in NI_FQDN? 39 * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other. | 1/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ 2 3/* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 23 unchanged lines hidden (view full) --- 32/* 33 * Issues to be discussed: 34 * - Thread safe-ness must be checked 35 * - RFC2553 says that we should raise error on short buffer. X/Open says 36 * we need to truncate the result. We obey RFC2553 (and X/Open should be 37 * modified). ipngwg rough consensus seems to follow RFC2553. 38 * - What is "local" in NI_FQDN? 39 * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other. |
40 * - (KAME extension) NI_WITHSCOPEID when called with global address, 41 * and sin6_scope_id filled | 40 * - (KAME extension) always attach textual scopeid (fe80::1%lo0), if 41 * sin6_scope_id is filled - standardization status? 42 * XXX breaks backward compat for code that expects no scopeid. 43 * beware on merge. |
42 */ 43 44#include <sys/cdefs.h> | 44 */ 45 46#include <sys/cdefs.h> |
45__FBSDID("$FreeBSD: head/lib/libc/net/getnameinfo.c 92986 2002-03-22 21:53:29Z obrien $"); | 47__FBSDID("$FreeBSD: head/lib/libc/net/getnameinfo.c 99252 2002-07-02 11:05:31Z ume $"); |
46 47#include <sys/types.h> 48#include <sys/socket.h> 49#include <net/if.h> 50#include <netinet/in.h> 51#include <arpa/inet.h> 52#include <arpa/nameser.h> 53#include <netdb.h> --- 249 unchanged lines hidden (view full) --- 303 == NULL) 304 return ENI_SYSTEM; 305 306 numaddrlen = strlen(numaddr); 307 if (numaddrlen + 1 > hostlen) /* don't forget terminator */ 308 return ENI_MEMORY; 309 strcpy(host, numaddr); 310 | 48 49#include <sys/types.h> 50#include <sys/socket.h> 51#include <net/if.h> 52#include <netinet/in.h> 53#include <arpa/inet.h> 54#include <arpa/nameser.h> 55#include <netdb.h> --- 249 unchanged lines hidden (view full) --- 305 == NULL) 306 return ENI_SYSTEM; 307 308 numaddrlen = strlen(numaddr); 309 if (numaddrlen + 1 > hostlen) /* don't forget terminator */ 310 return ENI_MEMORY; 311 strcpy(host, numaddr); 312 |
311#ifdef NI_WITHSCOPEID 312 if ( 313#ifdef DONT_OPAQUE_SCOPEID 314 (IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)addr) || 315 IN6_IS_ADDR_MULTICAST((struct in6_addr *)addr)) && 316#endif 317 ((const struct sockaddr_in6 *)sa)->sin6_scope_id) { 318#ifndef ALWAYS_WITHSCOPE 319 if (flags & NI_WITHSCOPEID) 320#endif /* !ALWAYS_WITHSCOPE */ 321 { 322 char scopebuf[MAXHOSTNAMELEN]; 323 int scopelen; | 313 if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) { 314 char zonebuf[MAXHOSTNAMELEN]; 315 int zonelen; |
324 | 316 |
325 /* ip6_sa2str never fails */ 326 scopelen = ip6_sa2str((const struct sockaddr_in6 *)sa, 327 scopebuf, sizeof(scopebuf), 328 flags); 329 if (scopelen + 1 + numaddrlen + 1 > hostlen) 330 return ENI_MEMORY; 331 /* 332 * construct <numeric-addr><delim><scopeid> 333 */ 334 memcpy(host + numaddrlen + 1, scopebuf, 335 scopelen); 336 host[numaddrlen] = SCOPE_DELIMITER; 337 host[numaddrlen + 1 + scopelen] = '\0'; 338 } | 317 /* ip6_sa2str never fails */ 318 zonelen = ip6_sa2str( 319 (const struct sockaddr_in6 *)(const void *)sa, 320 zonebuf, sizeof(zonebuf), flags); 321 if (zonelen < 0) 322 return EAI_MEMORY; 323 if (zonelen + 1 + numaddrlen + 1 > hostlen) 324 return ENI_MEMORY; 325 /* construct <numeric-addr><delim><scopeid> */ 326 memcpy(host + numaddrlen + 1, zonebuf, 327 (size_t)zonelen); 328 host[numaddrlen] = SCOPE_DELIMITER; 329 host[numaddrlen + 1 + zonelen] = '\0'; |
339 } | 330 } |
340#endif /* NI_WITHSCOPEID */ | |
341 342 return 0; 343} 344 345/* ARGSUSED */ 346static int 347ip6_sa2str(sa6, buf, bufsiz, flags) 348 const struct sockaddr_in6 *sa6; --- 26 unchanged lines hidden --- | 331 332 return 0; 333} 334 335/* ARGSUSED */ 336static int 337ip6_sa2str(sa6, buf, bufsiz, flags) 338 const struct sockaddr_in6 *sa6; --- 26 unchanged lines hidden --- |