473,396 Members | 1,693 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,396 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 9217
* 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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.