On 1/14/07, Grant Peel <[EMAIL PROTECTED]> wrote:
ACtually no,

Sory if the question was vauge,

What I am looking to do is to create a tool that will identify what MACHINE
(not domain) an ip is being used on.

Check out this:

#include <netinet/in.h>

#include <sys/types.h>
#include <sys/socket.h>

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

#define MAX_BUFF 128
#define MAX_NAME 128

int main(int argc, char **argv)
{
  char   buf[MAX_BUFF], name[MAX_NAME];
  int    recv, sock, addrlen;
  struct sockaddr_in addr, from;

  if(argc != 3)
  {
     fprintf(stderr, "usage: %s ip port\n", argv[0]);
     return(1);
  }

  addrlen = sizeof(struct sockaddr);

  /* get hostname */
  bzero(&name, MAX_NAME);
  if(gethostname(name, MAX_NAME) == -1)
  {
     perror("gethostname");
     return(1);
  }

  /* create socket */
  if((sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
  {
     perror("socket");
     return(1);
  }

  /* create addres */
  bzero(&addr, addrlen);
  addr.sin_family      = AF_INET;
  addr.sin_port        = htons((int)strtol(argv[2], (char **)NULL, 10));
  if(inet_aton(argv[1], addr.sin_addr) == 0)
  {
     perror("inet_aton");
     return(1);
  }

  /* bind */
  if(bind(sock, (struct sockaddr *)&addr, addrlen) == -1)
  {
     perror("bind");
     return(1);
  }

  /* loop infinitely */
  for(;;)
  {

     /* receive */
     if((recv = recvfrom(sock, buf, MAX_BUFF -1, 0, (struct sockaddr
*)&from, &addrlen)) == -1)
     {
        perror("recvfrom");
        continue;
     }
     buf[recv] = '\0';

     /* send hostname */
     if(sendto(sock, name, MAX_NAME, 0, (struct sockaddr *)&from,
sizeof(struct sockaddr)) == -1)
     {
        perror("sendto");
        continue;
     }
  }

  return(0);

}


-Grant

----- Original Message -----
From: "Pietro Cerutti" <[EMAIL PROTECTED]>
To: "Grant Peel" <[EMAIL PROTECTED]>
Cc: <freebsd-questions@freebsd.org>
Sent: Sunday, January 14, 2007 9:21 AM
Subject: Re: Identifying a Remote Machine.


> On 1/14/07, Grant Peel <[EMAIL PROTECTED]> wrote:
>> Hi all,
> Hello,
>
>> The only reply I need from the server is the hostname. That will tell ne
>> that the IP is live and what machine its on.
>
> Wouldn't a ping be enough if you just need to know whether the machine is
> on?
>
>>
>> -Grant
>
>
> --
> Pietro Cerutti
> ICQ: 117293691
> PGP: 0x9571F78E
>
> - ASCII Ribbon Campaign -
> against HTML e-mail and
> proprietary attachments
>   www.asciiribbon.org
>
>





--
Pietro Cerutti
ICQ: 117293691
PGP: 0x9571F78E

- ASCII Ribbon Campaign -
against HTML e-mail and
proprietary attachments
  www.asciiribbon.org
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to