UDP source port number is missing in the SETUP response message - android

I am working on a Wifi Display Sink application in android and am facing an issue where the source is not sending the UDP server-port number in the RTSP SETUP message.
The SETUP RESPONSE is as below
'RTSP/1.0 200 OK
cseq: 2
date: Tue, 11 Aug 2015 15:12:38 +0000
server: Mine/1.0
session: 1719935144;timeout=60
transport: RTP/AVP/UDP;unicast;client_port=15550-15551;
'
NOTE:
I have figured out the server-port number using tcpdump in the source device. It is 16660. It doesnot look like any specifically assigned port number as well.Seems like a random port number hardcoded into the source device for Wifi Display Application.
Is there any other way to know the server-port number to which I should listen to for incoming UDP packets?

You should be listening on port 15550 and 15551 and the incoming UDP packets will contain their source port.

Related

How to find an android phone ip via using python 3 on Raspberry Pi 3 B

I have a project which I need to do data communication with my android phone and Raspberry Pi 3.
Firstly, I connected raspberry pi 3 to my phone's wifi hotspot. Then with using very same code like
Sender
1 import socket #sender
2
3 UDP_IP = "127.0.0.1"
4 UDP_PORT = 5005
5 MESSAGE = "Hello, World!"
6
7 print "UDP target IP:", UDP_IP # My phone IP
8 print "UDP target port:", UDP_PORT
9 print "message:", MESSAGE
10
11 sock = socket.socket(socket.AF_INET, # Internet
12 socket.SOCK_DGRAM) # UDP
13 sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
which I obtained from https://wiki.python.org/moin/UdpCommunication;
I can manage the communication. However, I need to manually write UDP_IP which corresponds to my phone's IP. Problem is that sometimes the IP changes. Therefore, I need to find the phone's IP automatically so that i won't need to change.
I did the research but couldn't find it. So I need a code which finds android phone IP(not the Raspberry Pi host IP).
I would extract the gateway IP (should be your AndroidPhone) from the network info. Here you can find an algorithm to extract network info from ifconfig in Ubuntu with phyton: Algorithm to extract network info from ifconfig (ubuntu)

Bonjour(IPP) vs Jetdirect-Socket Printer

I am trying to use my android phone as a printer. I am using ServerSocket to receive the document to be printed. If I add my phone as IP printer by providing IP address and port and select Generic Postscript Printer, I am able to receive the file in ps format correctly. I don't want to add my phone as printer as IP printer. So Now I am using NsdManager to register my device as printer. It gets recognized as Bonjour printer automatically and I can successfully add as printer. But now every time I print a document from by computer I get this data in the socket's input stream.
POST / HTTP/1.1 Content-Length: 673 Content-Type: application/ipp Host:
Android-2.local:9200 User-Agent: CUPS/2.1.0 (Darwin 15.2.0; x86_64)
IPP/2.0 Expect: 100-continue Gattributes-charsetutf-8Hattributes-
natural-languageen-usEprinter-uriipp://Android-
2.local.:9200/Drequested-attributescompression-supportedDcopies-
supportedDcups-versionDdocument-format-supportedD marker-colorsDmarker-
high-levelsD marker-levelsDmarker-low-levelsDmarker-messageDmarker-
namesDmarker-typesDmedia-col-supportedD$multiple-document-handling-
supportedDoperations-supportedDprint-color-mode-supportedD printer-
alertDprinter-alert-descriptionDprinter-is-accepting-jobsD printer-
mandatory-job-attributesD printer-stateDprinter-state-messageDprinter-
state-reasons
I read the IPP documentation and I am sending 100 Continue in the response and all the required params like this
clientSocket.setTcpNoDelay(true);
BufferedOutputStream out = new BufferedOutputStream(clientSocket.getOutputStream());
out.write("HTTP/1.1 100\r\n".getBytes("UTF-8"));
out.write("\r\n".getBytes("UTF-8"));
out.write("compression-supported: \"none\"\r\n".getBytes("UTF-8"));
out.write("printer-is-accepting-jobs: \"true\"\r\n".getBytes("UTF-8"));
.....
....
out.flush();
After that if i try to read the input stream for document, it gives null and on my computer i receive message "Printing: Connected to Printer" but if do
out.close();
in to close the outputstream for the socket I get the message "unable to get printer status" on my computer.
Please help me. Is there any way I just receive the document and not this post request or way to send a correct response and get the document? I am stuck with this for quite a long time now. Any help is highly appreciated.
Your computer/CUPS (Mac with El Capitain I guess) is trying to print via IPP, but your phone-print-device does not implement IPP. Obviously, that's not going to work.
Solution 1:
add the printer in CUPS with the correct setup.
for network printers CUPS offers:
IPP - http
IPP - https
IPP - ipp
IPP - ipps
LPD/LPR-Host
Windows printer via spoolss
AppSocket/HP JetDirect
the selection depends on the procotol you have implemented or plan to support in your app. IPP is not an option for you, except...
Solution 2:
Implement IPP in your "Print-Server-App". That's going to be tough!
There's a lot to implement... see https://www.pwg.org/ipp/
Solution 3:
Properly announce your service via Bonjour Printing 1.2
_pdl-datastream._tcp should be the correct service type.
(see also chapter 7.6, Flagship Naming)
I was finally able to implement it. Here is an excellent implementation for network printer using Node.js. It explains the details of IPP https://github.com/watson/ipp-printer
Also this video is good demonstration
https://www.youtube.com/watch?v=58Ti8w1yX2w
And I am using https://github.com/NanoHttpd/nanohttpd to handle the printing requests on my android phone.

TCPDUMP's Network Packets in IPv6 Format

I am new to tcpdump tool and I am working in the analysis of network packets, I have analysed the IPv4 Ip packtes generated in case of wifi. But Now I am running my android phone in sim's 3g network which is generated the IPv6 packets ,completely different form IPv4 format. I am confused about the IPv6 packets structure,
Again, I have gone through the IPv6 header format, and my phone's packets given below, These two format does not match. I am totally confused about IPv6 header.
My mobiles's local ip is 100.87.163.16 ,my question is how to detect the received packets and sending packets. Also I want to find out the header length , payload length, source and destination ip address in IPv4 format. I am looking for your valuable suggestions.
Thanks.
10:59:06.365651 00:00:32:06:af:56 (oui Unknown) > 45:00:00:a8:35:49 (oui Unknown), ethertype Unknown (0xd83a), length 168:
0x0000: c40e 6457 a310 01bb e6c0 f6b1 b5ed ec6b �.dW�..������k
0x0010: 23f8 8018 015e dfc7 0000 0101 080a 17c2 #�...^��.......�
0x0020: 6af1 0014 f0c3 1703 0300 6f00 0000 0000 j�..��....o.....
0x0030: 0000 0208 7db4 d0c1 846d ca75 323c e6cb ....}���.m�u2<��
0x0040: 1636 be16 942f 51ea 1caf 1c09 c085 3dbc .6�../Q�.�..�.=�
0x0050: 7642 vB
OK, let's reconstruct the full raw packet contents.
The driver supplied an ARPHRD_ value that got mapped to DLT_EN10MB (probably an inappropriate ARPHRD_ value; this is a known botch in some Android mobile phone interfaces, probably done to cope with inadequacies in the DHCP implementation, and later versions of libpcap work around it), so the packet was interpreted as if it were an Ethernet packet, when it probably was, in fact, not an Ethernet packet.
So tcpdump printed the packet as if the first 6 bytes were a destination MAC address, the next 6 bytes were a source MAC address, and the next 2 bytes were the type/length field.
Thus, the packet began with:
45 00 00 a8 35 49 00 00 32 06 af 56 d8 3a
and that really looks like an IPv4 packet with no link-layer header - which is exactly what the mobile phone interfaces in question provide as packets.
libpcap 1.6.2 and later have the libpcap workaround; if you use a version of tcpdump that uses a later libpcap, that will probably show the packets correctly. (If they don't, perhaps the hack libpcap uses to detect the bad ARPHRD_ values need to check for more interface names; please report this to tcpdump-workers#lists.tcpdump.org or on the GitHub issues list for libpcap. (Report this as a libpcap issue, not a tcpdump issue, as that's what it is.))

Dataloss at connection android tablet -> lan - RS232 converter, but not on android tablet ->winpc pc -> converter

i have a big problem and i doubt about my intellect... I connected my android tablet (intenso tab814) to a RS232 converter (USR-TCP232-E) via a router (TL-WR740-N) and i send 7 hexadezimal bytes in a block, kinda 03 20 05... with further numbers. My problem is, if i let my tablet send, the converter receives the data, but does not submit it to a listening program on an pc behind the converter complete. There are often complete blocks missing (bnot single Bytes, but the whole command line i send), but if i send my data via tablet to another PC, and let HIM do the sending work to the converter every single byte arrives. It may be a bit dazzling, but i dont know, where this problem could belong to. My App sends every block correctly (the pc is able to receive)
The converters yellow RJ45 port-LED blinks, but i does not give the data to the listening pc.
For better understand:
Tablet(selfpogrammed app) sends data -> router -> converter (everytime blinks) seldom gives the command -> PC(selfwritten listening programm(not written by me, but by the one, i am the follower of, not familiar with language.)
But if i:
Tablet(same app) -> router -> PC (receives all the data) -> router -> converter always give the data to the listening progamm ->pc
What is the matter here? Why does the converter gives the data from app -> pc to listening pc, but not from app to listenign pc?
Tablet is connected via W-Lan to router, the pc's via RJ45-cable, the converter either. Using TCP/IP converter as server.
PLS HELP Q_Q
EDIT:
configuration:
Baud Rate: 115200bits/second
Data Size: 8 bits/characterParity: None NoneOddEvenMarkSpace
Stop Bits: 1bit(s)
Flow Control: None
Local Telnet Port Number: 2001
Remote Telnet Port Number: N/A
Telnet Mode: TCP Server
Telnet Server IP: N/A . . .
Telnet Timeout: 0seconds seconds (< 256, 0 for no timeout)
UART packet Time: 10ms ms (< 256)
UART packet length: 200
EDIT:
forgot sth to mention. the converter is via RS232 to an USB converter from RS232 to USB connected. Its receiving lamp does not blink, when the listening programm does not show my commands, but if the programm spits my lines out, the USB-part blinks too. So the converter receives, but does not give it to the USB. But only if i use my tablet. Same interval all the time.
Was my own fault, forgot to use a bufferedoutputstream, now it works.

What port should be specified in FTP

Im am converting a program from Basic4PPC to Basic4Android.
That program uses FTP to read a small file from a server. The original program works very well. Now with Basic4Android reading a file results in success = false. FTPConnection closed without indication. I have to specify a port number. The sample code shows 21. Is that port the only one which should work? How to find the correct port number?
Harry
The FTP protocol is defined in RFC 959 and specifies port 21 for connections, with port 20 used for data transmissions as necessary. Whilst you don't have to use port 21 to establish an FTP connection, you should do so unless you have a very good reason to diverge from the standard.

Categories

Resources