kamalkgarg
asked on
C program to print octets from receiving from a socket
Hi,
Can someone please tell me how to print the octets (in hex format) of data received from socket in linux using C programming?
the data received is stored in pipebuf.
Thanks
Can someone please tell me how to print the octets (in hex format) of data received from socket in linux using C programming?
the data received is stored in pipebuf.
Thanks
read(pipe_fd, &rgptr, sizeof(rgptr));
memcpy(pipebuf, rgptr, config.buffer_size);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It would make more sense to print the number of bytes read instead of entire buffer.
make sure your buffer is unsigned, or you may have your hex results mangled with memory addresses.
unsigned char buf[2048];
int recvLen;
int i;
//*initialize socket
recvLen = recv(socket,buf,sizeof[buf ]);
for (i=0; i < recvLen; i++) {
printf("%02x ", buf[i]); //*space after the 'x' to make readable.
}
unsigned char buf[2048];
int recvLen;
int i;
//*initialize socket
recvLen = recv(socket,buf,sizeof[buf
for (i=0; i < recvLen; i++) {
printf("%02x ", buf[i]); //*space after the 'x' to make readable.
}
>make sure your buffer is unsigned, or you may have your hex results mangled with memory addresses.
why would that happen?
why would that happen?