The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Parse::SNI - parse Server Name Indication from TLS handshake


    use Parse::SNI;
    use IO::Socket;

    my $srv = IO::Socket::INET->new( LocalAddr => 'localhost', LocalPort => 443, Listen => 1 ) or die $@;

    while ( my $cli = $srv->accept() ) {
        $cli->sysread( my $buf, 4096 ) or next;
        my $sni = parse_sni($buf);



Tries to parse SNI from the passed data string, which should contain complete initial TLS handshake record from the client. On success returns SNI string in scalar context and (SNI string, start position of SNI in $data) in list context. On error dies with human readable message. One of the usefull error message to parse is /Incomplete TLS record: expected \d+ bytes, got \d+/. This may occure when u didn't read all of initial handshake from the client. You should catch it, read remaining message from the client and try again.

This function exported by default.




Copyright Oleg G <>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.