• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

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?

0
pancoder
Asked:
pancoder
1 Solution
 
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
 
EinarThCommented:
Short answer: You send to the broadcast address.

Better Answer: Go get the Stevens book on Unix Network programming.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
stefan73Commented:
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
 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now