Help in writing a C program as a service deamon

I want to write a deamon program that will create a random string and send it to its adjecent PC in a LAN?
First i want to know is that possible to send to neighbour PC? Is that require me to know its IP address?
I want to execute this program periodicaaly by 5 minutes and deamon will also store it in a file say /misc/text.txt file
 And i want to make it standard service deamon on redhat Linux 9 PC.
how to do it?

pancoderAsked:
Who is Participating?
 
stefan73Connect With a Mentor Commented:
pancoder,
There's no simple way to know who your neighbour is. A "physical" neighbour isn't necessarily a logical one.
You could write its IP address into /etc/hosts, though. Then you can name it specifically.
0
 
stefan73Commented:
Hi pancoder,
If you want to write your data in a file, I suggest you use NFS for that.
Export the target directory on your target PC, then mount it from the random-generating PC using NFS.
You can write directly to the file.

Cheers!

Stefan
0
 
pancoderAuthor Commented:
hi stefan73,
              No i dont want it. i want it through only C socket programs. cause file to be written replaces each random string after its updation to it occurs.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
EinarThCommented:
Short answer: You send to the broadcast address.

Better Answer: Go get the Stevens book on Unix Network programming.
0
 
pancoderAuthor Commented:
hello EinarTh,
              No i want to send only to neighbour by my pc by automatically detecting its ip address. how to detect ip address of neighbour pc. i dont want to send to every pc in LAN
0
 
NVRAMCommented:
Maybe I'm reaching, but is this an attempt to secure the machine (so that access to the source PC & the random string is required to access the target PC)?

If so, you might want to look into SSH/PGP and or Kerberos -- it's likely it will fix the problem and avoid the problem of requiring you encrypt the random string over your socket to avoid packet snooping.

If not, can you be more explicit about what you are trying to do, and about what you mean by "neighbor pc"?  As Stefan73 said, there's usually no network information about the physical location -- do you already know the machine's name, and can it be found by DNS -- can you "ping" it?


0
 
sanjoybasuCommented:
pancoder,
Answere to your Comment
 " No i want to send only to neighbour by my pc by automatically detecting its ip address. how to detect ip address of neighbour pc. i dont want to send to every pc in LAN"

Assumming you are connected to Ethernet network there is no way to define your neighbor's PC because its a broadcast media
Who is  A's neighbor B or C?
 
 ---                  ----
| A |               | B |
 ---                  ----
   |                    |
==============
           |
         ----
        | C |
         ----
You have to specify either the IP address or destination machine name . In later case the name should able to resolve to IP through /etc/hosts or DNS  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.