Marin D wrote:
>
> Hi,
>
> Is there a portable way to find the struct sock* corresponding to a
> src-addr/src-port?
This is what I use:
char ip="1.2.3.4";
int port=1234;
struct sockaddr_in sin;
memset(&sin, 0, sizeof(sin));
sin.sin_port = htons(port);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr(ip);
or
if(!inet_aton(ip,&sin.sin_addr)) {
fprintf(stderr,"Invalid IP: %s\n");
exit(1);
}
It seems to be reasonable portable, but then most systems I have been in
contact with has at least some BSD compability in them...
---
Henrik Nordström