ill provide you with the whole code:
Code:
/*
bannergrab written by [email protected]
02/23/03
usage: ./bannergrab <hostname/ip> <port>
*/
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#define VERSION "0.1"
void banner(void);
int main (int argc, char *argv[])
{
int sockfd;
struct sockaddr_in dest;
struct hostent *he;
int recmsgleng = 2048;
char *buffer;
int port = atoi(argv[2]);
banner();
if (argc != 3)
{
printf("usage: %s <hostname/ip> <port>\n", argv[0]);
return 1;
}
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
perror("socket");
if((he = gethostbyname(argv[1])) == NULL)
{
perror("gethostbyname");
return 1;
}
dest.sin_family = AF_INET;
dest.sin_port = htons(port);
dest.sin_addr = *((struct in_addr *) he -> h_addr);
memset(&(dest.sin_zero), '\0', 8);
if((connect(sockfd, (struct sockaddr *)&dest, sizeof(struct sockaddr))) == -1)
perror("connect");
printf("connection to %s established\n", argv[1]);
printf("before receiving data: %s\n", buffer);
recv(sockfd, buffer, recmsgleng, 0);
printf("there is the following service running:\n%s\n", buffer);
close(sockfd);
return 0;
}
void banner(void)
{
printf("bannergrab version: %s\nwritten by thread\n", VERSION);
}
try to compile that code, and connect to a server to a port where a service is running.
i am only getting strange symbols printed on the screen, even if there is a service running.
hope you can help me.
thanks