[SDL] convert IPaddress to string

Spencer Salazar ssalazar at CS.Princeton.EDU
Mon Jul 17 15:49:53 PDT 2006


use this macro:

#define getByte(d,i) ( ( ( d ) >> ( ( i ) * 8 ) ) & 0xff )

where d is your int, and i is the byte number.

also, please use snprintf() when its available...

spencer

On Jul 17, 2006, at 6:38 PM, Roger D. Vargas wrote:

>
>> Char Buffer[256]
>>
>> sprint(Buffer,"%i.%i.%i.%i",byte1,byte2,byte3,byte4);
>
> The problem is that IPaddress.host is a 32 bit integer. How do I  
> convert
> that to 4 independent bytes?
>
>>
>> I don't know the structure member names but that'd be a decent way  
>> to do
>> it
>>
>> -----Original Message-----
>> From: sdl-bounces+atrix2=cox.net at libsdl.org
>> [mailto:sdl-bounces+atrix2=cox.net at libsdl.org] On Behalf Of Roger D.
>> Vargas
>> Sent: Monday, July 17, 2006 3:25 PM
>> To: SDL at libsdl.org
>> Subject: Re: [SDL] convert IPaddress to string
>>
>> El lun, 17-07-2006 a las 12:12 -0700, 1337p337 escribió:
>>> On 17/07/06, Roger D. Vargas <roger at ehtsc.co.cu> wrote:
>>>> What is the best way to convert the host member of IPaddress  
>>>> struct to
>>> a
>>>> printable string?
>>>
>>> There doesn't seem to be a function for this in SDL_Net (looking
>>> briefly over the docs), but you could probably get away with
>>> sprintf(ip_string, "%s", inet_ntoa((struct in_addr) ip.host);
>>>
>>> Make sure to include sys/socket.h, netinet/in.h, and arpa/inet.h.
>>> Hope that helps.
>>> ]
>> Is tha portable? I was thining in something like decomposing the  
>> int in
>> four bytes and printing them in the string.
>>
>>> _______________________________________________
>>> SDL mailing list
>>> SDL at libsdl.org
>>> http://www.libsdl.org/mailman/listinfo/sdl
>> --
>> Roger D. Vargas <roger at ehtsc.co.cu>
>> Formatur Santiago
>>
>>
>> _______________________________________________
>> SDL mailing list
>> SDL at libsdl.org
>> http://www.libsdl.org/mailman/listinfo/sdl
>>
>>
>> _______________________________________________
>> SDL mailing list
>> SDL at libsdl.org
>> http://www.libsdl.org/mailman/listinfo/sdl
>>
>
>
> -- 
> Roger D. Vargas
> http://dsgp.blogspot.com
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl





More information about the SDL mailing list