|
Grex > Jelly > #55: Okay, I should have probably read h2xs before asking this. | |
|
| Author |
Message |
herasleftnut
|
|
Okay, I should have probably read h2xs before asking this.
|
Oct 29 16:42 UTC 2006 |
I tried reading the linux internal documentation, but couldn't find the answer
to the following:
When I use CGI, I go something like the following:
#!/usr/local/bin/perl -w
use CGI;
$q = new CGI;
print $q->header,
$q->start_html('hello world'),
$q->h1('hello world'),
$q->end_html;
The way I understand it, $q holds the reference to new(). This reference is
then passed to functions like header(), start_html(), etc.
The confusion stems from the socket module. According to the man pages, it
goes like:
use Socket;
$proto = getprotobyname('tcp');
socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto);
$port = getservbyname('smtp', 'tcp');
$sin = sockaddr_in($port,inet_aton("127.1"));
$sin = sockaddr_in(7,inet_aton("localhost"));
$sin = sockaddr_in(7,INADDR_LOOPBACK);
connect(Socket_Handle,$sin);
In this case, there is no pass by reference. Why? I'm drawing a blank.
The man pages made a comment that this module is just translation of the C
socket.h file. Is this part of the reason?
|
| 11 responses total. |
cross
|
|
response 1 of 11:
|
Oct 29 17:18 UTC 2006 |
There's no need for pass by reference: all you're pushing around are scalars.
|
herasleftnut
|
|
response 2 of 11:
|
Oct 29 19:40 UTC 2006 |
Okay, I sat down and thought about this (sort of). Anyhow, here is what is
nagging at me worse than nharmons moms cheap pantyhose.
These lines:
$sin = sockaddr_in($port,inet_aton("127.1"));
$sin = sockaddr_in(7,inet_aton("localhost"));
$sin = sockaddr_in(7,INADDR_LOOPBACK);
are in Socket.pm
Perl doesnt bitch if I do something like:
#!/usr/bin/perl -w
use Socket;
$proto = getprotobyname('udp');
socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto);
$iaddr = gethostbyname('hishost.com');
$port = getservbyname('time', 'udp');
$sin = Socket::sockaddr_in($port, $iaddr);
send(Socket_Handle, 0, 0, $sin);
Where is gethostbyname() coming from? There is no prototype in the C socket.h
header file.
|
cross
|
|
response 3 of 11:
|
Oct 29 19:48 UTC 2006 |
Gethostbyname() comes from netdb.h. It certainly seems that they're
overwriting $sin three times.
|
herasleftnut
|
|
response 4 of 11:
|
Oct 29 23:56 UTC 2006 |
Yeah, but like netdb.h header doesn't get called in the Perl code. The module
only translates the socket.h header. So how is the code finding
gethostbyname() in this case?
|
nharmon
|
|
response 5 of 11:
|
Oct 30 00:29 UTC 2006 |
This response has been erased.
|
mcnally
|
|
response 6 of 11:
|
Oct 30 00:57 UTC 2006 |
If you read "perldoc Socket" it says that in addition to the stuff derived
from socket.h, Socket contains some additional functions. My guess is that
although it's not specifically mentioned in that part the Perl gethostbyname
is implemented as a combination of some of those calls (e.g. inet_aton)
|
herasleftnut
|
|
response 7 of 11:
|
Oct 30 01:50 UTC 2006 |
Are you still bitter about the earlier nuke?
|
herasleftnut
|
|
response 8 of 11:
|
Oct 30 01:53 UTC 2006 |
Here is Socket.pm. Please tell me where gethostbyname() is.
use Carp;
use warnings::register;
require Exporter;
use XSLoader ();
@ISA = qw(Exporter);
@EXPORT = qw(
inet_aton inet_ntoa
sockaddr_family
pack_sockaddr_in unpack_sockaddr_in
pack_sockaddr_un unpack_sockaddr_un
sockaddr_in sockaddr_un
INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
AF_802
AF_AAL
AF_APPLETALK
AF_CCITT
AF_CHAOS
AF_CTF
AF_DATAKIT
AF_DECnet
AF_DLI
AF_ECMA
AF_GOSIP
AF_HYLINK
AF_IMPLINK
AF_INET
AF_INET6
AF_ISO
AF_KEY
AF_LAST
AF_LAT
AF_LINK
AF_MAX
AF_NBS
AF_NIT
AF_NS
AF_OSI
AF_OSINET
AF_PUP
AF_ROUTE
AF_SNA
AF_UNIX
AF_UNSPEC
AF_USER
AF_WAN
AF_X25
IOV_MAX
MSG_BCAST
MSG_BTAG
MSG_CTLFLAGS
MSG_CTLIGNORE
MSG_CTRUNC
MSG_DONTROUTE
MSG_DONTWAIT
MSG_EOF
MSG_EOR
MSG_ERRQUEUE
MSG_ETAG
MSG_FIN
MSG_MAXIOVLEN
MSG_MCAST
MSG_NOSIGNAL
MSG_OOB
MSG_PEEK
MSG_PROXY
MSG_RST
MSG_SYN
MSG_TRUNC
MSG_URG
MSG_WAITALL
MSG_WIRE
PF_802
PF_AAL
PF_APPLETALK
PF_CCITT
PF_CHAOS
PF_CTF
PF_DATAKIT
PF_DECnet
PF_DLI
PF_ECMA
PF_GOSIP
PF_HYLINK
PF_IMPLINK
PF_INET
PF_INET6
PF_ISO
PF_KEY
PF_LAST
PF_LAT
PF_LINK
PF_MAX
PF_NBS
PF_NIT
PF_NS
PF_OSI
PF_OSINET
PF_PUP
PF_ROUTE
PF_SNA
PF_UNIX
PF_UNSPEC
PF_USER
PF_WAN
PF_X25
SCM_CONNECT
SCM_CREDENTIALS
SCM_CREDS
SCM_RIGHTS
SCM_TIMESTAMP
SHUT_RD
SHUT_RDWR
SHUT_WR
SOCK_DGRAM
SOCK_RAW
SOCK_RDM
SOCK_SEQPACKET
SOCK_STREAM
SOL_SOCKET
SOMAXCONN
SO_ACCEPTCONN
SO_ATTACH_FILTER
SO_BACKLOG
SO_BROADCAST
SO_CHAMELEON
SO_DEBUG
SO_DETACH_FILTER
SO_DGRAM_ERRIND
SO_DONTLINGER
SO_DONTROUTE
SO_ERROR
SO_FAMILY
SO_KEEPALIVE
SO_LINGER
SO_OOBINLINE
SO_PASSCRED
SO_PASSIFNAME
SO_PEERCRED
SO_PROTOCOL
SO_PROTOTYPE
SO_RCVBUF
SO_RCVLOWAT
SO_RCVTIMEO
SO_REUSEADDR
SO_REUSEPORT
SO_SECURITY_AUTHENTICATION
SO_SECURITY_ENCRYPTION_NETWORK
SO_SECURITY_ENCRYPTION_TRANSPORT
SO_SNDBUF
SO_SNDLOWAT
SO_SNDTIMEO
SO_STATE
SO_TYPE
SO_USELOOPBACK
SO_XOPEN
SO_XSE
UIO_MAXIOV
);
@EXPORT_OK = qw(CR LF CRLF $CR $LF $CRLF
IPPROTO_TCP
TCP_KEEPALIVE
TCP_MAXRT
TCP_MAXSEG
TCP_NODELAY
TCP_STDURG);
%EXPORT_TAGS = (
crlf => [qw(CR LF CRLF $CR $LF $CRLF)],
all => [@EXPORT, @EXPORT_OK],
);
BEGIN {
sub CR () {"\015"}
sub LF () {"\012"}
sub CRLF () {"\015\012"}
}
*CR = \CR();
*LF = \LF();
*CRLF = \CRLF();
sub sockaddr_in {
if (@_ == 6 && !wantarray) { # perl5.001m compat; use this && die
my($af, $port, @quad) = @_;
warnings::warn "6-ARG sockaddr_in call is deprecated"
if warnings::enabled();
pack_sockaddr_in($port, inet_aton(join('.', @quad)));
} elsif (wantarray) {
croak "usage: (port,iaddr) = sockaddr_in(sin_sv)" unless @_ == 1;
unpack_sockaddr_in(@_);
} else {
croak "usage: sin_sv = sockaddr_in(port,iaddr))" unless @_ == 2;
pack_sockaddr_in(@_);
}
}
sub sockaddr_un {
if (wantarray) {
croak "usage: (filename) = sockaddr_un(sun_sv)" unless @_ == 1;
unpack_sockaddr_un(@_);
} else {
croak "usage: sun_sv = sockaddr_un(filename)" unless @_ == 1;
pack_sockaddr_un(@_);
}
}
sub AUTOLOAD {
my($constname);
($constname = $AUTOLOAD) =~ s/.*:://;
croak "&Socket::constant not defined" if $constname eq 'constant';
my ($error, $val) = constant($constname);
if ($error) {
croak $error;
}
*$AUTOLOAD = sub { $val };
goto &$AUTOLOAD;
}
XSLoader::load 'Socket', $VERSION;
1;
|
herasleftnut
|
|
response 9 of 11:
|
Oct 30 01:55 UTC 2006 |
As you can see, Socket seems to just consist of constants (ie C Macros) and
structures.
|
cross
|
|
response 10 of 11:
|
Oct 30 04:38 UTC 2006 |
According to the ``perlfunc'' man page, gethostbyname() is a perl builtin
function.
|
herasleftnut
|
|
response 11 of 11:
|
Oct 30 05:39 UTC 2006 |
Shit, you beat me to the response. I just looked it up now in perlfunc.
|