2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afs/param.h>
18 #include "afs_config.h"
19 #include <lanahelper.h>
22 * DEFINITIONS ________________________________________________________________
28 static BOOL fFirstTime
= TRUE
;
30 LANAINFO
* lanainfo
= NULL
;
32 int GetAdapterNumber(TCHAR
*);
35 * PROTOTYPES _________________________________________________________________
39 void Binding_OnInitDialog (HWND hDlg
);
40 void Binding_OnOK(HWND hDlg
);
41 void Binding_OnCancel(HWND hDlg
);
42 BOOL
Binding_OnApply();
44 BOOL isGateway
= FALSE
;
46 * ROUTINES ___________________________________________________________________
50 BOOL CALLBACK
Binding_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
55 Binding_OnInitDialog (hDlg
);
58 case WM_CTLCOLORSTATIC
:
59 if ((HWND
)lp
== GetDlgItem (hDlg
, IDC_CHUNK_SIZE
))
61 if (IsWindowEnabled ((HWND
)lp
))
63 static HBRUSH hbrStatic
= CreateSolidBrush (GetSysColor (COLOR_WINDOW
));
64 SetTextColor ((HDC
)wp
, GetSysColor (COLOR_WINDOWTEXT
));
65 SetBkColor ((HDC
)wp
, GetSysColor (COLOR_WINDOW
));
66 return (BOOL
)hbrStatic
;
75 Binding_DlgProc (hDlg
, WM_HELP
, 0, 0);
83 Binding_OnCancel(hDlg
);
86 if (HIWORD(wp
) == BN_CLICKED
)
89 memset(name
, 0, sizeof(name
));
90 if (IsDlgButtonChecked(hDlg
,IDC_DEFAULTNIC
))
94 HWND hwndCombo
= GetDlgItem(hDlg
, IDC_NICSELECTION
);
95 if (SendMessage(hwndCombo
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
96 SendMessage(hwndCombo
, CB_SETCURSEL
, (WPARAM
)0, (LPARAM
)0);
98 TCHAR selected
[MAX_PATH
];
99 memset(selected
, 0, sizeof(selected
));
100 SendDlgItemMessage(hDlg
, IDC_NICSELECTION
,
101 WM_GETTEXT
, sizeof(selected
),
104 if (_tcslen(selected
) <= 0)
108 nLanAdapter
= GetAdapterNumber(selected
);
111 lana_GetAfsNameString(nLanAdapter
, isGateway
, name
);
112 SetDlgItemText (hDlg
, IDC_BINDING_MESSAGE
, name
);
113 EnableWindow(GetDlgItem(hDlg
,IDC_NICSELECTION
),(nLanAdapter
!=-1));
116 case IDC_NICSELECTION
:
117 if (HIWORD(wp
) == CBN_SELCHANGE
)
119 TCHAR name
[MAX_PATH
];
120 TCHAR selected
[MAX_PATH
];
121 memset(name
, 0, sizeof(name
));
122 memset(selected
, 0, sizeof(selected
));
123 HWND hwndCombo
= GetDlgItem(hDlg
, IDC_NICSELECTION
);
124 int i
= SendMessage(hwndCombo
, CB_GETCURSEL
, 0, 0);
126 SendMessage(hwndCombo
, CB_GETLBTEXT
, (WPARAM
)i
,
129 if (_tcslen(selected
) <= 0)
132 nLanAdapter
= GetAdapterNumber(selected
);
135 lana_GetAfsNameString(nLanAdapter
, isGateway
, name
);
136 SetDlgItemText (hDlg
, IDC_BINDING_MESSAGE
, name
);
144 WinHelp (hDlg
, g
.szHelpFile
, HELP_CONTEXT
, IDH_AFSCONFIG_ADVANCED_MISC
);
152 void Binding_OnInitDialog (HWND hDlg
)
154 TCHAR name
[MAX_PATH
];
155 memset(name
, 0, sizeof(name
));
158 Config_GetLanAdapter(&g
.Configuration
.nLanAdapter
);
159 nLanAdapter
= g
.Configuration
.nLanAdapter
;
160 isGateway
= g
.Configuration
.fBeGateway
;
164 lanainfo
= lana_FindLanaByName(NULL
);
166 // TODO: Show more useful error message.
168 MessageBox(hDlg
, "Unable to obtain LANA list", "LANA ERROR", MB_ICONERROR
);
172 HWND hwndCombo
= GetDlgItem(hDlg
, IDC_NICSELECTION
);
175 while (_tcslen(lanainfo
[index
].lana_name
) > 0)
177 _stprintf(tmp
, "%s (lana number = %d)", lanainfo
[index
].lana_name
,
178 lanainfo
[index
].lana_number
);
179 SendMessage(hwndCombo
, CB_ADDSTRING
,
181 if (nLanAdapter
== lanainfo
[index
].lana_number
)
182 SendMessage(hwndCombo
, CB_SELECTSTRING
, (WPARAM
)-1,
188 lana_GetAfsNameString(nLanAdapter
, isGateway
, name
);
189 SetDlgItemText (hDlg
, IDC_BINDING_MESSAGE
, name
);
191 CheckDlgButton (hDlg
, IDC_DEFAULTNIC
, (nLanAdapter
==-1));
193 EnableWindow(GetDlgItem(hDlg
,IDC_NICSELECTION
),(nLanAdapter
!=-1));
196 void Binding_OnOK (HWND hDlg
)
198 if (IsDlgButtonChecked(hDlg
,IDC_DEFAULTNIC
))
202 TCHAR selected
[MAX_PATH
];
203 memset(selected
, 0, sizeof(selected
));
204 SendDlgItemMessage(hDlg
, IDC_NICSELECTION
,
205 WM_GETTEXT
, sizeof(selected
),
208 if (_tcslen(selected
) <= 0)
210 MessageBox(hDlg
, "Please select the NIC to bind to", "Error", MB_ICONERROR
);
214 nLanAdapter
= GetAdapterNumber(selected
);
218 EndDialog(hDlg
, IDOK
);
222 BOOL
Binding_OnApply()
227 if (nLanAdapter
!= g
.Configuration
.nLanAdapter
) {
228 if (!Config_SetLanAdapter (nLanAdapter
))
230 g
.Configuration
.nLanAdapter
= nLanAdapter
;
238 void Binding_OnCancel(HWND hDlg
)
248 EndDialog(hDlg
, IDCANCEL
);
252 int GetAdapterNumber(TCHAR
* n
)
255 while (_tcslen(lanainfo
[index
].lana_name
) > 0)
257 if (_tcsncmp(lanainfo
[index
].lana_name
, n
, _tcslen(lanainfo
[index
].lana_name
)) == 0)
259 return lanainfo
[index
].lana_number
;