🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #18384

Re: Direccion IP en C y PPP.

#18384
From: Luis Paúl Tomillo
Date: Tue, 14 Sep 1999 00:00
36 lines
1633 bytes
Ander <sarratea@mixmail.com> wrote:
> Hola,
> Teniendo el PPP en marcha, como consigo en C la direccion IP asignada por el
> proveedor ?

> Gracias.

> ASarratea @msi.mcc.es

Quiz�s la siguiente funci�n te ayude:

/* Obtener direccion IP de maquina. Devuelve 0 si error. */
int obtener_dir(char* maquina, struct sockaddr_in* si)
{
   struct hostent* phost;

   phost = gethostbyname(maquina);
   if (phost == NULL) return 0;
   bcopy((char *)phost->h_addr, (char *)&si->sin_addr, phost->h_length);
   si->sin_family = phost->h_addrtype;

   return 1;
}     

En teor�a podr�as especificar el nombre de la m�quina local y obtener
a trav�s de "si" la direcci�n IP asociada.

Otra forma podr�a ser lanzando desde C el programa hostname -i y recogiendo
la salida de este programa.

-- 
            _                |\ 
           / \   __  /\_    /  \ _
         _/   \ /  \/   \__/    V \_
        /      V                    \_
Luis Paul Tomillo	luispaul@bbvnet.com
Technical Details
Message-ID: <5hslr7.714.ln@belcebu.ccr.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7rlgo6$lgm$1@batcher.rediris.es>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,50e1a3e59813ade5
X-Google-Attributes: gidf86c8,public
From: Luis Paúl Tomillo <luis@belcebu.ccr.es>
Subject: Re: Direccion IP en C y PPP.
Date: 1999/09/14
Message-ID: <5hslr7.714.ln@belcebu.ccr.es>
X-Deja-AN: 525314691
Distribution: es
Content-Transfer-Encoding: 8bit
References: <7rlgo6$lgm$1@batcher.rediris.es>
Content-Type: text/plain; charset=ISO-8859-1
Organization: Telefonica Transmision de Datos
Mime-Version: 1.0
User-Agent: tin/pre-1.4-980618 (UNIX) (Linux/2.2.7 (i586))
Newsgroups: es.comp.os.linux.programacion