Link to home
Start Free TrialLog in
Avatar of altobravo
altobravo

asked on

Perl Sockets - Raw Data

I am using a modified sample script to capture udp packets on a single port and then send the data back to the sender. This seems to work fine. My issue is that the payload being sent seems to be converted to ascii. Anything that I have tried converts the data to ascii then back to hex, something gets lost in translation. What I need is the original message as it is sent.  Thanks

Sample packet data

8305123100138201010102034c4b28ead64b28ead618a74dd4d422467a00003c4d0000002101170620001affab0f280f0005030200000000000000c594




#!/usr/bin/perl -w
# udpqotd - UDP message server
use strict;
use IO::Socket;

my($sock, $newmsg, $hisaddr, $MAXLEN, $PORTNO);
$MAXLEN = 1024;
$PORTNO = 21210;
$sock = IO::Socket::INET->new(LocalPort => $PORTNO, Proto => 'udp' )
    or die "socket: $@";
print "Awaiting UDP messages on port $PORTNO\n";

while ($sock->recv($newmsg, $MAXLEN)) {
    my($port, $ipaddr) = sockaddr_in($sock->peername);

    print "This: $newmsg \n" ;
    $sock->send($newmsg);
}
die "recv: $!";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tobias
Tobias
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial