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.sin.sin_addr.s_addr 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.sin.sin_addr.s_addr to
be put into syslog.
I have tried the following:
syslog(LOG_DEBUG,"%s",(char *)RealHostAddr.sin.sin_addr.s_addr);
and
syslog(LOG_DEBUG,"%s",(char *)RealHostAddr.sin.sin_addr.s_addr, 10);
and
syslog(LOG_DEBUG,"%d",(int)RealHostAddr.sin.sin_ad dr.s_addr, 10);
and
syslog(LOG_DEBUG,"%d",(long)RealHostAddr.sin.sin_a ddr.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 5 1287
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.sin.sin_addr.s_addr 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.sin.sin_addr.s_addr 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.programmer
or comp.os.linux.development.apps, where they would be completely
on-topic.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
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.sin.sin_addr.s_addr 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.sin.sin_addr.s_addr 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.programmer or comp.os.linux.development.apps, where they would be completely on-topic. Regards, Jens
OK!
Thanks!
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.sin.sin_addr.s_addr 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.sin.sin_addr.s_addr to be put into syslog.
I have tried the following: syslog(LOG_DEBUG,"%s",(char *)RealHostAddr.sin.sin_addr.s_addr); and syslog(LOG_DEBUG,"%s",(char *)RealHostAddr.sin.sin_addr.s_addr, 10); and syslog(LOG_DEBUG,"%d",(int)RealHostAddr.sin.sin_a ddr.s_addr, 10); and syslog(LOG_DEBUG,"%d",(long)RealHostAddr.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
--
Al Balmer
Balmer Consulting re************************@att.net
# I'm on Linux and i know that i have an IP address in the member
# variable RealHostAddr.sin.sin_addr.s_addr 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(0x61626364);
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.
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.sin.sin_addr.s_addr 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(0x61626364); 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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>...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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,...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |