./c0de/c/httpver.txt

0.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
/* Way to find out version of remote httpd server */
/* Written by Shok.      --==+*~(Shok)~*+==--     */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
 
#define ERROR -1 
#define MAXDATASIZE 300
 
char buf[MAXDATASIZE];
char message[] = "HEAD / HTTP/1.0\n\n";
 
/* Function prototypes */
char *GetHTTPVer(char *);
 
 
void main(int argc, char **argv)
{
  GetHTTPVer(argv[1]);
}
 
char *GetHTTPVer(char *host)
{
  char *p;
  int s;   
  int i;    
  int numbytes;
  struct sockaddr_in sock;
  struct hostent *he;
 
 
  if ((he=gethostbyname(host)) == NULL) {
	herror("gethostbyname");
	exit(1);
  }
 
  if ((s = socket(AF_INET, SOCK_STREAM, 0)) == ERROR) {
	perror("socket");
	exit(1);
  }
 
 
  sock.sin_family = AF_INET;
  sock.sin_port = htons(80);
  sock.sin_addr =  *((struct in_addr *)he->h_addr);  
  bzero(&(sock.sin_zero), 8);
 
  if (connect(s, (struct sockaddr *)&sock, sizeof(struct sockaddr)) == ERROR) 
  {
	perror("connect");
        exit(1);
  }
 
  if ((send(s, message, strlen(message), 0)) == ERROR) { 
   	perror("send");
        close(s);
	exit(1);
  }
 
  for (i=0;i<5;i++) {
  	if((numbytes=recv(s, buf, MAXDATASIZE, 0)) == ERROR) {
  		perror("recv");
                close(s);
		exit(1);
  	} 
 
         buf[numbytes] = '\0';
         p=strstr(buf, "Server");
         printf("%s\n", p);
 
  }
 
  close(s);
  return buf;
}
 
 

Back