Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-15-2008, 12:33 PM
Junior Member
 
Join Date: Jul 2008
Posts: 0
iTrader: (0)
cool_yogs is on a distinguished road
Default Returning an IPv4 Address in an IPv6-Enabled Environment

Hi All,

This is my first post in this forum. I am not sure if this is the right thread for my question. Please direct me the correct post if it's needed.
Q: I have an ASP page (test.asp) that reads Request.ServerVariables("REMOTE_ADDR") and passes it down to c++ dll which then reports in log.

When my service is running on XP/2003, it returns following results when above 4 sites are hit:
  1. http://localhost/test.asp reports 127.0.0.1
  2. http://servername/test.asp form the server itself reports 127.0.0.1
  3. http://IPv4AddressOfserver/test.asp from any client machine reports 10.1.1.12 (client's IP4 address)
  4. http://servername/test.asp from any client reports 10.1.1.12 (client's IP4 address)

But if it's running on Vista/Server2008 this function returns different addresses as follows:
  1. http://localhost/test.asp returns "::1" (it's IP6 address for localhost, when I do "ping localhost" from cmdline on server I get ::1)
  2. http://servername/test.asp from the server "fe80::8998:7ecb:2a73:57f6%10" (it's IP6 address of servername, when I do "ping <server name>" on server I get this address).
  3. http://IPv4AddressOfserver/test.asp from any (XP/2003/2008) machine returns IPv4 address of the client machine.
  4. http://servername/test.asp from any (XP/2003/2008) machine returns IPv4 address of the client machine.

Is there a way to convert these IPv6 addresses into Ipv4 format as shown in first case? Is there any pure (no managed code) CPP function that can convert/extract IPv4 address from the IPv6 address. Does anyone happen to know the solution or can guide/direct me towards the solutions?

I am currently trying following in my cpp dll where sClientIP is being passed down by test.asp:

get_Init(LPSTR sClientIP) {
struct sockaddr_storage ss;
int sslen = sizeof(ss);
memset(&ss, 0, sslen);
reinterpret_cast<sockaddr_in6*>(&ss)->sin6_family = AF_INET6;
int status = 2;
status = ::WSAStringToAddressA(theClientIP, AF_INET6, NULL, reinterpret_cast<sockaddr*>(&ss), &sslen);
if(status == 0) {
struct in6_addr sin6;
sin6 = ((struct sockaddr_in6 *)&ss)->sin6_addr;

struct in_addr sin4;
sin4.S_un.S_un_b.s_b1 = sin6.u.Byte[12];
sin4.S_un.S_un_b.s_b2 = sin6.u.Byte[13];
sin4.S_un.S_un_b.s_b3 = sin6.u.Byte[14];
sin4.S_un.S_un_b.s_b4 = sin6.u.Byte[15];
theClientIP = inet_ntoa(sin4);
}
}

But this returns me following:
  1. http://localhost/test.asp reports 0.0.0.1
  2. http://servername/test.asp form the server itself reports 42.115.87.246
  3. http://IPv4AddressOfserver/test.asp from any client machine reports 10.1.1.12 (client's IP4 address)
  4. http://servername/test.asp from any client reports 10.1.1.12 (client's IP4 address)

Any help is greatly appreciated!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-10-2008, 10:14 AM
Junior Member
 
Join Date: Dec 2008
Posts: 6
iTrader: (0)
marshtric is on a distinguished road
Default

The Internet is best described as a "network of networks," and every device which is connected to the Internet is uniquely identified by its Internet Protocol (IP) address
__________________
banner displays trade show booths
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -6. The time now is 06:03 PM.