003 File Manager
Current Path:
/usr/src/crypto/heimdal/lib/roken
usr
/
src
/
crypto
/
heimdal
/
lib
/
roken
/
π
..
π
ChangeLog
(61.03 KB)
π
Makefile.am
(4.47 KB)
π
Makefile.in
(126.5 KB)
π
base64-test.c
(2.95 KB)
π
base64.c
(3.69 KB)
π
base64.h
(1.99 KB)
π
bswap.c
(2.01 KB)
π
chown.c
(1.75 KB)
π
cloexec.c
(2.05 KB)
π
closefrom.c
(1.92 KB)
π
concat.c
(2.91 KB)
π
copyhostent.c
(3.07 KB)
π
ct.c
(2.34 KB)
π
daemon.c
(2.36 KB)
π
doxygen.c
(1.89 KB)
π
dumpdata.c
(2.62 KB)
π
ecalloc.3
(2.71 KB)
π
ecalloc.c
(1.96 KB)
π
emalloc.c
(1.91 KB)
π
environment.c
(3.76 KB)
π
eread.c
(1.9 KB)
π
erealloc.c
(1.93 KB)
π
err.c
(1.8 KB)
π
err.hin
(3.02 KB)
π
errx.c
(1.8 KB)
π
esetenv.c
(1.88 KB)
π
estrdup.c
(1.89 KB)
π
ewrite.c
(1.91 KB)
π
fchown.c
(1.75 KB)
π
flock.c
(3.82 KB)
π
fnmatch.c
(5.05 KB)
π
fnmatch.hin
(2.3 KB)
π
freeaddrinfo.c
(1.94 KB)
π
freehostent.c
(2.03 KB)
π
gai_strerror.c
(2.62 KB)
π
get_default_username.c
(2.58 KB)
π
get_window_size.c
(3.38 KB)
π
getaddrinfo-test.c
(4.04 KB)
π
getaddrinfo.c
(10.05 KB)
π
getaddrinfo_hostspec.c
(3.17 KB)
π
getarg.3
(9.56 KB)
π
getarg.c
(15.34 KB)
π
getarg.h
(3.15 KB)
π
getcap.c
(25.29 KB)
π
getcwd.c
(1.94 KB)
π
getdtablesize.c
(2.89 KB)
π
getegid.c
(1.76 KB)
π
geteuid.c
(1.76 KB)
π
getgid.c
(1.75 KB)
π
gethostname.c
(2.34 KB)
π
getifaddrs.c
(32.46 KB)
π
getipnodebyaddr.c
(2.33 KB)
π
getipnodebyname.c
(2.52 KB)
π
getnameinfo.c
(3.51 KB)
π
getnameinfo_verified.c
(3.14 KB)
π
getopt.c
(3.82 KB)
π
getprogname.c
(1.84 KB)
π
gettimeofday.c
(2.43 KB)
π
getuid.c
(1.75 KB)
π
getusershell.c
(4.47 KB)
π
glob.c
(19.59 KB)
π
glob.hin
(3.83 KB)
π
h_errno.c
(1.69 KB)
π
hex-test.c
(3.02 KB)
π
hex.c
(2.85 KB)
π
hex.h
(2.08 KB)
π
hostent_find_fqdn.c
(2.05 KB)
π
hstrerror.c
(2.54 KB)
π
ifaddrs.hin
(2.52 KB)
π
inet_aton.c
(1.94 KB)
π
inet_ntop.c
(3.97 KB)
π
inet_pton.c
(2.94 KB)
π
initgroups.c
(1.75 KB)
π
innetgr.c
(1.79 KB)
π
install-sh
(5.47 KB)
π
iruserok.c
(7.48 KB)
π
issuid.c
(2.01 KB)
π
k_getpwnam.c
(2.08 KB)
π
k_getpwuid.c
(2.07 KB)
π
localtime_r.c
(2.03 KB)
π
lstat.c
(1.76 KB)
π
memmove.c
(2.02 KB)
π
mini_inetd.c
(5.67 KB)
π
missing
(6.14 KB)
π
mkinstalldirs
(671 B)
π
mkstemp.c
(2.4 KB)
π
ndbm_wrap.c
(5.18 KB)
π
ndbm_wrap.h
(3.13 KB)
π
net_read.c
(3.13 KB)
π
net_write.c
(2.9 KB)
π
parse_bytes-test.c
(2.81 KB)
π
parse_bytes.c
(2.55 KB)
π
parse_bytes.h
(2.13 KB)
π
parse_reply-test.c
(3.49 KB)
π
parse_time-test.c
(4.07 KB)
π
parse_time.3
(4.82 KB)
π
parse_time.c
(2.49 KB)
π
parse_time.h
(2.19 KB)
π
parse_units.c
(7.41 KB)
π
parse_units.h
(2.73 KB)
π
putenv.c
(2.51 KB)
π
qsort.c
(5.35 KB)
π
rand.c
(1.84 KB)
π
rcmd.c
(1.92 KB)
π
readv.c
(2.17 KB)
π
realloc.c
(1.83 KB)
π
recvmsg.c
(2.26 KB)
π
resolve-test.c
(4.91 KB)
π
resolve.c
(21.5 KB)
π
resolve.h
(7.26 KB)
π
rkpty.c
(7.89 KB)
π
roken-common.h
(11.68 KB)
π
roken.awk
(875 B)
π
roken.h.in
(27.79 KB)
π
roken_gethostby.c
(7.26 KB)
π
rtbl.3
(6.53 KB)
π
rtbl.c
(12.11 KB)
π
rtbl.h
(3.61 KB)
π
search.hin
(1007 B)
π
sendmsg.c
(5.37 KB)
π
setegid.c
(1.9 KB)
π
setenv.c
(2.37 KB)
π
seteuid.c
(1.9 KB)
π
setprogname.c
(2.44 KB)
π
signal.c
(2.34 KB)
π
simple_exec.c
(7.51 KB)
π
snprintf-test.c
(8.16 KB)
π
snprintf.c
(14.93 KB)
π
socket.c
(7.89 KB)
π
socket_wrapper.c
(40.97 KB)
π
socket_wrapper.h
(4.52 KB)
π
strcasecmp.c
(2 KB)
π
strcollect.c
(2.64 KB)
π
strdup.c
(1.84 KB)
π
strerror.c
(2 KB)
π
strerror_r.c
(2.73 KB)
π
strftime.c
(8.32 KB)
π
strlcat.c
(2.21 KB)
π
strlcpy.c
(2.23 KB)
π
strlwr.c
(1.86 KB)
π
strncasecmp.c
(2.04 KB)
π
strndup.c
(1.96 KB)
π
strnlen.c
(1.79 KB)
π
strpftime-test.c
(6.04 KB)
π
strpftime-test.h
(2.19 KB)
π
strpool.c
(2.74 KB)
π
strptime.c
(9.21 KB)
π
strsep.c
(1.95 KB)
π
strsep_copy.c
(2.22 KB)
π
strtok_r.c
(2.05 KB)
π
strupr.c
(1.86 KB)
π
swab.c
(1.87 KB)
π
test-mem.c
(4.96 KB)
π
test-mem.h
(1.85 KB)
π
test-readenv.c
(3 KB)
π
timegm.c
(2.72 KB)
π
timeval.c
(2.34 KB)
π
tm2time.c
(2.01 KB)
π
tsearch.c
(4.17 KB)
π
unsetenv.c
(2.14 KB)
π
unvis.c
(6.39 KB)
π
verify.c
(2.1 KB)
π
verr.c
(1.79 KB)
π
verrx.c
(1.79 KB)
π
version-script.map
(3.33 KB)
π
vis.c
(11.45 KB)
π
vis.hin
(4.38 KB)
π
vsyslog.c
(3.13 KB)
π
vwarn.c
(1.77 KB)
π
vwarnx.c
(1.77 KB)
π
warn.c
(1.75 KB)
π
warnerr.c
(2.12 KB)
π
warnx.c
(1.79 KB)
π
write_pid.c
(2.65 KB)
π
writev.c
(2.15 KB)
π
xdbm.h
(1.91 KB)
π
xfree.c
(1.7 KB)
Editing: roken_gethostby.c
/* * Copyright (c) 1998 Kungliga Tekniska HΓΆgskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Neither the name of the Institute nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <config.h> #include "roken.h" #undef roken_gethostbyname #undef roken_gethostbyaddr static struct sockaddr_in dns_addr; static char *dns_req; static int make_address(const char *address, struct in_addr *ip) { if(inet_aton(address, ip) == 0){ /* try to resolve as hostname, it might work if the address we are trying to lookup is local, for instance a web proxy */ struct hostent *he = gethostbyname(address); if(he) { unsigned char *p = (unsigned char*)he->h_addr; ip->s_addr = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; } else { return -1; } } return 0; } static int setup_int(const char *proxy_host, short proxy_port, const char *dns_host, short dns_port, const char *dns_path) { memset(&dns_addr, 0, sizeof(dns_addr)); if(dns_req) free(dns_req); dns_req = NULL; if(proxy_host) { if(make_address(proxy_host, &dns_addr.sin_addr) != 0) return -1; dns_addr.sin_port = htons(proxy_port); if (asprintf(&dns_req, "http://%s:%d%s", dns_host, dns_port, dns_path) < 0) return -1; } else { if(make_address(dns_host, &dns_addr.sin_addr) != 0) return -1; dns_addr.sin_port = htons(dns_port); asprintf(&dns_req, "%s", dns_path); } dns_addr.sin_family = AF_INET; return 0; } static void split_spec(const char *spec, char **host, int *port, char **path, int def_port) { char *p; *host = strdup(spec); p = strchr(*host, ':'); if(p) { *p++ = '\0'; if(sscanf(p, "%d", port) != 1) *port = def_port; } else *port = def_port; p = strchr(p ? p : *host, '/'); if(p) { if(path) *path = strdup(p); *p = '\0'; }else if(path) *path = NULL; } ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_gethostby_setup(const char *proxy_spec, const char *dns_spec) { char *proxy_host = NULL; int proxy_port = 0; char *dns_host, *dns_path; int dns_port; int ret = -1; split_spec(dns_spec, &dns_host, &dns_port, &dns_path, 80); if(dns_path == NULL) goto out; if(proxy_spec) split_spec(proxy_spec, &proxy_host, &proxy_port, NULL, 80); ret = setup_int(proxy_host, proxy_port, dns_host, dns_port, dns_path); out: free(proxy_host); free(dns_host); free(dns_path); return ret; } /* Try to lookup a name or an ip-address using http as transport mechanism. See the end of this file for an example program. */ static struct hostent* roken_gethostby(const char *hostname) { int s; struct sockaddr_in addr; char *request = NULL; char buf[1024]; int offset = 0; int n; char *p, *foo; size_t len; if(dns_addr.sin_family == 0) return NULL; /* no configured host */ addr = dns_addr; if (asprintf(&request, "GET %s?%s HTTP/1.0\r\n\r\n", dns_req, hostname) < 0) return NULL; if(request == NULL) return NULL; s = socket(AF_INET, SOCK_STREAM, 0); if(s < 0) { free(request); return NULL; } if(connect(s, (struct sockaddr*)&addr, sizeof(addr)) < 0) { close(s); free(request); return NULL; } len = strlen(request); if(write(s, request, len) != (ssize_t)len) { close(s); free(request); return NULL; } free(request); while(1) { n = read(s, buf + offset, sizeof(buf) - offset); if(n <= 0) break; offset += n; } buf[offset] = '\0'; close(s); p = strstr(buf, "\r\n\r\n"); /* find end of header */ if(p) p += 4; else return NULL; foo = NULL; p = strtok_r(p, " \t\r\n", &foo); if(p == NULL) return NULL; { /* make a hostent to return */ #define MAX_ADDRS 16 static struct hostent he; static char addrs[4 * MAX_ADDRS]; static char *addr_list[MAX_ADDRS + 1]; int num_addrs = 0; he.h_name = p; he.h_aliases = NULL; he.h_addrtype = AF_INET; he.h_length = 4; while((p = strtok_r(NULL, " \t\r\n", &foo)) && num_addrs < MAX_ADDRS) { struct in_addr ip; inet_aton(p, &ip); ip.s_addr = ntohl(ip.s_addr); addr_list[num_addrs] = &addrs[num_addrs * 4]; addrs[num_addrs * 4 + 0] = (ip.s_addr >> 24) & 0xff; addrs[num_addrs * 4 + 1] = (ip.s_addr >> 16) & 0xff; addrs[num_addrs * 4 + 2] = (ip.s_addr >> 8) & 0xff; addrs[num_addrs * 4 + 3] = (ip.s_addr >> 0) & 0xff; addr_list[++num_addrs] = NULL; } he.h_addr_list = addr_list; return &he; } } ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL roken_gethostbyname(const char *hostname) { struct hostent *he; he = gethostbyname(hostname); if(he) return he; return roken_gethostby(hostname); } ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL roken_gethostbyaddr(const void *addr, size_t len, int type) { struct in_addr a; const char *p; struct hostent *he; he = gethostbyaddr(addr, len, type); if(he) return he; if(type != AF_INET || len != 4) return NULL; p = addr; a.s_addr = htonl((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); return roken_gethostby(inet_ntoa(a)); } #if 0 /* this program can be used as a cgi `script' to lookup names and ip-addresses */ #include <stdio.h> #include <stdlib.h> #include <netdb.h> #include <sys/param.h> int main(int argc, char **argv) { char *query = getenv("QUERY_STRING"); char host[MAXHOSTNAMELEN]; int i; struct hostent *he; printf("Content-type: text/plain\n\n"); if(query == NULL) exit(0); he = gethostbyname(query); strncpy(host, he->h_name, sizeof(host)); host[sizeof(host) - 1] = '\0'; he = gethostbyaddr(he->h_addr, he->h_length, AF_INET); printf("%s\n", he->h_name); for(i = 0; he->h_addr_list[i]; i++) { struct in_addr ip; unsigned char *p = (unsigned char*)he->h_addr_list[i]; ip.s_addr = htonl((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); printf("%s\n", inet_ntoa(ip)); } exit(0); } #endif
Upload File
Create Folder