![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 2
Rep Power: 0
![]() |
send() problem w/ http server
I'm writing a simple server for my cs class. Whenever i run the server, i can access it just fine with firefox/iexplorer and it displays my simple home page. It handles 404's just fine too. My problem is that whenever i connect to my server w/ telnet/netcat it doesnt return the header info. i.e. telnet/netcat never displays "HTTP 200 OK...." etc. So obviously there's a problem, it's just not affecting the browser. Anyone have any ideas?
// handles a get header f/m client.
static void handle_get (int connection_fd, const char* page)
{
char response[1024];
//char *string = "HTTP/1.0 OK 200";
/* Test for root/home page*/
if (!strcmp(page,"/")) {
//fprintf(stderr, "handle_get\n");
//send(connection_fd, string, strlen(string),0);
send_head(connection_fd, 200, strlen(HOME_PAGE));
send (connection_fd, HOME_PAGE, strlen (HOME_PAGE),0);
}
else {
/* Send the HTTP response indicating success, and the HTTP header
for an HTML page. */
send_head(connection_fd, 404, strlen(ERROR_404));
send (connection_fd, response, strlen (response),0);
}
}
/* Process an HTTP "HEAD" request for PAGE, and send the results to the
file descriptor CONNECTION_FD. */
void handle_head(int connection_fd, const char* page)
{
if(*page == '/')
{
send_head(connection_fd, 200, 0);
}
}
//send_head - send an HTTP 1.0 header with given status and content-len
void send_head(int conn_fd, int status, int len)
{
char *statstr, buff[BUFFSIZE];
/* convert the status code to a string */
switch(status) {
case 200:
statstr = "OK";
break;
case 400:
statstr = "Bad Request";
break;
case 404:
statstr = "Not Found";
break;
default:
statstr = "Unknown";
break;
}
/*
* send an HTTP/1.0 response with Server, Content-Length,
* and Content-Type headers.
*/
(void) sprintf(buff, "HTTP/1.0 %d %s\r\n", status, statstr);
(void) send(conn_fd, buff, strlen(buff), 0);
(void) sprintf(buff, "Server: %s\r\n", SERVER_NAME);
(void) send(conn_fd, buff, strlen(buff), 0);
(void) sprintf(buff, "Content-Length: %d\r\n", len);
(void) send(conn_fd, buff, strlen(buff), 0);
(void) sprintf(buff, "Content-Type: text/html\r\n");
(void) send(conn_fd, buff, strlen(buff), 0);
(void) sprintf(buff, "\r\n");
(void) send(conn_fd, buff, strlen(buff), 0);
} |
|
|
|
|
|
#2 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
I'd reccomend using a packet sniffer such as Ethereal or Ettercap to determine what the browser and server are exchanging compared to nc or telnet.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2005
Posts: 2
Rep Power: 0
![]() |
alright, thanks ill try that
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|