[b2f9d3]: get_ipaddr.c  Maximize  Restore  History

Download this file

68 lines (55 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
***************************************************************************
*
* Author: Georg Ottinger
*
* Copyright (C) 2012 Georg Ottinger
*
* georg@otelo.or.at
*
***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
***************************************************************************
*
* This version of GPL is at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*
***************************************************************************
*/
#include <stdio.h>
#include <string.h>
int main()
{
char line[100];
char *ip,*end;
fgets(line, 100, stdin);
ip = strchr(line, ':');
if(!ip)
{
fprintf(stderr,"No IPv4-Address found!\n");
return -1;
}
ip++;
end=strchr(ip,' ');
if(end)
{
*end = 0;
} else {
fprintf(stderr,"Space not found!\n");
return -1;
}
printf("%s",ip);
return 0;
}