Maclir has asked for the wisdom of the Perl Monks concerning the following question:

I have to work on a small utility that was written several years ago that makes use of the old "socket.ph" library. Where can I find some explanation of the arcane words and processes? (like $sockaddr = 'S n a4 x8', to quote just one line.)

And yes, I will rewrite it to use the Socket module - once I can work out what it is doing.

Thanks

Replies are listed 'Best First'.
Re: Ancient socket.ph Help
by mdillon (Priest) on May 16, 2000 at 06:44 UTC
    "$sockaddr = 'S n a4 x8'" is a format string for packing a sockaddr struct for passing to bind(2). it reads as follows:
    • S: unsigned 16bit int, native order (POSIX address family)
    • n: signed 16bit int, network order (port number)
    • a4: 4 null-padded ascii chars (IPv4 address)
    • x8: 8 null bytes
    basically, this is used to create the C struct byte-by-byte to pass to 'bind(2)'. i'm not a C programmer, so it gets beyond me here. from what i can infer, this struct is 2 bytes for the address family, 2 bytes for the port number, and up to 12 bytes for the address. what you should probably pay attention to are the arguments to pack with that format string. possibly take a look at 'man 2 socket' and its relatives like 'man 2 bind'as well, to determine the signature of the system functions in question. the man pages often describe the byte format of the relevant structs (but unfortunately i can't find sockaddr in the glibc docs).