blob: f3501cf75334c6d86d763533952037e00993156d [file] [log] [blame]
San Mehat168415b2009-05-06 11:14:21 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef _NETLINKEVENT_H
17#define _NETLINKEVENT_H
18
Mike J. Chen17260b12011-06-23 15:00:30 -070019#include <sysutils/NetlinkListener.h>
20
San Mehat168415b2009-05-06 11:14:21 -070021#define NL_PARAMS_MAX 32
22
23class NetlinkEvent {
24 int mSeq;
25 char *mPath;
26 int mAction;
27 char *mSubsystem;
28 char *mParams[NL_PARAMS_MAX];
29
30public:
31 const static int NlActionUnknown;
32 const static int NlActionAdd;
33 const static int NlActionRemove;
34 const static int NlActionChange;
Mike J. Chenec16b9d2011-06-23 14:55:28 -070035 const static int NlActionLinkDown;
36 const static int NlActionLinkUp;
Lorenzo Colittif3486132013-09-03 00:25:14 +090037 const static int NlActionAddressUpdated;
38 const static int NlActionAddressRemoved;
San Mehat168415b2009-05-06 11:14:21 -070039
40 NetlinkEvent();
41 virtual ~NetlinkEvent();
42
Mike J. Chen17260b12011-06-23 15:00:30 -070043 bool decode(char *buffer, int size, int format = NetlinkListener::NETLINK_FORMAT_ASCII);
San Mehat168415b2009-05-06 11:14:21 -070044 const char *findParam(const char *paramName);
45
46 const char *getSubsystem() { return mSubsystem; }
47 int getAction() { return mAction; }
San Mehatd6744132009-12-24 07:17:09 -080048
49 void dump();
Mike J. Chenec16b9d2011-06-23 14:55:28 -070050
51 protected:
Lorenzo Colittia4b4e9a2013-08-02 05:58:37 +090052 bool parseIfAddrMessage(int type, struct ifaddrmsg *ifaddr, int rtasize);
Mike J. Chenec16b9d2011-06-23 14:55:28 -070053 bool parseBinaryNetlinkMessage(char *buffer, int size);
54 bool parseAsciiNetlinkMessage(char *buffer, int size);
San Mehat168415b2009-05-06 11:14:21 -070055};
56
57#endif