Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 680
  • Last Modified:

Sockets

Hello,
I've found this in a book, but can't get it to work.

Code:
open_SOCKET($server, 80);
sub open_SOCKET {
  my ($server, $port) = @_;
  $port = getservbyname($port, 'tcp') if $port !~ /^[0-9]/;
  socket SOCKET, AF_INET, SOCK_STREAM, 0 or die "open socket: $!";
  connect(SOCKET, sockaddr_in($port, inet_aton($server)));
}

Error:
Argument "SOCK_STREAM" isn't numeric in socket
Argument "AF_INET" isn't numeric in socket

Output:
open socket: Unknown Error: 0x0000273c

Martin
0
martinag
Asked:
martinag
  • 2
  • 2
1 Solution
 
ozoCommented:
Did you
 use Socket;
to get the proper definitions imported?

0
 
martinagAuthor Commented:
No I didn't...Claim you points, ozo.

But why weren't AF_INET and SOCK_STREAM undefined?

Martin
0
 
ozoCommented:
With
  no strict 'subs';
an undefiled bareword is treated as if it were a quoted string
(the -w switch will warn you about these)
0
 
martinagAuthor Commented:
Ok, thanks.

Martin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now