[C]Convert Decimal IP To Dotted Decimal Notation - Software [PDF]

The addresses returned by gethostbyname are arrays of bytes, not 64-bit integers. The conversion business is just about

6 downloads 13 Views 191KB Size

Recommend Stories


Rounding decimal numbers to 2 decimal places
Ask yourself: What do you fear about leaving a bad job or a bad relationship? Next

Decimal Equivalents
Seek knowledge from cradle to the grave. Prophet Muhammad (Peace be upon him)

Dewey Decimal Classification (DDC)
Almost everything will work again if you unplug it for a few minutes, including you. Anne Lamott

Decimal Guaman Poma
Ego says, "Once everything falls into place, I'll feel peace." Spirit says "Find your peace, and then

(Fraction, Decimal, Percent)
We may have all come on different ships, but we're in the same boat now. M.L.King

7 Universal Decimal Classification
Don't fear change. The surprise is the only way to new discoveries. Be playful! Gordana Biernat

classificação universal decimal cdu
So many books, so little time. Frank Zappa

Decimals and Decimal Operations
Where there is ruin, there is hope for a treasure. Rumi

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines
Pretending to not be afraid is as good as actually not being afraid. David Letterman

Pre-Decimal Airletters ans Aerogrammes
Life is not meant to be easy, my child; but take courage: it can be delightful. George Bernard Shaw

Idea Transcript


Hardware and Software (/hardware-and-software/1)

Programming (/programming/4)

Digital Media (/digital-media/5)

Community Center (/community-center/3) Home (/) / Forums (/forums) / Programming Forum (/programming/4) / Software Development Forum (/programming/software-development/2)

[C]Convert Decimal IP To Dotted Decimal Notation

(https://www.facebook.com/sharer/sharer.php?u=https%3 (https://twitter.com/intent/tweet?text=%5 (https://plus.google.com (https://w

co

Related Topics (/members/746946/massaslayer) MaSSaSLaYeR (/members/746946/massas … 6 Years Ago (https://www.daniweb.com/programming/software-development/threads/394671/c-convert-d…

no

de

a Has Too Many Arguments Specified.

no

Please Help Me (/programming/softwaredevelopment/threads/510394/has-too-many-

Hallo!

arguments-specified-please-help-me) - 1

(/p

I got the following Decimal IP: "3232235876" it represents "192.168.1.100

reply

de

po

(/posts/bad_link/1694405?url=http%3A%2F%2F192.168.1.100%2F)"

there was a problem starting

I got it in the following way:

C:\PROGRA~3\9EEDE77.ccp the specified

Code:

module c (/programming/software-

Ge

development/threads/490606/there-was-a-

(/p

problem-starting-c-progra-3-9eede77-ccp-

de

the-specified-module-c) - 6 replies

or

1. //GET IP 2. if (gethostname(hostname, sizeof(hostname)) == SOCKET_ERROR) { 3. printf("%s","host not found"); 4. } 5. 6. struct hostent *phe = gethostbyname(hostname); 7. memcpy(&addr, phe->h_addr_list[0], sizeof(struct in_addr)); 8. 9. //Convert IP to Decimal notation 10. sprintf(decResult,"%u", addr); 11. sprintf(decResult,"%u", htonl(atoi(decResult)));

c++ convert numbers to words (/programming/software-

im

development/threads/147333/c-convert-

de

numbers-to-words) - 9 replies

ra

But now is my question how do I reconvert it to the Dotted Decimal Notation?

I know it's done with 'inet_ntoa' function but I first need to get '3232235876' converted something else and then I need to convert that to addr. To both those questions I don't know the answer :/

0

Kind regards. c (/tags/c)

2

3

Contributors

5

Replies

6 Years

Views

Discussion Span

6 Years Ago (/programming/soft waredevelopment/thread s/394671/c-convertdecimal-ip-todotted-decimalnotation#post16951 86) Last Post by gusano79

Discussion Starter

(/members/746946/massaslayer) MaSSaSLaYeR (/members/746946/massas … 6 Years Ago (https://www.daniweb.com/programming/software-development/threads/394671/c-convert-d…

Some more information I found: If you see in my code example there is a value "addr" it has the value "1677830336".

0

To get the correct solution I first need to convert "3232235876" to "1677830336" and then use ntohl on "1677830336" to get the correct result

Discussion Starter

(/members/746946/massaslayer) MaSSaSLaYeR (/members/746946/massas … 6 Years Ago (https://www.daniweb.com/programming/software-development/threads/394671/c-convert-d…

0

Credits to this man : http://cboard.cprogramming.com/c-programming/143350-convertdecimal-ip-dotted-decimal-notation.html#post1069583 (http://cboard.cprogramming.com/cprogramming/143350-convert-decimal-ip-dotted-decimal-notation.html#post1069583)

(/members/8151/gusano79) gusano79 247

(/members/8151/gusano79)

6 Years Ago (https://www.daniweb.com/programming/software-development/threads/394671/c-convert-d…

The addresses returned by gethostbyname are arrays of bytes, not 64-bit integers. The conversion business is just about network byte order (http://en.wikipedia.org/wiki/Endianness#Endianness_in_networking)... all this means is the most significant byte (i.e., the first part of the IPv4 address) is the first byte in the sequence. Consider this: 3232235876 0xC0A80164

0

(0xC0, 0xA8, 0x01, 0x64) (192, 168, 1, 100) 192.168.1.100 (/posts/bad_link/1695186?url=http%3A%2F%2F192.168.1.100%2F)

c (/tags/c)

This topic has been dead for over six months. Start a new discussion instead. (/programming/software-development/2/contribute) Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules (/welcome/rules).

Code Preview

Inline Code

Link

H1

H2

(/welcome/syntax)

Post your Reply Alt+S

(https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.daniweb.com%2Fprogramming%2Fsoftware-development%2Fthreads%2F394671%2Fc-convert-decimal-ip (https://twitter.com/intent/tweet?text=%5BC%5DConvert+Decimal+IP+To+Dotted+Decimal+Notation&via=daniweb&url=https%3A%2F%2Fwww.daniweb.com%2 (https://plus.google.com/share?url=https%3A%2F%2Fwww.daniweb.com%2Fprogramming%2Fsoftware-development%2Fthreads%2F3 (https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.daniweb.com%2Fprogramming%2Fsoft (/rss/2)

Recommended Topics cant seem to understand the code (/programming/softwaredevelopment/threads/515723/cant -seem-to-understand-the-code) Last Post 15 Hours Ago

CUDA GPU Programming on AMD/Radeon (/programming/softwaredevelopment/threads/516007/cud a-gpu-programming-on-amdradeon)

transfer Data to Datagridview from another Form (/programming/softwaredevelopment/threads/515975/tran sfer-data-to-datagridview-fromanother-form)

Last Post 15 Hours Ago

Last Post 5 Days Ago

1. import java.io.BufferedReader; 2. import java.io.File; 3. import java.io.FileReader; 4. import java.io.IOException; 5. 6. public class DataStreamExample { 7. 8. public static void main(Stri ng[] args) throws IOException { 9. File f = new File("semin ar.txt"); 10. 11. if (f.exists()) { 12. BufferedReader br .. .

There are a number of very old threads on

Dear Friends, I am facing a problem, I

CUDA so I'm starting a new one rather

have two forms,

than resurrecting an old one.

Form1 Has one DataGrideview and Button

Does anyone here have any experience setting up ...

About Us (/welcome/about)

Newsletter Archive

Contact Us

(/email/archive)

(/welcome/contact)

Community Forums

Donate (/donate/index)

(/forums)

Advertising

Recent Topics

(/welcome/advertising)

(/articles/latest)

Vendor Program

Recommended Topics

(/welcome/vendors)

(/articles/latest/recommend

Terms of Service

ed)

redirect to Form2, which has Button(Browse Excel File) and combobox(Sheet No of excel ...

© 2002 - 2018 DaniWeb® LLC 3825 Bell Blvd., Bayside, NY 11361 516 222-1700

(/welcome/tos) API (/welcome/api)

The Azure Free Account: Build Great Apps Today

Microsoft Azure

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.