Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pretty printing IP addresses

15 views
Skip to first unread message

Matthew X. Economou

unread,
Sep 23, 2002, 2:10:52 PM9/23/02
to
I'm writing some code that manipulates IP addresses. I would like to
give the IP address object a pretty-printable and readable
representation. Currently, I'm using a DEFTYPE declaration of
(SIMPLE-BIT-VECTOR 32) as my IP address object, and the only way I can
think of making something that would be usable with PPRINT-DISPATCH
and friends is to create a DEFCLASS or DEFSTRUCT wrapper around the
actual bit array.

This sucks and I'd really prefer not to be in the boxing-and-unboxing
objects business. Is there a better way?


--
Matthew X. Economou <xeno...@irtnog.org> - Unsafe at any clock speed!
I'm proud of my Northern Tibetian heritage! (http://www.subgenius.com)

Tim Bradshaw

unread,
Sep 23, 2002, 2:49:38 PM9/23/02
to
* Matthew X Economou wrote:

> This sucks and I'd really prefer not to be in the boxing-and-unboxing
> objects business. Is there a better way?

I don't see that there can be. In order to print some object
specially the system needs some indication that it is a special
object. The type of the object is pretty much it, I think.

--tim

Erik Naggum

unread,
Sep 23, 2002, 4:22:06 PM9/23/02
to
* Matthew X. Economou

| I'm writing some code that manipulates IP addresses.

A class wrapper around a one-element vector specialized to contain 32-bit
integers seems like a good choice. Provide readers and setters that return
and accept (respectively) a string, an integer, and four bytes.

| I would like to give the IP address object a pretty-printable and readable
| representation.

Simple and easy with a class wrapper.

| Currently, I'm using a DEFTYPE declaration of (SIMPLE-BIT-VECTOR 32)

Why on earth? The overhead of constructing and deconstructing it bit by bit
must be enormous.

| Is there a better way?

See `print-object´. Specialize methods on it for your wrapper class.

--
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

Frode Vatvedt Fjeld

unread,
Sep 23, 2002, 4:44:51 PM9/23/02
to
"Matthew X. Economou" <xenopho...@irtnog.org> writes:

> This sucks and I'd really prefer not to be in the
> boxing-and-unboxing objects business. Is there a better way?

I don't see how you can specialize on the semantic meaning of an
object.. But if what you are really conserned with is printing these
IP addresses for human consumption, you can use the tilde-slash format
directive:

(defun pprint-ip-address (stream object &optional colon-p at-p)
...)

(format t "IP address: ~/pprint-ip-address/." <ip-address>)

You could even make the output of pprint-ip-address readable by means
of an appropriate reader macro.

--
Frode Vatvedt Fjeld

Matthew X. Economou

unread,
Sep 23, 2002, 6:04:34 PM9/23/02
to
>>>>> "Erik" == Erik Naggum <er...@naggum.no> writes:

Erik> Why on earth [(SIMPLE-BIT-VECTOR 32)]? The overhead of
Erik> constructing and deconstructing it bit by bit must be
Erik> enormous.

The C mindset on my part. I figured it would make parsing packet
traces easier if I used the on-the-wire formats in memory.

Thomas F. Burdick

unread,
Sep 23, 2002, 7:14:21 PM9/23/02
to
"Matthew X. Economou" <xenopho...@irtnog.org> writes:

> >>>>> "Erik" == Erik Naggum <er...@naggum.no> writes:
>
> Erik> Why on earth [(SIMPLE-BIT-VECTOR 32)]? The overhead of
> Erik> constructing and deconstructing it bit by bit must be
> Erik> enormous.
>
> The C mindset on my part. I figured it would make parsing packet
> traces easier if I used the on-the-wire formats in memory.

??? Wouldn't the C-mindset version be to use an (unsigned-byte 32)?
FWIW, that's not a bad representation, either[*], since CL has much
better bit-bashing abilities than C does.

[*] Of course, a thin class wrapper around it is better, because then
you have type information attached to the number about what it means.

--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'

Matthew X. Economou

unread,
Sep 23, 2002, 7:34:10 PM9/23/02
to
>>>>> "Thomas" == Thomas F Burdick <t...@famine.OCF.Berkeley.EDU> writes:

Thomas> ??? Wouldn't the C-mindset version be to use an
Thomas> (unsigned-byte 32)? FWIW, that's not a bad representation,
Thomas> either[*], since CL has much better bit-bashing abilities
Thomas> than C does.

Aren't (SIMPLE-BIT-VECTOR 32) and (UNSIGNED-BYTE 32) the same thing?

In any case, I was attempting to build an interface that was "zero
copy", where the in-memory and on-the-wire (or on-the-filesystem)
formats were identical. This is probably an example of premature
optimization on my part.

Barry Margolin

unread,
Sep 23, 2002, 8:00:51 PM9/23/02
to
In article <w4od6r4...@eco-fs1.irtnog.org>,

Matthew X. Economou <xenopho...@irtnog.org> wrote:
>>>>>> "Thomas" == Thomas F Burdick <t...@famine.OCF.Berkeley.EDU> writes:
>
> Thomas> ??? Wouldn't the C-mindset version be to use an
> Thomas> (unsigned-byte 32)? FWIW, that's not a bad representation,
> Thomas> either[*], since CL has much better bit-bashing abilities
> Thomas> than C does.
>
>Aren't (SIMPLE-BIT-VECTOR 32) and (UNSIGNED-BYTE 32) the same thing?

No. SIMPLE-BIT-VECTOR is a type of array, and will have all the usual
array overhead (typically a dope vector containing the dimensions and type
info). Also, you can only access it a bit at a time. The elements of the
array will most likely be packed into a single, 32-bit word, though.

>In any case, I was attempting to build an interface that was "zero
>copy", where the in-memory and on-the-wire (or on-the-filesystem)
>formats were identical. This is probably an example of premature
>optimization on my part.

I'm not sure how you were planning on doing that with the bit vector.
Doesn't your input routine need a loop that calls SETF for each bit?

--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Erik Naggum

unread,
Sep 23, 2002, 8:15:38 PM9/23/02
to
* Matthew X. Economou

| Aren't (SIMPLE-BIT-VECTOR 32) and (UNSIGNED-BYTE 32) the same thing?

Not even remotely comparable.

| In any case, I was attempting to build an interface that was "zero copy",
| where the in-memory and on-the-wire (or on-the-filesystem) formats were
| identical.

You cannot write any integers into bit-vectors other than 0 and 1. You
address each individual bit. It is slow and expensive to turn an integer
into a bit-vector or vice versa unless you get at the implementation details.

Something tells me you have no running code at this point.

Bulent Murtezaoglu

unread,
Sep 23, 2002, 8:42:45 PM9/23/02
to
>>>>> "EN" == Erik Naggum <er...@naggum.no> writes:
[...]
EN> Something tells me you have no running code at this point.

I have the same hunch. Maybe we ought to point out that looking up
dpb ldb etc. might be helpful at this point.

cheers,

BM


Vassil Nikolov

unread,
Sep 23, 2002, 11:10:18 PM9/23/02
to
"Matthew X. Economou" <xenopho...@irtnog.org> wrote in message news:<w4olm5s...@eco-fs1.irtnog.org>...

> I'm writing some code that manipulates IP addresses. I would like to
> give the IP address object a pretty-printable and readable
> representation. Currently, I'm using a DEFTYPE declaration of
> (SIMPLE-BIT-VECTOR 32) as my IP address object, and the only way I can
> think of making something that would be usable with PPRINT-DISPATCH
> and friends is to create a DEFCLASS or DEFSTRUCT wrapper around the
> actual bit array.
>
> This sucks and I'd really prefer not to be in the boxing-and-unboxing
> objects business. Is there a better way?

Defining a class may suck less when you go beyond IPv4.

---Vassil.

Michael J. Ferrador

unread,
Sep 24, 2002, 12:05:39 AM9/24/02
to
How do you decide that a structure is around enough to warrant
being able to read back in it's printed representation?

Will we have to worry about read dispatch character collisions?

What else is useful to bundle with IP addrs? :netmask :vlsm-bits :wildcard
(Is Cisco the only one who uses wildcards?) :gateway :route :dns ?
:dhcp - to make it a dynamic variable

Matthew X. Economou <xenopho...@irtnog.org> wrote in message
news:w4olm5s...@eco-fs1.irtnog.org...

> I'm writing some code that manipulates IP addresses. I would like to
> give the IP address object a pretty-printable and readable
> representation.

---

remove my First- and -Last name, from around my call sign

Matthew X. Economou

unread,
Sep 24, 2002, 12:34:30 AM9/24/02
to
>>>>> "Bulent" == Bulent Murtezaoglu <b...@acm.org> writes:

>>>>> "EN" == Erik Naggum <er...@naggum.no> writes:

EN> Something tells me you have no running code at this point.

Bulent> I have the same hunch. Maybe we ought to point out that
Bulent> looking up dpb ldb etc. might be helpful at this point.

Unfortunately, you are both correct. I'll try LDB/DPB and friends,
and go from there. I was trying to create an FFI for WinPcap in
Corman Lisp, but for now, I think it will be easier if I just try to
read in the sniffer traces off the disk.

Thanks for all your help with the bit-bashing.

Marco Antoniotti

unread,
Sep 24, 2002, 10:25:22 AM9/24/02
to

Off Topic....

Barry Margolin <bar...@genuity.net> writes:

> In article <w4od6r4...@eco-fs1.irtnog.org>,
> Matthew X. Economou <xenopho...@irtnog.org> wrote:
> >>>>>> "Thomas" == Thomas F Burdick <t...@famine.OCF.Berkeley.EDU> writes:
> >
> > Thomas> ??? Wouldn't the C-mindset version be to use an
> > Thomas> (unsigned-byte 32)? FWIW, that's not a bad representation,
> > Thomas> either[*], since CL has much better bit-bashing abilities
> > Thomas> than C does.
> >
> >Aren't (SIMPLE-BIT-VECTOR 32) and (UNSIGNED-BYTE 32) the same thing?
>
> No. SIMPLE-BIT-VECTOR is a type of array, and will have all the usual
> array overhead (typically a dope vector containing the dimensions and type

^^^^^^^^^^^

It has been a very long time since I heard this expression :)

Cheers

--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
715 Broadway 10th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.

Greg Menke

unread,
Sep 24, 2002, 5:32:23 PM9/24/02
to
Marco Antoniotti <mar...@cs.nyu.edu> writes:

> Off Topic....
>
> Barry Margolin <bar...@genuity.net> writes:
>
> > >
> > >Aren't (SIMPLE-BIT-VECTOR 32) and (UNSIGNED-BYTE 32) the same thing?
> >
> > No. SIMPLE-BIT-VECTOR is a type of array, and will have all the usual
> > array overhead (typically a dope vector containing the dimensions and type
> ^^^^^^^^^^^
>
> It has been a very long time since I heard this expression :)
>

Does this dope in that context mean drugs, dumb or airplane fabric
treatment? The Jargon File doesn't have list the term.


Gregm

Barry Margolin

unread,
Sep 24, 2002, 5:42:38 PM9/24/02
to
In article <m33crzx...@europa.pienet>,

Greg Menke <gregm...@toadmail.com> wrote:
>Marco Antoniotti <mar...@cs.nyu.edu> writes:
>
>> Off Topic....
>>
>> Barry Margolin <bar...@genuity.net> writes:
>>
>> > >
>> > >Aren't (SIMPLE-BIT-VECTOR 32) and (UNSIGNED-BYTE 32) the same thing?
>> >
>> > No. SIMPLE-BIT-VECTOR is a type of array, and will have all the usual
>> > array overhead (typically a dope vector containing the dimensions and type
>>
>> It has been a very long time since I heard this expression :)
>
>Does this dope in that context mean drugs, dumb or airplane fabric
>treatment? The Jargon File doesn't have list the term.

I'm not sure of the etymology, but I suspect it may be similar to the word
"doping" when used in the context of semiconductors, which refers to adding
extra stuff to material.

In CS, a dope vector is an internal data structure containing information
about a user-visible data structure. For an array it contains the type and
dimension information; for a CLOS instance the class object and any caches
used by the implementation would serve this purpose.

Ng Pheng Siong

unread,
Sep 25, 2002, 12:58:34 AM9/25/02
to
According to Bulent Murtezaoglu <b...@acm.org>:

OP can also check out CLOCC which has ipaddr-to-dotted and
dotted-to-ipaddr; these may already do what he wants.


--
Ng Pheng Siong <ng...@netmemetic.com> * http://www.netmemetic.com

Tim Bradshaw

unread,
Sep 25, 2002, 5:28:05 AM9/25/02
to
* Barry Margolin wrote:

> I'm not sure of the etymology, but I suspect it may be similar to the word
> "doping" when used in the context of semiconductors, which refers to adding
> extra stuff to material.

Isn't there a term in some US slang `the straight dope'? I'm not sure
what it means (or if it is a term in fact), but I think it's something
to do with getting information about something, which would explain te
`dope vector' usage.

--tim

Joseph Dale

unread,
Sep 25, 2002, 6:24:50 AM9/25/02
to

"The straight dope" is a term, and I understand it to mean "the real
information, without any lies or BS". This is likely to be derived from
the drug context, where "straight dope" would refer to pure, unadultered
material. Which could be rephrased, mixing in the semiconductor
metaphor, as "dope with no dope".

;)


Joe

Rob Warnock

unread,
Sep 25, 2002, 6:40:18 AM9/25/02
to
Tim Bradshaw <t...@cley.com> wrote:
+---------------

| * Barry Margolin wrote:
|
| > I'm not sure of the etymology, but I suspect it may be similar to the word
| > "doping" when used in the context of semiconductors, which refers to adding
| > extra stuff to material.
|
| Isn't there a term in some US slang `the straight dope'?
+---------------

One of the dictionary definitions of "dope" is "information,
especially from a reliable source" (as in "the inside dope").
The dictionary says it dates back to 1807, and comes from the
Dutch word for "sauce" (as in "dip").

+---------------
| ...I think it's something to do with getting information about
| something, which would explain the `dope vector' usage.
+---------------

Exactly. Typical usage: "Did you get the new dope on the weather?"

By the way, a special case of "dope vectors" are "Iliffe vectors",
which are one implementation of multi-dimensional arrays. (See
<URL:http://www.cs.man.ac.uk/~pjj/cs2111/ho/node17.html> for more
discussion of both of these.)

The ALGOl-60 compiler on the DEC PDP-10 used Iliffe vectors, since
that made array addressing almost trivial given the PDP-10's multi-level
index+indirect modes in memory-reference instructions. If a, b, & c
were already in the proper registers, "foo[a,b,c] := foo[a,b,c] + 1"
could be done in *one* instruction!! (No joke.)


-Rob

-----
Rob Warnock, PP-ASEL-IA <rp...@rpw3.org>
627 26th Avenue <URL:http://www.rpw3.org/>
San Mateo, CA 94403 (650)572-2607

Rob Warnock

unread,
Sep 25, 2002, 6:46:05 AM9/25/02
to
Joseph Dale <jdal...@sbcglobal.net> wrote:
+---------------

| "The straight dope" is a term, and I understand it to mean "the real
| information, without any lies or BS".
+---------------

Something like that.

+---------------


| This is likely to be derived from the drug context, where
| "straight dope" would refer to pure, unadultered material.

+---------------

Sorry, "dope" as "(reliable) information" long pre-dates the
current drug sub-culture. Check out any WW2-era movie for some
then-current usage, e.g., "Hey, Joe, did you talk to Sarge?
What's the dope on our mission?

+---------------


| Which could be rephrased, mixing in the semiconductor metaphor,
| as "dope with no dope".

+---------------

Probably not. The semiconductor metaphor indeed probably derives
from the *medical* [though not originally "druggie"] slang for
medication (e.g., "Has he been doped yet?"), but "dope vectors"
comes from the earlier, pure meaning of "information".

Joseph Dale

unread,
Sep 25, 2002, 8:35:45 AM9/25/02
to
Rob Warnock wrote:
> Joseph Dale <jdal...@sbcglobal.net> wrote:
> +---------------
> | This is likely to be derived from the drug context, where
> | "straight dope" would refer to pure, unadultered material.
> +---------------
>
> Sorry, "dope" as "(reliable) information" long pre-dates the
> current drug sub-culture. Check out any WW2-era movie for some
> then-current usage, e.g., "Hey, Joe, did you talk to Sarge?
> What's the dope on our mission?
>

Actually, OED dates the drug/medical usage of "dope" back to the
1870s/80s -- for example, in the context of opium, whose drug subculture
probably has an even longer history than that just in America, let alone
in other English-speaking nations and colonies. On the other hand, no
references for the "information" usage appear before the 1900s.

Joe

Daniel Barlow

unread,
Sep 25, 2002, 7:16:32 AM9/25/02
to
Tim Bradshaw <t...@cley.com> writes:

> Isn't there a term in some US slang `the straight dope'? I'm not sure
> what it means (or if it is a term in fact), but I think it's something
> to do with getting information about something, which would explain te
> `dope vector' usage.

It's also the name of Cecil Adam's syndicated column and website,
on approximately that subject: http://www.straightdope.com/

This is, strictly speaking, off-topic for cll, but it's hard not to
feel some kind of sympathetic resonance with a web site describing
itself as "Fighting ignorance since 1973 (it's taking longer than we
thought)"


-dan

--

http://ww.telent.net/cliki/ - Link farm for free CL-on-Unix resources

Duane Rettig

unread,
Sep 25, 2002, 5:00:01 PM9/25/02
to
Joseph Dale <jdal...@sbcglobal.net> writes:

Perhaps all of these definitions are related to or derived from
(or derive) the 4th definition my own dictionary gives for "dope":

"oil, grease, or fuel additive, used to make machinery run
smoothly"

To get somewhat back on-topic, I view (without authority) this above
definition as being the more likely derivation for a "dope vector".


--
Duane Rettig du...@franz.com Franz Inc. http://www.franz.com/
555 12th St., Suite 1450 http://www.555citycenter.com/
Oakland, Ca. 94607 Phone: (510) 452-2000; Fax: (510) 452-0182

0 new messages