[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] + getip: hostname2ip



---
 src/modules/c/getip/Makefile.all |    7 ++++
 src/modules/c/getip/main.c       |   69 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 src/modules/c/getip/Makefile.all
 create mode 100644 src/modules/c/getip/main.c

diff --git a/src/modules/c/getip/Makefile.all b/src/modules/c/getip/Makefile.all
new file mode 100644
index 0000000..59d796e
--- /dev/null
+++ b/src/modules/c/getip/Makefile.all
@@ -0,0 +1,7 @@
+shopt -s extglob
+source $LOST_BUILDMK_ROOT/config.sh
+
+echo "LD   $1/apps/getip"
+$LOST_TOOLS_LD -ogetip -Ttext=0x40000000 *.o --start-group $2 --end-group
+
+mv getip $1/apps/
diff --git a/src/modules/c/getip/main.c b/src/modules/c/getip/main.c
new file mode 100644
index 0000000..754ccd7
--- /dev/null
+++ b/src/modules/c/getip/main.c
@@ -0,0 +1,69 @@
+/*  
+ * Copyright (c) 2007 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Roman Muentener.
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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 "stdlib.h"
+#include "string.h"
+#include "netdb.h"
+#include "stdio.h"
+#include "arpa/inet.h"
+
+
+
+int
+ main ( int argc , char* argv[] )
+{
+  printf( "getip\n-----\n\n" );
+
+  if( argc != 2 )
+  {
+    printf ( "Incorrect usage!\n" );
+    return 0;
+  }
+
+  struct in_addr addr;
+
+  struct hostent* info;
+  info = gethostbyname( argv[1] );
+  int i = 0;
+  while ( info->h_addr_list[i] != 0 )
+  {
+    addr.s_addr = *( unsigned long *) info->h_addr_list[i++];
+
+    printf( "IP Address: %s \n" , inet_ntoa( addr ) );
+  }
+
+  return 0;
+}
-- 
1.6.0.4