I'm making an android application where I'm intercepting the TCP packets sent from the phone/to the phone (UL/DL). I'm getting the information like length of the packets, port etc but I can't find a way to get the band at which the packets are being sent.
Any lead would be appreciated.
Related
I want to find the devices in the Wi-Fi using arp.
(It must be arp, not icmp packet)
I found a similar app on the Play Store, and It was sending Arp.
Captured on WireShark (192.168.0.22 is android)
Is there any api or function available?
I don't know where to start.
I would appreciate any link or document that might help.
You can cause an ARP packet to be sent if you attempt to reach an IP, which you can do by many ways. One convenient way is:
InetAddress.getByName("192.168.0.22")?.isReachable(2000)
which will send an ARP followed by a ICMP ping packet to the address you pass in.
I have a native C application on an Android 4.3 device which transmits and receives data via UDP.
I noticed that the device is sending out ARP messages every 30-45 seconds while data are being actively transmitted/received via UDP to/from a remote IP address.
I would expect that as long as data are being exchanged actively there wouldn't be a need for sending out ARP messages as a cache is maintained. However, that doesn't seem to be the case.
Is this default and expected behavior on Android ?
Is there some configurable option when creating a socket which controls the frequency of these ARP messages?
I'm using VpnService to capture packets and after capturing them I want to send them to their destination. Now, the capturing aspect works. I got the protocol, Source IP / Destination IP and the Source Port / Destination Port from the packets.
I was thinking about creating a socket with these parameters. VpnService has actually a method protect() which protects the socket and the traffic will not be forwarded through VPN.
I don't have muche experience with sockets. But the other day I read a comment here saying I only send the actual data through the socket and not the IP or TCP header? But since TCP uses a 3-way-handshake (correct me if i'm wrong) the first packets wouldn't have any data, just a SYN - flag.
Does that mean this method doesn't work or can i send a packet with the header through the socket?
Yes, we can send data via sockets and dont have to worry about Transport-layer or IP layer headers. Depending upon the socket type (SOCK_STREAM or SOCK_DGRAM), the underlying layer (and the stack for behavior) adds TCP or UDP header on top of application data. Lastly, before sending it out, the IP layer would add IP header. But, if your design requires, you can always "encapsulate" your entire packet with IP/TCP/Data as a data and send it to the other end. When the other end receives the packet, the application layer would receive data which would actually be the original IP/TCP/Data.
Edit
You should explore 2 more questions: a) how would we maintain the packet boundary and (b) what about MTU size. The first one needs to be thought about since TCP does not bother about packet boundary, so it is possible that when you read data on the receiver, it would not start with the header -- one quick solution would be to check if you are hitting the header and then read the length of the packet and continue to read till you have read that much data. The second one is if your packet is already the size of MTU, then adding 2 additional headers would throw it beyond MTU and hence, would likely be fragmented. If you are worried about performance, then this may not be a good thing.
I am facing weird problem in receiving udp packets on Sony Xperia Z tablet. My application didn't receive many udp packets. So I have rooted the tablet to install the shark app and captured the network traffic using shark app after rooting the device. When I analyzed the report, the device has received all the packets but my application did not receive many of them. If the application didn't receive any packets, issue could be the packet filter which blocks broadcast packets. Here, my application receives few packets but misses packets received by device. I have not observed this issue with samsung tab 2 and motorola xoom tablet where it receives all the packets. It sounds like there is no code issue. Have anybody faced similar problem? Let me know if you have any suggestions or inputs that I can try.
UPDATE:
I have added my comments below.
I'd tell you a UDP joke, but you might not get it.
Packet loss is a documented feature of the UDP protocol.
UDP protocol does not guarantee that the package will be delivered to the addressee.
http://en.wikipedia.org/wiki/User_Datagram_Protocol
I have found why my app missed some packets received by device. I have set datagram socket receiver buffer size to small value. I removed this code setting buffer size and then it strated receving all the packets. By default, android sets buffer size as 163840B but I set the size to 64 bytes. It is working fine with default buffer size set by android.
Why do the UDP recipient recevie the same packet in twice? The UDP sender just send one packet to the recipient, but the recipient receive the packet in twice and the two packet are same.The sender and recipient are runned in the differnt device.The sender APP is runned in the android device and the receipient is runned in the iOS device. How to explain this case and how to fix it?
From http://en.wikipedia.org/wiki/User_Datagram_Protocol
UDP uses a simple transmission model with a minimum of protocol mechanism.
It has no handshaking dialogues, and thus exposes any unreliability of the
underlying network protocol to the user's program. As this is normally IP
over unreliable media, there is no guarantee of delivery, ordering or
duplicate protection.
If you want to avoid such scenarios, you'll have to use TCP instead.