Estaba buscando como obtener el id con algun lenguaje que no fuera php, y no necesitara internet y estaba este:
Código:
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
struct sockaddr whereto;
struct hostent *hp;
struct sockaddr_in *to;
char *target;
char *hostname;
memset(&whereto, 0, sizeof(struct sockaddr));
to = (struct sockaddr_in *)&whereto;
to->sin_family = AF_INET;
to->sin_addr.s_addr = inet_addr(target);
if (to->sin_addr.s_addr != -1)
hostname = target;
else
{
hp = gethostbyname(target);
if (!hp)
printf("host desconocido%s\n", target);
else
{
to->sin_family = hp->h_addrtype;
memcpy(&(to->sin_addr.s_addr), hp->h_addr, hp->h_length);
hostname = hp->h_name;
printf("gethostbyname ejecutado correctamente\n");
}
}
pero lo compile en linux y obtuve este error
ip2.cpp:29:2: aviso: no hay caractér de fin de línea al final del fichero
ip2.cpp:11: error: expected constructor, destructor, or type conversion before ‘(’ token
ip2.cpp:12: error: expected constructor, destructor, or type conversion before ‘=’ token
ip2.cpp:13: error: ‘to’ no nombra a un tipo
ip2.cpp:14: error: ‘to’ no nombra a un tipo
ip2.cpp:15: error: expected unqualified-id before ‘if’
ip2.cpp:17: error: expected unqualified-id before ‘else’
Que esta mal en el codigo?