473,545 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help!

Hello!

I'm a beginner and are struggling to learn.

I'm on Linux and i know that i have an IP address in the member
variable RealHostAddr.si n.sin_addr.s_ad dr in HEX format. However i'm not
sure if this is a char[], long or what it is.

I have tried to have the contents of RealHostAddr.si n.sin_addr.s_ad dr to
be put into syslog.

I have tried the following:
syslog(LOG_DEBU G,"%s",(char *)RealHostAddr. sin.sin_addr.s_ addr);
and
syslog(LOG_DEBU G,"%s",(char *)RealHostAddr. sin.sin_addr.s_ addr, 10);
and
syslog(LOG_DEBU G,"%d",(int)Rea lHostAddr.sin.s in_addr.s_addr, 10);
and
syslog(LOG_DEBU G,"%d",(long)Re alHostAddr.sin. sin_addr.s_addr , 10);

And many other but nothing seems to work. I have reasons to believe that
the IP is stored backwards so that 192.168.20.50 is 50.20.168.192. So i
also later want to use ntohl().

Fredrik

Nov 14 '05 #1
5 1293
Fredrik Håkansson <fr*****@spamme .younix.se> wrote:
I'm on Linux and i know that i have an IP address in the member
variable RealHostAddr.si n.sin_addr.s_ad dr in HEX format. However i'm not
sure if this is a char[], long or what it is. I have tried to have the contents of RealHostAddr.si n.sin_addr.s_ad dr to
be put into syslog.


Sorry, but you're rather off-topic here since your problem is not
really one about the language C but some details of platform spe-
cific networking functions etc. which aren't even mentioned in the
C standard. So you will have a lot more success with getting answers
to your question when you would post them to e.g. comp.unix.progr ammer
or comp.os.linux.d evelopment.apps , where they would be completely
on-topic.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #2
On Fri, 30 Jul 2004 09:25:29 +0000, Jens.Toerring wrote:
Fredrik Håkansson <fr*****@spamme .younix.se> wrote:
I'm on Linux and i know that i have an IP address in the member
variable RealHostAddr.si n.sin_addr.s_ad dr in HEX format. However i'm not
sure if this is a char[], long or what it is.

I have tried to have the contents of RealHostAddr.si n.sin_addr.s_ad dr to
be put into syslog.


Sorry, but you're rather off-topic here since your problem is not
really one about the language C but some details of platform spe-
cific networking functions etc. which aren't even mentioned in the
C standard. So you will have a lot more success with getting answers
to your question when you would post them to e.g. comp.unix.progr ammer
or comp.os.linux.d evelopment.apps , where they would be completely
on-topic.
Regards, Jens


OK!

Thanks!

Nov 14 '05 #3
On Fri, 30 Jul 2004 09:00:49 GMT, Fredrik Håkansson
<fr*****@spamme .younix.se> wrote:
Hello!

I'm a beginner and are struggling to learn.

I'm on Linux and i know that i have an IP address in the member
variable RealHostAddr.si n.sin_addr.s_ad dr in HEX format. However i'm not
sure if this is a char[], long or what it is.
You've been told elsethread that this question is offtopic, but there
is a C question hidden here. The proper answer to your question is
that you don't _want_ to know what type the s_addr is. You should
consider it an opaque structure, subject to change. Knowing what it
"really" is can only get you in trouble. The API you're using provides
functions to access the contents.

<OT> Do you have access to W. Richard Stevens "Unix Network
Programming" Volume 1? It's a bit pricey, but it's the bible for this
kind of thing. </OT>

I have tried to have the contents of RealHostAddr.si n.sin_addr.s_ad dr to
be put into syslog.

I have tried the following:
syslog(LOG_DEB UG,"%s",(char *)RealHostAddr. sin.sin_addr.s_ addr);
and
syslog(LOG_DEB UG,"%s",(char *)RealHostAddr. sin.sin_addr.s_ addr, 10);
and
syslog(LOG_DEB UG,"%d",(int)Re alHostAddr.sin. sin_addr.s_addr , 10);
and
syslog(LOG_DEB UG,"%d",(long)R ealHostAddr.sin .sin_addr.s_add r, 10);

And many other but nothing seems to work. I have reasons to believe that
the IP is stored backwards so that 192.168.20.50 is 50.20.168.192. So i
also later want to use ntohl().

Fredrik


--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 14 '05 #4
# I'm on Linux and i know that i have an IP address in the member
# variable RealHostAddr.si n.sin_addr.s_ad dr in HEX format. However i'm not
# sure if this is a char[], long or what it is.

# And many other but nothing seems to work. I have reasons to believe that
# the IP is stored backwards so that 192.168.20.50 is 50.20.168.192. So i
# also later want to use ntohl().

Different machines stores bytes in different orders. If you have 4 byte
longs and a union like
union {long i; char c[4];} u;
and then do
u.i = 0x61626364;
printf("%.4s\n" ,u.c);
sometimes you'll get ABCD, sometimes DCBA, or, if you still have PDP-11
around, BADC.

u.i = ntohl(0x6162636 4);
puts the bytes in the same order on every machine so that
printf("%.4s\n" ,u.c);
is ABCD. htonl is the inverse function of ntohl.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Don't say anything. Especially you.
Nov 14 '05 #5
On Sat, 31 Jul 2004 16:37:52 +0000, SM Ryan wrote:
# I'm on Linux and i know that i have an IP address in the member
# variable RealHostAddr.si n.sin_addr.s_ad dr in HEX format. However i'm not
# sure if this is a char[], long or what it is.

# And many other but nothing seems to work. I have reasons to believe that
# the IP is stored backwards so that 192.168.20.50 is 50.20.168.192. So i
# also later want to use ntohl().

Different machines stores bytes in different orders. If you have 4 byte
longs and a union like
union {long i; char c[4];} u;
and then do
u.i = 0x61626364;
printf("%.4s\n" ,u.c);
sometimes you'll get ABCD, sometimes DCBA, or, if you still have PDP-11
around, BADC.

u.i = ntohl(0x6162636 4);
puts the bytes in the same order on every machine so that
printf("%.4s\n" ,u.c);
is ABCD. htonl is the inverse function of ntohl.


Thanks your explanation was great it helped me to understand and to
complete my code.

Fredrik

Nov 14 '05 #6

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

Similar topics

0
1686
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web browser that Hotmail does not support. If you continue to use your current browser software we cannot guarantee that Hotmail will work correctly for...
7
3579
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
7
3259
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that I believe if it's solved, the remaining stuff is easy... my full program until now is here: http://www.geocities.com/tom4_h4wk/progmail.zip the...
23
3241
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
13
4302
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error "operation is not allowed when object is open" so I take out the line of code: BookDetails.Connection1.Open and it comes up with the error...
1
9599
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the...
1
54477
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and we instruct our experts to ignore any such PMs completely Be sure to give the version of Access that you are working with and the Platform and OS if...
0
3036
by: 2Barter.net | last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA Inbox Reply Reply to all Forward Print Add 2Barter.net to Contacts list Delete this message Report phishing Show original
6
3294
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID, EmpName,DeptID,DateOfJoin, Sal, Addr) Finance (EmpID, Sal) Club (Clubname, EmpID, Fee, DateOfJoin) Leave (EmpID, Date) Department (DeptID, DeptName,...
5
2295
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks for user name, check in the system but does not return the correct answer please help me with it. or if you have better way of doing it would you...
0
7499
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7689
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7943
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6022
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.