5 from socket emulation library for Minix 2.0.x
13 #include <sys/ioctl.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
17 #include <net/gen/in.h>
18 #include <net/gen/tcp.h>
19 #include <net/gen/tcp_io.h>
20 #include <net/gen/udp.h>
30 int getsockname(int fd
, struct sockaddr
*_RESTRICT address
,
31 socklen_t
*_RESTRICT address_len
)
33 nwio_tcpconf_t tcpconf
;
35 struct sockaddr_in sin
;
38 fprintf(stderr
,"mnx_getsockname: ioctl fd %d.\n", fd
);
40 if (ioctl(fd
, NWIOGTCPCONF
, &tcpconf
)==-1) {
42 fprintf(stderr
,"mnx_getsockname: error %d\n", errno
);
47 fprintf(stderr
, "mnx_getsockname: from %s, %u",
48 inet_ntoa(tcpconf
.nwtc_remaddr
),
49 ntohs(tcpconf
.nwtc_remport
));
50 fprintf(stderr
," for %s, %u\n",
51 inet_ntoa(tcpconf
.nwtc_locaddr
),
52 ntohs(tcpconf
.nwtc_locport
));
55 addr->sin_addr.s_addr = tcpconf.nwtc_remaddr ;
56 addr->sin_port = tcpconf.nwtc_locport;
58 memset(&sin
, '\0', sizeof(sin
));
59 sin
.sin_family
= AF_INET
;
60 sin
.sin_addr
.s_addr
= tcpconf
.nwtc_locaddr
;
61 sin
.sin_port
= tcpconf
.nwtc_locport
;
64 if (len
> sizeof(sin
))
66 memcpy(address
, &sin
, len
);