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>
21 #include <net/gen/udp_io.h>
31 int getsockname(int fd
, struct sockaddr
*_RESTRICT address
,
32 socklen_t
*_RESTRICT address_len
)
34 nwio_tcpconf_t tcpconf
;
36 struct sockaddr_in sin
;
39 fprintf(stderr
,"mnx_getsockname: ioctl fd %d.\n", fd
);
41 if (ioctl(fd
, NWIOGTCPCONF
, &tcpconf
)==-1) {
43 fprintf(stderr
,"mnx_getsockname: error %d\n", errno
);
48 fprintf(stderr
, "mnx_getsockname: from %s, %u",
49 inet_ntoa(tcpconf
.nwtc_remaddr
),
50 ntohs(tcpconf
.nwtc_remport
));
51 fprintf(stderr
," for %s, %u\n",
52 inet_ntoa(tcpconf
.nwtc_locaddr
),
53 ntohs(tcpconf
.nwtc_locport
));
56 addr->sin_addr.s_addr = tcpconf.nwtc_remaddr ;
57 addr->sin_port = tcpconf.nwtc_locport;
59 memset(&sin
, '\0', sizeof(sin
));
60 sin
.sin_family
= AF_INET
;
61 sin
.sin_addr
.s_addr
= tcpconf
.nwtc_locaddr
;
62 sin
.sin_port
= tcpconf
.nwtc_locport
;
65 if (len
> sizeof(sin
))
67 memcpy(address
, &sin
, len
);