Re: How can I extract the destination IP address from incoming req
- From: "Ben Voigt" <rbv@xxxxxxxxxxxxx>
- Date: Tue, 9 Jan 2007 09:22:58 -0600
"Arkady Frenkel" <arkadyf@xxxxxxxxxxxxxxxx> wrote in message
news:OvvIhY9MHHA.4992@xxxxxxxxxxxxxxxxxxxxxxx
getsockname() will give you that for local socket
That will be INADDR_ANY for a multihomed machine bound to all interfaces.
Arkady
"Bassam" <Bassam@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C3955032-6067-447C-BBDE-24BB8A340216@xxxxxxxxxxxxxxxx
Dear Arkady,
I am afraid that you couldn't understand my post. However, the
clientAddress
contains all the information of the source peer (the client), while I am
looking for the information of the destination peer.
My code is on a multihomed server, and I want to know the destination
address that sent by the client in order to know on which interface or
destiantion IP the request has been made by the client. In otherword, by
which interface the request has been received.
regards
Bassam
"Arkady Frenkel" wrote:
From clientAddress. It's of type
struct sockaddr_in {
short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
} where sin_addr struct include IPArkady
Arkady
"Bassam" <Bassam@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B5EB246F-A4DA-406E-AF7D-EE80133A8F26@xxxxxxxxxxxxxxxx
Dear All,
I am writing a Radius server using winsock2 with win32 C++ on visual
C++
2005 express edition on windows xp pro.
My application is listening for all the UDP packets on all the
interfaces
on
a multihomed machin. However, I am trying to add a feature to my
server
where
I can reject requests incoming from or sent to a specific
interface(s).
That's better accomplished by your packet filter. No reason every TCP
server in the world should have to re-implement firewall rules.
My question is that how to extract the destination IP address of all
the
request targeted to my server so that I can decide whether to further
process
the request or just ignore it.
A snippet pf my code:
------------------------------------------------
ADDRINFO addressHints;
LPADDRINFO radiusResult = NULL, pointerResult = NULL;
//some code here
SecureZeroMemory(&addressHints, sizeof(addressHints));
addressHints.ai_flags = AI_PASSIVE;
addressHints.ai_family = AF_UNSPEC;
addressHints.ai_socktype = SOCK_DGRAM;
addressHints.ai_protocol = IPPROTO_UDP;
//Listen to all the interfaces
if(getaddrinfo(NULL, "1812", &addressHints, &radiusResult) != 0)
{
cerr << "\n\n\nError no." << WSAGetLastError() << ": check
getaddrinfo()"
<< endl;
exit(EXIT_FAILURE);
}
//create IPv4 and IPv6 sockets for radius (authentication and
authorization)
//and then bind it to the socket address structures
count = 0;
pointerResult = radiusResult;
while(pointerResult)
{
//create the authentication and authorization sockets for both IPv4
and
IPv6
if((radiusSocket[count] = WSASocket(pointerResult->ai_family,
pointerResult->ai_socktype, pointerResult->ai_protocol, NULL, 0,
NULL)) ==
INVALID_SOCKET)
{
cerr << "\n\n\nError no." << WSAGetLastError() << ": check
WSASocket()" <<
endl;
exit(EXIT_FAILURE);
}
if(bind(radiusSocket[count], pointerResult->ai_addr,
pointerResult->ai_addrlen)== SOCKET_ERROR)
{
cerr << "\n\n\nError no." << WSAGetLastError() << ": check bind()" <<
endl;
exit(EXIT_FAILURE);
}
count++;
//get the next entry of the winsock cataloge
pointerResult = pointerResult->ai_next;
}
while(true)
{
FD_ZERO(&fdReadSockets);
//Add all the socket handlers to all fd_set
for (count = 0; count < MAX_SOCKETS_ARRAY_SIZE; count++)
{
FD_SET(radiusSocket[count], &fdReadSockets);
FD_SET(accountSocket[count], &fdReadSockets);
}
if ((functionReturnValue = select(0, &fdReadSockets, NULL, NULL,
&selectTimeOut)) == SOCKET_ERROR)
{
cerr << "\n\n\nError no." << WSAGetLastError() << ": check select()"
<<
endl;
exit(EXIT_FAILURE);
}
if (functionReturnValue > 0)
{
for (count = 0; count < MAX_SOCKETS_ARRAY_SIZE; count++)
{
//check the data received for authentication and authorization
if (FD_ISSET(radiusSocket[count], &fdReadSockets))
{
//some code here
flags = 0;
clientAddressSize = sizeof(clientAddress);
if ((WSARecvFrom(radiusSocket[count], radiusPacketData,
RADIUS_PACKET_FIELDS, &bytesReceived, &flags,
reinterpret_cast<PSOCKADDR>(&clientAddress), &clientAddressSize, NULL,
NULL)
== SOCKET_ERROR) && (WSAGetLastError() != WSAECONNRESET))
{
cerr << "\n\n\nError no." << WSAGetLastError() << ": check
WSARecvFrom()"
<< endl;
exit(EXIT_FAILURE);
}
if (WSASendTo(radiusSocket[count], radiusPacketData,
RADIUS_PACKET_FIELDS,
&bytesSent, flags, reinterpret_cast<PSOCKADDR>(&clientAddress),
clientAddressSize, NULL, NULL) == SOCKET_ERROR)
{
cerr << "\n\n\nError no." << WSAGetLastError() << ": check
WSASendTo()"
<< endl;
exit(EXIT_FAILURE);
}
}
}
//house keeping stuff
------------------------------------------
Your help is much appreciated
Regards
Bassam
.
- Follow-Ups:
- Re: How can I extract the destination IP address from incoming req
- From: Arkady Frenkel
- Re: How can I extract the destination IP address from incoming req
- References:
- How can I extract the destination IP address from incoming request
- From: Bassam
- Re: How can I extract the destination IP address from incoming request
- From: Arkady Frenkel
- Re: How can I extract the destination IP address from incoming req
- From: Bassam
- Re: How can I extract the destination IP address from incoming req
- From: Arkady Frenkel
- How can I extract the destination IP address from incoming request
- Prev by Date: Re: How to convert two byte sequence to an unsigned short.
- Next by Date: Re: How can I extract the destination IP address from incoming req
- Previous by thread: Re: How can I extract the destination IP address from incoming req
- Next by thread: Re: How can I extract the destination IP address from incoming req
- Index(es):
Relevant Pages
|
Loading