Getting socket address from struct socket

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

 



Hello!

In a kernel module of mine I have a struct socket available and need to get a 
struct sockaddr_in or something equivalent from it. The goal is to get IP 
address and port for sockets of family AF_INET or AF_INET6.

I have tried the following (sock is a struct socket):

struct sockaddr addr;
int len = sizeof(struct sockaddr);
sock->ops->getname(sock, &addr, &len, 2);

Every call of getname returns the error code -107.

The socket structure represents a BSD socket. It has a field pointing to an 
INET socket (struct sock *sk). That is an internal networking protocol 
agnostic socket representation. Therefore, there are no fields for IP 
addresses and ports as this is protocol dependent.

Do you have any advice on how to get the needed information?

Cheers
Andreas
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux