Lines Matching refs:buf

248         InetAddress srcIp, short destUdp, short srcUdp, ByteBuffer buf,
259 buf.clear();
260 buf.order(ByteOrder.BIG_ENDIAN);
267 buf.put(IP_VERSION_HEADER_LEN);
268 buf.put(IP_TOS_LOWDELAY); // tos: IPTOS_LOWDELAY
269 ipLengthOffset = buf.position();
270 buf.putShort((short)0); // length
271 buf.putShort((short)0); // id
272 buf.putShort(IP_FLAGS_OFFSET); // ip offset: don't fragment
273 buf.put(IP_TTL); // TTL: use default 64 from RFC1340
274 buf.put(IP_TYPE_UDP);
275 ipChecksumOffset = buf.position();
276 buf.putShort((short) 0); // checksum
278 buf.put(srcIpArray);
279 buf.put(destIpArray);
280 endIpHeader = buf.position();
283 udpHeaderOffset = buf.position();
284 buf.putShort(srcUdp);
285 buf.putShort(destUdp);
286 udpLengthOffset = buf.position();
287 buf.putShort((short) 0); // length
288 udpChecksumOffset = buf.position();
289 buf.putShort((short) 0); // UDP checksum -- initially zero
293 buf.put(requestCode);
294 buf.put((byte) 1); // Hardware Type: Ethernet
295 buf.put((byte) mClientMac.length); // Hardware Address Length
296 buf.put((byte) 0); // Hop Count
297 buf.putInt(mTransId); // Transaction ID
298 buf.putShort((short) 0); // Elapsed Seconds
301 buf.putShort((short) 0x8000); // Flags
303 buf.putShort((short) 0x0000); // Flags
306 buf.put(mClientIp.getAddress());
307 buf.put(mYourIp.getAddress());
308 buf.put(mNextIp.getAddress());
309 buf.put(mRelayIp.getAddress());
310 buf.put(mClientMac);
311 buf.position(buf.position() +
315 buf.putInt(0x63825363); // magic number
316 finishPacket(buf);
319 if ((buf.position() & 1) == 1) {
320 buf.put((byte) 0);
327 short udpLen = (short)(buf.position() - udpHeaderOffset);
328 buf.putShort(udpLengthOffset, udpLen);
335 udpSeed += intAbs(buf.getShort(ipChecksumOffset + 2));
336 udpSeed += intAbs(buf.getShort(ipChecksumOffset + 4));
337 udpSeed += intAbs(buf.getShort(ipChecksumOffset + 6));
338 udpSeed += intAbs(buf.getShort(ipChecksumOffset + 8));
344 buf.putShort(udpChecksumOffset, (short) checksum(buf, udpSeed,
346 buf.position()));
348 buf.putShort(ipLengthOffset, (short)buf.position());
350 buf.putShort(ipChecksumOffset,
351 (short) checksum(buf, 0, 0, endIpHeader));
373 private int checksum(ByteBuffer buf, int seed, int start, int end) {
375 int bufPosition = buf.position();
379 buf.position(start);
380 ShortBuffer shortBuf = buf.asShortBuffer();
383 buf.position(bufPosition);
396 short b = buf.get(start);
415 protected void addTlv(ByteBuffer buf, byte type, byte value) {
416 buf.put(type);
417 buf.put((byte) 1);
418 buf.put(value);
424 protected void addTlv(ByteBuffer buf, byte type, byte[] payload) {
426 buf.put(type);
427 buf.put((byte) payload.length);
428 buf.put(payload);
435 protected void addTlv(ByteBuffer buf, byte type, InetAddress addr) {
437 addTlv(buf, type, addr.getAddress());
444 protected void addTlv(ByteBuffer buf, byte type, List<InetAddress> addrs) {
446 buf.put(type);
447 buf.put((byte)(4 * addrs.size()));
450 buf.put(addr.getAddress());
458 protected void addTlv(ByteBuffer buf, byte type, Integer value) {
460 buf.put(type);
461 buf.put((byte) 4);
462 buf.putInt(value.intValue());
469 protected void addTlv(ByteBuffer buf, byte type, String str) {
471 buf.put(type);
472 buf.put((byte) str.length());
475 buf.put((byte) str.charAt(i));
483 protected void addTlvEnd(ByteBuffer buf) {
484 buf.put((byte) 0xFF);
537 private static String readAsciiString(ByteBuffer buf, int byteCount) {
539 buf.get(bytes);