Thread: seg_fault printing IP_header->src help

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    103

    seg_fault printing IP_header->src help

    Hey guys I am trying to print out data from an IP header however I seem to always seg fault when I try to print out the "saddr" and "daddr" from the IP Header.

    Here's what I've for the saddr output:

    Code:
    fprintf(stderr,"Saddr:       %s\n", (char *) inet_ntoa(&ip_header->saddr));
    Again when I comment this part and the "daddr" part the code works. Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Is there a reason you're using & there, since I don't believe it makes sense to do so? (That is to say: isn't ip_header->saddr already a pointer?)

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    103
    Yeah i originally had this

    Code:
     (char *)inet_ntoa(ip_header->saddr)
    Above is a result of me guessing :\

    I get this warning if it helps:
    warning: cast to pointer from integer of different size

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    inet_ntoa is defined to return a char*, so if the compiler thinks you're casting an integer, that means there's no prototype for the function available. Type "man inet_ntoa" at your system, and make sure all the headers that it gives are #included in your program.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    103
    OMG.
    No manual entry for inet_ntoa
    I guess I'm missing the library for this beast. Anyone know the quick way to get this library (coulda sworn I updated everything ubuntu9.10)

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you were missing the library, your computer wouldn't run at all (it's in glibc, and that's kinda important). What you're missing is the documentation, so run apt-get manpages-dev.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    103
    well I don't know why i didn't have the man pages for inet_ntoa, but thanks tabstop. Needed to

    Code:
    #include <arpa/inet.h>
    "Looks like this post is [puts on glasses] SOLVED!"

    thnx guys
    Last edited by TaiL; 04-24-2010 at 08:40 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 02:20 AM
  3. printing data to a file
    By coralreef in forum C Programming
    Replies: 3
    Last Post: 11-02-2006, 08:10 PM
  4. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 04:46 AM
  5. Printing using DrawText() or TextOut()
    By Eversman in forum Windows Programming
    Replies: 1
    Last Post: 05-24-2004, 12:12 PM