diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-09-27 14:43:02 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-09-27 14:43:02 +0000 |
commit | 09ee756ce5a4553e280bfe542c5859ec8e36cc55 (patch) | |
tree | f91a62db1e9fc5c075af7b7ba479a40c3a644833 | |
parent | 2007-09-27 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | ada-examples-09ee756ce5a4553e280bfe542c5859ec8e36cc55.tar.bz2 |
2007-09-27 Joel Sherrill <joel.sherrill@oarcorp.com>
* ChangeLog, Makefile, README, dumpwebpage.adb: New files.
-rw-r--r-- | dumpwebpage/ChangeLog | 4 | ||||
-rw-r--r-- | dumpwebpage/Makefile | 28 | ||||
-rw-r--r-- | dumpwebpage/README | 12 | ||||
-rw-r--r-- | dumpwebpage/dumpwebpage.adb | 52 |
4 files changed, 96 insertions, 0 deletions
diff --git a/dumpwebpage/ChangeLog b/dumpwebpage/ChangeLog new file mode 100644 index 0000000..2fd5d37 --- /dev/null +++ b/dumpwebpage/ChangeLog @@ -0,0 +1,4 @@ +2007-09-27 Joel Sherrill <joel.sherrill@oarcorp.com> + + * ChangeLog, Makefile, README, dumpwebpage.adb: New files. + diff --git a/dumpwebpage/Makefile b/dumpwebpage/Makefile new file mode 100644 index 0000000..3f32bf2 --- /dev/null +++ b/dumpwebpage/Makefile @@ -0,0 +1,28 @@ +# +# Makefile for Ada Dump URL example +# +# See README.Makefiles in the main ada-examples directory. +# + +PROGRAM=dumpwebpage + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +# stack size for the first Ada thread +CFLAGS +=-DGNAT_MAIN_STACKSPACE=100 + +# initialize the network stack -- assumes existence of networkconfig.h +CFLAGS +=-DMAIN_USE_NETWORKING=1 + +# Should we prompt for command line arguments? +# DEFINES +=-DMAIN_USE_REQUIRES_COMMAND_LINE + +# If you want to hard-code the command line, define this to a string +# DEFINES += -DMAIN_COMMAND_LINE="ARGS" + +# Some tests need to be able to do a gethostbyname +NEED_ROOTFS_FOR_HOST_INFO=yes + +include ../Makefile.shared diff --git a/dumpwebpage/README b/dumpwebpage/README new file mode 100644 index 0000000..3108530 --- /dev/null +++ b/dumpwebpage/README @@ -0,0 +1,12 @@ +# +# $Id$ +# + +This example is based upon the code posted at: + +http://en.wikibooks.org/wiki/Ada_Programming/Libraries/GNAT.Sockets_examples + +I changed the name of procedure and added some comments on +the URL IP address. + +--joel sherrill diff --git a/dumpwebpage/dumpwebpage.adb b/dumpwebpage/dumpwebpage.adb new file mode 100644 index 0000000..c7cc82b --- /dev/null +++ b/dumpwebpage/dumpwebpage.adb @@ -0,0 +1,52 @@ +-- +-- Dump Web Page GNAT Sockets Example +-- +-- $Id$ +-- + +with Ada.Text_IO; use Ada.Text_IO; +with GNAT.Sockets; use GNAT.Sockets; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; + +with Ada.Streams; +use type Ada.Streams.Stream_Element_Count; + + +procedure dumpWebPage is + + Client : Socket_Type; + Address : Sock_Addr_Type; + Channel : Stream_Access; + + Send : String := (1 => ASCII.CR, 2 => ASCII.LF); + Offset : Ada.Streams.Stream_Element_Count; + Data : Ada.Streams.Stream_Element_Array (1 .. 256); + + -- public IP of www.rtems.org as of 25 September 2007 + -- Server : String := "216.186.189.3"; + -- private OAR IP to test with + Server : String := "192.168.1.103"; + +begin + + Initialize; + Create_Socket (Client); + Address.Addr := Inet_Addr(Server); + Address.Port := 80; + + Connect_Socket (Client, Address); + Channel := Stream (Client); + + Put_Line( "GET / HTTP/1.1" & Send ); + Put_Line( "Host: " & Server & Send ); + String'Write (Channel, "GET / HTTP/1.1" & Send); + String'Write (Channel, "Host: " & Server & Send & Send); + loop + Ada.Streams.Read (Channel.All, Data, Offset); + exit when Offset = 0; + for I in 1 .. Offset loop + Ada.Text_IO.Put (Character'Val (Data (I))); + end loop; + end loop; + +end dumpWebPage; |