Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-08-2008, 10:41 PM   #1
LQ Newbie
Registered: Oct 2008
Posts: 4

Rep: Reputation: 0
Reading the ip address from a packet raw sockets

I'm trying to read the ip address from a packet buffer from recvfrom, I can read the mac address but when i try the ip useing printf("%s",inet_itoa(ip->saddr)); it says wrong argument.
struct iphdr *ip;

I would perfer not to use libpcap. I've tryed to use sturct sockaddr_in *in printf("%s",inet_itoa(in->sin_addr)); ,and ip address is show ,but isn't correct

If you need anymore info just say.
Old 12-09-2008, 03:46 PM   #2
Senior Member
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
this website has this information:
printf("%-15s ", inet_ntoa(ip->saddr));

Compiling with "gcc -Wall -g -ansi -pedantic" result with a warning: "
incompatible type for argument 1 of `inet_ntoa' ". I came to know the
solution is to change the call into:

printf("%-15s ", inet_ntoa(*(struct in_addr *)&ip->saddr));
i think this is what your looking for. another website said that the inet_itoa is deprecated and suggests using inet_ntop to support ipv6.
Old 12-10-2008, 02:43 PM   #3
LQ Newbie
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks nadroj
It(ntop)allows me to use ip->saddr and just needed to change *packetbuf to packetbuf.

Cheers dude.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
raw sockets in c wee-face Programming 1 02-01-2007 09:35 AM
Raw Packet Sockets in Fedora Core 6 don't transmit Son_of_Merlin Linux - Networking 6 01-02-2007 12:55 AM
Raw Sockets Srikanth0210 Programming 2 12-05-2005 03:22 AM
raw sockets and C wrongman Programming 3 05-04-2004 02:17 PM
raw sockets BashTin Programming 1 06-07-2003 06:34 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration