tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / kern / amiga_dhcp.c
blob441d5732f5cfce4b735819ee05cf99cf946e2dc0
1 #include <conf.h>
3 #include <dos/dos.h>
4 #include <dos/dostags.h>
5 #include <proto/dos.h>
6 #include <kern/amiga_gui.h>
7 #include <net/if.h>
8 #include <net/if_sana.h>
10 #include <stdio.h> // for sprintf
12 extern UBYTE dhclient_path[];
13 extern struct ifnet *ifnet;
14 extern struct Library *logDOSBase;
16 #define DOSBase logDOSBase
18 static const TEXT dhclient_proc_name[] = "AROSTCP DHCP client";
19 static const TEXT dhclient_cmd_name[] = "dhclient";
21 void run_dhclient(struct ifnet *ifp)
23 BPTR seglist;
25 if (!ifp->if_data.ifi_aros_dhcp_pid) {
26 DDHCP(KPrintF("Starting DHCP client for %s%u\n", ifp->if_name, ifp->if_unit);)
27 snprintf(ifp->if_data.ifi_aros_dhcp_args, sizeof(ifp->if_data.ifi_aros_dhcp_args), "-q %s%u", ifp->if_name,
28 ifp->if_unit);
29 ifp->if_data.ifi_aros_dhcp_args[sizeof(ifp->if_data.ifi_aros_dhcp_args)-1] = 0;
30 seglist = LoadSeg(dhclient_path);
31 DDHCP(KPrintF("seglist = 0x%08lx\n", seglist);)
32 if (seglist) {
33 ifp->if_data.ifi_aros_dhcp_pid =
34 (pid_t)CreateNewProcTags(NP_Seglist, seglist,
35 NP_Arguments, ifp->if_data.ifi_aros_dhcp_args,
36 NP_Cli, TRUE,
37 NP_Name, dhclient_proc_name,
38 NP_CommandName, dhclient_cmd_name,
39 NP_ConsoleTask, NULL,
40 TAG_DONE);
41 DDHCP(KPrintF("dhclient pid = 0x%08lx\n", ifp->if_data.ifi_aros_dhcp_pid);)
42 if (!ifp->if_data.ifi_aros_dhcp_pid) {
43 UnLoadSeg(seglist);
44 seglist = BNULL;
47 if (!seglist)
48 error_request("Unable to start DHCP client for the interface %s%u",
49 (IPTR)ifp->if_name, (IPTR)ifp->if_unit);
53 void kill_dhclient(struct ifnet *ifp)
55 if (ifp->if_data.ifi_aros_dhcp_pid) {
56 Signal((APTR)ifp->if_data.ifi_aros_dhcp_pid, SIGBREAKF_CTRL_C);
57 ifp->if_data.ifi_aros_dhcp_pid = (pid_t)NULL;
61 void run_dhcp(void)
63 struct ifnet *ifp;
65 for (ifp = ifnet; ifp; ifp = ifp->if_next) {
66 if (ifp->if_flags & IFF_DELAYUP) {
67 DDHCP(KPrintF("Executing delayed DHCP start for %s%u\n", ifp->if_name, ifp->if_unit);)
68 ifp->if_flags &= ~IFF_DELAYUP;
69 run_dhclient(ifp);