April 16th, 2011, 12:41 PM
#1
port number in RtlIpv4AddressToStringEx
Syntax
CopyLONG NTAPI RtlIpv4AddressToStringEx(
__in const IN_ADDR *Address,
__in USHORT Port,
__out LPTSTR AddressString,
__inout PULONG AddressStringLength
);
Parameters
Address [in]
The IPv4 address in network byte order.
Port [in]
The port number in network byte order format. This parameter is optional.
AddressString [out]
The port number is optional. I don't understand . Could someone please clarify a bit ?
Thank you////
April 19th, 2011, 10:01 AM
#2
Re: port number in RtlIpv4AddressToStringEx
Optional means it may or may be not specified. If zero, it gets omitted in the resultant address string.
Code:
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <winsock2.h>
#include <MSTcpIP.h>
#pragma comment(lib, "ntdllstub")
#define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
int main(int argc, LPCTSTR* argv)
{
IN_ADDR addr = {0};
USHORT port = 0;
TCHAR addrStr[64] = {0};
ULONG cch = COUNTOF(addrStr);
LPTSTR delim = NULL;
if (argc > 1)
port = htons(atoi(argv[1]));
if (NO_ERROR == RtlIpv4StringToAddress(TEXT("192.168.0.1"), TRUE, &delim, &addr))
{
if (NO_ERROR == RtlIpv4AddressToStringEx(&addr, port , addrStr, &cch))
_tprintf(TEXT("IP = %s\n"), addrStr);
}
return 0;
}
Code:
E:\Temp\598>598.exe
IP = 192.168.0.1
E:\Temp\598>598.exe 2011
IP = 192.168.0.1:2011
Attached Files
Last edited by Igor Vartanov; April 19th, 2011 at 10:04 AM .
Best regards,
Igor
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width