Some Socket Problems...?

This is a discussion on Some Socket Problems...? within the Linux Programming forums, part of the Platform Specific Boards category; I'm trying to write a program that takes a host and outputs the name of the httpd they are running, ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    3

    Some Socket Problems...?

    I'm trying to write a program that takes a host and outputs the name of the httpd they are running, but this one doesnt seem to work:

    Code:
    /* Httpd-Chk, by Tal0n 03-20-04 */
    /* Uses fingerprints to try and identify httpd's... */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    
    int main(int argc, char *argv[]) {
    
    char buffer[4096];
    
    char *data = "HEAD / HTTP/1.1";
    int len = strlen(data);
    
    if(argc !=  2) {
    printf("\nHttpd-Chk, by Tal0n 03-20-04\n");
    printf("\nUsage: %s <host>\n\n", argv[0]);
    return 0; }
    
    if(argc == 2) {
    
    int sock;
    struct sockaddr_in remote;
    
    remote.sin_family = AF_INET;
    remote.sin_port = htons(80);
    remote.sin_addr.s_addr = inet_addr(argv[1]);
    
    if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("\nERROR: Can't create socket!\n\n");
    return -1; }
    
    if(connect(sock,(struct sockaddr *)&remote, sizeof(struct sockaddr)) < 0) {
    printf("\nERROR: Can't connect to %s!\n\n", argv[1]);
    return -1; }
    
    printf("\nTrying to identify httpd on %s...\n", argv[1]);
    
    if(send(sock, data, len, 0) < 0) {
    printf("\nERROR: Can't send data to %s!\n\n", argv[1]);
    return -1; }
    
    sleep(5);
    
    memset(buffer, 0, sizeof(buffer));
    read(sock, buffer, sizeof(buffer));
    
    sleep(3);
    
    if(strstr(buffer, "Apache")) {
    printf("\n%s is running Apache Httpd!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "Xitami")) {
    printf("\n%s is running Xitami Httpd!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "Netscape")) {
    printf("\n%s is running Netscape Enterprise Server!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "Zeus")) {
    printf("\n%s is running Zeus Httpd!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "IIS")) {
    printf("\n%s is running Microsoft IIS!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "thttpd")) {
    printf("\n%s is running Thttpd!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "AOL")) {
    printf("\n%s is running AOLServer!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "Lotus")) {
    printf("\n%s is running Lotus Httpd!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "Akami")) {
    printf("\n%s is running Akami Httpd!\n\n", argv[1]);
    return 0; }
    
    if(strstr(buffer, "Null")) {
    printf("\n%s is running Null Httpd!\n\n", argv[1]);
    return 0; }
    
    close(sock);
    
    return 0; }
    
    return 0; }
    When I compile and run it, it just sits there, does nothing after:

    Code:
    Trying to identify httpd on xx.x.xxx.xx...
    All help is much appreciated.

    Thanks,

    -Tal0n

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    try changing

    Code:
    char *data = "HEAD / HTTP/1.1";
    to
    Code:
    char *data = "HEAD / HTTP/1.1\r\n\r\n";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Raw socket
    By like_no_other in forum Networking/Device Communication
    Replies: 4
    Last Post: 03-28-2009, 02:05 PM
  2. Casting a struct for sending to socket
    By chrisjmoss in forum Networking/Device Communication
    Replies: 6
    Last Post: 04-08-2008, 09:11 AM
  3. Having Buffer Problems With Overlapped I/O --
    By Sargera in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 03:46 PM
  4. Socket handles
    By nico in forum Networking/Device Communication
    Replies: 2
    Last Post: 04-03-2005, 10:33 PM
  5. Socket Problems
    By (TNT) in forum Windows Programming
    Replies: 4
    Last Post: 08-18-2001, 06:59 AM

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