Hi, Borrowing some code found on perlmonks.org, I am attempting a udp relay server as a programming exercise. I'm using the strawberry perl distro. It's built with mingw and has great cpan support

I learned that IO::Socket just doesn't work on Win32, so I used Socket. What I need to do next is to at least examine the win32 UDP packets in an attempt to rewrite the destination to another subnet. NetPacket::UDP doesn't give me anything to work with. I don't know where, or how many places I've gone wrong, so I'm ready for a few lessons. Here's the code I used:

use warnings; use strict; use NetPacket::UDP; use NetPacket::Ethernet qw(:strip); use Socket qw(:all); use Data::Dumper $|++; # no suffering from buffering my $udp_port = 1434; socket( UDPSOCK, PF_INET, SOCK_DGRAM, getprotobyname('udp') ) or die " +socket: $!"; select( ( select(UDPSOCK), $|=1 )[0] ); # no suffering from buffering setsockopt( UDPSOCK, SOL_SOCKET, SO_REUSEADDR, 1 ) or die "setsockopt SO_REUSEADDR: $!"; setsockopt( UDPSOCK, SOL_SOCKET, SO_BROADCAST, 1 ) or die "setsockopt SO_BROADCAST: $!"; my $broadcastAddr = sockaddr_in( $udp_port, INADDR_ANY ); bind( UDPSOCK, $broadcastAddr ) or die "bind failed: $!\n"; my $input; while( my $addr = recv( UDPSOCK, $input, 1024, 0 ) ) { print "$addr => $input\n"; my $ip_obj = NetPacket::UDP::decode(NetPacket::Ethernet::eth_stri +p($addr)); my $udp_obj = NetPacket::UDP->decode($ip_obj->{data}); # my $udp_obj = NetPacket::UDP->decode($ip_obj->{data}); my $test = $ip_obj->{dest_ip}; print " $test \n"; }
Output::

☻ ♂~¼▼Å0 => ☻

Use of uninitialized value $test in concatenation (.) or string at socket2.pl line 33.


In reply to UDP Server on Win32 by mpapet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.