|
Two ways to get IP address from the socket address (4 byte hex value). Do
shift operations on each byte to get each hop, or use the inet_ntoa()
socket call to convert for you. These are C solutions, but you can
devise your own.
Take the Connection struction from the exit point interface and do the
following:
/********************************************************************/
/* Calculate the IP address for analysis. Must store the IP in */
/* local var else next call to inet_ntoa() will trash it. */
/********************************************************************/
pSockAddr = (struct sockaddr_in *)pConnection->Internet_address;
pClientIP = inet_ntoa(pSockAddr->sin_addr);
strcpy(ClientIP, pClientIP);
iClientPort = pSockAddr->sin_port;
Or take the Connection structure again and do the following:
/**********************************************************************/
/* @function GetDottedDecAddr() */
/* */
/* Parameters: */
/* */
/* unsigned int uiIntNetAddr */
/* char *acDottedDecimalAddr */
/* */
/* Description: */
/* */
/* GetDottedDecAddr determines the "dotted" Internet address based on */
/* the unsigned integer representation. */
/**********************************************************************/
void GetDottedDecAddr(unsigned long uiIntNetAddr,
char *acDottedDecimalAddr)
{
unsigned int uiPart1, uiPart2, uiPart3, uiPart4,
ONE_BYTE = 8,
TWO_BYTES = 16,
THREE_BYTES = 24;
/*******************************************************************/
/* The Internet address passed here is a 32 bit (4-byte) unsigned */
/* integer. The 4 pieces of the "dotted" address are contained in */
/* the unsigned int, 1 piece per byte. To get each piece, we need */
/* to shift the UINT the appropriate number of bits right and/or */
/* left. As we are dealing with an unsigned integer, when the */
/* value is shifted right, zeros are inserted into the left-most */
/* bit. Zeros are always inserted into the right-most bit when */
/* shifting left. */
/*******************************************************************/
uiPart1 = uiIntNetAddr >> THREE_BYTES;
uiPart2 = (uiIntNetAddr << ONE_BYTE) >> THREE_BYTES;
uiPart3 = (uiIntNetAddr << TWO_BYTES) >> THREE_BYTES;
uiPart4 = (uiIntNetAddr << THREE_BYTES) >> THREE_BYTES;
sprintf(acDottedDecimalAddr, "%d.%d.%d.%d", uiPart1, uiPart2, uiPart3,
uiPart4);
}
--
J.S. (Jeffrey) Stevens AS/400 TCP/IP (Telnet/WSG/LPD)
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.