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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 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 displayed as 20480.

Any help will be really appreciated. Please CC me in on the reply.

Thanks,

Cliffe.



--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux