Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 608393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:27:26+00:00 2026-05-13T17:27:26+00:00

This is a continuation of my previous question: In Perl, how can I check

  • 0

This is a continuation of my previous question:

In Perl, how can I check for the existence of Socket options without generating warnings?

If I run the following code I get the result I expect:

#!/usr/bin/perl -w
use strict;
use diagnostics;
use Socket qw(:all);

my %opts;

if ( defined( eval { SO_REUSEPORT } ) ) {
    $opts{'SO_REUSEPORT'}
        =  {opt_level =>SOL_SOCKET,opt_name=>SO_REUSEPORT,opt_print=>\&sock_str_flag};
} else {
    print "SO_REUSEPORT undefined\n";
    $opts{'SO_REUSEPORT'}
        =  {opt_level =>0,opt_name=>0,opt_print=>undef};
}
=head
# IPV6 options
if ( defined( eval { IPV6_DONTFRAG } ) ) {
    $opts{'IPV6_DONTFRAG'}
        =  {opt_level =>IPPROTO_IPV6,opt_name=>IPV6_DONTFRAG,opt_print=>\&sock_str_flag};
} else {
    print "IPV6_DONTFRAG undefined\n";
    $opts{'IPV6_DONTFRAG'}
        =  {opt_level =>0,opt_name=>0,opt_print=>undef};
}
=cut

It outputs:

anon@perl$ ./test.pl 
SO_REUSEPORT undefined

But if I uncomment the block for IPV6_DONTFRAG I get:

Bareword "IPV6_DONTFRAG" not allowed while "strict subs" in use at ./test.pl line 17.
Bareword "IPV6_DONTFRAG" not allowed while "strict subs" in use at ./test.pl line 17.

Why is one undefined bareword causing it to barf and the other not? And how can the error be propagating out of the eval { } block?

Edit

Apparently, SO_REUSEPORT is exported by Socket.pm in some manner as it’s in the @EXPORT array. So apparently it’s defined but using it throws an error which the eval catches.

That still doesn’t explain what’s going on with IPV6_DONTFRAG. I suppose I would need to define it myself and then just call getsockopt to check if it’s supported…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:27:27+00:00Added an answer on May 13, 2026 at 5:27 pm

    I recommend writing it this way:

    if ( defined( &IPV6_DONTFRAG ) ) {
        $opts{'IPV6_DONTFRAG'}
            =  {opt_level =>IPPROTO_IPV6,opt_name=>&IPV6_DONTFRAG,opt_print=>\&sock_str_flag};
    } else {
        print "IPV6_DONTFRAG undefined\n";
        $opts{'IPV6_DONTFRAG'}
            =  {opt_level =>0,opt_name=>0,opt_print=>undef};
    }
    

    Note the added ampersand in the value for opt_name, which evades constraints due to strict 'subs'.

    The documentation for defined explains:

    You may also use defined(&func) to check whether subroutine &func has ever been defined. The return value is unaffected by any forward declarations of &func. Note that a subroutine which is not defined may still be callable: its package may have an AUTOLOAD method that makes it spring into existence the first time that it is called—see perlsub.

    For example, with SO_BROADCAST

    if (defined &SO_BROADCAST) {
      print "SO_BROADCAST = ", SO_BROADCAST, "\n";
    }
    

    the output on my machine is

    SO_BROADCAST = 6
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a continuation of my previous question here . In the following example:
This question is continuation of my previous one. Without going into too much details,
This is a continuation of my previous question .NET regex engine returns no matches
This question is a continuation of my previous question here zend models architecture (big
This question is in continuation to my previous question . I am trying to
This is continuation of my previous question Android: Music Player gets started itself after
This is the continuation of my previous question. deleting lines from text files based
This is in continuation to my previous question which was closed cause of similarity
This is a continuation of my previous question which I posted when I wasn't
This question is in continuation to my previous question, in which I asked about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.