Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

my_Ip

[es] :: C/C++ programiranje :: my_Ip

[ Pregleda: 2632 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

c00l_daem0n
Beograd

Član broj: 309
Poruke: 294
*.telekom.yu

Jabber: andrew@elitesecurity.org
ICQ: 53650656


Profil

icon my_Ip28.02.2002. u 19:18 - pre 269 meseci
Evo ga kod koji sam ja napisao :o), i koji treba da vrati ip adresu, i on to vrati (127.0.0.1) kada sam offline ali kada sam na netu on opet vrne isto.
Secam se da je i predator svojevremeno :o), imao isti problem, ali je na kraju napisao, i ja sam imao taj kod ali sada ne mogu nikako da nadjem, nego da predjem na stvar:

Code:

#include <stdio.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
  
int main()
{
 char  names[100];
 struct hostent *h;

 gethostname(names, strlen(names));

if ((h=gethostbyname(names))== NULL) {  // get the host info
    herror("gethostbyname");
    exit(1);
    }
if ((h=gethostbyname(names))== NULL) {  // get the host info
    herror("gethostbyname");
    exit(1);
    }

printf("gethostname:Host name  : %s\n",names);  // moje debugiranje...
printf("gethostbyname:Host name  : %s\n", h->h_name);
printf("IP Address : %s\n", inet_ntoa(*((struct in_addr *)h->h_addr)));
               
return 0;
                      
}                                                      


Moze neko i da bachi predatorov kod ako ima!
Would you translate me on the other page in face = Da li biste me preveli na drugu stranu ulice
 
Odgovor na temu

leka
Dejan Lekić
senior software engineer, 3Developers
Ltd.
London, UK

Član broj: 234
Poruke: 2534
*.telia.com

Sajt: dejan.lekic.org


+2 Profil

icon Re: my_Ip11.04.2002. u 02:41 - pre 268 meseci
Verovo ili ne ovo na brzaka sklepano parče koda radi posao:
Code:

#include <stdio.h>

int gethostname(char *name, int namelen);

main()
{
    char buf[100];
    
    if (gethostname(buf,99) < 0)
    {
        perror("gethostname probljemi");
        exit(1);
    }
    
    printf("Host: %s n", buf);
}


Prilepiću i fajl...
Dejan Lekic
software engineer, MySQL/PgSQL DBA, sysadmin
Prikačeni fajlovi
 
Odgovor na temu

[es] :: C/C++ programiranje :: my_Ip

[ Pregleda: 2632 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.