vfs: check userland buffers before reading them.
[haiku.git] / src / preferences / network / IPAddressControl.cpp
blob11619a6d4e5873ca4ff19a8f02284b519c7e9557
1 /*
2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, <axeld@pinc-software.de>
7 */
10 #include "IPAddressControl.h"
12 #include <NetworkAddress.h>
15 static const uint32 kMsgModified = 'txmd';
18 IPAddressControl::IPAddressControl(int family, const char* label,
19 const char* name)
21 BTextControl(name, label, "", NULL),
22 fFamily(family),
23 fAllowEmpty(true)
25 SetModificationMessage(new BMessage(kMsgModified));
29 IPAddressControl::~IPAddressControl()
34 bool
35 IPAddressControl::AllowEmpty() const
37 return fAllowEmpty;
41 void
42 IPAddressControl::SetAllowEmpty(bool empty)
44 fAllowEmpty = empty;
48 void
49 IPAddressControl::AttachedToWindow()
51 BTextControl::AttachedToWindow();
52 SetTarget(this);
53 _UpdateMark();
57 void
58 IPAddressControl::MessageReceived(BMessage* message)
60 switch (message->what) {
61 case kMsgModified:
62 _UpdateMark();
63 break;
65 default:
66 BTextControl::MessageReceived(message);
67 break;
72 void
73 IPAddressControl::_UpdateMark()
75 if (TextLength() == 0) {
76 MarkAsInvalid(!fAllowEmpty);
77 return;
80 BNetworkAddress address;
81 bool success = address.SetTo(fFamily, Text(), (char*)NULL,
82 B_NO_ADDRESS_RESOLUTION) == B_OK;
84 MarkAsInvalid(!success);