#!/usr/bin/perl -w
#------------------------------------------------------------------------------
# /usr/sbin/respond.pl - respond interface for capi2text
#
# Copyright (c) 2005-2007  Andreas Pohl, apohl(at)ibp-consult(dot)com
# Copyright (c) 2008-2024  The Eisfair Team, team(at)eisfair(dot)org
#
# Creation   : 2005-08-24 apohl
# Last Update: $Id$
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#------------------------------------------------------------------------------

use strict;
use Socket;

# check if sufficient command line parameters can be found
unless (3 == scalar(@ARGV)) {
    die "Script requires three argument\n  respond.pl udp-port msg-text ip-/broadcast-address\n";
}

my $port     = $ARGV[0];
my $msg      = $ARGV[1];
my $ipaddr   = inet_aton($ARGV[2]);

my $proto    = getprotobyname('udp');
my $portaddr = sockaddr_in($port, $ipaddr);

socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) or die;
setsockopt(SOCKET, SOL_SOCKET, SO_BROADCAST, 1);
send(SOCKET, $msg, 0, $portaddr) == length($msg) or die;
