Skip to content

Tag: sockets

Simple socket forwarding in linux

The scenario is pretty simple: Using TCP/IP I have a client which connects to me (server) I want to forward the data the socket sends me to another socket which I opened and the data I received from that socket backwards.Just like a proxy. Right now I have 1 thread one who listens from incoming connection and…

Linux/Unix Socket Self-connection

When a client try to connect to a server, if client and server are both localhost, self-connection may happen(source port and destination port happened to be the same.). But my problem is, client is not listening to that port, how can self-connection be possible? Answer We can simple reproduce this phenomenon…

How to prevent kernel from passing packets to network layer?

Frames received by the network card will be handled by the driver and then passed to the upper layer of the protocol stack by the Linux kernel. Is there an easy way to prevent the kernel from passing packets to network layer? So that I can receive the frames from datalink layer and handle all the packets by m…

Socket data length questions

I have a couple of questions related to the following code: The questions: Why I read 255 not 256 ? Let’s say I want to send the word: “Cool” from the client to the server. How many bytes should I write “in client” and how many bytes should i read “in the server”? I&#…