<p dir="ltr"><br>
On Oct 12, 2012 9:36 PM, "Pietro Paolini" <<a href="mailto:P.Paolini@ext.adbglobal.com">P.Paolini@ext.adbglobal.com</a>> wrote:<br>
><br>
> Hello,<br>
><br>
> I am struggling with the byte order question on a x86_32 arch, I am doing some modifications on a program which actually works fine on a MIPS arch.<br>
><br>
> I do a reading from a RAW socket in this way:<br>
><br>
> /* Configure socket */<br>
> if ((fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP)) < 0) {<br>
> perror("Error on socket creation, exit");<br>
> exit(1);<br>
> }<br>
> ....<br>
> if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, (void *)&va, sizeof(va))) {<br>
> perror("Error on setsockopt, exit");<br>
> exit(1);<br>
> }<br>
> va = 0;<br>
> ....<br>
> ....<br>
> struct msghdr mhdr;<br>
> struct __in_pktinfo *pktinfo = NULL;<br>
> ...<br>
> ...<br>
> nrd = recvmsg(env->mrouter_fd, &mhdr, 0);<br>
> ...<br>
> ip = (struct iphdr *)iov.iov_base;<br>
><br>
> When I print the saddr (or daddr) of the received ip packet it is printed as host byte order instead of what I am expecting, the network byte order. I can just use the htonl() family functions for solve the problem but I would like understand if it is the normal behavior or if there is an issues on my code, or if the device driver of my NIC can influence the question.</p>
<p dir="ltr">I think you should use ntoh*() functions when accessing data rx'ed from the n/w. Network byte order is big endian and your host is little endian, so you'll have convert it to the right order before accessing. You should use hton*() functions when tx'ing data. CMIIW.</p>
<p dir="ltr">HTH,<br>
-mandeep</p>
<p dir="ltr">> Many thanks,<br>
> Pietro.<br>
><br>
><br>
> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a></p>