ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
what i want to do:
i want write some functions which are able to create a socket descriptor for me which i can use with standard read(); and write(); functions and every socket function which is available in the socket api BUT i don't want that the socket gets opened by the three way handshake
explanation:
read this scenario (it's just an example and has nothing to do with final sense of my question, it only describes what i want to do):
1. HOST A (192.168.0.1) connects to HOST B (192.168.0.2) on port 0xcafe
2. HOST C (192.168.0.3) connects to HOST B
3. HOST B sends every information which is needed by HOST C (i don't know which information is needed, this is another part of my topic here) to USE the already opened connection between HOST A and HOST B.
4. HOST C sends a packet to HOST A through a socket descriptor for which NO three way handshake has been done, because:
HOST A thinks it gets the packet from HOST B
to help you understand this i would also explain it this way:
i want to do something like "connection sharing"
i know there are some attacks which fake the sender ip address of the packet so they can do a DoS attack or such stuff
i don't want it that way! i want that the connection, which has been opened by HOST B, can be used by HOST C without using HOST B as a gateway! i want that HOST A and HOST C can communicate directly
another way of explanation:
if you look at HOST A only ONE connection has been opened, but 2 HOSTS (HOST B and HOST C) are able to communicate independent of each other
i know if this works i have many synchronization problems, but for now i only want to know
if this works?
how does this work?
will it be a kernel hack? or can i use socket api functions? (maybe raw sockets (never used it) or such stuff)
any resources on this topic would be great?
a source code example would be perfect but i want to do it by myself, for learning purpose ...
the second step would be that HOST B can close his socket without affecting the connection of HOST C
the third step would be to synchronize the whole stuff
but that's not my main problem now ;-)
I don't think it is possible to do what you want. At least not as I understood it!
You can use UDP datagrams to have a stateless connection but they will still be reliant on the IP address & ultimately the MAC address of the network interface. So you could send data from B and C to A without a 'connection' you could even get C to change the IP address so that A thinks it comes from B but when A replies it will send the modified packet from C back to B, because that is where it though it came from. B could then be programmed to forward it on but this would fail as soon as B drops out of the loop.
Having said that you may want to look further into UDP datagrams in that they may provide enough of what you wanted to get going. They don't have the three way handshake but they do generate their own connection information on the transport layer stack. This allows for a reply to the machine with a simple write, but the machine's IP details are known.
hmm
yes UDP would be a possibility in a different way
but that's not the challenge i want to try ;-)
maybe later
to make it clear so i understand
the problem is that the kernel associates a socket with a destination mac address and destination ip/port?
correct?
so the kernel would simply discard my packet from HOST C because the source address of the packet is not the same as from HOST B who created the connection
OR
the kernel would simply send the response to HOST B and only ignores that the source of the request came from HOST C
is that the main problem?
if yes it seems there is a need for a new api supported by the kernel --> it's a kernel hack *damn*
What you need is multicast. The thing is that you'd need to do it in a real multicast, not something emulated over unicast IP. That may be a problem because of the addressing etc. If you're doing a thing that's not very complicated, it seems easier to do it all using standard sockets connecting two hosts each.
as i understood multicast is just sending messages to more than one host and less than all hosts (broadcast)
and this seems to be done through udp
or some other multicast protocols which are available
so it seems that i want to make a tcp multicast
and i think it should be possible
just using raw sockets (neither the server nor the client can use the simple socket api, they have to use raw sockets, i think)
so i could use a subnet mask and do a logical & with the IP address received so i know WHO wants to talk and who is allowed to talk to the multicast server
and every host (server or client) has to set the network interface in promiscuous mode so it can read every packet which is received
using this scenario (and make it a bit better, but its an approach) it should be possible to do multicasts using tcp
i think i could use libnet library
if this works i have a good "one to many" or "many to many" tcp inter process communication technique which would work locally or over the network
the problem is that only root can use it because of raw sockets
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
TCP and multicast are mutually exclusive. It is not the Linux kernel that prevent you to do that, but the TCP/IP standard.
TCP is maintaining data offset to make sure the flow of bytes travelling between two hosts are orderly sent to the upper layer application. Having more than two actors in the party breaks that.
As others already wrote, you'd better either go the UDP/multicast way, or have separated TCP connections handling.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
One way is indeed to use IP multicasting, and on top of that, one existing protocol that is compatible with multicast (UDP being the best candidate), and on top of UDP, either use another existing protocol if one fit your needs or just build your own ...
You can also go a more experimental way and try IP alternatives: SCTP, reliable multicast an the likes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.