]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed | 2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
a6e5c172 | 3 | * 1998, 2010 |
94ff9470 | 4 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
25697a35 GS |
5 | * |
6 | * SARG donations: | |
7 | * please look at http://sarg.sourceforge.net/donations.php | |
8 | * --------------------------------------------------------------------- | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
23 | * | |
24 | */ | |
25 | ||
26 | #include "include/conf.h" | |
5f3cfd1d | 27 | #include "include/defs.h" |
25697a35 | 28 | |
a1c55d8c | 29 | void ip2name(char *ip,int ip_len) |
9c7c6346 | 30 | { |
25697a35 | 31 | u_long addr; |
936c9905 FM |
32 | struct hostent *hp; |
33 | char **p; | |
25697a35 GS |
34 | |
35 | if ((int)(addr = inet_addr(ip)) == -1) | |
36 | return; | |
37 | ||
936c9905 FM |
38 | hp = gethostbyaddr((char *)&addr, sizeof (addr), AF_INET); |
39 | if (hp == NULL) | |
25697a35 GS |
40 | return; |
41 | ||
936c9905 FM |
42 | for (p = hp->h_addr_list; *p != 0; p++) { |
43 | struct in_addr in; | |
25697a35 | 44 | |
936c9905 | 45 | (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr)); |
a1c55d8c FM |
46 | strncpy(ip,hp->h_name,ip_len-1); |
47 | ip[ip_len-1]=0; | |
936c9905 | 48 | } |
25697a35 GS |
49 | |
50 | return; | |
936c9905 | 51 | } |
25697a35 GS |
52 | |
53 | void name2ip(char *name) | |
9c7c6346 | 54 | { |
25697a35 GS |
55 | struct in_addr ia; |
56 | struct hostent *hp; | |
32e71fa4 FM |
57 | char *port; |
58 | char n1[4]; | |
59 | char n2[4]; | |
60 | char n3[4]; | |
61 | char n4[4]; | |
9c7c6346 | 62 | struct getwordstruct gwarea; |
25697a35 | 63 | |
32e71fa4 FM |
64 | port=strchr(name,':'); |
65 | if (port) *port=0; | |
25697a35 GS |
66 | |
67 | if((hp=gethostbyname(name))==NULL) | |
68 | return; | |
9c7c6346 | 69 | |
32e71fa4 FM |
70 | memcpy(&ia.s_addr,hp->h_addr_list[0],sizeof(ia.s_addr)); |
71 | ia.s_addr=ntohl(ia.s_addr); | |
9c7c6346 FM |
72 | getword_start(&gwarea,inet_ntoa(ia)); |
73 | if (getword(n4,sizeof(n4),&gwarea,'.')<0 || getword(n3,sizeof(n3),&gwarea,'.')<0 || | |
74 | getword(n2,sizeof(n2),&gwarea,'.')<0 || getword(n1,sizeof(n1),&gwarea,0)<0) { | |
75 | printf("SARG: Maybe you have a broken record or garbage in your %s ip address.\n",gwarea.beginning); | |
32e71fa4 | 76 | exit(1); |
25697a35 | 77 | } |
32e71fa4 | 78 | sprintf(name,"%s.%s.%s.%s",n1,n2,n3,n4); |
25697a35 GS |
79 | |
80 | return; | |
9c7c6346 | 81 | } |