Solved

Help in writing a C program as a service deamon

Posted on 2004-10-26
283 Views
Last Modified: 2011-09-20
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
Question by:pancoder
    7 Comments
     
    LVL 12

    Expert Comment

    by:stefan73
    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
     

    Author Comment

    by:pancoder
    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
     
    LVL 4

    Expert Comment

    by:EinarTh
    Short answer: You send to the broadcast address.

    Better Answer: Go get the Stevens book on Unix Network programming.
    0
     

    Author Comment

    by:pancoder
    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
     
    LVL 12

    Accepted Solution

    by:
    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
     
    LVL 4

    Expert Comment

    by:NVRAM
    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
     

    Expert Comment

    by:sanjoybasu
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    934 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now