how to split an IP address into octets ?

  • Follow


Hi,

which unix function allows me to split an ip address
returned from gethostbyname into octets ?

Thank you,
-- 
Bye,
Colossus
Mizio, a proxy scanner tool with GUI for Linux
http://mizio.sourceforge.net
0
Reply colossusNO_SPAM (7) 5/25/2004 12:36:28 PM

Colossus <colossusNO_SPAM@freemail.it> writes:

> Hi,
>
> which unix function allows me to split an ip address
> returned from gethostbyname into octets ?

What exactly do you want to do?

-- 
M�ns Rullg�rd
mru@kth.se
0
Reply iso 5/25/2004 12:52:50 PM


M�ns Rullg�rd wrote:

> What exactly do you want to do?
struct hostent *k = gethostbyname("www.google.com");

        char packet[10];
        packet[0] = 5;
        packet[1] = 1;
        packet[2] = 0;
        packet[3] = 1;
        packet[4] = 
        packet[5] = 
        packet[6] = 
        packet[7] = 
        packet[8] = 0;
        packet[9] = 80;

In packet[4] 5,6 and 7 I have to put the octets of the ip
address of google to form a socks5 request as stated in the
rfc section 4:
http://rfc.net/rfc1928.html

Thank you for replying,
-- 
Bye,
Colossus
Mizio, a proxy scanner tool with GUI for Linux
http://mizio.sourceforge.net
0
Reply Colossus 5/25/2004 12:59:59 PM

Colossus <colossusNO_SPAM@freemail.it> writes:

> M�ns Rullg�rd wrote:
>
>> What exactly do you want to do?
> struct hostent *k = gethostbyname("www.google.com");
>
>         char packet[10];
>         packet[0] = 5;
>         packet[1] = 1;
>         packet[2] = 0;
>         packet[3] = 1;
>         packet[4] = 
>         packet[5] = 
>         packet[6] = 
>         packet[7] = 
>         packet[8] = 0;
>         packet[9] = 80;
>
> In packet[4] 5,6 and 7 I have to put the octets of the ip
> address of google to form a socks5 request as stated in the
> rfc section 4:
> http://rfc.net/rfc1928.html

Why not memcpy(packet + 4, k->h_addr, 4)?

-- 
M�ns Rullg�rd
mru@kth.se
0
Reply iso 5/25/2004 1:49:22 PM

M�ns Rullg�rd wrote:

> Why not memcpy(packet + 4, k->h_addr, 4)?

Really many many thanks !
-- 
Bye,
Colossus
Mizio, a proxy scanner tool with GUI for Linux
http://mizio.sourceforge.net
0
Reply Colossus 5/26/2004 6:54:56 AM

Colossus <colossusNO_SPAM@freemail.it> writes:

> M�ns Rullg�rd wrote:
>
>> Why not memcpy(packet + 4, k->h_addr, 4)?
>
> Really many many thanks !

Of course, you should make sure that 4 is actually the size of the
address.  It could be an IPv6 address.  Multiple addresses should also
be handled properly.  Just using the first is normally reasonable, but
there may be situations where this isn't the right thing.

-- 
M�ns Rullg�rd
mru@kth.se
0
Reply iso 5/26/2004 7:28:26 AM

5 Replies
563 Views

(page loaded in 0.077 seconds)

Similiar Articles:













7/20/2012 2:49:15 PM


Reply: