0

please help me. What is problem with my code? It don't work at all. Please give me some advice. My aim is to get some information from whois server (from whois.nic.cz). Here is my code, which don't work (it gives no entry in whois server):

I have simplified code to minimum, but it still don't work (for example direct value in functions)

#include<stdio.h>   //scanf , printf
#include<string.h>  //strtok
#include<stdlib.h>  //realloc
#include<sys/socket.h>  //socket
#include<netinet/in.h> //sockaddr_in
#include<arpa/inet.h>   //getsockname
#include<netdb.h>   //hostent
#include<unistd.h>  //close

int main(int argc , char *argv[]){

    char buffer[5000];
    int sock , size = 0;
    struct sockaddr_in dest;
    sock = socket(AF_INET , SOCK_STREAM , 0);

        memset( &dest , 0 , sizeof(dest) );
        dest.sin_family = AF_INET;     
    dest.sin_addr.s_addr = inet_addr("217.31.205.42");
    dest.sin_port = htons(43);

    if(connect( sock , (const struct sockaddr*) &dest , sizeof(dest) ) < 0)
    {
        perror("connect failed");
    }
    if( send(sock , "77.75.75.176\r\n" , strlen("77.75.75.176\r\n") , 0) < 0)
    {
        perror("send failed");
    }
    printf("HERE\n");
    size = recv(sock , buffer , sizeof(buffer) , 0);

    printf("HERE\n");
    printf("size:%dBUFFER:\n%s\n", size, buffer);
    fflush(stdout);

    close(sock);
    return 0;
}

I expected some result from whois server, but it gives no entry in whois server

Petr Marek
  • 59
  • 1
  • 7
  • 1
    You aren't sending a correct line termination and you aren't reading anything except the first response. Protocol is here: https://tools.ietf.org/html/rfc3912 – stark Oct 10 '19 at 13:54
  • you are right, I edited line where I send request to this: "if( send(sock , "77.75.75.176\r\n" , strlen("77.75.75.176\r\n") , 0) < 0)" And now it works, BUT it dont give me eny result (whois server respond is "%ERROR:101: no entries found % % No entries found. " Can you help me? Both IP address are correct and on whois server actually is entry for given ip address) – Petr Marek Oct 10 '19 at 14:00
  • 1
    The whois server has no results for this ip: https://www.nic.cz/whois/object/77.75.75.176/ – Joe DF Oct 10 '19 at 15:38

0 Answers0