473,242 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

How to use htonl in IPv6

Hello all,
I have the following program, which will take ipv4 address as input
in command line and convert it from host byte order to network byte
order. I need similar thing to be done for IPv6. Any help is
appriciated. Thanks in advance.

#include <stdio.h>
main( int argc, char *argv[] )
{
unsigned int ip, b1, b2, b3, b4;
ip=b1=b2=b3=b4=0;

if (sscanf(argv[1], "%d.%d.%d.%d", &b1, &b2, &b3, &b4)
== 4 && b1<=255U && b2<=255U && b3<=255U && b4<=255U) {
//For IPv4 address
ip = htonl( (b1<<24)|(b2<<16)|(b3<<8)|b4 );
}
printf("IP_TO_LONG:%ld\n", ip);
}

Feb 9 '06 #1
2 9175
* linuxer:
Hello all,
I have the following program, which will take ipv4 address as input
in command line and convert it from host byte order to network byte
order. I need similar thing to be done for IPv6. Any help is
appriciated. Thanks in advance.

#include <stdio.h>
main( int argc, char *argv[] )
{
unsigned int ip, b1, b2, b3, b4;
ip=b1=b2=b3=b4=0;

if (sscanf(argv[1], "%d.%d.%d.%d", &b1, &b2, &b3, &b4)
== 4 && b1<=255U && b2<=255U && b3<=255U && b4<=255U) {
//For IPv4 address
ip = htonl( (b1<<24)|(b2<<16)|(b3<<8)|b4 );
}
printf("IP_TO_LONG:%ld\n", ip);
}


"htonl" is not part of standard C++ or the standard C++ library.

So you're off-topic, and I don't know where to send you, except,
use a search engine such as Google.

The above code should not even compile.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 9 '06 #2

linuxer wrote:
Hello all,
I have the following program, which will take ipv4 address as input
in command line and convert it from host byte order to network byte
order. I need similar thing to be done for IPv6. Any help is
appriciated. Thanks in advance.


On Linux use inet_ntop().
man inet_ntop

Feb 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Agent | last post by:
I would like to invite you and your associates to attend the US IPv6 (Internet Protocol version 6) Summit, December 8-11, 2003 in Crystal City, VA, near the Pentagon. This major opportunity to...
7
by: Torsten Schmidt | last post by:
Hi, I'm trying to connect to a mysql-Server using PHP's mysql-function mysql_connect. The host on which the mysql-server is running is not the same as the host apache and php are running on. The...
8
by: John Burton | last post by:
I'm not sure if this is a question about python socket support or sockets in general ... I have a socket server with which I want to accept incoming connections on ipv4 and ipv6. I've found...
2
by: PaulH | last post by:
I am attempting to write a functon that can perform IPv6 compliant pings. But, Icmp6SendEcho2 causes an access violation whenever it is called: First-chance exception at 0x76d641e8 in mping2.exe:...
2
by: gregory_may | last post by:
First the research links: IPv6 spec (look for 'jumbo payload'): http://www.cs-ipv6.lancs.ac.uk/ipv6/documents/rfcs/archive/rfc1883.txt IPv6 Sample C# Client/Server...
8
by: prabhuram.k | last post by:
Can anybody know how to validate IPV4 and IPV6 address in C++
3
by: jiri.juranek | last post by:
Hello, is there any common function for validation if string contains valid ip address(both ipv4 and ipv6)? Or does sb wrote some regular expression for this? thanks J
3
by: Pramod TK | last post by:
Hello All, I have some queries related to python support for IPv6. Can you kindly clarify the doubts which I have - 1. Does python support IPv6? 2. Does it support setting of QoS flags? 3. Does...
8
by: Giampaolo Rodola' | last post by:
I'm not sure if this is a question about python programming, system administration or sockets in general... I have the FTP server in my signature to which I'd want to add IPv6 support. My hosting...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.