Re: How to convert a port number (_be16) to a string

2009-03-18 Thread Cliffe
I figured it out. It turns out you need to use ntohs(inet-dport) to convert between host and network byte order. Cliffe wrote: Hi, I have the destination port from a struct socket and I need to convert it to a string. struct inet_sock *inet = inet_sk(sock-sk); unsigned int

Re: How to convert a port number (_be16) to a string

2009-03-18 Thread Shaz
On Wed, Mar 18, 2009 at 2:08 PM, Cliffe cli...@ii.net wrote: I figured it out. It turns out you need to use ntohs(inet-dport) to convert between host and network byte order. Both make sense to me equally but will try it sometime. I have one confusion about byte order conversion. Why do we

How to convert a port number (_be16) to a string

2009-03-17 Thread Cliffe
Hi, I have the destination port from a struct socket and I need to convert it to a string. struct inet_sock *inet = inet_sk(sock-sk); unsigned int sport = inet-sport; I have tried using snprintf with %d, and %lu but I am not getting the values I expect. For example port 80 is

Re: How to convert a port number (_be16) to a string

2009-03-17 Thread Matthias Kaehlcke
El Wed, Mar 18, 2009 at 02:59:28AM +0800 Cliffe ha dit: I have the destination port from a struct socket and I need to convert it to a string. struct inet_sock *inet = inet_sk(sock-sk); unsigned int sport = inet-sport; I have tried using snprintf with %d, and %lu but I am