Pigeon protocol analysis

Source: Internet
Author: User
Recently, some of my friends encountered some problems when writing network programs. Therefore, I posted the documents translated during ipmsg, hoping to help new users in network programming, if you are looking for a programming project, you can refer to this document to write your own ipmsg.

This article only contains several important commands and the Chinese translation of the operating mechanism. For more information, see the following ipmsg English document.

Statement: The following protocols omitted some of which were not used during programming. The original ipmsg protocol was written in Japanese. The following protocols were translated by myself (cugb_cat) from Mr. kanazawa English document. This translation document can be freely transmitted and used.

IP Messenger transmission protocol (Draft Version 9th)
Revision

H. shirouzu
Shirouzu@h.email.ne.jp

About IP Messenger:
The IP Messenger uses the TCP/UDP protocol to provide sending and receiving messages and files (directories ).
Features:
The IP Messenger can be installed on any operating system installed with the TCP/IP protocol stack. It uses the dynamic identification mechanism of online users to exchange information with all online users.
Running Mechanism introduction:
Use the TCP/UDP port (default port 2425), UDP protocol for message sending and receiving, and TCP protocol for file (folder) sending and receiving.
1. command words:
1) Basic command words (8-bit lower than 32-bit command words)
Ipmsg_nooperation
Ipmsg_br_entry user online
Ipmsg_br_exit user quit
Ipmsg_ansentry online
Ipmsg_sendmsg
Ipmsg_recvmsg indicates that a message is received.
Ipmsg_getfiledata requests transmit files over TCP
Ipmsg_releasefiles stop receiving files
Ipmsg_getdirfiles request transmission folder
2) Option bit (24-bit high for 32-bit command words)
Ipmsg_sendcheckopt transfer check (the recipient needs to return confirmation Information)
Ipmsg_fileattachopt file transfer option
3) attachment-type commands (eight characters lower than file-type commands)
Ipmsg_file_regular common file
Ipmsg_file_dir directory file
Ipmsg_file_retparent
2. data packet format (using strings ):
1) data packet format (version 1 format)
Version (1): Package number: sender name: sender Host Name: Command word: Additional information
2) Example
& Quot; 1: 100: shirouzu: Jupiter: 32: Hello & quot"
3. Data Packet Handling Overview:
1) User Identification
When ipmsg is started, the command ipmsg_br_entry is broadcasted to the network, prompting all online users of the arrival of a new user (that is, "I'm coming "); all online users add the new online user to their own user list and send the ipmsg_ansentry command ("I am online") to the new online user "); after the new online user receives the ipmsg_ansentry command, the online user is added to the user list.
2) send and receive messages
Use the ipmsg_sendmsg command to send a message, and add the message content to the additional information. When receiving the message, if the recipient requires a reply confirmation (ipmsg_sendcheckopt is enabled ), you need to send the ipmsg_recvmsg command and put the number of the packet sent by the other party in the additional information and send it to the sender.
3) Extension of additional files (added to version 9th)
The ipmsg_sendmsg command with the ipmsg_fileattachopt bit can be used to transmit files. The file attributes and content are added to the additional information. The file content is added after the message content and separated by the '/0. When a file is transferred, the following information will be added to the message content (including the format): file number: File Name: size (unit: bytes): Last modification time: File Attribute [: additional attribute = val1 [, val2…] [: Additional information =…] :/A: file number...
(The file size, last modification time, and file attributes are in hexadecimal format. If the file name contains ':', use ':' instead ).
When the receiving end starts to receive files, the request transmission file command ipmsg_getfiledata will be sent to the TCP port of the sending end (the same as the UDP sending port), and the package number sent by the sending end: file number: the offset (in hexadecimal format) is written to the additional information area for sending. After the file sender receives the request information and verifies the information correctly, it starts to send the file (No format is used, do not encrypt ).
When the receiving end receives the directory file, it sends the additional information area to the ipmsg_getdirfiles command of the Package number sent by the sending end: file number: offset (in hexadecimal format, the sender adds the header length: File Name: file size: file attribute: file content to the additional information area (except for the file name and file content, the rest are in hexadecimal format). The header length is the number of characters starting from the header length to before the file content ':' until the delimiter.
When the file attribute is ipmsg_file_dir, ipmsg can automatically identify it as a directory, and the data of the next file is after this directory.
When the file attribute is ipmsg_file_retparent, ipmsg identifies its action as returning to the upper-level directory. In this case, the file name is '.' And Its attribute is the value of the current directory.

The English version of ipmsg protocol is provided:

Quote: original ipmsg protocol specification is written in Japan.
This document was translated by mr. Kanazawa.
This document is not verified yet.

----------------------------------------------------------------------
IP Messenger communication protocol (draft-9) 1996/02/21
Modified 2003/01/14

H. shirouzu
Shirouzu@h.email.ne.jp
----------------------------------------------------------------------

About IP Messenger
This is a send/receive message service using the TCP/UDP port.

Characteristics
IP Messenger can be installed in any OS if TCP/IP is used on your machine.
Dynamic member recognition can be done within your network or specified network.
You can exchange messages between all ipmsg members.

Function Description
Use TCP/IP Port (default: 2425). See the following descriptions
(Message send/receive: UDP, file send/receive: TCP)

1. Command

1) command functions (low 8 bits from Command number 32 bits)

Ipmsg_nooperation no operation
Ipmsg_br_entry entry to service (start-up with a broadcast command)
Ipmsg_br_exit exit from service (end with a broadcast command)
Ipmsg_ansentry between y a new entry
Ipmsg_br_absence change absence Mode

Ipmsg_br_isgetlist search valid sending host members
Ipmsg_okgetlist host list sending notice
Ipmsg_getlist host list sending request
Ipmsg_anslist host list sending

Ipmsg_sendmsg message transmission
Ipmsg_recvmsg message refreshing ing check

Ipmsg_readmsg message open notice
Ipmsg_delmsg message discarded notice
Ipmsg_ansreadmsg message open confirmation notice (added from version-8)

Ipmsg_getfiledata file transfer request by TCP
Ipmsg_releasefiles discard Attachment File
Ipmsg_getdirfiles attachment hierarchical file request

Ipmsg_getinfo get ipmsg version info.
Ipmsg_sendinfo send ipmsg version info.

Ipmsg_getabsenceinfo get absence sentence
Ipmsg_sendabsenceinfo send absence sentence

Ipmsg_getpubkey RSA public key acquisition
Ipmsg_anspubkey RSA public key response

2) Option flag (high 24 bits from Command number 32 bits)

Ipmsg_absenceopt absence mode (member recognition command)
Ipmsg_serveropt server (Reserved)
Ipmsg_dialupopt send individual Member recognition command

Ipmsg_sendcheckopt transmission check
Ipmsg_secretopt sealed message
Ipmsg_readcheckopt sealed Message check (added from ver8)
Ipmsg_passwordopt lock
Ipmsg_broadcastopt broadcast message
Ipmsg_multicastopt multi-cast (multiple casts selection)
Ipmsg_newmutiopt New Version multi-cast (Reserved)
Ipmsg_autoretopt automatic response (Ping-Pong protection)
Ipmsg_nologopt no log files
Ipmsg_noaddlistopt notice to the members outside of br_entry

Ipmsg_fileattachopt file attachment
Ipmsg_encryptopt code

Ipmsg_nopopupopt (no longer valid)
Ipmsg_retryopt re-send flag (use when acquiring hostlist)

3) extended code flag (hex format combination)

Ipmsg_rsa_512
Ipmsg_rsa_1024
Ipmsg_rsa_2048
Ipmsg_rc2_40
Ipmsg_rc2_128
Ipmsg_rc2_256
Ipmsg_blowfish_128
Ipmsg_blowfish_256
Ipmsg_sign_md5

4) Extended Files for attachment (fileattr low 8 bits)

Ipmsg_file_regular
Ipmsg_file_dir
Ipmsg_file_retparent
Ipmsg_file_symlink
Ipmsg_file_cdev
Ipmsg_file_bdev
Ipmsg_file_fifo
Ipmsg_file_resfork

5) Attachment File extended attribute (fileattr high 24 bits)

Ipmsg_file_ronlyopt
Ipmsg_file_hiddenopt
Ipmsg_file_exhiddenopt
Ipmsg_file_archiveopt
Ipmsg_file_systemopt

6) extended file attribute for attachment file

Ipmsg_file_uid
Ipmsg_file_username
Ipmsg_file_gid
Ipmsg_file_groupname
Ipmsg_file_perm
Ipmsg_file_majorno
Ipmsg_file_minorno
Ipmsg_file_ctime
Ipmsg_file_mtime
Ipmsg_file_atime
Ipmsg_file_createtime

Ipmsg_file_creator
Ipmsg_file_filetype
Ipmsg_file_finderinfo

Ipmsg_file_acl
Ipmsg_file_aliasfname
Ipmsg_file_unicodefname

2. Command Format (use all character strings)

1) Command (format version-1)

Ver (1): packetno: sendername: senderhost: commandno: additionalsection

2) an example for message send/receive by using the current Command Format

"1: 100: shirouzu: Jupiter: 32: hello"

3. Command Process Overview

1) member Recognition

An ipmsg_br_entry command notifies a new entry to the current
Members at start-up.

All members add the new member to their list after getting a notification message.
An ipmsg_ansentry Command sends a message back to the new member.

The new member gets the current member data by
Ipmsg_ansentry command. All members can communicate as long as
IP packet exists.

An ipmsg_br_absence command broadcasts absence mode cancel or
Nickname change to all members. However, an ipmsg_ansentry command
Does not send a message back, which is different from an ipmsg_br_entry
Command.

Ipmsg_br_entry, ipmsg_ansentry, and ipmsg_br_absence commands
Use an ipmsg_absenceopt flag for absence mode. Input a nickname
Additional command.
Add an ipmsg_dialupopt flag for dial-up users who can't be reached
A broadcast command. A member recognition Command needs to be
Sent individually to the members with this optional flag.

(Extended group) ipmsg_br_entry and ipmsg_br_absence commands
Sends a group name by adding the new group name after the current
Command Format character strings (input '/0' between the current
Command and extended name ).

2) Send/receive message
Send message uses an ipmsg_sendmsg command that can input a message
In the extended area.
Receive message sends back an ipmsg_recvmsg command only
If an ipmsg_sendcheckopt flag is on. input the original packet number
To the extended area.

Broadcast message send uses an ipmsg_boadcastopt command
And an ipmsg_sendmsg flag shoshould be on.
Auto-send packet (Absence notice) needs to be added to ipmsg_autoretopt
For ping-pong protection. If either one or another packet is on, then
Confirmation/auto-send packet is not sent back.

Send message sealing needs to be an ipmsg_secretopt packet on.
In this case, receive message sends an ipmsg_readmsg command.
Input the original packet number to the extended area.

(Additional ipmsg_noaddlistopt)
When refreshing ing an ipmsg_sendmsg packet from a host that is
Not on your send/receive list, ipmsg will either confirm a host
Sending an ipmsg_br_entry command or add a host name
The send/receive list.
However, single-shot message send/receive action needs to be avoided.
Add an ipmsg_noaddlistopt flag to an ipmsg_sendmsg command.

(Additional ipmsg_readcheckopt from version-8)
When an ipmsg_readmsg command contains an ipmsg_readcheckopt flag,
Ipmsg process is the same as ipmsg_sendmsg with
Ipmsg_sendcheckopt flag.
However, send message uses an ipmsg_ansreadmsg command,
Not ipmsg_recvmsg.

3) Message send/receive encryption encrypted extension (added in the version-9)

Use the combination of public-key (RSA) and common key (RC2/blowfish ).
(Encrypted extension area is used in hex format .)

(Public Key acquisition) Send an ipmsg_getpubkey command to receive
Message. Receive message gets an ipmsg_anspubkey that
Means processing ing RSA public key from send message.

Ipmsg_getpubkey/ipmsg_anspubkey both require the value which is
Encryption capability (exp. ipmsg_rsa_1024) Flag uses "or" at first
Part of Extension

In addition, in ipmsg_anspubkey, Public Key written as EE-NNNNNN
E = exponent limit n = method) devide by ':'. and input the fdelimiter '-'
Between E and N.

This sequence can be skipped after the 2nd send/receive process
Memorizing public key and encrypted data.

(Encrypted message) after a sender creates a common key that is
Supported both sender and receiver er, a common key can encrypt a message.
In addition, a cipher er's public key encrypts the common key.

(Encrypted message transmission) ipmsg_encryptopt is used in
Ipmsg_sendmsg. At the first part of extension, input the value which
Is 'or' resoult from convination of public key and common key type.
Then use common key which encrypt with Public Key devide ':'.
Then input message which is eccrypted by Public Key devide ':'.
If both supports ipmsg_sign_xxx, then add': 'and signeture.

Also, in the method of encode padding, PKCS # 1ecb key is used for RSA,
PKCS #5 CBC common key is used for RC2/blowfish.

Also, the packet related to entry manifestation the capability
Ecryption support using ipmsg_encryptopt

4) extension with file attachment (available from version-9)

An ipmsg_sendmsg command with an ipmsg_fileattachopt flag
File Transfer (download permission) Notification sends a message
With attachment.
Input '/0' after the message and attachment file data.

Fileid: Filename: Size: mtime: fileattr [: Extend-ATTR = val1
[, Val2. ..] [: extend-attr2 =...]:/a: fileid...
(Size, mtime, and fileattr describe hex format.
If a filename contains ':', please replace "::".)

When receive message downloads an attachment file, an ipmsg_getfiledata
Command requests a data transmission packet to the TCP port that is the same number
As the UDP sending port number. Input packetid: fileid: offset to the extended area.
(Use all hex format .)
File Transfer side parameters es the request. After recognizing that it's a correct request,
Then send the specified data (no format)

When the data processing ing side downloads a hierarchical attachment file,
Use an ipmsg_getdirfiles command and input a packetid: fileid
To the extended area and send a data transmission request packet.
(ALL hex format)

Data sending side sends the following hierarchical data format.
Header-size: Filename: file-size: fileattr [: Extend-ATTR = val1
[, Val2. ..] [: extend-attr2 =...]: Contents-Data
Next headersize: Next filename...
(All hex format parameters T for filename and contetns-data)

Header-size is from the beginning of header-size to the delimiter ':'
That is before contents-Data. Extend-ATTR can be omitted and used multiple
Extended attributes. Use '=' for data input.

When fileattr is ipmsg_file_dir, ipmsg recognizes that it is automatically
In the directory, the next file data is after the directory.

When fileattr is ipmsg_file_retparent, impsg recognizes that it returns
To the parent directory. In this case, file name is always "." And the attribute
Value is the current directory data.

Sending process starts from the attachment directly and returns
Ipmsg_file_retparent command to the attachment directory.

Add an ipmsg_fileattachopt flag for an entry packet to support
Attachment File.

5) Other commands

When acquiring different versions, send an ipmsg_getinfo command.
Grouping side sends the version information character string
Extended area.

Send an ipmsg_getabsenceinfo command for acquiring an absence message.
Processing side sends an ipmsg_sendabsenceinfo back if the status is absence mode.
If the status is not absence mode, a character string "not absence mode" will be sent back.

6) Confirmation/retry

If a confirmation packet for ipmsg_sendmsg or ipmsg_recvmsg is not delivered
Within a specified time, then it will be sent again.
A number of retry actions or interval period is depended on the current condition.

4. Other

1) linefeed

Linefeed characters in send message is standardized with Unix type ('0x0a ').
Please change if needed.

2) delimiter ':'

':' Is used as a delimiter. You can't use this delimiter for user name
And host name.
If the use/host names contain a': ', please replace with another sign,
For an example ';'.
Although using this delimiter isn' t problem as yet, I may create
Escape Sequence.

3) Kanji Codes

Sjis

5. Contact e-mail address

E-mail shirouzu@h.email.ne.jp

Note
See ipmsg. h for command codes.
Please e-mail me your comments and suggestions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.