1 /* 2 * junixsocket 3 * 4 * Copyright 2009-2024 Christian Kohlschütter 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.newsclub.net.unix; 19 20 import java.io.IOException; 21 import java.nio.charset.StandardCharsets; 22 23 /** 24 * TIPC-specific code that resides in the native library. To be used by {@code AFTIPCSocket} and 25 * {@code AFTIPCDatagramSocket} only. 26 * 27 * @author Christian Kohlschütter 28 */ 29 public final class AFTIPCSocketImplExtensions implements 30 AFSocketImplExtensions<AFTIPCSocketAddress> { 31 private final AncillaryDataSupport ancillaryDataSupport; 32 33 AFTIPCSocketImplExtensions(AncillaryDataSupport ancillaryDataSupport) { 34 this.ancillaryDataSupport = ancillaryDataSupport; 35 } 36 37 /** 38 * Returns the TIPC "ErrInfo" data from the ancillary receive buffer. 39 * 40 * Invalid for any other use. 41 * 42 * @return The errinfo. 43 */ 44 public int[] getTIPCErrInfo() { 45 return ancillaryDataSupport.getTIPCErrorInfo(); 46 } 47 48 /** 49 * Returns the TIPC "DestName" data from the ancillary receive buffer. 50 * 51 * Invalid for any other use. 52 * 53 * @return The DestName. 54 */ 55 public int[] getTIPCDestName() { 56 return ancillaryDataSupport.getTIPCDestName(); 57 } 58 59 /** 60 * Retrieves the 16-byte TIPC node identity given a node hash. 61 * 62 * @param peer The node hash. 63 * @return The node identity, or {@code null} if unsupported. 64 * @throws IOException on error. 65 */ 66 public byte[] getTIPCNodeId(int peer) throws IOException { 67 return NativeUnixSocket.tipcGetNodeId(peer); 68 } 69 70 /** 71 * Retrieves the TIPC link name given a node hash and bearer Id. 72 * 73 * @param peer The node hash. 74 * @param bearerId The bearer Id. 75 * @return The link name, or {@code null} if unsupported. 76 * @throws IOException on error. 77 */ 78 public String getTIPCLinkName(int peer, int bearerId) throws IOException { 79 byte[] name = NativeUnixSocket.tipcGetLinkName(peer, bearerId); 80 return name == null ? null : new String(name, StandardCharsets.UTF_8); 81 } 82 }