/* * getip v1.0 Looks up an IP address based on hostname * * Copyright (C) 2000 Mats Peterson * * 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; either version 2 of the License, or * (at your option) any later version. * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * Please send any comments/bug reports to * mats_peterson@swipnet.se (Mats Peterson) */ #include #include #include #include #include #include #include #include #include #include int get_addr(struct sockaddr_in *name, const char *hostname) { struct hostent *hostinfo; if (! (hostinfo = gethostbyname(hostname))) return h_errno; name->sin_addr = *(struct in_addr *) hostinfo->h_addr; return 0; } void usage(void) { fprintf(stderr, "usage: getip \n"); exit(0); } int main(int argc, char **argv) { struct sockaddr_in name; time_t start; if (argc == 1) usage(); if (get_addr(&name, argv[1])) { fprintf(stderr, "Host name lookup failure\n"); exit(1); } printf("%s\n", inet_ntoa(name.sin_addr)); } .