Packetsize in Gamepsparks Realtime - unity3d

My packet in gamesparks contains:
Two vector2: 8bytes x 2 = 16bytes
key values with vector 2 = 8bytes
peerid present in packet = 4bytes
opCode present in packet = 4bytes
Total = 32bytes.
However my packet size is a little big bigger than this. Am i missing something in the packet that i should account for ?

Related

how to extract information from a ipv6 packet

I am writing my own packet sniffer using python sockets by retrieving the
packet information such as source ip, source port, destination ip,
destion port, TTL, Flags (SYN, ACK, FIN, RST, PSH, URG) etc.
For IPv4, I am able to unpack the packet based on the respective positions, and the result is similar to what I see with tshark. See code below:
IPv4_UNPACK_PATTERN = '!BBHHHBBH4s4s'
IPv6_UNPACK_PATTERN = '!4sHBB16s16s'
IPv4_HDR_LEN = 20
IPv6_HDR_LEN = 40
TCP_HDR_LEN = 20
ETH_HDR_LEN = 14
# IP ATTRIBUTES
IP_VERSION_POS = 0
IP_TOS_POS = 1
IP_LENGTH_POS = 2
IP_IDENTIFICATION_POS = 3
IP_FRAGMENT_OFFSET_POS = 4
IP_TTL_POS = 5
IP_PROTOCOL_POS = 6
IP_HDR_CHCKSUM_POS = 7
IP_SRC_ADDR_POS = 8
IP_DST_ADDR_POS = 9
TCP_FLAG_POS = 5
TCP_WINDOW_POS = 6
# main program:
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0003))
packet = s.recvfrom(SOCKET_BUFF_SIZE)
pkt_type = extract_type(packet)
ip_header(packet, pkt_type)
# this function extracts the information from pkt
def ip_header(pkt, pkt_type):
if pkt_type=='ipv4':
data = unpack(IPv4_UNPACK_PATTERN, pkt[ETH_HDR_LEN:ETH_HDR_LEN + IPv4_HDR_LEN])
version = data[IP_VERSION_POS]
total_length = data[IP_LENGTH_POS]
ttl = data[IP_TTL_POS]
protocol = data[IP_PROTOCOL_POS]
ip_header = (version & 0xF) * 4
start_pos = ETH_HDR_LEN + IPv4_HDR_LEN
# Unpacking TCP
tcp_obj = unpack(TCP_UNPACK_PATTERN, data[start_pos:start_pos + TCP_HDR_LEN])
tcp_flag = tcp_obj[TCP_FLAG_POS]
window = str(tcp_obj[TCP_WINDOW_POS])
else: # ipv6
data = unpack(IPv6_UNPACK_PATTERN, pkt[ETH_HDR_LEN:ETH_HDR_LEN + IPv6_HDR_LEN])
# what bit positions to be used here for ipv6?
But for the IPv6 packet, I do not know the correct bit positions for ipv6 fields.
Can anybody point me to the document which describes the bit positions for ipv6 packets for the following fields:
version
ip total length
TTL
protocol
ip header
TCP flags
Window size
Don't fragment bit
More fragment bit

Logical Address in 2 level paging

Consider a system using 2 level paging.Page table is divided into 2K pages each of size 4 KW. The page table entry size is 2W. If PAS is 64 MW which is divided into 16K frames. Memory is word addressable,Calculate length of Logical Address (LA), Physical Address(PA),Outer Page Table Size (OPTS)and Inner Page Table Size (IPTS).
What I did -
PAS=64MW= 2^26
Thus,PA=26 Bits
LAS = Page Size* No. of Pages * Page Table Entry Size
= 4KW * 2K * 2W
= 2^23
Thus LA=23 bits.
The answer are as follows :
1.LA=35 bits
2.PA=26 bits
3.OPTS=4KW
4.IPTS=8KW
I can't make out how did LA becomes 35 bits instead of 22 bits. How is LA distributed in terms of P1,P2 & d ? Can someone help me ?
Size of page = 4KW = 2^12 W. This means that offset(d) is 12 bits.
Let us assume that LAS(logical address space) consist of total 2^x pages. Because it is 2 level paging, we have
((2^x)*2)/(size of 1 page) = 2K pages
This means that 2^(x + 1 - 12) = 2^(11). Therefore, we have x = 22. Hence, the logical address space = 22 + 12 = 34 bits

Bluetooth in SWIFT: Get 19 bytes data and convert to UInt

I would like to connect the Concept2 rower to my iPhone.
The corresponding Bluetooth data sheet can be found here : http://www.concept2.com/files/pdf/us/monitors/PM5_BluetoothSmartInterfaceDefinition.pdf
I would like to get back the different data: ElapsedTime, Distance, Split/interval, etc..
From the UUID adress 0X0031 I get a 19 bytes data in the following order:Elapsed Time Lo (0.01 sec lsb), Elapsed Time Mid, Elapsed Time High, Distance Lo (0.1 m lsb), Distance Mid, Distance Hi, ...
So 1 byte corresponds to 1 attribute.
I need to extract the bytes corresponding to the attribute and convert them.
I think all bytes data are unsigned types (for extraction).
The ElapsedTime variable is on 3 bytes. SO to build the ElapsedTime variable I was computing like this:
class func dataToUnsignedBytes8(value:NSData) -> [UInt8]{
let count = value.length
var array = [UInt8](count: count, repeatedValue: 0)
value.getBytes(&array, length: count * sizeof(UInt8))
return array
}
class func getElapsedTime(value : NSData) -> Double {
let dataFromSensor = dataToSignedBytes8(value)
let elapsedTime = Double(dataFromSensor[2] * 65536 + dataFromSensor[1]*256 + dataFromSensor[0])
return elapsedTime
}
But I'm not sure about what I'm doing.
Does the ElapsedTime_Hi byte is at index 3 of dataFromSensor, ElapsedTime_Mid is at index 2 of dataFromSensor and ElapsedTime_Lo at index 0 dataFromSensor ?
What is the best way to extract the corresponding byte for other attributes ?
Thank you in advance
Regards

Amount of data to be sent to peripheral using bluetooth in ios 8

I am working in data transferring using bluetooth from BLE device to peripheral hardware. I want to write data from binary file in chunks as total data length is 143233. I found one line "Maximal MTU was 132 bytes for iOS 7 devices and 20 B for iOS 6" but what about iOS 8?
What will be maximum size of chunks for iOS 8? This is the code which I have used, I dont know whether i am going right way or not so help me and guide me if i am going wrong. Thanks in advance.
var count:Int = 0
var counter:Int = 0
var str:NSString = NSBundle.mainBundle().pathForResource("spp", ofType: "bin")!
println("string value is \(str)")
var dataFile:NSString = NSString.stringWithContentsOfFile(str, encoding: NSASCIIStringEncoding, error: nil)
data = dataFile.dataUsingEncoding(NSUTF8StringEncoding)
println(data!.length)
println(dataFile.length)
var dataLen:Int = data!.length
if (dataLen > 132)
{
while(count < dataLen && dataLen - count > 132)
{
peripheral.writeValue(data!.subdataWithRange(NSMakeRange(count, 132)), forCharacteristic: arrCharacteristics!.objectAtIndex(1) as CBCharacteristic , type: CBCharacteristicWriteType.WithResponse)
NSThread.sleepForTimeInterval(0.005)
println("Write performed \(counter++ )")
count += 132
}
} if (count < dataLen)
{
peripheral.writeValue(data!.subdataWithRange(NSMakeRange(count, dataLen - count)), forCharacteristic: arrCharacteristics!.objectAtIndex(1) as CBCharacteristic , type: CBCharacteristicWriteType.WithResponse)
}
I'm guessing Jalek found his answer but for anyone else seeking the figures.
iOS 7 requests a 135 byte MTU (132 bytes data + 3 overhead).
iOS 8 requests a 158 byte MTU (155 bytes data + 3 overhead).
Obviously, it will depend on the other device whether these values are accepted or a lower value returned.

Calculating size of the page table

Consider a machine with 64 MB physical memory and a 32-bit virtual address space. If the page size is 4 KB, what is the approximate size of the page table ?
My Solution:
Number of pages in physical memory = (size of physical memory)/(size of page)
= 64 * 2^10 / 4
= 2^14
Number of pages in virtual memory = (size of virtual memory)/(size of page)
size of virtual memory = 2^32 bits
= 2^29 bytes
= 2^19 kBytes
Number of pages in virtual memory = 2^19/4 = 2^17
=> Number of entries in page table = 2^17
Size of each entry = 17+14 =31 bits
Size of page table = 31 * 2^17 bits
= 31 * 2^14 bytes
= 31 * 2^4 KB
= 31*16
= 496 KB
But the answer is 8 MB. Why?
8MB cannot be the answer,
Physical Address Space = 64MB = 2^26B
Virtual Address = 32-bits, ∴ Virtual Address Space = 2^32B
Page Size = 4KB = 2^12B
Number of pages = 2^32/2^12 = 2^20 pages.
Number of frames = 2^26/2^12 = 2^14 frames.
∴ Page Table Size = 2^20×14-bits ≈ 2^20×16-bits ≈ 2^20×2B = 2MB.
The question has been asked before. However, there is not sufficient information in the question to determine the size of the page table.
It does not specify the size of the page table entries.
It does not specify the number of pages mapped to the process address space.
It does not specify the division between the process and system address pace. How much of the 32 bits is part of the process address space.
It does not specify whether this is a process or system table.