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