Sponsored Content
Top Forums UNIX for Advanced & Expert Users "Phantom character" in Socket (RESOLVED) Post 302332247 by trutoman on Thursday 9th of July 2009 09:18:12 AM
Old 07-09-2009
"Phantom character" in Socket (RESOLVED)

Hi everyone:

I have built a tcl script, this script communicate with an ADA program trough a socket, sending binary data, the sender proc is this one:

The code where im sending info is here:
Code:
proc p_send_data { DATA } {
  global connection
  puts "Sending trough $connection..."
 
  # This is just the string of bytes im sending
  binary scan $DATA H22 hexa
  puts "IM SENDING THIS ------>  $hexa"

  # Put it trough socket
  puts -nonewline "$connection" $DATA
  flush $connection
  }

It usually works fine, but with some values of DATA, socket, a little demon or something is adding a byte to my string !!

The output of program "IM SENDING THIS -----> 0109450900018813bc0400"

Like you can see this line is printed just before puts data in socket.

The "tcpdump" capture ----------------------------------> 010945090001c28813bc0400

The bytes are the same excepts that c2 insertion.

With strace i can see how system writes in socket this:

Code:
write(1, "IM SENDING THIS ------>  010945090001"..., 44IM SENDING THIS ------>  0109450900018813bc0400) = 44
sendto(4, "\1\tE\t\0\1\302\210\23\302\274\4\0001212", 17, 0, NULL, 0) = 17

Sometimes with different values of DATA this byte "c2" appears......always in the same position !! . After looking info trough internet, iknow that c2 is 194 in decimal and it doesn't look like a dangerous character like "\00" "\7f" could be.

Perhaps an error in c libraries of sockets??

This is my system : Linux 2.6.9-67
TCLInterpreter : 8.4

Plz Help me . THX!!

---------- Post updated 09-07-09 at 03:18 PM ---------- Previous update was 08-07-09 at 07:01 PM ----------

Nobody response.

I have fixed it !!!! exactly 20 hours after.

Par default a socket connection its created with "-encoding = utf-8" . But i was sending binary data, so sometimes (when my binary bytes matched up with a ascii code) it interpret that like some ascii char and the socket translated automatically to ascii code.
So the solution is to configure socket with "-encoding = binary".in tcl.
"fconfigure connection -encoding binary"

it was quite easy ....... like ever.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

removing the "\" and "\n" character using sed or tr

Hi All, I'm trying to write a ksh script to parse a file. When the "\" character is encountered, it should be removed and the next line should be concatenated with the current line. For example... this is a test line #1\ should be concatenated with line #2\ and line number 3 when this... (3 Replies)
Discussion started by: newbie_coder
3 Replies

2. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

3. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

4. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

7. UNIX for Advanced & Expert Users

"Phantom" overwrite with dd on sda*?

Greetings. Just wondering about a little "quirk" which I seem to have found when using dd ;) (FWIW on that note, I'm using a flash install of Parted Magic to run dd in these tests...) Thinking about it, there should be some measurable excitement associated withdd if=/dev/zero of=/dev/sda*... (4 Replies)
Discussion started by: LinQ
4 Replies

8. Post Here to Contact Site Administrators and Moderators

Marking thread "Resolved"

Can the OP of a thread still mark the thread "Resolved" when the question is answered? (2 Replies)
Discussion started by: wbport
2 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
SOCKET_RECVFROM(3)							 1							SOCKET_RECVFROM(3)

socket_recvfrom - Receives data from a socket whether or not it is connection-oriented

SYNOPSIS
int socket_recvfrom (resource $socket, string &$buf, int $len, int $flags, string &$name, [int &$port]) DESCRIPTION
The socket_recvfrom(3) function receives $len bytes of data in $buf from $name on port $port (if the socket is not of type AF_UNIX) using $socket. socket_recvfrom(3) can be used to gather data from both connected and unconnected sockets. Additionally, one or more flags can be specified to modify the behaviour of the function. The $name and $port must be passed by reference. If the socket is not connection-oriented, $name will be set to the internet protocol address of the remote host or the path to the UNIX socket. If the socket is connection-oriented, $name is NULL. Additionally, the $port will contain the port of the remote host in the case of an unconnected AF_INET or AF_INET6 socket. PARAMETERS
o $socket - The $socket must be a socket resource previously created by socket_create(). o $buf - The data received will be fetched to the variable specified with $buf. o $len - Up to $len bytes will be fetched from remote host. o $flags - The value of $flags can be any combination of the following flags, joined with the binary OR ( |) operator. Possible values for $flags +-------------+---------------------------------------------------+ | Flag | | | | | | | Description | | | | +-------------+---------------------------------------------------+ | | | | MSG_OOB | | | | | | | Process out-of-band data. | | | | | | | | MSG_PEEK | | | | | | | Receive data from the beginning of the receive | | | queue without removing it from the queue. | | | | | | | |MSG_WAITALL | | | | | | | Block until at least $len are received. However, | | | if a signal is caught or the remote host discon- | | | nects, the function may return less data. | | | | | | | |MSG_DONTWAIT | | | | | | | With this flag set, the function returns even if | | | it would normally have blocked. | | | | +-------------+---------------------------------------------------+ o $name - If the socket is of the type AF_UNIX type, $name is the path to the file. Else, for unconnected sockets, $name is the IP address of, the remote host, or NULL if the socket is connection-oriented. o $port - This argument only applies to AF_INET and AF_INET6 sockets, and specifies the remote port from which the data is received. If the socket is connection-oriented, $port will be NULL. RETURN VALUES
socket_recvfrom(3) returns the number of bytes received, or FALSE if there was an error. The actual error code can be retrieved by calling socket_last_error(3). This error code may be passed to socket_strerror(3) to get a textual explanation of the error. EXAMPLES
Example #1 socket_recvfrom(3) example <?php error_reporting(E_ALL | E_STRICT); $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_bind($socket, '127.0.0.1', 1223); $from = ''; $port = 0; socket_recvfrom($socket, $buf, 12, 0, $from, $port); echo "Received $buf from remote address $from and remote port $port" . PHP_EOL; ?> This example will initiate a UDP socket on port 1223 of 127.0.0.1 and print at most 12 characters received from a remote host. CHANGELOG
+--------+----------------------------------------+ |Version | | | | | | | Description | | | | +--------+----------------------------------------+ | 4.3.0 | | | | | | | socket_recvfrom(3) is now binary safe. | | | | +--------+----------------------------------------+ SEE ALSO
socket_recv(3), socket_send(3), socket_sendto(3), socket_create(3). PHP Documentation Group SOCKET_RECVFROM(3)
All times are GMT -4. The time now is 03:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy