Re: how to specify power of number



On 18 Apr 2008 at 21:46, user923005 wrote:
If we look at his original post (and knowing he is just turning these
TCP/IP addresses into 4 byte integers):
"
numericip=atoi(textip[0])*256*256*256+atoi(textip[1])*256*256+atoi(textip[2­])*256+atoi(textip[3]);"

It could clearly be done as {assuming textip[] is an array of unsigned
char} as:
numericip = (unsigned long)textip[0] << 24 +
(unsigned long)textip[1] << 16 +
(unsigned long)textip[2] << 8 +
(unsigned long)textip[3] ;

True, and someone had already suggested this. But the discussion
broadened, and someone claimed that using pow() was the best way to
raise integers to (positive) integer powers: it was this assertion that
I was responding to.

Or {better yet} simply use inet_aton() {which is also fine for
Winsock, though WSAStringToAddress() is an alternative}. That is what
would be normally done to retrieve a TCP/IP address from a dotted
address string.

HOWEVER!

The OP should keep in mind that inet_aton() does NOT support IPv6 and
that getnameinfo() should be used instead for IPv4/v6 dual stack
support.

Good advice.

To the O.P.:
You can't go wrong with "Unix Network Programming" By W. Richard
Stevens

Agreed.

.



Relevant Pages

  • Re: CAsyncSocket and Send
    ... The sending side sends an 'f' char immediately before a file is sent. ... > Are you using TCP/IP or UDP? ... > Are you making sure that, if you are handling strings, that you insert a terminating NUL ... >>in C and the receiving side is MFC. ...
    (microsoft.public.vc.mfc)
  • Re: .NET Remoting/Serialization way too slow vs C++ binary/tcp
    ... > would take to transmit objects numerous times via TCP/IP using C# ... > of sending an object from a client process to a server process, ... serialize the object to a byte array and send the client the length of the ... array followed by the byte array. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: help:Tansfer a big double[] array by TCP/IP,
    ... use System.BitConverter to flatten the array into a continuous ... Principal Architect ... > string and then parse it into bytes and then transfer it. ... > TCP/IP, and needn't transfer it to string and then bytes. ...
    (microsoft.public.dotnet.framework.compactframework)