0

This is for a networks project I'm working on. It requires us to simulate a bridge. The sockets become the ports basically.

But I was told in order for a Unixsocket to work it needs the full path to the socket and I don't know what the full path is.

Is there anyway to get around this?

  s = UNIXSocket.new(SOCK_SEQPACKET)
  s.connect(padder(lan_one[i]))

The part thats going wrong is padder(lan_one[i]). Padder basically pads a "port" until its 108 characters long. Anyways because the "port" is made up it doesn't actually exist anywhere. Therefore I can't path to it.

isignisign
  • 541
  • 2
  • 4
  • 13

1 Answers1

1

I don't know what the full path is.

You specify the path as a constructor argument. In other words, the path is what you say it is. Opening a socket this way creates an actual file on the file system if there isn't one already, and it fails (or should do) if it cannot create the file, such as because a file with the specified name already exists, or because a directory segment of the specified path does not exist.

The part thats going wrong is padder(lan_one[i]). Padder basically pads a "port" until its 108 characters long. Anyways because the "port" is made up it doesn't actually exist anywhere. Therefore I can't path to it.

It's unclear to me exactly how you should proceed. Unix-domain sockets don't have ports, per se, and certainly, you cannot connect to a socket that does not exist. You could simulate ports with paths, though. For example, you could use paths of this general form:

/base/dir/application/port

Do note that there is a system-specific limit on how long the names of Unix-domain sockets can be.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • So firstly thank you for answering. I'm not actually dealing with any files. I will receive ID for LAN names. The UNIXsockets will become the ports themselves. This is all an effort to emulate a bridge like set up. So the port would be something like 0aa8. Which is a random name that was picked. So there is no path to anything. – isignisign Feb 08 '16 at 20:39
  • @isignisign, I'm not sure what part you're missing here. If you want to create Unix-domain sockets individually, as opposed to in anonymous, pre-connected pairs, then they *will* exist on the filesystem, and it is *your* responsibility to assign the necessary paths. The the purpose for which you intend the sockets is irrelevant. The nature and form of the so-called ports is irrelevant, except inasmuch as your socket paths most not exceed a maximum length and must be viable filesystem paths. – John Bollinger Feb 08 '16 at 20:56
  • I want to make unconnected Unix Sockets that will take and send messages. I can't give a path because I don't have one and I cant just give it any path. The scripts going to be run on a remote server where I can just let files get created. – isignisign Feb 08 '16 at 22:02
  • @isignisign, I see I am still not getting through. **You have no alternative to giving a path.** Moreover, you have no alternative to files getting created -- that's how named Unix-domain sockets work. On the other hand, the relevant files should live only as long as the sockets themselves; you don't need to manage them directly. My suggestion was that you designate a directory (on the server where this will run) to serve as a parent to the paths. That should keep things tidy, and it may be convenient from a permissions perspective. – John Bollinger Feb 08 '16 at 22:09
  • Okay so I took your advice and made a directory for the files to be made in. However It still gives me this `./3700bridge:33:in initialize': No such file or directory - connect(2) for /testDirc/#isignisi#11597#1 (Errno::ENOENT)` – isignisign Feb 08 '16 at 22:17
  • @isignisign, It appears you are not specifying the correct path for the socket you are trying to connect to. Based only on the code presented in your question, I speculate that you are *modifying* the socket path, perhaps by adding something intended to emulate a port number. That, of course, would give you a different path. Just as every TCP socket is associated with exactly one port, if you want to emulate different address/port combinations with Unix-domain sockets then you need a separate socket (with a distinct name) for each address/port pair. – John Bollinger Feb 08 '16 at 22:41