• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 package android.net.cts;
18 
19 import java.io.FileDescriptor;
20 import java.io.IOException;
21 
22 public class NetlinkSocket {
23 
24     static {
25         System.loadLibrary("cts_jni");
26     }
27 
create_native(FileDescriptor fd)28     private static native void create_native(FileDescriptor fd);
sendmsg(FileDescriptor fd, int pid, byte[] bytes)29     private static native int sendmsg(FileDescriptor fd, int pid, byte[] bytes);
30 
31     private FileDescriptor fd = new FileDescriptor();
32 
33     /** no public constructors */
NetlinkSocket()34     private NetlinkSocket() { }
35 
create()36     public static NetlinkSocket create() {
37         NetlinkSocket retval = new NetlinkSocket();
38         create_native(retval.fd);
39         return retval;
40     }
41 
valid()42     public boolean valid() {
43         return fd.valid();
44     }
45 
sendmsg(int pid, byte[] bytes)46     public int sendmsg(int pid, byte[] bytes) throws IOException {
47         int retval = sendmsg(fd, pid, bytes);
48         if (retval == -1) {
49             throw new IOException("Unable to send message to PID=" + pid);
50         }
51         return retval;
52     }
53 }
54