LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-01-2004, 12:38 AM   #1
Bassam
Member
 
Registered: Mar 2003
Location: Malaysia
Posts: 63

Rep: Reputation: 15
A problem with CGI programing


Hi All,
I am new to CGI programing with C language on Linux redhat plateform. I am trying to get the remote host name by using the "REMOTE_HOST" environment variable but unfortunately I am getting NULL every time. The program is shown as below:
Code:
#include <stdlib.h>
#include <sys/socket.h>
#include <netdb.h>

int main()
{
        char *remote_host_address, *remote_host_name;

        printf("Content-type: text/html\n\n");
        printf("<HTML>\n");
        printf("<HEAD>\n");
        printf("<TITLE>First</TITLE>\n");
        printf("</HEAD>\n");
        printf("<BODY>\n");
        printf("<H1>This CGI program has written by C Language</H1>\n");
        printf("<HR>\n");
        printf("<H2>Server Information</H2>\n");
        printf("<P>Server Name: %s</P>\n", getenv("SERVER_NAME"));
        printf("<P>Server Address: %s</P>\n", getenv("SERVER_ADDR"));
        printf("<P>Server Port: %s</P>\n", getenv("SERVER_PORT"));
        printf("<HR>\n");
        printf("<H2>Remote Host Information</H2>");

        remote_host_address = getenv("REMOTE_ADDR");
        remote_host_name = getenv("REMOTE_HOST");
        printf("<P>Remote Host Name: %s</P>\n", remote_host_name);
        printf("<P>Remote Host Address: %s</P>\n", remote_host_address);

        exit(0);
}
So how can I ge the remote host name, is there another way for that?
I am exepecting your appreciated help

Regards
Bassam

Last edited by Bassam; 11-01-2004 at 12:52 AM.
 
Old 11-04-2004, 11:38 PM   #2
karlan
Member
 
Registered: Aug 2003
Location: San Francisco, California
Distribution: Slackware
Posts: 158

Rep: Reputation: 30
remote_host is not a valid cgi/1.1 variable. What result were you expecting?
btw, check out http://karlan.us.to/cgi-bin/env.cgi for a good set of cgi vars, many are extra, and may not be present on all web servers.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI to work out side of cgi-bin? crashedspine Linux - Newbie 13 09-02-2004 08:49 PM
CGI Problem amit_28oct Programming 2 03-23-2004 09:50 PM
Bash programing problem zWaR Programming 3 01-01-2004 05:57 PM
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM
http://www.burstnet.com/cgi-bin/ads/ad7954a.cgi/3980/RETURN-CODE rverlander LQ Suggestions & Feedback 1 06-07-2002 07:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration