|
| 1 | +/** |
| 2 | + * Copyright (C) 2015-2018 Jxnet |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Lesser General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU Lesser General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +packagecom.ardikars.jxnet; |
| 19 | + |
| 20 | +importcom.ardikars.common.net.Inet4Address; |
| 21 | +importcom.ardikars.common.util.Builder; |
| 22 | +importcom.ardikars.jxnet.exception.BpfProgramCloseException; |
| 23 | +importcom.ardikars.jxnet.exception.PcapCloseException; |
| 24 | +importcom.ardikars.jxnet.exception.PcapDumperCloseException; |
| 25 | +importcom.ardikars.jxnet.exception.PlatformNotSupportedException; |
| 26 | + |
| 27 | +importjava.nio.ByteBuffer; |
| 28 | +importjava.util.List; |
| 29 | +importjava.util.concurrent.Executor; |
| 30 | +importjava.util.concurrent.ExecutorService; |
| 31 | + |
| 32 | +/** |
| 33 | + * Application context for wrap a pcap handle. |
| 34 | + * |
| 35 | + * @author <a href="mailto:contact@ardikars.com">Ardika Rommy Sanjaya</a> |
| 36 | + * @since 1.1.5 |
| 37 | + * @deprecated please use {@link com.ardikars.jxnet.context.ApplicationContext}. |
| 38 | + */ |
| 39 | +@Deprecated |
| 40 | +publicfinalclassApplicationContextimplementsContext { |
| 41 | + |
| 42 | +privatefinalcom.ardikars.jxnet.context.Contextctx; |
| 43 | + |
| 44 | +protectedApplicationContext(com.ardikars.jxnet.context.Contextctx) { |
| 45 | +this.ctx =ctx; |
| 46 | +} |
| 47 | + |
| 48 | +@Override |
| 49 | +publicStringgetApplicationName() { |
| 50 | +returnctx.getApplicationName(); |
| 51 | + } |
| 52 | + |
| 53 | +@Override |
| 54 | +publicStringgetApplicationDisplayName() { |
| 55 | +returnctx.getApplicationDisplayName(); |
| 56 | +} |
| 57 | + |
| 58 | +@Override |
| 59 | +publicStringgetApplicationVersion() { |
| 60 | +returnctx.getApplicationVersion(); |
| 61 | + } |
| 62 | + |
| 63 | +@Override |
| 64 | +publicContextnewInstance(Builder<Pcap,Void>builder) { |
| 65 | +com.ardikars.jxnet.context.Contextcontext =ctx.newInstance(builder); |
| 66 | +returnnewApplicationContext(context); |
| 67 | +} |
| 68 | + |
| 69 | +@Override |
| 70 | +public <T>PcapCodepcapLoop(intcnt,PcapHandler<T>callback,Tuser)throwsPcapCloseException { |
| 71 | +returnctx.pcapLoop(cnt,callback,user); |
| 72 | +} |
| 73 | + |
| 74 | +@Override |
| 75 | +public <T>PcapCodepcapLoop(finalintcnt,finalPcapHandler<T>callback,finalTuser,finalExecutorexecutor) |
| 76 | +throwsPcapCloseException { |
| 77 | +returnctx.pcapLoop(cnt,callback,user,executor); |
| 78 | +} |
| 79 | + |
| 80 | +@Override |
| 81 | +public <T>PcapCodepcapLoop(finalintcnt,finalPcapHandler<T>callback,finalTuser,finalExecutorServiceexecutor) |
| 82 | +throwsPcapCloseException { |
| 83 | +returnctx.pcapLoop(cnt,callback,user,executor); |
| 84 | +} |
| 85 | + |
| 86 | +@Override |
| 87 | +public <T>PcapCodepcapDispatch(intcnt,PcapHandler<T>callback,Tuser)throwsPcapCloseException { |
| 88 | +returnctx.pcapDispatch(cnt,callback,user); |
| 89 | +} |
| 90 | + |
| 91 | +@Override |
| 92 | +public <T>PcapCodepcapDispatch(finalintcnt,finalPcapHandler<T>callback,finalTuser,finalExecutorexecutor) |
| 93 | +throwsPcapCloseException { |
| 94 | +returnctx.pcapDispatch(cnt,callback,user,executor); |
| 95 | +} |
| 96 | + |
| 97 | +@Override |
| 98 | +publicPcapCodepcapDumpOpen(Stringfname)throwsPcapCloseException { |
| 99 | +returnctx.pcapDumpOpen(fname); |
| 100 | +} |
| 101 | + |
| 102 | +@Override |
| 103 | +publicvoidpcapDump(PcapPktHdrh,ByteBuffersp)throwsPcapDumperCloseException { |
| 104 | +ctx.pcapDump(h,sp); |
| 105 | +} |
| 106 | + |
| 107 | +@Override |
| 108 | +publicPcapCodepcapCompile(Stringstr,BpfProgram.BpfCompileModeoptimize,intnetmask)throwsPcapCloseException,BpfProgramCloseException { |
| 109 | +returnctx.pcapCompile(str,optimize,netmask); |
| 110 | +} |
| 111 | + |
| 112 | +@Override |
| 113 | +publicPcapCodepcapSetFilter()throwsPcapCloseException,BpfProgramCloseException { |
| 114 | +returnctx.pcapSetFilter(); |
| 115 | +} |
| 116 | + |
| 117 | +@Override |
| 118 | +publicPcapCodepcapSendPacket(ByteBufferbuf,intsize)throwsPcapCloseException { |
| 119 | +returnctx.pcapSendPacket(buf,size); |
| 120 | +} |
| 121 | + |
| 122 | +@Override |
| 123 | +publicByteBufferpcapNext(PcapPktHdrh)throwsPcapCloseException { |
| 124 | +returnctx.pcapNext(h); |
| 125 | +} |
| 126 | + |
| 127 | +@Override |
| 128 | +publicPcapCodepcapNextEx(PcapPktHdrpktHeader,ByteBufferpktData)throwsPcapCloseException { |
| 129 | +returnctx.pcapNextEx(pktHeader,pktData); |
| 130 | +} |
| 131 | + |
| 132 | +@Override |
| 133 | +publicvoidpcapClose()throwsPcapCloseException { |
| 134 | +ctx.pcapClose(); |
| 135 | +} |
| 136 | + |
| 137 | +@Override |
| 138 | +publicPcapCodepcapDumpFlush()throwsPcapDumperCloseException { |
| 139 | +returnctx.pcapDumpFlush(); |
| 140 | +} |
| 141 | + |
| 142 | +@Override |
| 143 | +publicvoidpcapDumpClose(PcapDumperpcapDumper)throwsPcapDumperCloseException { |
| 144 | +ctx.pcapDumpClose(pcapDumper); |
| 145 | +} |
| 146 | + |
| 147 | +@Override |
| 148 | +publicDataLinkTypepcapDataLink()throwsPcapCloseException { |
| 149 | +returnctx.pcapDataLink(); |
| 150 | +} |
| 151 | + |
| 152 | +@Override |
| 153 | +publicPcapCodepcapSetDataLink(DataLinkTypedataLinkType)throwsPcapCloseException { |
| 154 | +returnctx.pcapSetDataLink(dataLinkType); |
| 155 | +} |
| 156 | + |
| 157 | +@Override |
| 158 | +publicvoidpcapBreakLoop()throwsPcapCloseException { |
| 159 | +ctx.pcapBreakLoop(); |
| 160 | +} |
| 161 | + |
| 162 | +@Override |
| 163 | +publicStringpcapGetErr()throwsPcapCloseException { |
| 164 | +returnctx.pcapGetErr(); |
| 165 | +} |
| 166 | + |
| 167 | +@Override |
| 168 | +publicPcapCodepcapIsSwapped()throwsPcapCloseException { |
| 169 | +returnctx.pcapIsSwapped(); |
| 170 | +} |
| 171 | + |
| 172 | +@Override |
| 173 | +publicintpcapSnapshot()throwsPcapCloseException { |
| 174 | +returnctx.pcapSnapshot(); |
| 175 | +} |
| 176 | + |
| 177 | +@Override |
| 178 | +publicintpcapMajorVersion()throwsPcapCloseException { |
| 179 | +returnctx.pcapMajorVersion(); |
| 180 | +} |
| 181 | + |
| 182 | +@Override |
| 183 | +publicintpcapMinorVersion()throwsPcapCloseException { |
| 184 | +returnctx.pcapMinorVersion(); |
| 185 | +} |
| 186 | + |
| 187 | +@Override |
| 188 | +publicPcapCodepcapSetNonBlock(booleannonblock,StringBuildererrbuf)throwsPcapCloseException { |
| 189 | +returnctx.pcapSetNonBlock(nonblock,errbuf); |
| 190 | +} |
| 191 | + |
| 192 | +@Override |
| 193 | +publicPcapCodepcapGetNonBlock(StringBuildererrbuf)throwsPcapCloseException { |
| 194 | +returnctx.pcapGetNonBlock(errbuf); |
| 195 | +} |
| 196 | + |
| 197 | +@Override |
| 198 | +publiclongpcapDumpFTell()throwsPcapDumperCloseException { |
| 199 | +returnctx.pcapDumpFTell(); |
| 200 | +} |
| 201 | + |
| 202 | +@Override |
| 203 | +publicvoidpcapFreeCode()throwsBpfProgramCloseException { |
| 204 | +ctx.pcapFreeCode(); |
| 205 | +} |
| 206 | + |
| 207 | +@Override |
| 208 | +publicPcapCodepcapStats(PcapStatpcapStat)throwsPcapCloseException { |
| 209 | +returnctx.pcapStats(pcapStat); |
| 210 | +} |
| 211 | + |
| 212 | +@Override |
| 213 | +publicPcapCodepcapCompileNoPcap(intsnaplen,DataLinkTypedataLinkType,Stringfilter, |
| 214 | +BpfProgram.BpfCompileModeoptimize,Inet4Addressmask) |
| 215 | +throwsBpfProgramCloseException { |
| 216 | +returnctx.pcapCompileNoPcap(snaplen,dataLinkType,filter,optimize,mask); |
| 217 | +} |
| 218 | + |
| 219 | +@Override |
| 220 | +publicvoidpcapPError(Stringprefix)throwsPcapCloseException { |
| 221 | +ctx.pcapPError(prefix); |
| 222 | +} |
| 223 | + |
| 224 | +@Override |
| 225 | +publicPcapCodepcapCanSetRfMon()throwsPcapCloseException { |
| 226 | +returnctx.pcapCanSetRfMon(); |
| 227 | +} |
| 228 | + |
| 229 | +@Override |
| 230 | +publicPcapCodepcapSetDirection(PcapDirectiondirection)throwsPcapCloseException,PlatformNotSupportedException { |
| 231 | +returnctx.pcapSetDirection(direction); |
| 232 | +} |
| 233 | + |
| 234 | +@Override |
| 235 | +publicPcapTimestampPrecisionpcapGetTStampPrecision()throwsPcapCloseException,PlatformNotSupportedException { |
| 236 | +returnctx.pcapGetTStampPrecision(); |
| 237 | +} |
| 238 | + |
| 239 | +@Override |
| 240 | +publicPcapCodepcapListDataLinks(List<DataLinkType>dtlBuffer)throwsPcapCloseException,PlatformNotSupportedException { |
| 241 | +returnctx.pcapListDataLinks(dtlBuffer); |
| 242 | +} |
| 243 | + |
| 244 | +@Override |
| 245 | +publicPcapCodepcapListTStampTypes(List<PcapTimestampType>tstampTypesp)throwsPcapCloseException,PlatformNotSupportedException { |
| 246 | +returnctx.pcapListTStampTypes(tstampTypesp); |
| 247 | +} |
| 248 | + |
| 249 | +@Override |
| 250 | +publicPcapCodepcapOfflineFilter(BpfProgramfp,PcapPktHdrh,ByteBufferpkt) { |
| 251 | +returnctx.pcapOfflineFilter(fp,h,pkt); |
| 252 | +} |
| 253 | + |
| 254 | +@Override |
| 255 | +publicPcapCodepcapInject(ByteBufferbuf,intsize)throwsPcapCloseException,PlatformNotSupportedException { |
| 256 | +returnctx.pcapInject(buf,size); |
| 257 | +} |
| 258 | + |
| 259 | +@Override |
| 260 | +publicvoidclose()throwsException { |
| 261 | +ctx.close(); |
| 262 | +} |
| 263 | + |
| 264 | +} |