Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (42 sloc) 1.2 kb
7257579b »
2012-06-13 Git repository created from hping3-clockskew-0.tar.gz
1 /*
2 * $smu-mark$
3 * $name: gethostname.c$
4 * $author: Salvatore Sanfilippo <antirez@invece.org>$
5 * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
6 * $license: This software is under GPL version 2 of license$
7 * $date: Fri Nov 5 11:55:47 MET 1999$
8 * $rev: 8$
9 */
10
11 /* $Id: gethostname.c,v 1.2 2003/09/01 00:22:06 antirez Exp $ */
12
13 #include <stdio.h>
14 #include <netdb.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
19 #include <string.h>
20
21 size_t strlcpy(char *dst, const char *src, size_t siz);
22
23 char *get_hostname(char* addr)
24 {
25 static char answer[1024];
26 static char lastreq[1024] = {'\0'}; /* last request */
27 struct hostent *he;
28 struct in_addr naddr;
29 static char *last_answerp = NULL;
30
31 printf(" get hostname..."); fflush(stdout);
32 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
33 " "
34 "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
35
36 if (!strcmp(addr, lastreq))
37 return last_answerp;
38
39 strlcpy(lastreq, addr, 1024);
40 inet_aton(addr, &naddr);
41 he = gethostbyaddr((char*)&naddr, 4, AF_INET);
42
43 if (he == NULL) {
44 last_answerp = NULL;
45 return NULL;
46 }
47
48 strlcpy(answer, he->h_name, 1024);
49 last_answerp = answer;
50
51 return answer;
52 }
53
Something went wrong with that request. Please try again.