Firstly what type is %x as I've not encountered it before?
Now the problem: I'm trying to alter a host masking system for ircd so
that it masks all but the isp name and location (if .uk.us etc..).
However the crc32 stuff doesnt return as a string, and because the
number of hostname fields is not static I need to build a string which
contains each hostname field hashed and joined together.
if (parc > 4) /* There are isp's like *.isp.co.uk etc out
there */
{
for (i=2; i < (parc - 2); i++)
{
hash[i] = ((crc32(parv[i], strlen(parv[i])) + KEY2) ^ KEY1) ^
KEY3;
hash[i] <<= 2;
hash[i] >>= 2;
/* what goes here to make buf complete? */
}
sprintf(mask, "%s%s.%s.%s", buf, parv[parc - 3], parv[parc - 2],
parv[parc - 1]);
}
hash[0] and [1] are always the first two hostname fields, and in other
conditions are sprintf'ed into mask as %x.
Ultimately what im aiming is to have mask.mask.mydomain.co.uk,
mask.mask.mask.otherdomain.co.uk, mask.mask.mask.domain3.com etc..
Hope this makes sense :)
Kind Regards,
Ian
--
Swap 'invalid' for 'co.uk' and fill
the void with 'ian' to reply via email
-- 6 2597
On Sun, 18 Jan 2004 01:22:53 -0000, "Ian Gibbons"
<vo**@mywits-end.invalid> wrote in comp.lang.c: Firstly what type is %x as I've not encountered it before? Now the problem: I'm trying to alter a host masking system for ircd so that it masks all but the isp name and location (if .uk.us etc..). However the crc32 stuff doesnt return as a string, and because the number of hostname fields is not static I need to build a string which contains each hostname field hashed and joined together.
if (parc > 4) /* There are isp's like *.isp.co.uk etc out there */
What is parc?
{ for (i=2; i < (parc - 2); i++) { hash[i] = ((crc32(parv[i], strlen(parv[i])) + KEY2) ^ KEY1) ^ KEY3;
What is hash? What is parv? What does crc32() return?
hash[i] <<= 2; hash[i] >>= 2; /* what goes here to make buf complete? */ } sprintf(mask, "%s%s.%s.%s", buf, parv[parc - 3], parv[parc - 2], parv[parc - 1]); }
hash[0] and [1] are always the first two hostname fields, and in other conditions are sprintf'ed into mask as %x. Ultimately what im aiming is to have mask.mask.mydomain.co.uk, mask.mask.mask.otherdomain.co.uk, mask.mask.mask.domain3.com etc..
Hope this makes sense :)
Kind Regards, Ian
Your posted sample code containing quite a few variables and one
function without explaining what they are.
As for the question in your first sentence, %x and %X are conversion
specifier for the printf() family of functions that can be used
anywhere %d or %u can be used, including with a leading l for long
values. They specify that the integer type argument is to be
converted to hexadecimal text representation.
Example:
printf("%d, %x, %X, %04X\n", 63, 63, 63, 63);
....should output:
63, 3f, 3F, 003F
The lower case %x specifies that hex digits a...f are output as lower
case, %X displays A...F as upper case. All of the usual conversion
modifiers may be used, such a "%04X", which prints four characters
with leading '0' fill.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
"Jack Klein" <ja*******@spamcop.net> crawled outside to scribble in 31********************************@4ax.com the following: On Sun, 18 Jan 2004 01:22:53 -0000, "Ian Gibbons" <vo**@mywits-end.invalid> wrote in comp.lang.c:
Firstly what type is %x as I've not encountered it before? Now the problem: I'm trying to alter a host masking system for ircd so that it masks all but the isp name and location (if .uk.us etc..). However the crc32 stuff doesnt return as a string, and because the number of hostname fields is not static I need to build a string which contains each hostname field hashed and joined together.
if (parc > 4) /* There are isp's like *.isp.co.uk etc out there */
What is parc?
{ for (i=2; i < (parc - 2); i++) { hash[i] = ((crc32(parv[i], strlen(parv[i])) + KEY2) ^ KEY1) ^ KEY3;
What is hash? What is parv? What does crc32() return?
hash[i] <<= 2; hash[i] >>= 2; /* what goes here to make buf complete? */ } sprintf(mask, "%s%s.%s.%s", buf, parv[parc - 3], parv[parc - 2], parv[parc - 1]); }
hash[0] and [1] are always the first two hostname fields, and in other conditions are sprintf'ed into mask as %x. Ultimately what im aiming is to have mask.mask.mydomain.co.uk, mask.mask.mask.otherdomain.co.uk, mask.mask.mask.domain3.com etc..
Hope this makes sense :)
Kind Regards, Ian
Your posted sample code containing quite a few variables and one function without explaining what they are.
As for the question in your first sentence, %x and %X are conversion specifier for the printf() family of functions that can be used anywhere %d or %u can be used, including with a leading l for long values. They specify that the integer type argument is to be converted to hexadecimal text representation.
Example:
printf("%d, %x, %X, %04X\n", 63, 63, 63, 63);
...should output:
63, 3f, 3F, 003F
The lower case %x specifies that hex digits a...f are output as lower case, %X displays A...F as upper case. All of the usual conversion modifiers may be used, such a "%04X", which prints four characters with leading '0' fill.
Cheers for that, now its just working out converting those to build the
buffer needed.
The crc32() function uses a huge array of hex values which I presume is
a referance for the actual crc32 method of masking things.
/* Return a 32-bit CRC of the contents of the buffer. */
unsigned long crc32(const unsigned char *s, unsigned int len)
{
unsigned int i;
unsigned long crc32val;
crc32val = 0;
for (i = 0; i < len; i++)
{
crc32val = crc32_tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8);
}
return crc32val;
}
Where crc32_tab[] is the array of hex values. parc is the count of
hostname fields, determined by making an array of the full hostname
using strtok. parv is then filled with each hostname field.
hash is set as "unsigned long hash[8];". I will at some stage add code
to make sure the loop doesn't try and fill above [8], but for now im
more concerned on getting it working how I want it :)
As a side note, the orignal code isn't mine and only hashed a fixed
number of hostname fields. I'm simply attempting to modify it to hash
all but the isp name.
Ie, with a host 5 or more fields long, to mask all but the last 3 fields
(domain.co.uk, dial.ntl.com etc..)
Also, if there's an obvious problem that would prevent this working I'd
be glad to have it explained why not.. I'm what could be called a
'learning' C coder, as the need to do mods for ircd is how I've learnt
what I have. I tend to learn best by practical samples rather than books
;p
Kind Regards,
Ian
--
Swap 'invalid' for 'co.uk' and fill
the void with 'ian' to reply via email
--
"Ian Gibbons" <vo**@mywits-end.invalid> crawled outside to scribble in
TK*********************@stones.force9.net the following: "Jack Klein" <ja*******@spamcop.net> crawled outside to scribble in 31********************************@4ax.com the following:
On Sun, 18 Jan 2004 01:22:53 -0000, "Ian Gibbons" <vo**@mywits-end.invalid> wrote in comp.lang.c:
Firstly what type is %x as I've not encountered it before? Now the problem: I'm trying to alter a host masking system for ircd so that it masks all but the isp name and location (if .uk.us etc..). However the crc32 stuff doesnt return as a string, and because the number of hostname fields is not static I need to build a string which contains each hostname field hashed and joined together.
if (parc > 4) /* There are isp's like *.isp.co.uk etc out there */
What is parc?
{ for (i=2; i < (parc - 2); i++) { hash[i] = ((crc32(parv[i], strlen(parv[i])) + KEY2) ^ KEY1) ^ KEY3;
What is hash? What is parv? What does crc32() return?
hash[i] <<= 2; hash[i] >>= 2; /* what goes here to make buf complete? */ } sprintf(mask, "%s%s.%s.%s", buf, parv[parc - 3], parv[parc - 2], parv[parc - 1]); }
hash[0] and [1] are always the first two hostname fields, and in other conditions are sprintf'ed into mask as %x. Ultimately what im aiming is to have mask.mask.mydomain.co.uk, mask.mask.mask.otherdomain.co.uk, mask.mask.mask.domain3.com etc..
Hope this makes sense :)
Kind Regards, Ian
Your posted sample code containing quite a few variables and one function without explaining what they are.
As for the question in your first sentence, %x and %X are conversion specifier for the printf() family of functions that can be used anywhere %d or %u can be used, including with a leading l for long values. They specify that the integer type argument is to be converted to hexadecimal text representation.
Example:
printf("%d, %x, %X, %04X\n", 63, 63, 63, 63);
...should output:
63, 3f, 3F, 003F
The lower case %x specifies that hex digits a...f are output as lower case, %X displays A...F as upper case. All of the usual conversion modifiers may be used, such a "%04X", which prints four characters with leading '0' fill.
Cheers for that, now its just working out converting those to build the buffer needed.
The crc32() function uses a huge array of hex values which I presume is a referance for the actual crc32 method of masking things.
/* Return a 32-bit CRC of the contents of the buffer. */ unsigned long crc32(const unsigned char *s, unsigned int len) { unsigned int i; unsigned long crc32val;
crc32val = 0; for (i = 0; i < len; i++) { crc32val = crc32_tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8); } return crc32val; }
Where crc32_tab[] is the array of hex values. parc is the count of hostname fields, determined by making an array of the full hostname using strtok. parv is then filled with each hostname field. hash is set as "unsigned long hash[8];". I will at some stage add code to make sure the loop doesn't try and fill above [8], but for now im more concerned on getting it working how I want it :)
As a side note, the orignal code isn't mine and only hashed a fixed number of hostname fields. I'm simply attempting to modify it to hash all but the isp name. Ie, with a host 5 or more fields long, to mask all but the last 3 fields (domain.co.uk, dial.ntl.com etc..)
Also, if there's an obvious problem that would prevent this working I'd be glad to have it explained why not.. I'm what could be called a 'learning' C coder, as the need to do mods for ircd is how I've learnt what I have. I tend to learn best by practical samples rather than books ;p
Kind Regards, Ian -- Swap 'invalid' for 'co.uk' and fill the void with 'ian' to reply via email
Think I have the solution, where the comment was for the unknown code I
now have:
sprintf(htob, "%x", hash[i]);
strcat(buf, htob);
strcat(buf, ".");
htob is set exactly the same as mask, and a slight change of the i
condition check to <= seems to be working fine.
All I need is a friend to join tmw to test it works ;p
Tested now, it works. But....
Some hosts are now too long to fit in HOSTLEN :p
How annoying lol.
So I'm off to bed and then I'll think of a solution.
Regards,
Ian
--
Swap 'invalid' for 'co.uk' and fill
the void with 'ian' to reply via email
--
"Jack Klein" <ja*******@spamcop.net> wrote in message
news:31********************************@4ax.com...
.... printf("%d, %x, %X, %04X\n", 63, 63, 63, 63);
...should output:
63, 3f, 3F, 003F
That's the Committee's intent, but...
printf("%d, %x, %X, %04X\n", 63, 63u, 63u, 63u);
....is still prefered by some. [Matching an expected unsigned int to each
%x/%X specifier.]
--
Peter
Ian Gibbons wrote: "Jack Klein" <ja*******@spamcop.net> crawled outside to scribble in On Sun, 18 Jan 2004 01:22:53 -0000, "Ian Gibbons"
.... snip ... What is hash? What is parv? What does crc32() return?
.... snip ... The crc32() function uses a huge array of hex values which I presume is a referance for the actual crc32 method of masking things.
I don't think Jack really cares. His actual point, which you seem
to have missed, is that you posted incomplete code and asked for
help with it. You should always reduce things to a minimum
compilable _standard C_ program before requesting help.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
"CBFalconer" <cb********@yahoo.com> crawled outside to scribble in 40***************@yahoo.com the following: Ian Gibbons wrote: "Jack Klein" <ja*******@spamcop.net> crawled outside to scribble in On Sun, 18 Jan 2004 01:22:53 -0000, "Ian Gibbons" ... snip ... What is hash? What is parv? What does crc32() return? ... snip ... The crc32() function uses a huge array of hex values which I presume is a referance for the actual crc32 method of masking things.
I don't think Jack really cares. His actual point, which you seem to have missed, is that you posted incomplete code and asked for help with it. You should always reduce things to a minimum compilable _standard C_ program before requesting help.
Noted..
This just seemed the place to ask while going through all the available
newsgroups :-)
I came across a major problem with what I was attempting, so I had to
ditch that idea and stick with a fixed approach. Still, it meant I
learnt something I previously did not understand (the %x/%X types) and
that if doing such a loop to be careful not to exceed the length of your
complete string, which obviously didn't occur to me until I noticed the
chopped string when run.
Regards,
Ian
--
Swap 'invalid' for 'co.uk' and fill
the void with 'ian' to reply via email
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: pancho |
last post by:
Greetings, I need help configuring/building PHP3 with MySQL as a DSO
on a Solaris 8 box - this module is needed to host some existing
sites I will be migrating
Note. I built PHP4 from source and...
|
by: RiGGa |
last post by:
Hi,
I am trung to create a mysql query string that contais two variables, the
first holds a table name and the second holds the values as a tuple. I
have tried the following however I can not...
|
by: johnsocs |
last post by:
All -
I am very stuck on building a schema for the following xml message. I
feel I'm very close as the message validates if I remove the...
|
by: MNFV |
last post by:
Hi,
I've wrote the code GRAPHIC_ENGINE.ASPX.VB
but it doesn't work properly, because the chart appears only with one
dataline (the last line resulting from the query). Can anyone tell me
what...
|
by: Diane |
last post by:
Could you please explain me how can I output nested strings?
Here is an example:
"adsd{rfkm}xcv"
The output should start from the inner parentheses, such as:
dfF
rfkm
|
by: Jack Wu |
last post by:
Hi
I've spent a good majority of my day trying to figure out how to have
PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I
have not gotten anywhere. Could somebody please...
|
by: pic078 via AccessMonster.com |
last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files)
that remains stuck in task manager after exiting the application - you can't
reopen database after exiting as a result...
|
by: ewpatton |
last post by:
Good day,
I've been trying to work with SQL and an Access database in order to
handle custom user profiles. I haven't had any trouble reading from my
database, but inserting new entries into...
|
by: Good Man |
last post by:
Hi there
I'm trying to compare two arrays at a time to figure out if data has
changed, and array_diff_assoc is telling me that there *are differences*
between:
Array
(
=2878.17
=12343.97
|
by: jrod11 |
last post by:
hi,
I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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: 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: 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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
| |