reading http packets in C

This is a discussion on reading http packets in C within the C Programming forums, part of the General Programming Boards category; I am trying to access the HTTP environment variables, particularly REMOTE_ADDR HTTP_VIA HTTP_X_FORWARDED_FOR i have written a small program that ...

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    reading http packets in C

    I am trying to access the HTTP environment variables, particularly
    REMOTE_ADDR
    HTTP_VIA
    HTTP_X_FORWARDED_FOR

    i have written a small program that dumps the contents of a http packet to the screen, but i cant see the full set of variables i want. Does anyone know how i can access the full set of http variables.
    (Linux, gcc)

    This is the output of my program:

    HTTP-Dump is starting on port 80
    HTTP-Dump is listening on port 80


    Waiting for a connection
    Connection :
    packet recieved :
    packet size: 8500
    GET http://www.google.com/ HTTP/1.1
    Host: www.google.com
    User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040618
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Proxy-Connection: keep-alive
    Cookie: PREF=ID=730cd87420aa9d66:CR=1:TM=1108661555:LM=110 8755738:GM=1:S=o86Whlr8YN1seXdf
    Monday - what a way to spend a seventh of your life

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    HTTP_VIA and HTTP_X_FORWARDED_FOR are optionally added by proxy servers and will not be present for a direct connection. REMOTE_ADDR is a cgi variable that is set to the remote address of the client (as returned by accept). It is not part of the request packet. You should not rely on any variable being present.
    Last edited by anonytmouse; 03-30-2005 at 07:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small HTTP proxy
    By zacs7 in forum Networking/Device Communication
    Replies: 8
    Last Post: 09-11-2007, 03:53 AM
  2. help with reading from stream
    By movl0x1 in forum C Programming
    Replies: 7
    Last Post: 05-31-2007, 10:36 PM
  3. Fun with reading hex
    By dpro in forum C++ Programming
    Replies: 7
    Last Post: 02-17-2006, 05:41 PM
  4. reading file word by word
    By 98holb in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 04:49 PM
  5. problems reading data into an array and printing output
    By serino78 in forum C Programming
    Replies: 4
    Last Post: 04-28-2003, 08:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21