Reputation: 379
I am writing the Socket filter in which most of call back functions for socket filtering(struct sflt_filter
) have input parameter socket_t so
as shown below:
errno_t ( *sf_bind_func)(
void *cookie,
socket_t so,
const struct sockaddr *to);
Need to get Port and IP from socket_t so
.
Is anyone have the idea how to do this?
Upvotes: 0
Views: 839
Reputation: 379
Got the solution in OSx and iOS Kernel programming Book.
function sock_getsockname()
do the job. Find following code snippet:
unsigned char addrStr[256];
struct sockaddr_in addrLcl;
sock_getsockname(so, (struct sockaddr *)&addrLcl, sizeof(addrLcl));
inet_ntop(AF_INET, &addrLcl.sin_addr, (char *)addrStr, sizeof(addrStr));
printf("SFWebSecBind() : <%s> Hex:<%X>", addrStr, ntohs(addrLcl.sin_port));
Upvotes: 1