-1

I need to find out the address of the TFTP server that is specified in the DHCP configuration.

When the PC is started on, the computer receives the IP address via DHCP, then downloads the image from the PXE server. During the download of the distribution, I need to run a utility that accesses the Database to the server from which this image was downloaded (where the TFTP server is running).

In theory, it would be possible to register the necessary address of the TFTP server in the downloadable image of the distribution. But the bottom line is that such a scheme exists in various subnets. And specifying its TFTP server for each subnet is an irrational approach. It would be more convenient to get the address of the TFTP server from the DHCP server, which is listed there as next-server

I found something similar at Busybox.

Is it possible to implement something like this in C/C++ and how can it be done? I don't have any ideas.

Some example of the code of contacting the DHCP server to get an address or parameter. Open a socket and make a request or something like that... At least I haven't found any similar examples on the Internet.

P.S. I will put a dislike and send it to read man, than I will answer the question constructively. Nice!

  • If you can implement it in *any* other language, of course you can also implement it in C *or* C++ (there's no such language as "C/C++" they are distinct and very different languages). Also, how to interact with DHCP and TFTP servers is quite well documented and many programs do it. – Jesper Juhl Aug 15 '22 at 16:22
  • 1
    Looks like XY-problem. Isn't easier to configure DHCP client to call a script with extracted options from DHCP offer, including next-server? – dimich Aug 15 '22 at 16:59
  • I understand that C and C++ are different languages. In context, I meant OR. – alexanderzhirov Aug 15 '22 at 17:19
  • The best you can do is to issue a DHCPINFORM request to the server. Please keep in mind that the server can be configured to answer with a different response depending from whom and with what parameters he gets asked. Not a very reliable way to detect the TFTP server. – urutech Aug 16 '22 at 16:24

1 Answers1

0

If you are using the ISC dhcp-client then

man dhclient-script

If you are using some other dhcp client then it might have support for calling scripts too. Or it might store the dhcp lease somewhere in a parseable format, like /var/lib/dhcp/dhclient.leases. You can extract the dhcp options from that.

Goswin von Brederlow
  • 11,875
  • 2
  • 24
  • 42