PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : gethostbyname2



403
26-06-2006, 17:55
Hallo .*

Als langsamster C Programierer der Welt ;) mal folgende Frage zu einem
Coredump. Ich möcht eigentlich nur ::1 zu localhost auflösen, bzw. später
2001::23 zu rtfm.local usw...



#include<stdio.h>
#include<err.h>
#include<netdb.h>
#include<netinet/in.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<resolv.h>


//static int
int lookup_host6 (char *host, struct in6_addr *ip6addr)
{
extern int h_errno;
struct hostent *he;
printf("in_lookup_host6_before_gethostbyname2\n");

if (!inet_pton(AF_INET6, host, ip6addr)) {
if ((he = gethostbyname2(host, AF_INET6)) == NULL)
printf("h_errno: %d\n",h_errno);
printf("he==NULL\n");
return(-1);
printf("nach_lookup_host6_before_gethostbyname2\n");
memcpy(ip6addr, he->h_addr_list[0], sizeof( struct in6_addr));
}
return(0);
}

int main(int argc, char *argv[]) {

char *host = argv[1];
int family = 28 ;
struct in6_addr *ip6addr;
//socklen_t ss = sizeof(argv[1]); //ai.addrlen ;
//extern const struct in6_addr in6addr_any;
//extern const struct in6_addr in6addr_loopback;
res_init();
_res.options |= RES_USE_INET6;
_res.options |= RES_DEBUG;

if (!argv[1]) {
printf("usage: %s IPv6 Address\n", argv[0]);
exit(1);
}

printf("before_main:lookup_host\n");
printf("%s has Address %s, family %d\n", argv[1],lookup_host6(ip6addr,family));
//printf("%s has Address %s n", lookup_host6(argv[1],ip6addr));
//printf("%s has Address %d, family %d\n", argv[1],lookup_host6(host,ip6addr));
printf("after_main:lookup_host\n");
}
%gcc -Wall -g broken.c
broken.c: In function `lookup_host6':
broken.c:25: warning: implicit declaration of function `memcpy'
broken.c: In function `main':
broken.c:44: warning: implicit declaration of function `exit'
broken.c:48: warning: passing arg 1 of `lookup_host6' from incompatible pointer type
broken.c:48: warning: passing arg 2 of `lookup_host6' makes pointer from integer without a cast
broken.c:48: warning: format argument is not a pointer (arg 3)
broken.c:48: warning: too few arguments for format
broken.c:32: warning: unused variable `host'
broken.c:52: warning: control reaches end of non-void function



Start des Programms:


%./a.out ::1
before_main:lookup_host
in_lookup_host6_before_gethostbyname2
;; res_querydomain(\uffff\uffff\uffffU\uffff\uffff\uf fff\uffff\uffff\uffffE\uffff\uffffE^L\uffffE\uffff \uffffE\uffffE\uffff\uffffE\uffff\uffffE\uffff, foobar.de, 1, 28)
;; res_query(\uffff\uffff\uffffU\uffff\uffff\uffff\uf fff\uffff\uffffE\uffff\uffffE^L\uffffE\uffff\uffff E\uffffE\uffff\uffffE\uffff\uffffE\uffff.foobar.de , 1, 28)
;; res_mkquery(0, \uffff\uffff\uffffU\uffff\uffff\uffff\uffff\uffff\ uffffE\uffff\uffffE^L\uffffE\uffff\uffffE\uffffE\u ffff\uffffE\uffff\uffffE\uffff.foobar.de, 1, 28)
;; res_send()
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49562
;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; \201\195\144U\137\229\131\236\024\139E\008\137E\23 6\139E\012\137E\240\139E\016\137E\244\141E\232\199 E\232\002.foobar.de, type = AAAA, class = IN
;; Querying server (# 1) address = 0.0.0.0
;; got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 49562
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; \201\195\144U\137\229\131\236\024\139E\008\137E\23 6\139E\012\137E\240\139E\016\137E\244\141E\232\199 E\232\002.foobar.de, type = AAAA, class = IN
foobar.de. 2D IN SOA foobar.de. root.foobar.de. (
2006021022 ; serial
1D ; refresh
2H ; retry
1W ; expiry
2D ) ; minimum

;; rcode = 3, ancount=0
;; res_querydomain(\uffff\uffff\uffffU\uffff\uffff\uf fff\uffff\uffff\uffffE\uffff\uffffE^L\uffffE\uffff \uffffE\uffffE\uffff\uffffE\uffff\uffffE\uffff, <Nil>, 1, 28)
;; res_query(\uffff\uffff\uffffU\uffff\uffff\uffff\uf fff\uffff\uffffE\uffff\uffffE^L\uffffE\uffff\uffff E\uffffE\uffff\uffffE\uffff\uffffE\uffff, 1, 28)
;; res_mkquery(0, \uffff\uffff\uffffU\uffff\uffff\uffff\uffff\uffff\ uffffE\uffff\uffffE^L\uffffE\uffff\uffffE\uffffE\u ffff\uffffE\uffff\uffffE\uffff, 1, 28)
;; res_send()
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49563
;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; \201\195\144U\137\229\131\236\024\139E\008\137E\23 6\139E\012\137E\240\139E\016\137E\244\141E\232\199 E\232\002, type = AAAA, class = IN
;; Querying server (# 1) address = 0.0.0.0
server rejected query:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 49563
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; \201\195\144U\137\229\131\236\024\139E\008\137E\23 6\139E\012\137E\240\139E\016\137E\244\141E\232\199 E\232\002, type = AAAA, class = IN
;; res_query: send error
res_search failed (-1)
h_errno: 2
he==NULL
Segmentation fault (core dumped)
%gdb ./aout aout.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...
Core was generated by `a.out'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
#0 0x2811fe5f in __vfprintf () from /lib/libc.so.6
(gdb) bt full
#0 0x2811fe5f in __vfprintf () from /lib/libc.so.6
No symbol table info available.
#1 0x28120a1c in vfprintf () from /lib/libc.so.6
No symbol table info available.
#2 0x2810e09b in printf () from /lib/libc.so.6
No symbol table info available.
#3 0x08048735 in main (argc=2, argv=0xbfbfea14) at broken.c:48
host = 0xbfbfeaf4 "::1"
family = 28
ip6addr = (struct in6_addr *) 0x28127641
(gdb) quit
%exit
exit


Offenbar versucht das Ding bereits aufzulösen.