2
0

dhcp-inform.pl 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/perl
  2. #
  3. # Send DHCPACK when you receive a DHCPINFORM from a polycom
  4. # so we can provide the provisioning URL to the phone
  5. #
  6. # Authors: (and wish lists)
  7. #
  8. # Brian West <brian@freeswitch.org> http://www.amazon.com/gp/registry/wishlist/1BWDJUX5LYQE0
  9. # Raymond Chandler <intralanman@freeswitch.org> http://www.amazon.com/gp/registry/wishlist/27XDISBBI4NOU
  10. #
  11. #
  12. use IO::Socket::INET;
  13. use Net::DHCP::Packet;
  14. use Net::DHCP::Constants;
  15. use Getopt::Std;
  16. getopt("du");
  17. $| = 1;
  18. if (!$opt_u) {
  19. print "Usage: $0 -u <url> [-d 1]\n";
  20. exit;
  21. }
  22. $sock = IO::Socket::INET->new(
  23. LocalPort => '67',
  24. Proto => 'udp',
  25. Broadcast => 1,
  26. ReuseAddr => 1,
  27. ) or die "socket: $@";
  28. while ($sock->recv($newmsg, 1024)) {
  29. my $dhcpreq = Net::DHCP::Packet->new($newmsg);
  30. if ($opt_d) {
  31. print $dhcpreq->toString();
  32. print "\n---------------------------------------------------------------------\n";
  33. }
  34. $tmp = $dhcpreq->chaddr();
  35. print "--$tmp--\n";
  36. if ($dhcpreq->getOptionValue(DHO_DHCP_MESSAGE_TYPE()) == 8 && $dhcpreq->chaddr() =~ /^0004f2/) {
  37. my $dhcpresp = new Net::DHCP::Packet(
  38. Op => BOOTREPLY(),
  39. Hops => $dhcpreq->hops(),
  40. Xid => $dhcpreq->xid(),
  41. Htype => $dhcpreq->htype(),
  42. Ciaddr => $dhcpreq->ciaddr(),
  43. Chaddr => $dhcpreq->chaddr(),
  44. DHO_DHCP_MESSAGE_TYPE() => DHCPACK(),
  45. DHO_DHCP_SERVER_IDENTIFIER() => $sock->sockhost,
  46. DHO_TFTP_SERVER() => "$opt_u",
  47. );
  48. if ($opt_d) {
  49. print $dhcpresp->toString();
  50. print "\n---------------------------------------------------------------------\n";
  51. }
  52. print "Sending option 66 as $opt_u\n";
  53. $sock->send($dhcpresp->serialize())
  54. }
  55. }