how do i get the Port from an in_addr value? - vb.net

I am trying to extract the port from a given in_addr value in windows.
So far I am able to get the IP address using inet_ntoa but not the port.
Thanks.

You do not: it is only an IP address
Perhaps you mean to use sockaddr which contains this information, when applicable.

Related

Net functions behave slightly different for IPv4 from IPv6. Why?

I'm using BigQuery to truncate IPv4 & IP46 IP addresses. By that I mean I want to drop the part that might be used to identify a real person.
Here's some demo code:
select *,
NET.IP_TO_STRING(NET.IP_TRUNC(NET.IP_FROM_STRING(v.IPv4Address), 24)),
NET.IP_TO_STRING(NET.IP_TRUNC(NET.IP_FROM_STRING(v.IPv6Address), 64))
from (
select struct(
"254.34.78.20" as `IPV4Address`,
"2a02:c7e:3f0d:e00:48e:abff:d697:9cc2" as `IPv6Address`
) as v
)
It returns:
v
f0_
f1_
{ "IPV4Address": "254.34.78.20", "IPv6Address": "2a02:c7e:3f0d:e00:48e:abff:d697:9cc2" }
254.34.78.0
2a02:c7e:3f0d:e00::
I'd simply like to know why these functions return a 0 for the truncated portion of the IPv4 address but nothing for the truncated portion of the IPv6 address.
I know this isn't really a BigQuery question per se as its more about networks and I suspect BigQuery is just doing what any other such library would do... but interested to know why this is nonetheless. Maybe I'll tag it with IPv6 too
I'd simply like to know why these functions return a 0 for the
truncated portion of the IPv4 address but nothing for the truncated
portion of the IPv6 address.
It is returning 0 for the truncated part of the IPv6 address.
IPv6 addresses can have several forms, but the canonical form requires you to shorten the longest run of 0 fields with a double colon (::). That is at the end of your address 2a02:c7e:3f0d:e00::, and that means it is 2a02:c7e:3f0d:e00:0:0:0:0 properly shortened.

Can IP Port use as alphanumeric instead of numeric?

It is possible if I do like this?
http://myurl:abc
Port : abc instead of 123
No.
According to RFC3986, the port part of a URI is defined thus (my bold):
The port subcomponent of authority is designated by an optional port number in decimal following the host and delimited from it by a single colon (":") character.
That RFC has been updated by both RFC6874 and RFC7320, but neither of those effect any changes on the relevant section.
No, that cannot be the case. The port is a number always, as per specification.

How should I pick which source specific multicast address to use?

"The 232.0.0.0/8 (IPv4) and FF3x::/32 (IPv6) block is reserved for use by source-specific multicast."
So I assume this means I can use any address from 232.0.0.0 to 232.255.255.255 for source-specific multicasting. What should I be considering when I choose which address to use?
Choose whatever you want. It only has to be unique per sending system. There is no algorithm for this. It's source specific after all ☺

Incorrect domain name in objective-c for mac machine

I am trying to get the domain name of my macbook pro using following method.
NSString *name = [[NSHost currentHost] name];
It returns me the name like 'The-Special-MBP.local' but this is not consistent, It returns me some other string sometimes.
I am not getting why is this happening, the same function call returns two different values at different times.
Basically I need to indicate the different machines in network with some unique id or string hence I am reading the name from NSHost class but it gives different values for same machine.
Any help is appreciated.
If you want a unique id for your MAC, you may refer the following:
https://stackoverflow.com/a/5868967/1987246
It depends on your ethernet connection. Please you are connected in same network

Sort IP address column

I'm having one column named IPAddress in my table. I want to get IPAddress in sorted order.
IP Address:
8.123.10.124
192.23.34.45
If I use Order by IPAddress, i will get output as
192.23.34.45
8.123.10.124
Because order by sort it as string.
But I want output as
8.123.10.124
192.23.34.45
How to write a query for the same.
Is there any way to split a string in HSQL
You first need to convert the IP Address from string to int. For example, IP address 1.1.1.1 would be 001001001001 you can use following logic
while(ip[j]!='\0')
{
if(ip[j]!='.')
a[i]=a[i]*10+ip[j]-'0';
else
i++;
j++;
}
After that you can multiple a[0],a[1].... by appropriate numbers (1e9,1e6,1e3,1e0) and add .
However, you need to take some precaution such string which stores IP address doesn't have any white space saved with them and use unsigned long long int to store IP address in integer form