I have a process that attempts to get the package name from another process. I am using C++ code and compiling it using Android toolchain. I have its socket fd and ip address, however, I didn't find in the api a function that will return a string containing the package name. I have the socket fd and the address, if it helps:
uid_t GetSocketID(int sockfd)
{
int err;
socklen_t len;
struct sockaddr_in addr;
len = sizeof(addr);
int res = getpeername(sockfd, (struct sockaddr*)&addr, &len);
if (res < 0)
{
err = errno;
return -1;
}
int iSockIp = addr.sin_addr.s_addr;
int iSockPort = ntohs(addr.sin_port);
int iUid = -1;
if (iSockIp == 0 || iSockPort == 0)
{
return -1;
}
}
example taken from: https://github.com/android/platform_system_core/blob/master/libcutils/qtaguid.c
Does anybody know how can I get the package name?
Thanks!